diff --git a/Mage.Client/src/main/java/mage/client/components/LegalityLabel.java b/Mage.Client/src/main/java/mage/client/components/LegalityLabel.java index 2998015766..5683375127 100644 --- a/Mage.Client/src/main/java/mage/client/components/LegalityLabel.java +++ b/Mage.Client/src/main/java/mage/client/components/LegalityLabel.java @@ -26,6 +26,9 @@ public class LegalityLabel extends JLabel { protected static final Dimension DIM_MAXIMUM = new Dimension(150, 75); protected static final Dimension DIM_PREFERRED = new Dimension(75, 25); + protected static final int TOOLTIP_TABLE_WIDTH = 300; // size of the label's tooltip + protected static final int TOOLTIP_MAX_ERRORS = 20; // max errors to show in tooltip + protected Deck currentDeck; protected String errorMessage; protected DeckValidator validator; @@ -108,16 +111,26 @@ public class LegalityLabel extends JLabel { protected String formatInvalidTooltip(java.util.List sortedErrorsList) { return sortedErrorsList.stream() - .reduce("

Deck is INVALID

The following problems have been found:
", - (str, error) -> String.format("%s", str, escapeHtml(error.getGroup()), escapeHtml(error.getMessage())), String::concat) - + "
%s%s
"; + .reduce("" + + "

Deck is INVALID

" + + "The following problems have been found:" + + "
" + + "", + (str, error) -> String.format("%s", str, escapeHtml(error.getGroup()), escapeHtml(error.getMessage())), String::concat) + + "
%s%s
" + + ""; } protected String formatPartlyValidTooltip(java.util.List sortedErrorsList) { return sortedErrorsList.stream() - .reduce("

Deck is PARTLY VALID

The following problems have been found:
", - (str, error) -> String.format("%s", str, escapeHtml(error.getGroup()), escapeHtml(error.getMessage())), String::concat) - + "
%s%s
"; + .reduce("" + + "

Deck is PARTLY VALID

" + + "The following problems have been found:" + + "
" + + "", + (str, error) -> String.format("%s", str, escapeHtml(error.getGroup()), escapeHtml(error.getMessage())), String::concat) + + "
%s%s
" + + ""; } private String appendErrorMessage(String string) { @@ -169,9 +182,9 @@ public class LegalityLabel extends JLabel { if (validator.validate(deck)) { showStateLegal("Deck is VALID"); } else if (validator.isPartlyValid()) { - showStatePartlyLegal(formatPartlyValidTooltip(validator.getErrorsListSorted())); + showStatePartlyLegal(formatPartlyValidTooltip(validator.getErrorsListSorted(TOOLTIP_MAX_ERRORS))); } else { - showStateNotLegal(formatInvalidTooltip(validator.getErrorsListSorted())); + showStateNotLegal(formatInvalidTooltip(validator.getErrorsListSorted(TOOLTIP_MAX_ERRORS))); } } catch (Exception e) { showStateUnknown(String.format("Deck could not be validated!
The following error occurred while validating this deck:
%s", escapeHtml(e.getMessage()))); diff --git a/Mage/src/main/java/mage/cards/decks/DeckValidator.java b/Mage/src/main/java/mage/cards/decks/DeckValidator.java index b36c03c553..465c708531 100644 --- a/Mage/src/main/java/mage/cards/decks/DeckValidator.java +++ b/Mage/src/main/java/mage/cards/decks/DeckValidator.java @@ -51,15 +51,19 @@ public abstract class DeckValidator implements Serializable { return this.errorsList; } + public List getErrorsListSorted() { + return getErrorsListSorted(Integer.MAX_VALUE); + } + /** * Get errors list sorted by error type and texts * * @return */ - public List getErrorsListSorted() { + public List getErrorsListSorted(int maxErrors) { List list = new ArrayList<>(this.getErrorsList()); - Collections.sort(list, new Comparator() { + list.sort(new Comparator() { @Override public int compare(DeckValidatorError e1, DeckValidatorError e2) { int res = 0; @@ -67,22 +71,31 @@ public abstract class DeckValidator implements Serializable { // sort by error type Integer order1 = e1.getErrorType().getSortOrder(); Integer order2 = e2.getErrorType().getSortOrder(); - res = order2.compareTo(order1); + res = order1.compareTo(order2); // sort by group - if (res != 0) { - res = e2.getGroup().compareTo(e1.getGroup()); + if (res == 0) { + res = e1.getGroup().compareTo(e2.getGroup()); } // sort by message - if (res != 0) { - res = e2.getMessage().compareTo(e1.getMessage()); + if (res == 0) { + res = e1.getMessage().compareTo(e2.getMessage()); } return res; } }); + if (list.size() <= maxErrors) { + return list; + } else { + int otherErrorsCount = list.size() - maxErrors; + list = list.stream().limit(maxErrors).collect(Collectors.toList()); + list.add(new DeckValidatorError(DeckValidatorErrorType.OTHER, "...", + "and more " + otherErrorsCount + " error" + (otherErrorsCount > 1 ? "s" : ""))); + } + return list; }