mirror of
https://github.com/correl/mage.git
synced 2025-01-12 19:25:44 +00:00
UI: added close choice window with ESC button (if not required)
This commit is contained in:
parent
17bed090f0
commit
72aef2638c
2 changed files with 29 additions and 15 deletions
|
@ -739,6 +739,7 @@ public class ConnectDialog extends MageDialog {
|
|||
private void doFastFlagSearch(){
|
||||
Choice choice = new ChoiceImpl(false);
|
||||
|
||||
// collect data from country combobox String[name][code]
|
||||
Map<String, String> choiceItems = new LinkedHashMap<>();
|
||||
DefaultComboBoxModel flagModel = (DefaultComboBoxModel)cbFlag.getModel();
|
||||
String[] flagItem;
|
||||
|
@ -751,14 +752,16 @@ public class ConnectDialog extends MageDialog {
|
|||
choice.setKeyChoices(choiceItems);
|
||||
choice.setMessage("Select your coutry");
|
||||
|
||||
// current selection restore
|
||||
// current selection value restore
|
||||
String needSelectValue = null;
|
||||
flagItem = (String[])flagModel.getSelectedItem();
|
||||
if (flagItem != null){
|
||||
needSelectValue = flagItem[1];
|
||||
}
|
||||
|
||||
|
||||
// ask for new value
|
||||
PickChoiceDialog dlg = new PickChoiceDialog();
|
||||
dlg.setWindowSize(300, 500);
|
||||
dlg.showDialog(choice, needSelectValue);
|
||||
if(choice.isChosen()){
|
||||
flagItem = new String[2];
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
*/
|
||||
package mage.client.dialog;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
@ -13,9 +15,14 @@ import java.awt.event.MouseEvent;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.ActionMap;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.InputMap;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import mage.choices.Choice;
|
||||
|
@ -135,6 +142,19 @@ public class PickChoiceDialog extends MageDialog {
|
|||
}
|
||||
});
|
||||
|
||||
// listeners for ESC close
|
||||
if(!choice.isRequired()){
|
||||
String cancelName = "cancel";
|
||||
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
|
||||
ActionMap actionMap = getRootPane().getActionMap();
|
||||
actionMap.put(cancelName, new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doCancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// window settings
|
||||
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
|
||||
if (mageDialogState != null) {
|
||||
|
@ -169,6 +189,10 @@ public class PickChoiceDialog extends MageDialog {
|
|||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void setWindowSize(int width, int heigth){
|
||||
this.setSize(new Dimension(width, heigth));
|
||||
}
|
||||
|
||||
private void loadData(){
|
||||
// load data to datamodel after filter or on startup
|
||||
String filter = choice.getSearchText();
|
||||
|
@ -229,19 +253,6 @@ public class PickChoiceDialog extends MageDialog {
|
|||
initComponents();
|
||||
this.listChoices.setModel(dataModel);
|
||||
this.setModal(true);
|
||||
|
||||
// Close the dialog when Esc is pressed
|
||||
/*
|
||||
String cancelName = "cancel";
|
||||
InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
||||
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
|
||||
ActionMap actionMap = getRootPane().getActionMap();
|
||||
actionMap.put(cancelName, new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
doCancel();
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
public boolean setChoice() {
|
||||
|
|
Loading…
Reference in a new issue