diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form
index 5adaf97cd92..4b4f2fa9812 100644
--- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form
+++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form
@@ -1,13 +1,6 @@
-
diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java
index 07095dbded2..ba596b84134 100644
--- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java
+++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java
@@ -1,43 +1,23 @@
/*
-* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without modification, are
-* permitted provided that the following conditions are met:
-*
-* 1. Redistributions of source code must retain the above copyright notice, this list of
-* conditions and the following disclaimer.
-*
-* 2. Redistributions in binary form must reproduce the above copyright notice, this list
-* of conditions and the following disclaimer in the documentation and/or other materials
-* provided with the distribution.
-*
-* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
-* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
-* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
-* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*
-* The views and conclusions contained in the software and documentation are those of the
-* authors and should not be interpreted as representing official policies, either expressed
-* or implied, of BetaSteward_at_googlemail.com.
-*/
-
-/*
- * PickNumberDialog.java
- *
- * Created on Feb 25, 2010, 12:03:39 PM
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
*/
-
package mage.client.dialog;
import java.awt.Point;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
import java.util.Map;
import java.util.UUID;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
import javax.swing.JLayeredPane;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
import mage.choices.Choice;
import mage.client.MageFrame;
import mage.client.util.SettingsManager;
@@ -46,37 +26,103 @@ import mage.client.util.gui.MageDialogState;
/**
*
- * @author BetaSteward_at_googlemail.com
+ * @author JayDi85
*/
+
public class PickChoiceDialog extends MageDialog {
- /** Creates new form PickNumberDialog */
- public PickChoiceDialog() {
- initComponents();
- this.setModal(true);
- }
Choice choice;
- boolean autoSelect;
-
+ ArrayList allItems = new ArrayList<>();
+ DefaultListModel dataModel = new DefaultListModel();
+
+ final private static String HTML_TEMPLATE = "%s
";
+
public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState) {
- this.lblMessage.setText("" + choice.getMessage());
this.choice = choice;
- this.autoSelect = false;
- btnAutoSelect.setVisible(choice.isKeyChoice());
- if (choice.isKeyChoice()){
-
- ComboItem[] comboItems = new ComboItem[choice.getKeyChoices().size()];
- int count = 0;
- for (Map.Entry entry : choice.getKeyChoices().entrySet()) {
- comboItems[count] = new ComboItem(entry.getKey(), entry.getValue());
- count++;
+ setLabelText(this.labelMessage, choice.getMessage());
+ setLabelText(this.labelSubMessage, choice.getSubMessage());
+
+ btCancel.setEnabled(!choice.isRequired());
+
+ // 2 modes: string or key-values
+ // sore data in allItems for inremental filtering
+ // http://logicbig.com/tutorials/core-java-tutorial/swing/list-filter/
+ this.allItems.clear();
+ if (choice.isKeyChoice()){
+ for (Map.Entry entry: choice.getKeyChoices().entrySet()) {
+ this.allItems.add(new KeyValueItem(entry.getKey(), entry.getValue()));
}
- this.lstChoices.setListData(comboItems);
} else {
- this.lstChoices.setListData(choice.getChoices().toArray());
+ for (String value: choice.getChoices()){
+ this.allItems.add(new KeyValueItem(value, value));
+ }
}
+ // search
+ if(choice.isSearchEnabled())
+ {
+ panelSearch.setVisible(true);
+ this.editSearch.setText(choice.getSearchText());
+ }else{
+ panelSearch.setVisible(false);
+ this.editSearch.setText("");
+ }
+
+ // listeners for inremental filtering
+ editSearch.getDocument().addDocumentListener(new DocumentListener() {
+ @Override
+ public void insertUpdate(DocumentEvent e) {
+ choice.setSearchText(editSearch.getText());
+ loadData();
+ }
+
+ @Override
+ public void removeUpdate(DocumentEvent e) {
+ choice.setSearchText(editSearch.getText());
+ loadData();
+ }
+
+ @Override
+ public void changedUpdate(DocumentEvent e) {
+ choice.setSearchText(editSearch.getText());
+ loadData();
+ }
+ });
+
+ // listeners for select up and down without edit focus lost
+ editSearch.addKeyListener(new KeyListener() {
+ @Override
+ public void keyTyped(KeyEvent e) {
+ //System.out.println("types");
+ }
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ if(e.getKeyCode() == KeyEvent.VK_UP){
+ doPrevSelect();
+ }else if(e.getKeyCode() == KeyEvent.VK_DOWN){
+ doNextSelect();
+ }
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ //System.out.println("released");
+ }
+ });
+
+ // listeners double click choose
+ listChoices.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if(e.getClickCount() == 2){
+ doChoose();
+ }
+ }
+ });
+
+ // window settings
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
if (mageDialogState != null) {
mageDialogState.setStateToDialog(this);
@@ -87,154 +133,306 @@ public class PickChoiceDialog extends MageDialog {
GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this);
}
+ // final load
+ loadData();
this.setVisible(true);
}
-
- public boolean isAutoSelect() {
- return autoSelect;
+
+ private void loadData(){
+ // load data to datamodel after filter or on startup
+ String filter = choice.getSearchText();
+ if (filter == null){ filter = ""; }
+ filter = filter.toLowerCase();
+
+ this.dataModel.clear();
+ for(KeyValueItem item: this.allItems){
+ if(!choice.isSearchEnabled() || item.Value.toLowerCase().contains(filter)){
+ this.dataModel.addElement(item);
+ }
+ }
+ }
+
+ private void setLabelText(JLabel label, String text){
+ if ((text != null) && !text.equals("")){
+ label.setText(String.format(HTML_TEMPLATE, text));
+ label.setVisible(true);
+ }else{
+ label.setText("");
+ label.setVisible(false);
+ }
+ }
+
+ private void doNextSelect(){
+ int newSel = this.listChoices.getSelectedIndex() + 1;
+ int maxSel = this.listChoices.getModel().getSize() - 1;
+ if(newSel <= maxSel){
+ this.listChoices.setSelectedIndex(newSel);
+ }
+ }
+
+ private void doPrevSelect(){
+ int newSel = this.listChoices.getSelectedIndex() - 1;
+ if(newSel >= 0){
+ this.listChoices.setSelectedIndex(newSel);
+ }
}
- public void setChoice() {
- if (this.lstChoices.getSelectedValue() == null) {
- choice.clearChoice();
+ private void doChoose(){
+ if(setChoice()){
+ this.hideDialog();
+ }
+ }
+
+ private void doCancel(){
+ this.listChoices.clearSelection();
+ this.choice.clearChoice();
+ hideDialog();
+ }
+
+ /**
+ * Creates new form PickChoiceDialog
+ */
+ public PickChoiceDialog() {
+ 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() {
+ KeyValueItem item = (KeyValueItem)this.listChoices.getSelectedValue();
+
+ // auto select one item (after incemental filtering)
+ if((item == null) && (this.listChoices.getModel().getSize() == 1)){
+ this.listChoices.setSelectedIndex(0);
+ item = (KeyValueItem)this.listChoices.getSelectedValue();
}
- if (choice.isKeyChoice()) {
- ComboItem item = (ComboItem)this.lstChoices.getSelectedValue();
- if (item != null) {
- choice.setChoiceByKey(item.getValue());
- } else {
- choice.clearChoice();
+ if(item != null){
+ if(choice.isKeyChoice()){
+ choice.setChoiceByKey(item.getKey());
+ }else{
+ choice.setChoice(item.getKey());
}
- } else {
- choice.setChoice((String)this.lstChoices.getSelectedValue());
+ return true;
+ }else{
+ choice.clearChoice();
+ return false;
}
}
+
+ class KeyValueItem
+ {
+ private final String Key;
+ private final String Value;
+
+ public KeyValueItem(String value, String label) {
+ this.Key = value;
+ this.Value = label;
+ }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
+ public String getKey() {
+ return this.Key;
+ }
+
+ public String getValue() {
+ return this.Value;
+ }
+
+ @Override
+ public String toString() {
+ return this.Value;
+ }
+ }
+
+ /**
+ * This method is called from within the constructor to initialize the form.
+ * WARNING: Do NOT modify this code. The content of this method is always
+ * regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
- btnAutoSelect = new javax.swing.JButton();
- btnCancel = new javax.swing.JButton();
- btnOk = new javax.swing.JButton();
- jScrollPane1 = new javax.swing.JScrollPane();
- lstChoices = new javax.swing.JList();
- lblMessage = new javax.swing.JLabel();
+ panelHeader = new javax.swing.JPanel();
+ labelMessage = new javax.swing.JLabel();
+ labelSubMessage = new javax.swing.JLabel();
+ panelSearch = new javax.swing.JPanel();
+ labelSearch = new javax.swing.JLabel();
+ editSearch = new javax.swing.JTextField();
+ scrollList = new javax.swing.JScrollPane();
+ listChoices = new javax.swing.JList();
+ panelCommands = new javax.swing.JPanel();
+ btOK = new javax.swing.JButton();
+ btCancel = new javax.swing.JButton();
- setResizable(true);
- setMinimumSize(new java.awt.Dimension(280, 200));
- setName(""); // NOI18N
+ labelMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
+ labelMessage.setText("example long message example long message example long message example long message example long message
");
- btnAutoSelect.setText("Auto select");
- btnAutoSelect.setToolTipText("If you select an effect with \"Auto select\", this effect will be selected the next time automatically first.");
- btnAutoSelect.addActionListener(evt -> btnAutoSelectActionPerformed(evt));
+ labelSubMessage.setFont(labelSubMessage.getFont().deriveFont((labelSubMessage.getFont().getStyle() | java.awt.Font.ITALIC) | java.awt.Font.BOLD));
+ labelSubMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
+ labelSubMessage.setText("example long message example long
");
- btnCancel.setText("Cancel");
- btnCancel.addActionListener(evt -> btnCancelActionPerformed(evt));
+ javax.swing.GroupLayout panelHeaderLayout = new javax.swing.GroupLayout(panelHeader);
+ panelHeader.setLayout(panelHeaderLayout);
+ panelHeaderLayout.setHorizontalGroup(
+ panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(panelHeaderLayout.createSequentialGroup()
+ .addGroup(panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(labelMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)
+ .addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE))
+ .addGap(0, 0, 0))
+ );
+ panelHeaderLayout.setVerticalGroup(
+ panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(panelHeaderLayout.createSequentialGroup()
+ .addGap(0, 0, 0)
+ .addComponent(labelMessage)
+ .addGap(0, 0, 0)
+ .addComponent(labelSubMessage))
+ );
- btnOk.setText("OK");
- btnOk.addActionListener(evt -> btnOkActionPerformed(evt));
+ labelSearch.setText("Search:");
- lstChoices.setModel(new javax.swing.AbstractListModel() {
- final String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
+ editSearch.setText("sample search text");
+
+ javax.swing.GroupLayout panelSearchLayout = new javax.swing.GroupLayout(panelSearch);
+ panelSearch.setLayout(panelSearchLayout);
+ panelSearchLayout.setHorizontalGroup(
+ panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(panelSearchLayout.createSequentialGroup()
+ .addGap(0, 0, 0)
+ .addComponent(labelSearch)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(editSearch)
+ .addGap(0, 0, 0))
+ );
+ panelSearchLayout.setVerticalGroup(
+ panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(panelSearchLayout.createSequentialGroup()
+ .addGap(3, 3, 3)
+ .addGroup(panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(labelSearch)
+ .addComponent(editSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addGap(3, 3, 3))
+ );
+
+ listChoices.setModel(new javax.swing.AbstractListModel() {
+ String[] strings = { "item1", "item2", "item3" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
- jScrollPane1.setViewportView(lstChoices);
+ scrollList.setViewportView(listChoices);
- lblMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- lblMessage.setText("message");
+ btOK.setText("Choose");
+ btOK.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btOKActionPerformed(evt);
+ }
+ });
+
+ btCancel.setText("Cancel");
+ btCancel.addActionListener(new java.awt.event.ActionListener() {
+ public void actionPerformed(java.awt.event.ActionEvent evt) {
+ btCancelActionPerformed(evt);
+ }
+ });
+
+ javax.swing.GroupLayout panelCommandsLayout = new javax.swing.GroupLayout(panelCommands);
+ panelCommands.setLayout(panelCommandsLayout);
+ panelCommandsLayout.setHorizontalGroup(
+ panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(panelCommandsLayout.createSequentialGroup()
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(btOK)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap())
+ );
+
+ panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOK});
+
+ panelCommandsLayout.setVerticalGroup(
+ panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addGroup(panelCommandsLayout.createSequentialGroup()
+ .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
+ .addComponent(btCancel)
+ .addComponent(btOK))
+ .addContainerGap())
+ );
+
+ getRootPane().setDefaultButton(btOK);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
+ .addGroup(layout.createSequentialGroup()
.addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
- .addGroup(layout.createSequentialGroup()
- .addGap(0, 0, Short.MAX_VALUE)
- .addComponent(btnAutoSelect)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnOk)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnCancel))
- .addComponent(lblMessage, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE))
+ .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+ .addComponent(scrollList, javax.swing.GroupLayout.Alignment.TRAILING)
+ .addComponent(panelCommands, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(panelHeader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+ .addComponent(panelSearch, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGap(6, 6, 6)
- .addComponent(lblMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap()
+ .addComponent(panelHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
+ .addComponent(panelSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnCancel)
- .addComponent(btnOk)
- .addComponent(btnAutoSelect))
- .addGap(10, 10, 10))
+ .addComponent(scrollList, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addContainerGap())
);
pack();
}// //GEN-END:initComponents
- private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
- setChoice();
- this.hideDialog();
- }//GEN-LAST:event_btnOkActionPerformed
+ private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed
+ doChoose();
+ }//GEN-LAST:event_btOKActionPerformed
- private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
- this.lstChoices.clearSelection();
- this.choice.clearChoice();
- this.hideDialog();
- }//GEN-LAST:event_btnCancelActionPerformed
+ private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed
+ doCancel();
+ }//GEN-LAST:event_btCancelActionPerformed
- private void btnAutoSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAutoSelectActionPerformed
- this.autoSelect = true;
- setChoice();
- this.hideDialog();
- }//GEN-LAST:event_btnAutoSelectActionPerformed
+ /**
+ * Closes the dialog
+ */
+ private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
+ doCancel();
+ }//GEN-LAST:event_closeDialog
// Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton btnAutoSelect;
- private javax.swing.JButton btnCancel;
- private javax.swing.JButton btnOk;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JLabel lblMessage;
- private javax.swing.JList lstChoices;
+ private javax.swing.JButton btCancel;
+ private javax.swing.JButton btOK;
+ private javax.swing.JTextField editSearch;
+ private javax.swing.JLabel labelMessage;
+ private javax.swing.JLabel labelSearch;
+ private javax.swing.JLabel labelSubMessage;
+ private javax.swing.JList listChoices;
+ private javax.swing.JPanel panelCommands;
+ private javax.swing.JPanel panelHeader;
+ private javax.swing.JPanel panelSearch;
+ private javax.swing.JScrollPane scrollList;
// End of variables declaration//GEN-END:variables
-
}
- class ComboItem {
-
- private final String value;
- private final String label;
-
- public ComboItem(String value, String label) {
- this.value = value;
- this.label = label;
- }
-
- public String getValue() {
- return this.value;
- }
-
- public String getLabel() {
- return this.label;
- }
-
- @Override
- public String toString() {
- return label;
- }
- }
\ No newline at end of file
diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java
index a014167df0a..ab0daf3e706 100644
--- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java
+++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java
@@ -1220,14 +1220,17 @@ public final class GamePanel extends javax.swing.JPanel {
public void getChoice(Choice choice, UUID objectId) {
hideAll();
+ // TODO: remember last choices and search incremental for same events?
PickChoiceDialog pickChoice = new PickChoiceDialog();
pickChoice.showDialog(choice, objectId, choiceWindowState);
if (choice.isKeyChoice()) {
+ SessionHandler.sendPlayerString(gameId, choice.getChoiceKey());
+ /* // old code, auto complete was for auto scripting?
if (pickChoice.isAutoSelect()) {
SessionHandler.sendPlayerString(gameId, '#' + choice.getChoiceKey());
} else {
SessionHandler.sendPlayerString(gameId, choice.getChoiceKey());
- }
+ }*/
} else {
SessionHandler.sendPlayerString(gameId, choice.getChoice());
}
diff --git a/Mage/src/main/java/mage/abilities/effects/common/ChooseCreatureTypeEffect.java b/Mage/src/main/java/mage/abilities/effects/common/ChooseCreatureTypeEffect.java
index 3a9b80b9941..f707e908249 100644
--- a/Mage/src/main/java/mage/abilities/effects/common/ChooseCreatureTypeEffect.java
+++ b/Mage/src/main/java/mage/abilities/effects/common/ChooseCreatureTypeEffect.java
@@ -33,6 +33,7 @@ import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.choices.Choice;
+import mage.choices.ChoiceCreatureType;
import mage.choices.ChoiceImpl;
import mage.constants.Outcome;
import mage.constants.SubType;
@@ -63,9 +64,7 @@ public class ChooseCreatureTypeEffect extends OneShotEffect {
mageObject = game.getObject(source.getSourceId());
}
if (controller != null && mageObject != null) {
- Choice typeChoice = new ChoiceImpl(true);
- typeChoice.setMessage("Choose creature type");
- typeChoice.setChoices(SubType.getCreatureTypes(false).stream().map(SubType::toString).collect(Collectors.toCollection(LinkedHashSet::new)));
+ Choice typeChoice = new ChoiceCreatureType(mageObject);
while (!controller.choose(outcome, typeChoice, game)) {
if (!controller.canRespond()) {
return false;
diff --git a/Mage/src/main/java/mage/choices/Choice.java b/Mage/src/main/java/mage/choices/Choice.java
index 9a20c066bb4..3bfcffa2a83 100644
--- a/Mage/src/main/java/mage/choices/Choice.java
+++ b/Mage/src/main/java/mage/choices/Choice.java
@@ -37,19 +37,34 @@ import java.util.Set;
*/
public interface Choice {
- boolean isChosen();
- boolean isRequired();
- void clearChoice();
String getMessage();
void setMessage(String message);
- void setChoice(String choice);
- void setChoiceByKey(String choiceKey);
- Set getChoices();
- Map getKeyChoices();
- void setChoices(Set choices);
- void setKeyChoices(Map choices);
- String getChoice();
- String getChoiceKey();
- boolean isKeyChoice();
+
+ String getSubMessage();
+ void setSubMessage(String subMessage);
+
+ void clearChoice();
+ boolean isChosen();
+ boolean isRequired();
+
Choice copy();
+
+ // string choice
+ void setChoices(Set choices);
+ Set getChoices();
+ void setChoice(String choice);
+ String getChoice();
+
+ // key-value choice
+ boolean isKeyChoice();
+ void setKeyChoices(Map choices);
+ Map getKeyChoices();
+ void setChoiceByKey(String choiceKey);
+ String getChoiceKey();
+
+ // search
+ boolean isSearchEnabled();
+ void setSearchEnabled(boolean isEnabled);
+ void setSearchText(String searchText);
+ String getSearchText();
}
diff --git a/Mage/src/main/java/mage/choices/ChoiceCreatureType.java b/Mage/src/main/java/mage/choices/ChoiceCreatureType.java
index 558a6ecb5c4..7ffbab88294 100644
--- a/Mage/src/main/java/mage/choices/ChoiceCreatureType.java
+++ b/Mage/src/main/java/mage/choices/ChoiceCreatureType.java
@@ -1,5 +1,6 @@
package mage.choices;
+import mage.MageObject;
import mage.constants.SubType;
import java.util.LinkedHashSet;
@@ -7,10 +8,28 @@ import java.util.stream.Collectors;
public class ChoiceCreatureType extends ChoiceImpl {
+ private static String DEFAULT_MESSAGE = "Choose a creature type";
+
public ChoiceCreatureType() {
- super(true);
+ this(true, DEFAULT_MESSAGE, null);
+ }
+
+ public ChoiceCreatureType(MageObject source) {
+ this(true, DEFAULT_MESSAGE, source);
+ }
+
+ public ChoiceCreatureType(String chooseMessage, MageObject source) {
+ this(true, chooseMessage, source);
+ }
+
+ public ChoiceCreatureType(boolean required, String chooseMessage, MageObject source){
+ super(required);
this.setChoices(SubType.getCreatureTypes(false).stream().map(SubType::toString).collect(Collectors.toCollection(LinkedHashSet::new)));
- this.message = "Choose a creature type:";
+ this.setMessage(chooseMessage);
+ if(source != null) {
+ this.setSubMessage(source.getIdName());
+ }
+ this.setSearchEnabled(true);
}
public ChoiceCreatureType(final ChoiceCreatureType choice) {
diff --git a/Mage/src/main/java/mage/choices/ChoiceImpl.java b/Mage/src/main/java/mage/choices/ChoiceImpl.java
index bee47239a86..56928171b77 100644
--- a/Mage/src/main/java/mage/choices/ChoiceImpl.java
+++ b/Mage/src/main/java/mage/choices/ChoiceImpl.java
@@ -47,6 +47,9 @@ public class ChoiceImpl implements Choice, Serializable {
protected Set choices = new LinkedHashSet<>();
protected Map keyChoices = new LinkedHashMap<>();
protected String message;
+ protected String subMessage;
+ protected boolean searchEnabled;
+ protected String searchText;
public ChoiceImpl() {
this(false);
@@ -61,6 +64,7 @@ public class ChoiceImpl implements Choice, Serializable {
this.chosen = choice.chosen;
this.required = choice.required;
this.message = choice.message;
+ this.message = choice.subMessage;
this.choices.addAll(choice.choices);
this.choiceKey = choice.choiceKey;
this.keyChoices = choice.keyChoices; // list should never change for the same object so copy by reference
@@ -88,6 +92,12 @@ public class ChoiceImpl implements Choice, Serializable {
this.message = message;
}
+ @Override
+ public String getSubMessage(){ return subMessage; }
+
+ @Override
+ public void setSubMessage(String subMessage){ this.subMessage = subMessage; }
+
@Override
public Set getChoices() {
return choices;
@@ -150,4 +160,24 @@ public class ChoiceImpl implements Choice, Serializable {
return !keyChoices.isEmpty();
}
-}
+ @Override
+ public boolean isSearchEnabled(){
+ return this.searchEnabled;
+ };
+
+ @Override
+ public void setSearchEnabled(boolean isEnabled){
+ this.searchEnabled = isEnabled;
+ };
+
+ @Override
+ public void setSearchText(String searchText){
+ this.searchText = searchText;
+ };
+
+ @Override
+ public String getSearchText(){
+ return this.searchText;
+ };
+
+}
\ No newline at end of file