From 3b6afdf1db91641135ed3dc43c50e0803f6f52fa Mon Sep 17 00:00:00 2001 From: drdev Date: Sun, 6 Sep 2015 16:41:02 +0000 Subject: [PATCH] Improve selection and formatting of numeric operators --- .../src/forge/toolbox/FChoiceList.java | 3 +- .../forge/itemmanager/AdvancedSearch.java | 57 ++++++++++--------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/forge-gui-mobile/src/forge/toolbox/FChoiceList.java b/forge-gui-mobile/src/forge/toolbox/FChoiceList.java index 45313eafa28..d5a173d20f9 100644 --- a/forge-gui-mobile/src/forge/toolbox/FChoiceList.java +++ b/forge-gui-mobile/src/forge/toolbox/FChoiceList.java @@ -19,6 +19,7 @@ import forge.game.card.CardView; import forge.game.card.IHasCardView; import forge.game.player.PlayerView; import forge.item.PaperCard; +import forge.itemmanager.AdvancedSearch.FilterOperator; import forge.screens.match.MatchController; import forge.screens.match.views.VAvatar; import forge.screens.match.views.VStack; @@ -67,7 +68,7 @@ public class FChoiceList extends FList implements ActivateHandler { else if (item instanceof PlayerView) { renderer = new PlayerItemRenderer(); } - else if (item instanceof Integer) { + else if (item instanceof Integer || item == FilterOperator.EQUALS) { //allow numeric operators to be selected horizontally renderer = new NumberRenderer(); } else { diff --git a/forge-gui/src/main/java/forge/itemmanager/AdvancedSearch.java b/forge-gui/src/main/java/forge/itemmanager/AdvancedSearch.java index d191f051715..126c0d754a6 100644 --- a/forge-gui/src/main/java/forge/itemmanager/AdvancedSearch.java +++ b/forge-gui/src/main/java/forge/itemmanager/AdvancedSearch.java @@ -24,7 +24,7 @@ import forge.util.gui.SGuiChoose; import forge.util.gui.SOptionPane; public class AdvancedSearch { - private enum FilterOption { + public enum FilterOption { NONE("(none)", null, null, null), CARD_NAME("Name", PaperCard.class, FilterOperator.STRING_OPS, new StringEvaluator() { @Override @@ -259,7 +259,7 @@ public class AdvancedSearch { } } - private enum FilterOperator { + public enum FilterOperator { //Boolean operators IS_TRUE("is true", "%1$s is true", FilterValueCount.ZERO, new OperatorEvaluator() { @Override @@ -281,7 +281,7 @@ public class AdvancedSearch { }), //Numeric operators - EQUALS("is equal to", "%1$s = %2$d", FilterValueCount.ONE, new OperatorEvaluator() { + EQUALS("=", "%1$s = %2$d", FilterValueCount.ONE, new OperatorEvaluator() { @Override public boolean apply(Integer input, List values) { if (input != null) { @@ -290,7 +290,7 @@ public class AdvancedSearch { return false; } }), - NOT_EQUALS("is not equal to", "%1$s <> %2$d", FilterValueCount.ONE, new OperatorEvaluator() { + NOT_EQUALS("<>", "%1$s <> %2$d", FilterValueCount.ONE, new OperatorEvaluator() { @Override public boolean apply(Integer input, List values) { if (input != null) { @@ -299,7 +299,7 @@ public class AdvancedSearch { return true; } }), - GREATER_THAN("is greater than", "%1$s > %2$d", FilterValueCount.ONE, new OperatorEvaluator() { + GREATER_THAN(">", "%1$s > %2$d", FilterValueCount.ONE, new OperatorEvaluator() { @Override public boolean apply(Integer input, List values) { if (input != null) { @@ -308,7 +308,7 @@ public class AdvancedSearch { return false; } }), - LESS_THAN("is less than", "%1$s < %2$d", FilterValueCount.ONE, new OperatorEvaluator() { + LESS_THAN("<", "%1$s < %2$d", FilterValueCount.ONE, new OperatorEvaluator() { @Override public boolean apply(Integer input, List values) { if (input != null) { @@ -317,7 +317,7 @@ public class AdvancedSearch { return false; } }), - GT_OR_EQUAL("is greater than or equal to", "%1$s >= %2$d", FilterValueCount.ONE, new OperatorEvaluator() { + GT_OR_EQUAL(">=", "%1$s >= %2$d", FilterValueCount.ONE, new OperatorEvaluator() { @Override public boolean apply(Integer input, List values) { if (input != null) { @@ -326,7 +326,7 @@ public class AdvancedSearch { return false; } }), - LT_OR_EQUAL("is less than or equal to", "%1$s <= %2$d", FilterValueCount.ONE, new OperatorEvaluator() { + LT_OR_EQUAL("<=", "%1$s <= %2$d", FilterValueCount.ONE, new OperatorEvaluator() { @Override public boolean apply(Integer input, List values) { if (input != null) { @@ -335,7 +335,7 @@ public class AdvancedSearch { return false; } }), - BETWEEN_INCLUSIVE("is between (inclusive)", "%2$d <= %1$s <= %3$d", FilterValueCount.TWO, new OperatorEvaluator() { + BETWEEN_INCLUSIVE("<=|<=", "%2$d <= %1$s <= %3$d", FilterValueCount.TWO, new OperatorEvaluator() { @Override public boolean apply(Integer input, List values) { if (input != null) { @@ -345,7 +345,7 @@ public class AdvancedSearch { return false; } }), - BETWEEN_EXCLUSIVE("is between (exclusive)", "%2$d < %1$s < %3$d", FilterValueCount.TWO, new OperatorEvaluator() { + BETWEEN_EXCLUSIVE("<|<", "%2$d < %1$s < %3$d", FilterValueCount.TWO, new OperatorEvaluator() { @Override public boolean apply(Integer input, List values) { if (input != null) { @@ -530,8 +530,8 @@ public class AdvancedSearch { private static abstract class FilterEvaluator { @SuppressWarnings("unchecked") - public final Filter createFilter(String message, FilterOption option, FilterOperator operator) { - final List values = getValues(message, option, operator); + public final Filter createFilter(FilterOption option, FilterOperator operator) { + final List values = getValues(option, operator); if (values == null || values.isEmpty()) { return null; } String caption = getCaption(values, option, operator); @@ -557,7 +557,7 @@ public class AdvancedSearch { return new Filter(option, operator, caption, predicate); } - protected abstract List getValues(String message, FilterOption option, FilterOperator operator); + protected abstract List getValues(FilterOption option, FilterOperator operator); protected abstract String getCaption(List values, FilterOption option, FilterOperator operator); protected abstract V getItemValue(T input); @@ -571,7 +571,7 @@ public class AdvancedSearch { } @Override - protected List getValues(String message, FilterOption option, FilterOperator operator) { + protected List getValues(FilterOption option, FilterOperator operator) { List values = new ArrayList(); values.add(operator == FilterOperator.IS_TRUE); //just always add a single boolean value so other logic works return values; @@ -592,20 +592,23 @@ public class AdvancedSearch { } @Override - protected List getValues(String message, FilterOption option, FilterOperator operator) { - String msg = message; - if (operator.valueCount == FilterValueCount.TWO) { - msg += " (Lower Bound)"; + protected List getValues(FilterOption option, FilterOperator operator) { + String message; + if (operator.valueCount == FilterValueCount.ONE) { + message = option.name + " " + operator.caption + " ?"; } - Integer lowerBound = SGuiChoose.getInteger(msg, min, max); + else { + message = "? " + operator.caption.replace("|", " " + option.name + " "); + } + Integer lowerBound = SGuiChoose.getInteger(message, min, max); if (lowerBound == null) { return null; } final List values = new ArrayList(); values.add(lowerBound); if (operator.valueCount == FilterValueCount.TWO) { //prompt for upper bound if needed - msg = message + " (Upper Bound)"; - Integer upperBound = SGuiChoose.getInteger(msg, lowerBound, max); + message = lowerBound + message.substring(1) + " ?"; + Integer upperBound = SGuiChoose.getInteger(message, lowerBound, max); if (upperBound == null) { return null; } values.add(upperBound); @@ -627,7 +630,8 @@ public class AdvancedSearch { } @Override - protected List getValues(String message, FilterOption option, FilterOperator operator) { + protected List getValues(FilterOption option, FilterOperator operator) { + String message = option.name + " " + operator.caption + " ?"; String value = SOptionPane.showInputDialog("", message); if (value == null) { return null; } @@ -659,11 +663,12 @@ public class AdvancedSearch { } @Override - protected List getValues(String message, FilterOption option, FilterOperator operator) { + protected List getValues(FilterOption option, FilterOperator operator) { int max = choices.size(); if (operator == FilterOperator.IS_EXACTLY && option.operatorOptions == FilterOperator.SINGLE_LIST_OPS) { max = 1; } + String message = option.name + " " + operator.caption + " ?"; return SGuiChoose.getChoices(message, 0, max, choices, null, toLongString); } @@ -731,7 +736,8 @@ public class AdvancedSearch { } @Override - protected List> getValues(String message, FilterOption option, FilterOperator operator) { + protected List> getValues(FilterOption option, FilterOperator operator) { + String message = option.name + " " + operator.caption + " ?"; PaperCard card = SGuiChoose.oneOrNone(message, FModel.getMagicDb().getCommonCards().getUniqueCards()); if (card == null) { return null; } @@ -782,8 +788,7 @@ public class AdvancedSearch { final FilterOperator operator = SGuiChoose.oneOrNone("Select an operator for " + option.name, option.operatorOptions, defaultOperator, null); if (operator == null) { return editFilter; } - final String message = option.name + " " + operator.caption + " ?"; - Filter filter = (Filter)option.evaluator.createFilter(message, option, operator); + Filter filter = (Filter)option.evaluator.createFilter(option, operator); if (filter == null) { filter = editFilter; }