From e4dfa5925bdd6daa2f6de0b0eb70d04c22873644 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Thu, 28 Dec 2017 22:38:18 +0400 Subject: [PATCH] UI: added start selection value on choice dialog popup; --- .../mage/client/dialog/PickChoiceDialog.java | 32 ++++++++++++++++++- Mage/src/main/java/mage/choices/Choice.java | 1 + .../main/java/mage/choices/ChoiceImpl.java | 10 ++++++ 3 files changed, 42 insertions(+), 1 deletion(-) 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 b0d371c19d..5193cdfd6d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java @@ -23,6 +23,7 @@ import mage.client.MageFrame; import mage.client.util.SettingsManager; import mage.client.util.gui.GuiDisplayUtil; import mage.client.util.gui.MageDialogState; +import org.jsoup.Connection; /** * @@ -36,8 +37,20 @@ public class PickChoiceDialog extends MageDialog { DefaultListModel dataModel = new DefaultListModel(); final private static String HTML_TEMPLATE = "
%s
"; - + + public void showDialog(Choice choice) { + showDialog(choice, null, null, null); + } + + public void showDialog(Choice choice, String startSelectionValue) { + showDialog(choice, null, null, startSelectionValue); + } + public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState) { + showDialog(choice, objectId, mageDialogState, null); + } + + public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState, String startSelectionValue) { this.choice = choice; setLabelText(this.labelMessage, choice.getMessage()); @@ -136,6 +149,23 @@ public class PickChoiceDialog extends MageDialog { // final load loadData(); + // start selection + if((startSelectionValue != null)){ + int selectIndex = -1; + for(int i = 0; i < this.listChoices.getModel().getSize() - 1; i++){ + KeyValueItem listItem = (KeyValueItem)this.listChoices.getModel().getElementAt(i); + if (listItem.Key.equals(startSelectionValue)){ + selectIndex = i; + break; + } + } + + if(selectIndex >= 0){ + this.listChoices.setSelectedIndex(selectIndex); + this.listChoices.ensureIndexIsVisible(selectIndex); + } + } + this.setVisible(true); } diff --git a/Mage/src/main/java/mage/choices/Choice.java b/Mage/src/main/java/mage/choices/Choice.java index 3bfcffa2a8..2ddc784c8c 100644 --- a/Mage/src/main/java/mage/choices/Choice.java +++ b/Mage/src/main/java/mage/choices/Choice.java @@ -61,6 +61,7 @@ public interface Choice { Map getKeyChoices(); void setChoiceByKey(String choiceKey); String getChoiceKey(); + String getChoiceValue(); // search boolean isSearchEnabled(); diff --git a/Mage/src/main/java/mage/choices/ChoiceImpl.java b/Mage/src/main/java/mage/choices/ChoiceImpl.java index a282171698..8f2a39858d 100644 --- a/Mage/src/main/java/mage/choices/ChoiceImpl.java +++ b/Mage/src/main/java/mage/choices/ChoiceImpl.java @@ -149,12 +149,22 @@ public class ChoiceImpl implements Choice, Serializable { return choiceKey; } + @Override + public String getChoiceValue() { + if ((keyChoices != null) && (keyChoices.containsKey(choiceKey))){ + return keyChoices.get(choiceKey); + }else{ + return null; + } + } + @Override public void setChoiceByKey(String choiceKey) { String choiceToSet = keyChoices.get(choiceKey); if (choiceToSet != null) { this.choice = choiceToSet; this.choiceKey = choiceKey; + this.chosen = true; } }