diff --git a/.gitattributes b/.gitattributes index 718320f9f77..d13e4cfbe8c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9,6 +9,7 @@ /CHANGES.txt svneol=native#text/plain /LICENSE.txt svneol=native#text/plain /README.txt svneol=native#text/plain +/editor.preferences -text /forge.properties svneol=native#text/plain /pom.xml svneol=native#text/xml res/AllTokens.txt svneol=native#text/plain @@ -10854,32 +10855,6 @@ res/draft/rare.txt svneol=native#text/plain res/draft/uncommon.txt svneol=native#text/plain res/gamedata/NonStackingKWList.txt svneol=native#text/plain res/gamedata/TypeLists.txt svneol=native#text/plain -res/images/deckeditor/filter_artifact_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_artifact_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_black_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_black_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_blue_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_blue_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_colorless_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_colorless_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_creature_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_creature_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_enchant_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_enchant_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_green_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_green_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_instant_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_instant_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_land_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_land_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_planeswalker_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_planeswalker_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_red_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_red_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_sorcery_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_sorcery_y.png -text svneol=unset#image/png -res/images/deckeditor/filter_white_n.png -text svneol=unset#image/png -res/images/deckeditor/filter_white_y.png -text svneol=unset#image/png res/lang/de.properties svneol=native#text/plain res/lang/en.properties svneol=native#text/plain res/lang/howTo/de.properties svneol=native#text/plain @@ -11610,7 +11585,6 @@ res/skins/the_simpsons/bg_texture.jpg -text res/skins/the_simpsons/font1.ttf -text res/skins/the_simpsons/sprite_avatars.png -text res/skins/the_simpsons/sprite_icons.png -text -res/sound/tap.mp3 -text svneol=unset#audio/mpeg res/token-images.txt -text src/main/config/Forge.icns -text src/main/config/backgroundImage.jpg -text svneol=unset#image/jpeg @@ -11935,34 +11909,47 @@ src/main/java/forge/gui/MultiLineLabelUI.java svneol=native#text/plain src/main/java/forge/gui/MultiPhaseProgressMonitorWithETA.java svneol=native#text/plain src/main/java/forge/gui/SOverlayUtils.java -text src/main/java/forge/gui/WrapLayout.java -text -src/main/java/forge/gui/deckeditor/DeckController.java -text -src/main/java/forge/gui/deckeditor/DeckEditorBase.java -text -src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/DeckEditorLimited.java -text -src/main/java/forge/gui/deckeditor/DeckEditorQuest.java svneol=native#text/plain +src/main/java/forge/gui/deckeditor/CDeckEditorUI.java -text src/main/java/forge/gui/deckeditor/DeckImport.java -text -src/main/java/forge/gui/deckeditor/DraftingProcess.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/MenuBase.java -text src/main/java/forge/gui/deckeditor/MenuCommon.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/MenuLimited.java -text -src/main/java/forge/gui/deckeditor/MenuQuest.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/PresetColumns.java -text -src/main/java/forge/gui/deckeditor/QuestCardShop.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/elements/CardPanelBase.java -text -src/main/java/forge/gui/deckeditor/elements/CardPanelHeavy.java -text -src/main/java/forge/gui/deckeditor/elements/CardPanelLite.java -text -src/main/java/forge/gui/deckeditor/elements/CheckBoxWithIcon.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/elements/DeckAnalysis.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/elements/FilterCheckBoxes.java -text -src/main/java/forge/gui/deckeditor/elements/FilterNameTypeSetPanel.java -text -src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java -text -src/main/java/forge/gui/deckeditor/elements/TableColumnInfo.java -text -src/main/java/forge/gui/deckeditor/elements/TableModel.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/elements/TableSorter.java svneol=native#text/plain -src/main/java/forge/gui/deckeditor/elements/TableSorterCascade.java -text -src/main/java/forge/gui/deckeditor/elements/TableView.java -text -src/main/java/forge/gui/deckeditor/elements/package-info.java -text +src/main/java/forge/gui/deckeditor/SEditorIO.java -text +src/main/java/forge/gui/deckeditor/SEditorUtil.java -text +src/main/java/forge/gui/deckeditor/SFilterUtil.java -text +src/main/java/forge/gui/deckeditor/VDeckEditorUI.java -text +src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java -text +src/main/java/forge/gui/deckeditor/controllers/CAllDecks.java -text +src/main/java/forge/gui/deckeditor/controllers/CCardCatalog.java -text +src/main/java/forge/gui/deckeditor/controllers/CCurrentDeck.java -text +src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java -text +src/main/java/forge/gui/deckeditor/controllers/CEditorConstructed.java svneol=native#text/plain +src/main/java/forge/gui/deckeditor/controllers/CEditorDraftingProcess.java svneol=native#text/plain +src/main/java/forge/gui/deckeditor/controllers/CEditorLimited.java -text +src/main/java/forge/gui/deckeditor/controllers/CEditorPreferences.java -text +src/main/java/forge/gui/deckeditor/controllers/CEditorQuest.java svneol=native#text/plain +src/main/java/forge/gui/deckeditor/controllers/CEditorQuestCardShop.java -text +src/main/java/forge/gui/deckeditor/controllers/CFilters.java -text +src/main/java/forge/gui/deckeditor/controllers/CProbabilities.java -text +src/main/java/forge/gui/deckeditor/controllers/CStatistics.java -text src/main/java/forge/gui/deckeditor/package-info.java -text +src/main/java/forge/gui/deckeditor/tables/DeckController.java -text +src/main/java/forge/gui/deckeditor/tables/IntegerRenderer.java -text +src/main/java/forge/gui/deckeditor/tables/ManaCostRenderer.java -text +src/main/java/forge/gui/deckeditor/tables/SColumnUtil.java -text +src/main/java/forge/gui/deckeditor/tables/TableColumnInfo.java -text +src/main/java/forge/gui/deckeditor/tables/TableModel.java svneol=native#text/plain +src/main/java/forge/gui/deckeditor/tables/TableSorter.java svneol=native#text/plain +src/main/java/forge/gui/deckeditor/tables/TableSorterCascade.java -text +src/main/java/forge/gui/deckeditor/tables/TableView.java -text +src/main/java/forge/gui/deckeditor/tables/package-info.java -text +src/main/java/forge/gui/deckeditor/views/ITableContainer.java -text +src/main/java/forge/gui/deckeditor/views/VAllDecks.java -text +src/main/java/forge/gui/deckeditor/views/VCardCatalog.java -text +src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java -text +src/main/java/forge/gui/deckeditor/views/VDeckgen.java -text +src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java -text +src/main/java/forge/gui/deckeditor/views/VFilters.java -text +src/main/java/forge/gui/deckeditor/views/VProbabilities.java -text +src/main/java/forge/gui/deckeditor/views/VStatistics.java -text src/main/java/forge/gui/download/GuiDownloadPicturesLQ.java svneol=native#text/plain src/main/java/forge/gui/download/GuiDownloadPrices.java svneol=native#text/plain src/main/java/forge/gui/download/GuiDownloadQuestImages.java -text @@ -11978,8 +11965,8 @@ src/main/java/forge/gui/framework/ILocalRepaint.java -text src/main/java/forge/gui/framework/IVDoc.java -text src/main/java/forge/gui/framework/IVTopLevelUI.java -text src/main/java/forge/gui/framework/SDisplayUtil.java -text -src/main/java/forge/gui/framework/SIOUtil.java -text src/main/java/forge/gui/framework/SLayoutConstants.java -text +src/main/java/forge/gui/framework/SLayoutIO.java -text src/main/java/forge/gui/framework/SOverflowUtil.java -text src/main/java/forge/gui/framework/SRearrangingUtil.java -text src/main/java/forge/gui/framework/SResizingUtil.java -text @@ -11999,7 +11986,7 @@ src/main/java/forge/gui/home/quest/CSubmenuQuestPrefs.java -text src/main/java/forge/gui/home/quest/IStatsAndPet.java -text src/main/java/forge/gui/home/quest/QuestFileLister.java -text src/main/java/forge/gui/home/quest/QuestPreferencesHandler.java -text -src/main/java/forge/gui/home/quest/SubmenuQuestUtil.java -text +src/main/java/forge/gui/home/quest/SSubmenuQuestUtil.java -text src/main/java/forge/gui/home/quest/VSubmenuChallenges.java -text src/main/java/forge/gui/home/quest/VSubmenuDuels.java -text src/main/java/forge/gui/home/quest/VSubmenuQuestData.java -text @@ -12074,6 +12061,7 @@ src/main/java/forge/gui/toolbox/FRadioButton.java -text src/main/java/forge/gui/toolbox/FScrollPane.java -text src/main/java/forge/gui/toolbox/FSkin.java -text src/main/java/forge/gui/toolbox/FTextArea.java -text +src/main/java/forge/gui/toolbox/FTextField.java -text src/main/java/forge/gui/toolbox/SaveOpenDialog.java -text src/main/java/forge/gui/toolbox/package-info.java svneol=native#text/plain src/main/java/forge/item/BoosterPack.java -text @@ -12166,6 +12154,7 @@ src/main/java/forge/util/closures/Lambda.java svneol=native#text/plain src/main/java/forge/util/closures/Lambda0.java -text src/main/java/forge/util/closures/Lambda1.java svneol=native#text/plain src/main/java/forge/util/closures/Predicate.java -text +src/main/java/forge/util/closures/PredicateInteger.java -text src/main/java/forge/util/closures/PredicateString.java -text src/main/java/forge/util/closures/package-info.java -text svneol=native#text/plain src/main/java/forge/util/package-info.java -text diff --git a/.gitignore b/.gitignore index b0ce13d2b18..c348b8c8e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -268,8 +268,6 @@ res/decks/Zemox's[!!-~]Mono-Green[!!-~]Infect.dck res/decks/Zvi[!!-~]Mowshowitz's[!!-~]Mono-Black[!!-~]Control.dck res/decks/constructed/*.dck res/decks/o1.bdk -res/images/icons -res/images/themes res/layouts/*.xml res/oracleScript.log res/pics diff --git a/editor.preferences b/editor.preferences new file mode 100644 index 00000000000..f6eca9389ec --- /dev/null +++ b/editor.preferences @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/images/deckeditor/filter_artifact_n.png b/res/images/deckeditor/filter_artifact_n.png deleted file mode 100644 index 2523d044c0a..00000000000 Binary files a/res/images/deckeditor/filter_artifact_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_artifact_y.png b/res/images/deckeditor/filter_artifact_y.png deleted file mode 100644 index 0b551e67d93..00000000000 Binary files a/res/images/deckeditor/filter_artifact_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_black_n.png b/res/images/deckeditor/filter_black_n.png deleted file mode 100644 index 60b23423217..00000000000 Binary files a/res/images/deckeditor/filter_black_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_black_y.png b/res/images/deckeditor/filter_black_y.png deleted file mode 100644 index 6e4246a2beb..00000000000 Binary files a/res/images/deckeditor/filter_black_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_blue_n.png b/res/images/deckeditor/filter_blue_n.png deleted file mode 100644 index c2183dc0c50..00000000000 Binary files a/res/images/deckeditor/filter_blue_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_blue_y.png b/res/images/deckeditor/filter_blue_y.png deleted file mode 100644 index ff5b7e7d35b..00000000000 Binary files a/res/images/deckeditor/filter_blue_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_colorless_n.png b/res/images/deckeditor/filter_colorless_n.png deleted file mode 100644 index cf231becc4c..00000000000 Binary files a/res/images/deckeditor/filter_colorless_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_colorless_y.png b/res/images/deckeditor/filter_colorless_y.png deleted file mode 100644 index bce292d3086..00000000000 Binary files a/res/images/deckeditor/filter_colorless_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_creature_n.png b/res/images/deckeditor/filter_creature_n.png deleted file mode 100644 index d577f01ef08..00000000000 Binary files a/res/images/deckeditor/filter_creature_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_creature_y.png b/res/images/deckeditor/filter_creature_y.png deleted file mode 100644 index aee035d6445..00000000000 Binary files a/res/images/deckeditor/filter_creature_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_enchant_n.png b/res/images/deckeditor/filter_enchant_n.png deleted file mode 100644 index b23e3122a68..00000000000 Binary files a/res/images/deckeditor/filter_enchant_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_enchant_y.png b/res/images/deckeditor/filter_enchant_y.png deleted file mode 100644 index 054bfbdbb47..00000000000 Binary files a/res/images/deckeditor/filter_enchant_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_green_n.png b/res/images/deckeditor/filter_green_n.png deleted file mode 100644 index 95d9527074f..00000000000 Binary files a/res/images/deckeditor/filter_green_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_green_y.png b/res/images/deckeditor/filter_green_y.png deleted file mode 100644 index eb4a5112544..00000000000 Binary files a/res/images/deckeditor/filter_green_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_instant_n.png b/res/images/deckeditor/filter_instant_n.png deleted file mode 100644 index 7c25dd437a5..00000000000 Binary files a/res/images/deckeditor/filter_instant_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_instant_y.png b/res/images/deckeditor/filter_instant_y.png deleted file mode 100644 index 83cd0d9a9d3..00000000000 Binary files a/res/images/deckeditor/filter_instant_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_land_n.png b/res/images/deckeditor/filter_land_n.png deleted file mode 100644 index f54f4f2864d..00000000000 Binary files a/res/images/deckeditor/filter_land_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_land_y.png b/res/images/deckeditor/filter_land_y.png deleted file mode 100644 index 8cc194c5327..00000000000 Binary files a/res/images/deckeditor/filter_land_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_planeswalker_n.png b/res/images/deckeditor/filter_planeswalker_n.png deleted file mode 100644 index f7b4c8bd85b..00000000000 Binary files a/res/images/deckeditor/filter_planeswalker_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_planeswalker_y.png b/res/images/deckeditor/filter_planeswalker_y.png deleted file mode 100644 index 81d204b7756..00000000000 Binary files a/res/images/deckeditor/filter_planeswalker_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_red_n.png b/res/images/deckeditor/filter_red_n.png deleted file mode 100644 index 4c059bc8392..00000000000 Binary files a/res/images/deckeditor/filter_red_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_red_y.png b/res/images/deckeditor/filter_red_y.png deleted file mode 100644 index 6c3f7b1c34f..00000000000 Binary files a/res/images/deckeditor/filter_red_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_sorcery_n.png b/res/images/deckeditor/filter_sorcery_n.png deleted file mode 100644 index cbfb904f55a..00000000000 Binary files a/res/images/deckeditor/filter_sorcery_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_sorcery_y.png b/res/images/deckeditor/filter_sorcery_y.png deleted file mode 100644 index e7b1cf10f76..00000000000 Binary files a/res/images/deckeditor/filter_sorcery_y.png and /dev/null differ diff --git a/res/images/deckeditor/filter_white_n.png b/res/images/deckeditor/filter_white_n.png deleted file mode 100644 index 77a37ec4337..00000000000 Binary files a/res/images/deckeditor/filter_white_n.png and /dev/null differ diff --git a/res/images/deckeditor/filter_white_y.png b/res/images/deckeditor/filter_white_y.png deleted file mode 100644 index d6ed26b89b5..00000000000 Binary files a/res/images/deckeditor/filter_white_y.png and /dev/null differ diff --git a/res/skins/default/grid_icons.png b/res/skins/default/grid_icons.png index 7b3285fb277..482bfd5685e 100644 Binary files a/res/skins/default/grid_icons.png and b/res/skins/default/grid_icons.png differ diff --git a/res/skins/default/sprite_icons.png b/res/skins/default/sprite_icons.png index 4c891fd1086..0a2e4704aa4 100644 Binary files a/res/skins/default/sprite_icons.png and b/res/skins/default/sprite_icons.png differ diff --git a/res/sound/tap.mp3 b/res/sound/tap.mp3 deleted file mode 100644 index 806612a6aa3..00000000000 Binary files a/res/sound/tap.mp3 and /dev/null differ diff --git a/src/main/java/forge/card/CardRules.java b/src/main/java/forge/card/CardRules.java index 671522b1a4a..fbeea4fa9e2 100644 --- a/src/main/java/forge/card/CardRules.java +++ b/src/main/java/forge/card/CardRules.java @@ -27,18 +27,17 @@ import java.util.Set; import org.apache.commons.lang3.StringUtils; import forge.util.closures.Predicate; -import forge.util.closures.PredicateString; import forge.util.closures.Predicate.ComparableOp; import forge.util.closures.Predicate.PredicatesOp; +import forge.util.closures.PredicateString; /** - *

- * CardOracle class. - *

+ * A collection of methods containing full + * meta and gameplay properties of a card. * * @author Forge - * @version $Id: CardOracle.java 9708 2011-08-09 19:34:12Z jendave $ + * @version $Id: CardRules.java 9708 2011-08-09 19:34:12Z jendave $ */ public final class CardRules { @@ -389,8 +388,31 @@ public final class CardRules { return new LeafNumber(LeafNumber.CardField.CMC, op, what); } - // Power - // Toughness + /** + * + * @param op + * the op + * @param what + * the what + * @return the predicate + */ + public static Predicate power(final ComparableOp op, final int what) { + return new LeafNumber(LeafNumber.CardField.POWER, op, what); + } + + /** + * + * @param op + * the op + * @param what + * the what + * @return the predicate + */ + public static Predicate toughness(final ComparableOp op, final int what) { + return new LeafNumber(LeafNumber.CardField.TOUGHNESS, op, what); + } + + // P/T /** * Rules. * @@ -462,7 +484,7 @@ public final class CardRules { * @return the predicate */ public static Predicate wasPrintedInSets(final List setCodes) { - return new PredicateExitsInSets(setCodes); + return new PredicateExistsInSets(setCodes); } /** @@ -568,7 +590,7 @@ public final class CardRules { * @return the predicate */ public static Predicate hasCntColors(final byte cntColors) { - return new LeafColor(LeafColor.ColorOperator.Equals, cntColors); + return new LeafColor(LeafColor.ColorOperator.CountColors, cntColors); } /** @@ -634,18 +656,18 @@ public final class CardRules { @Override public boolean isTrue(final CardRules subject) { switch (this.op) { - case CountColors: - return subject.getColor().countColors() == this.color; - case CountColorsGreaterOrEqual: - return subject.getColor().countColors() >= this.color; - case Equals: - return subject.getColor().isEqual(this.color); - case HasAllOf: - return subject.getColor().hasAllColors(this.color); - case HasAnyOf: - return subject.getColor().hasAnyColor(this.color); - default: - return false; + case CountColors: + return subject.getColor().countColors() == this.color; + case CountColorsGreaterOrEqual: + return subject.getColor().countColors() >= this.color; + case Equals: + return subject.getColor().isEqual(this.color); + case HasAllOf: + return subject.getColor().hasAllColors(this.color); + case HasAnyOf: + return subject.getColor().hasAnyColor(this.color); + default: + return false; } } } @@ -747,10 +769,10 @@ public final class CardRules { } } - private static class PredicateExitsInSets extends Predicate { + private static class PredicateExistsInSets extends Predicate { private final List sets; - public PredicateExitsInSets(final List wantSets) { + public PredicateExistsInSets(final List wantSets) { this.sets = wantSets; // maybe should make a copy here? } @@ -808,6 +830,9 @@ public final class CardRules { public static final Predicate IS_NON_CREATURE_SPELL = Predicate.compose(Presets.IS_CREATURE, PredicatesOp.NOR, Presets.IS_LAND); + /** + * + */ @SuppressWarnings("unchecked") public static final Predicate IS_NONCREATURE_SPELL_FOR_GENERATOR = Predicate.or(Arrays.asList( Presets.IS_SORCERY, Presets.IS_INSTANT, Presets.IS_PLANESWALKER, Presets.IS_ENCHANTMENT, diff --git a/src/main/java/forge/control/FControl.java b/src/main/java/forge/control/FControl.java index 7a7bad40025..33f37631c53 100644 --- a/src/main/java/forge/control/FControl.java +++ b/src/main/java/forge/control/FControl.java @@ -31,8 +31,12 @@ import javax.swing.WindowConstants; import forge.AllZone; import forge.Singletons; import forge.control.KeyboardShortcuts.Shortcut; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.VDeckEditorUI; +import forge.gui.framework.SOverflowUtil; +import forge.gui.framework.SResizingUtil; import forge.gui.home.VHomeUI; -import forge.gui.home.quest.SubmenuQuestUtil; +import forge.gui.home.quest.SSubmenuQuestUtil; import forge.gui.match.VMatchUI; import forge.gui.match.controllers.CDock; import forge.gui.toolbox.CardFaceSymbols; @@ -55,16 +59,24 @@ public enum FControl { private JLayeredPane display; private int state = -1; - private WindowListener waDefault, waConcede, waLeaveBazaar; + private WindowListener waDefault, waConcede, waLeaveBazaar, waLeaveEditor; /** */ public static final int HOME_SCREEN = 0; /** */ public static final int MATCH_SCREEN = 1; /** */ - public static final int DEFAULT_EDITOR = 2; + public static final int DECK_EDITOR_CONSTRUCTED = 2; /** */ public static final int QUEST_BAZAAR = 3; + /** */ + public static final int DECK_EDITOR_LIMITED = 4; + /** */ + public static final int DECK_EDITOR_QUEST = 5; + /** */ + public static final int QUEST_CARD_SHOP = 6; + /** */ + public static final int DRAFTING_PROCESS = 7; /** *

@@ -75,11 +87,21 @@ public enum FControl { * instantiated separately by each state's top level view class. */ private FControl() { + this.waDefault = new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent e) { + Singletons.getView().getFrame().setDefaultCloseOperation( + WindowConstants.EXIT_ON_CLOSE); + } + }; + // "Close" button override during match this.waConcede = new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { - Singletons.getView().getFrame().setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + Singletons.getView().getFrame().setDefaultCloseOperation( + WindowConstants.DO_NOTHING_ON_CLOSE); + CDock.SINGLETON_INSTANCE.concede(); } }; @@ -88,19 +110,28 @@ public enum FControl { this.waLeaveBazaar = new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { - Singletons.getView().getFrame().setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - changeState(0); - SubmenuQuestUtil.updateStatsAndPet(); + Singletons.getView().getFrame().setDefaultCloseOperation( + WindowConstants.DO_NOTHING_ON_CLOSE); + + changeState(FControl.HOME_SCREEN); + SSubmenuQuestUtil.updateStatsAndPet(); } }; - // Default action on window close - this.waDefault = new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent e) { - Singletons.getView().getFrame().setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - } + this.waLeaveEditor = new WindowAdapter() { + @Override + public void windowClosing(final WindowEvent ev) { + Singletons.getView().getFrame().setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); + + if (CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().exit()) { + changeState(FControl.HOME_SCREEN); + } + } }; + + FView.SINGLETON_INSTANCE.getLpnDocument().addMouseListener(SOverflowUtil.getHideOverflowListener()); + FView.SINGLETON_INSTANCE.getLpnDocument().addComponentListener(SResizingUtil.getWindowResizeListener()); + Singletons.getView().getFrame().setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); } /** After view and model have been initialized, control can start. */ @@ -117,8 +148,6 @@ public enum FControl { this.shortcuts = KeyboardShortcuts.attachKeyboardShortcuts(); this.display = FView.SINGLETON_INSTANCE.getLpnDocument(); - //Singletons.getView().initialize(); - // Handles resizing in null layouts of layers in JLayeredPane. Singletons.getView().getFrame().addComponentListener(new ComponentAdapter() { @Override @@ -141,17 +170,19 @@ public enum FControl { clearChildren(JLayeredPane.DEFAULT_LAYER); this.state = i0; - /// TODO should these be here? + Singletons.getView().getFrame().removeWindowListener(waDefault); Singletons.getView().getFrame().removeWindowListener(waConcede); Singletons.getView().getFrame().removeWindowListener(waLeaveBazaar); - Singletons.getView().getFrame().addWindowListener(waDefault); + Singletons.getView().getFrame().removeWindowListener(waLeaveEditor); // Fire up new state switch (i0) { case HOME_SCREEN: + Singletons.getView().getFrame().addWindowListener(waDefault); VHomeUI.SINGLETON_INSTANCE.populate(); FView.SINGLETON_INSTANCE.getPnlInsets().setVisible(false); - //sizeChildren(); + VHomeUI.SINGLETON_INSTANCE.updateLayout(); + sizeChildren(); break; case MATCH_SCREEN: @@ -160,8 +191,14 @@ public enum FControl { Singletons.getView().getFrame().addWindowListener(waConcede); break; - case DEFAULT_EDITOR: - display.add(Singletons.getView().getViewEditor(), JLayeredPane.DEFAULT_LAYER); + case DECK_EDITOR_CONSTRUCTED: + case DECK_EDITOR_LIMITED: + case DECK_EDITOR_QUEST: + case QUEST_CARD_SHOP: + case DRAFTING_PROCESS: + VDeckEditorUI.SINGLETON_INSTANCE.populate(); + FView.SINGLETON_INSTANCE.getPnlInsets().setVisible(true); + Singletons.getView().getFrame().addWindowListener(waLeaveEditor); break; case QUEST_BAZAAR: diff --git a/src/main/java/forge/deck/Deck.java b/src/main/java/forge/deck/Deck.java index ee4cf8a67aa..5413a3823e9 100644 --- a/src/main/java/forge/deck/Deck.java +++ b/src/main/java/forge/deck/Deck.java @@ -33,7 +33,7 @@ import org.apache.commons.lang3.StringUtils; import forge.deck.io.DeckFileHeader; import forge.deck.io.DeckSerializer; -import forge.gui.deckeditor.elements.TableSorter; +import forge.gui.deckeditor.tables.TableSorter; import forge.item.CardPrinted; import forge.item.ItemPoolView; import forge.util.FileSection; diff --git a/src/main/java/forge/game/limited/BoosterDraft.java b/src/main/java/forge/game/limited/BoosterDraft.java index 6daa597e514..ab08aae76c0 100644 --- a/src/main/java/forge/game/limited/BoosterDraft.java +++ b/src/main/java/forge/game/limited/BoosterDraft.java @@ -290,7 +290,12 @@ public final class BoosterDraft implements IBoosterDraft { } } // computerChoose() - private int getCurrentBoosterIndex() { + /** + * + * TODO: Write javadoc for this method. + * @return int + */ + public int getCurrentBoosterIndex() { return this.currentBoosterPick % BoosterDraft.N_PLAYERS; } diff --git a/src/main/java/forge/game/player/Player.java b/src/main/java/forge/game/player/Player.java index 99f4e7961bd..439b9dfcb66 100644 --- a/src/main/java/forge/game/player/Player.java +++ b/src/main/java/forge/game/player/Player.java @@ -49,7 +49,7 @@ import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZoneComesIntoPlay; import forge.game.zone.ZoneType; import forge.gui.GuiUtils; -import forge.gui.match.VMatchUI; +import forge.gui.match.views.VDev; import forge.util.MyRandom; /** @@ -1838,7 +1838,7 @@ public abstract class Player extends GameEntity { * @return a boolean. */ public final boolean canPlayLand() { - if (VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getLblUnlimitedLands().getEnabled() && this.isHuman() + if (VDev.SINGLETON_INSTANCE.getLblUnlimitedLands().getEnabled() && this.isHuman() && Constant.Runtime.DEV_MODE[0]) { return PhaseHandler.canCastSorcery(this); } diff --git a/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java b/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java new file mode 100644 index 00000000000..5fe830b5f6a --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/CDeckEditorUI.java @@ -0,0 +1,113 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor; + +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +import forge.Card; +import forge.gui.CardContainer; +import forge.gui.deckeditor.controllers.ACEditorBase; +import forge.gui.match.controllers.CDetail; +import forge.gui.match.controllers.CPicture; + +/** + * Constructs instance of deck editor UI controller, used as a single point of + * top-level control for child UIs. Tasks targeting the view of individual + * components are found in a separate controller for that component and + * should not be included here. + * + *

(C at beginning of class name denotes a control class.) + */ +public enum CDeckEditorUI implements CardContainer { + /** */ + SINGLETON_INSTANCE; + + private ACEditorBase childController; + + private CDeckEditorUI() { + } + + //========== Overridden from CardContainer + + @Override + public void setCard(final Card c) { + CDetail.SINGLETON_INSTANCE.showCard(c); + CPicture.SINGLETON_INSTANCE.showCard(c); + } + + @Override + public Card getCard() { + return CDetail.SINGLETON_INSTANCE.getCurrentCard(); + } + + //========= Accessor/mutator methods + /** + * @return ACEditorBase + */ + public ACEditorBase getCurrentEditorController() { + return childController; + } + + /** + * Set controller for current configuration of editor. + * @param editor0   {@link forge.gui.deckeditor.controllers.ACEditorBase} + */ + public void setCurrentEditorController(ACEditorBase editor0) { + this.childController = editor0; + updateController(); + } + + //========== Other methods + /** + * Updates listeners for current controller. + */ + private void updateController() { + childController.getTableCatalog().getTable().addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(final KeyEvent e) { + if (e.getKeyChar() == ' ') { childController.addCard(); } + } + }); + + childController.getTableDeck().getTable().addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(final KeyEvent e) { + if (e.getKeyChar() == ' ') { childController.removeCard(); } + } + }); + + childController.getTableCatalog().getTable().addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + if (e.getClickCount() == 2) { childController.addCard(); } + } + }); + + childController.getTableDeck().getTable().addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + if (e.getClickCount() == 2) { childController.removeCard(); } + } + }); + + childController.init(); + } +} diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorBase.java b/src/main/java/forge/gui/deckeditor/DeckEditorBase.java deleted file mode 100644 index e2e586975e3..00000000000 --- a/src/main/java/forge/gui/deckeditor/DeckEditorBase.java +++ /dev/null @@ -1,358 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import java.awt.event.ActionEvent; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import javax.swing.JDialog; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; - -import forge.Command; -import forge.deck.DeckBase; -import forge.gui.deckeditor.elements.CardPanelBase; -import forge.gui.deckeditor.elements.DeckAnalysis; -import forge.gui.deckeditor.elements.FilterCheckBoxes; -import forge.gui.deckeditor.elements.TableView; -import forge.item.CardPrinted; -import forge.item.InventoryItem; -import forge.item.ItemPool; -import forge.item.ItemPoolView; -import forge.util.closures.Predicate; - -/** - * The Class DeckEditorBase. - * - * @param the generic type - * @param the generic type - */ -public abstract class DeckEditorBase extends JDialog { - private static final long serialVersionUID = -401223933343539977L; - - /** The filter boxes. */ - private FilterCheckBoxes filterBoxes; - // set this to false when resetting filter from code (like - // "clearFiltersPressed"), reset when done. - /** The is filters change firing update. */ - private boolean isFiltersChangeFiringUpdate = true; - - /** The card view. */ - private CardPanelBase cardView; - - // CardPools and Table data for top and bottom lists - /** The top. */ - private TableView topTableWithCards; - - /** The bottom. */ - private TableView bottomTableWithCards; - /** - * Instantiates a new deck editor base. - * - * @param parent the parent frame for this deck editor - */ - public DeckEditorBase(JFrame parent) { - super(parent, ModalityType.APPLICATION_MODAL); - } - - // top shows available card pool - // if constructed, top shows all cards - // if sealed, top shows N booster packs - // if draft, top shows cards that were chosen - /** - * Gets the top table model. - * - * @return the top table model - */ - public final TableView getTopTableModel() { - return this.getTopTableWithCards(); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckDisplay#getTop() - */ - /** - * Gets the top. - * - * @return the top - */ - public final ItemPoolView getTop() { - return this.getTopTableWithCards().getCards(); - } - - // bottom shows player's choice - be it deck or draft - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckDisplay#getBottom() - */ - /** - * Gets the bottom. - * - * @return the bottom - */ - public final ItemPoolView getBottom() { - return this.getBottomTableWithCards().getCards(); - } - - /** - * Gets the controller. - * - * @return the controller - */ - public abstract DeckController getController(); - - // THIS IS HERE FOR OVERLOADING!!!1 - // or may be return abstract getFilter from derived class + this filter ... - // virtual protected member, but later - /** - * Builds the filter. - * - * @return the predicate - */ - protected abstract Predicate buildFilter(); - - /** - * Show. - * - * @param exitCommand the exit command - */ - public abstract void show(final Command exitCommand); - - /** - * Analysis button_action performed. - * - * @param e - * the e - */ - final void analysisButtonActionPerformed(final ActionEvent e) { - final ItemPoolView deck = ItemPool.createFrom(this.getBottomTableWithCards().getCards(), - CardPrinted.class); - if (deck.isEmpty()) { - JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck", - JOptionPane.INFORMATION_MESSAGE); - } else { - final DeckEditorBase g = DeckEditorBase.this; - final DeckAnalysis dAnalysis = new DeckAnalysis(g, deck); - dAnalysis.setVisible(true); - g.setEnabled(false); - } - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckDisplay#setItems(forge.item.ItemPoolView, - * forge.item.ItemPoolView, forge.game.GameType) - */ - /** - * Update view. - */ - public abstract void updateView(); - - /** - * Update display. - */ - public final void updateDisplay() { - this.getTopTableWithCards().setFilter(this.buildFilter()); - } - - /** The item listener updates display. */ - private ItemListener itemListenerUpdatesDisplay = new ItemListener() { - @Override - public void itemStateChanged(final ItemEvent e) { - if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) { - DeckEditorBase.this.updateDisplay(); - } - } - }; - - /** - * This class is used for a feature: when you start typing card name, the - * list gets auto-filtered. - */ - protected class OnChangeTextUpdateDisplay implements DocumentListener { - private void onChange() { - if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) { - DeckEditorBase.this.updateDisplay(); - } - } - - /* - * (non-Javadoc) - * - * @see - * javax.swing.event.DocumentListener#insertUpdate(javax.swing.event - * .DocumentEvent) - */ - @Override - public final void insertUpdate(final DocumentEvent e) { - this.onChange(); - } - - /* - * (non-Javadoc) - * - * @see - * javax.swing.event.DocumentListener#removeUpdate(javax.swing.event - * .DocumentEvent) - */ - @Override - public final void removeUpdate(final DocumentEvent e) { - this.onChange(); - } - - /* - * (non-Javadoc) - * - * @see - * javax.swing.event.DocumentListener#changedUpdate(javax.swing.event - * .DocumentEvent) - */ - @Override - public void changedUpdate(final DocumentEvent e) { - } // Happend only on ENTER pressed - } - - /** - * Gets the item listener updates display. - * - * @return the itemListenerUpdatesDisplay - */ - public ItemListener getItemListenerUpdatesDisplay() { - return this.itemListenerUpdatesDisplay; - } - - /** - * Sets the item listener updates display. - * - * @param itemListenerUpdatesDisplay - * the itemListenerUpdatesDisplay to set - */ - public void setItemListenerUpdatesDisplay(final ItemListener itemListenerUpdatesDisplay) { - this.itemListenerUpdatesDisplay = itemListenerUpdatesDisplay; // TODO: - // Add 0 - // to - // parameter's - // name. - } - - /** - * Checks if is filters change firing update. - * - * @return the isFiltersChangeFiringUpdate - */ - public boolean isFiltersChangeFiringUpdate() { - return this.isFiltersChangeFiringUpdate; - } - - /** - * Sets the filters change firing update. - * - * @param isFiltersChangeFiringUpdate - * the isFiltersChangeFiringUpdate to set - */ - public void setFiltersChangeFiringUpdate(final boolean isFiltersChangeFiringUpdate) { - this.isFiltersChangeFiringUpdate = isFiltersChangeFiringUpdate; // TODO: - // Add 0 - // to - // parameter's - // name. - } - - /** - * Gets the card view. - * - * @return the cardView - */ - public CardPanelBase getCardView() { - return this.cardView; - } - - /** - * Sets the card view. - * - * @param cardView0 - * the cardView to set - */ - protected void setCardView(final CardPanelBase cardView0) { - this.cardView = cardView0; - } - - /** - * Gets the filter boxes. - * - * @return the filterBoxes - */ - public FilterCheckBoxes getFilterBoxes() { - return this.filterBoxes; - } - - /** - * Sets the filter boxes. - * - * @param filterBoxes0 - * the filterBoxes to set - */ - public void setFilterBoxes(final FilterCheckBoxes filterBoxes0) { - this.filterBoxes = filterBoxes0; - } - - /** - * Gets the bottom table with cards. - * - * @return the bottomTableWithCards - */ - public TableView getBottomTableWithCards() { - return this.bottomTableWithCards; - } - - /** - * Sets the bottom table with cards. - * - * @param bottomTableWithCards0 - * the bottomTableWithCards to set - */ - public void setBottomTableWithCards(final TableView bottomTableWithCards0) { - this.bottomTableWithCards = bottomTableWithCards0; - } - - /** - * Gets the top table with cards. - * - * @return the topTableWithCards - */ - public TableView getTopTableWithCards() { - return this.topTableWithCards; - } - - /** - * Sets the top table with cards. - * - * @param topTableWithCards0 - * the topTableWithCards to set - */ - public void setTopTableWithCards(final TableView topTableWithCards0) { - this.topTableWithCards = topTableWithCards0; - } - -} diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java b/src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java deleted file mode 100644 index fa4058b03ce..00000000000 --- a/src/main/java/forge/gui/deckeditor/DeckEditorConstructed.java +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import java.awt.Container; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.List; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFrame; -import javax.swing.JLabel; - -import forge.Command; -import forge.Singletons; -import forge.deck.Deck; -import forge.error.ErrorViewer; -import forge.gui.deckeditor.elements.CardPanelHeavy; -import forge.gui.deckeditor.elements.FilterCheckBoxes; -import forge.gui.deckeditor.elements.FilterNameTypeSetPanel; -import forge.gui.deckeditor.elements.ManaCostRenderer; -import forge.gui.deckeditor.elements.TableColumnInfo; -import forge.gui.deckeditor.elements.TableView; -import forge.item.CardDb; -import forge.item.CardPrinted; -import forge.item.InventoryItem; -import forge.item.ItemPool; -import forge.util.closures.Lambda0; -import forge.util.closures.Predicate; -import net.miginfocom.swing.MigLayout; - -/** - *

- * Gui_DeckEditor class. - *

- * - * @author Forge - * @version $Id$ - */ -public final class DeckEditorConstructed extends DeckEditorBase { - /** Constant serialVersionUID=130339644136746796L. */ - private static final long serialVersionUID = 130339644136746796L; - - private final JButton removeButton = new JButton(); - private final JButton addButton = new JButton(); - private final JButton importButton = new JButton(); - - private final JButton analysisButton = new JButton(); - private final JButton clearFilterButton = new JButton(); - - private final JLabel jLabelAnalysisGap = new JLabel(""); - private FilterNameTypeSetPanel filterNameTypeSet; - - private final DeckController controller; - - /** - * Show. - * - * @param exitCommand - * the exit command - */ - @Override - public void show(final Command exitCommand) { - final Command exit = new Command() { - private static final long serialVersionUID = 5210924838133689758L; - - @Override - public void execute() { - DeckEditorConstructed.this.dispose(); - if (exitCommand != null) { - exitCommand.execute(); - } - } - }; - - final MenuCommon menu = new MenuCommon(this.getController(), exit); - this.setJMenuBar(menu); - - // do not change this!!!! - this.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent ev) { - menu.close(); - } - }); - - this.setup(); - - this.controller.newModel(); - - this.getTopTableWithCards().sort(1, true); - this.getBottomTableWithCards().sort(1, true); - - } // show(Command) - - private void setup() { - final List> columns = new ArrayList>(); - columns.add(new TableColumnInfo("Qty", 30, PresetColumns.FN_QTY_COMPARE, - PresetColumns.FN_QTY_GET)); - columns.add(new TableColumnInfo("Name", 175, PresetColumns.FN_NAME_COMPARE, - PresetColumns.FN_NAME_GET)); - columns.add(new TableColumnInfo("Cost", 75, PresetColumns.FN_COST_COMPARE, - PresetColumns.FN_COST_GET)); - columns.add(new TableColumnInfo("Color", 60, PresetColumns.FN_COLOR_COMPARE, - PresetColumns.FN_COLOR_GET)); - columns.add(new TableColumnInfo("Type", 100, PresetColumns.FN_TYPE_COMPARE, - PresetColumns.FN_TYPE_GET)); - columns.add(new TableColumnInfo("Stats", 60, PresetColumns.FN_STATS_COMPARE, - PresetColumns.FN_STATS_GET)); - columns.add(new TableColumnInfo("R", 25, PresetColumns.FN_RARITY_COMPARE, - PresetColumns.FN_RARITY_GET)); - columns.add(new TableColumnInfo("Set", 40, PresetColumns.FN_SET_COMPARE, - PresetColumns.FN_SET_GET)); - columns.add(new TableColumnInfo("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE, - PresetColumns.FN_AI_STATUS_GET)); - columns.get(2).setCellRenderer(new ManaCostRenderer()); - - this.getTopTableWithCards().setup(columns, this.getCardView()); - this.getBottomTableWithCards().setup(columns, this.getCardView()); - - this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay()); - - this.setSize(1024, 740); - } - - /** - * Instantiates a new deck editor common. - * - * @param parent the parent frame for this deck editor instance - */ - public DeckEditorConstructed(JFrame parent) { - super(parent); - try { - this.setFilterBoxes(new FilterCheckBoxes(true)); - this.setTopTableWithCards(new TableView("Available Cards", true, true, CardPrinted.class)); - this.setBottomTableWithCards(new TableView("Deck", true, CardPrinted.class)); - this.setCardView(new CardPanelHeavy()); - this.filterNameTypeSet = new FilterNameTypeSetPanel(); - - this.jbInit(); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - } - - final Lambda0 newCreator = new Lambda0() { - @Override - public Deck apply() { - return new Deck(); - } - }; - this.controller = new DeckController(Singletons.getModel().getDecks().getConstructed(), this, newCreator); - } - - private void jbInit() { - - final Font fButtons = new java.awt.Font("Dialog", 0, 13); - this.removeButton.setFont(fButtons); - this.addButton.setFont(fButtons); - this.importButton.setFont(fButtons); - this.clearFilterButton.setFont(fButtons); - this.analysisButton.setFont(fButtons); - - this.addButton.setText("Add to Deck"); - this.removeButton.setText("Remove from Deck"); - this.importButton.setText("Import a Deck"); - this.clearFilterButton.setText("Clear Filter"); - this.analysisButton.setText("Deck Analysis"); - - this.removeButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorConstructed.this.removeButtonClicked(e); - } - }); - this.addButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorConstructed.this.addButtonActionPerformed(e); - } - }); - this.importButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorConstructed.this.importButtonActionPerformed(e); - } - }); - this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorConstructed.this.clearFilterButtonActionPerformed(e); - } - }); - this.analysisButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorConstructed.this.analysisButtonActionPerformed(e); - } - }); - - // Type filtering - final Font f = new Font("Tahoma", Font.PLAIN, 10); - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - box.setFont(f); - box.setOpaque(false); - } - - // Color filtering - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - box.setOpaque(false); - } - - // Do not lower statsLabel any lower, we want this to be visible at 1024 - // x 768 screen size - this.setTitle("Deck Editor"); - - final Container content = this.getContentPane(); - final MigLayout layout = new MigLayout("fill"); - content.setLayout(layout); - - boolean isFirst = true; - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - String growParameter = "grow"; - if (isFirst) { - growParameter = "cell 0 0, egx checkbox, grow, split 14"; - isFirst = false; - } - content.add(box, growParameter); - box.addItemListener(this.getItemListenerUpdatesDisplay()); - } - - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - content.add(box, "grow"); - box.addItemListener(this.getItemListenerUpdatesDisplay()); - } - - content.add(this.clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow"); - - content.add(this.filterNameTypeSet, "cell 0 1, grow"); - content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, push, grow"); - content.add(this.getTopTableWithCards().getLabel(), "cell 0 4"); - - content.add(this.addButton, "w 100, h 49, sg button, cell 0 5, split 5"); - content.add(this.removeButton, "w 100, h 49, sg button"); - content.add(this.importButton, "w 100, h 49, sg button, gapleft 40px"); - // Label is used to push the analysis button to the right to separate - // analysis button from add/remove card ones - content.add(this.jLabelAnalysisGap, "wmin 75, growx"); - content.add(this.analysisButton, "w 100, h 49, wrap"); - - content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow"); - content.add(this.getBottomTableWithCards().getLabel(), "cell 0 7"); - - content.add(this.getCardView(), "cell 1 0 1 8, flowy, grow"); - - this.getTopTableWithCards().getTable().addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - if (e.getClickCount() == 2) { - DeckEditorConstructed.this.addCardToDeck(); - } - } - }); - this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(final KeyEvent e) { - if (e.getKeyChar() == ' ') { - DeckEditorConstructed.this.addCardToDeck(); - } - } - }); - - // javax.swing.JRootPane rootPane = this.getRootPane(); - // rootPane.setDefaultButton(filterButton); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#buildFilter() - */ - @Override - protected Predicate buildFilter() { - final Predicate cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(), - this.filterNameTypeSet.buildFilter()); - return Predicate.instanceOf(cardFilter, CardPrinted.class); - } - - /** - * Clear filter button_action performed. - * - * @param e - * the e - */ - void clearFilterButtonActionPerformed(final ActionEvent e) { - // disable automatic update triggered by listeners - this.setFiltersChangeFiringUpdate(false); - - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - if (!box.isSelected()) { - box.doClick(); - } - } - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - if (!box.isSelected()) { - box.doClick(); - } - } - - this.filterNameTypeSet.clearFilters(); - - this.setFiltersChangeFiringUpdate(true); - - this.getTopTableWithCards().setFilter(null); - } - - /** - * Adds the button_action performed. - * - * @param e - * the e - */ - void addButtonActionPerformed(final ActionEvent e) { - this.addCardToDeck(); - } - - /** - * Adds the card to deck. - */ - void addCardToDeck() { - final InventoryItem item = this.getTopTableWithCards().getSelectedCard(); - if ((item == null) || !(item instanceof CardPrinted)) { - return; - } - - final CardPrinted card = (CardPrinted) item; - this.getBottomTableWithCards().addCard(card); - this.controller.notifyModelChanged(); - } - - /** - * Removes the button clicked. - * - * @param e - * the e - */ - void removeButtonClicked(final ActionEvent e) { - final InventoryItem item = this.getBottomTableWithCards().getSelectedCard(); - if ((item == null) || !(item instanceof CardPrinted)) { - return; - } - - final CardPrinted card = (CardPrinted) item; - this.getBottomTableWithCards().removeCard(card); - this.controller.notifyModelChanged(); - } - - /** - * Import button_action performed. - * - * @param e - * the e - */ - void importButtonActionPerformed(final ActionEvent e) { - final DeckEditorConstructed g = this; - final DeckImport dImport = new DeckImport(g); - dImport.setModalityType(ModalityType.APPLICATION_MODAL); - dImport.setVisible(true); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#updateView() - */ - @Override - public void updateView() { - // if constructed, can add the all cards above - this.getTopTableWithCards().setDeck(ItemPool.createFrom(CardDb.instance().getAllCards(), CardPrinted.class)); - this.getBottomTableWithCards().setDeck(this.controller.getModel().getMain()); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#getController() - */ - @Override - public DeckController getController() { - return this.controller; - } - -} diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorLimited.java b/src/main/java/forge/gui/deckeditor/DeckEditorLimited.java deleted file mode 100644 index c96551c0b56..00000000000 --- a/src/main/java/forge/gui/deckeditor/DeckEditorLimited.java +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import java.awt.Container; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.List; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFrame; -import javax.swing.JLabel; - -import forge.Command; -import forge.deck.Deck; -import forge.deck.DeckGroup; -import forge.error.ErrorViewer; -import forge.gui.deckeditor.elements.CardPanelHeavy; -import forge.gui.deckeditor.elements.FilterCheckBoxes; -import forge.gui.deckeditor.elements.FilterNameTypeSetPanel; -import forge.gui.deckeditor.elements.ManaCostRenderer; -import forge.gui.deckeditor.elements.TableColumnInfo; -import forge.gui.deckeditor.elements.TableView; -import forge.item.CardPrinted; -import forge.item.InventoryItem; -import forge.util.IStorage; -import forge.util.closures.Lambda0; -import forge.util.closures.Predicate; -import net.miginfocom.swing.MigLayout; - -/** - *

- * Gui_DeckEditor class. - *

- * - * @author Forge - * @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $ - */ -public final class DeckEditorLimited extends DeckEditorBase { - /** Constant serialVersionUID=130339644136746796L. */ - private static final long serialVersionUID = 130339644136746796L; - - private final JButton removeButton = new JButton(); - private final JButton addButton = new JButton(); - - private final JButton analysisButton = new JButton(); - private final JButton clearFilterButton = new JButton(); - - private final JLabel jLabelAnalysisGap = new JLabel(""); - private FilterNameTypeSetPanel filterNameTypeSet; - - private final DeckController controller; - - /** - * Show. - * - * @param exitCommand - * the exit command - */ - @Override - public void show(final Command exitCommand) { - final Command exit = new Command() { - private static final long serialVersionUID = 5210924838133689758L; - - @Override - public void execute() { - DeckEditorLimited.this.dispose(); - if (exitCommand != null) { - exitCommand.execute(); - } - } - }; - - final MenuLimited menu = new MenuLimited(this.getController(), exit); - - this.setJMenuBar(menu); - - // do not change this!!!! - this.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent ev) { - menu.close(); - } - }); - - this.setup(); - - this.getTopTableWithCards().sort(1, true); - this.getBottomTableWithCards().sort(1, true); - - } // show(Command) - - private void setup() { - final List> columns = new ArrayList>(); - columns.add(new TableColumnInfo("Qty", 30, PresetColumns.FN_QTY_COMPARE, - PresetColumns.FN_QTY_GET)); - columns.add(new TableColumnInfo("Name", 175, PresetColumns.FN_NAME_COMPARE, - PresetColumns.FN_NAME_GET)); - columns.add(new TableColumnInfo("Cost", 75, PresetColumns.FN_COST_COMPARE, - PresetColumns.FN_COST_GET)); - columns.add(new TableColumnInfo("Color", 60, PresetColumns.FN_COLOR_COMPARE, - PresetColumns.FN_COLOR_GET)); - columns.add(new TableColumnInfo("Type", 100, PresetColumns.FN_TYPE_COMPARE, - PresetColumns.FN_TYPE_GET)); - columns.add(new TableColumnInfo("Stats", 60, PresetColumns.FN_STATS_COMPARE, - PresetColumns.FN_STATS_GET)); - columns.add(new TableColumnInfo("R", 25, PresetColumns.FN_RARITY_COMPARE, - PresetColumns.FN_RARITY_GET)); - columns.add(new TableColumnInfo("Set", 40, PresetColumns.FN_SET_COMPARE, - PresetColumns.FN_SET_GET)); - columns.add(new TableColumnInfo("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE, - PresetColumns.FN_AI_STATUS_GET)); - columns.get(2).setCellRenderer(new ManaCostRenderer()); - - this.getTopTableWithCards().setup(columns, this.getCardView()); - this.getBottomTableWithCards().setup(columns, this.getCardView()); - - this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay()); - - this.setSize(1024, 740); - } - - /** - * Instantiates a new deck editor common. - * - * @param mainFrame the parent frame for this deck editor instance - * @param deckMap the deck map - */ - public DeckEditorLimited(JFrame mainFrame, final IStorage deckMap) { - super(mainFrame); - try { - this.setFilterBoxes(new FilterCheckBoxes(true)); - this.setTopTableWithCards(new TableView("Avaliable Cards", true, true, CardPrinted.class)); - this.setBottomTableWithCards(new TableView("Deck", true, CardPrinted.class)); - this.setCardView(new CardPanelHeavy()); - this.filterNameTypeSet = new FilterNameTypeSetPanel(); - - this.jbInit(); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - } - - final Lambda0 newCreator = new Lambda0() { - @Override - public DeckGroup apply() { - return new DeckGroup(""); - } - }; - this.controller = new DeckController(deckMap, this, newCreator); - } - - private void jbInit() { - - final Font fButtons = new java.awt.Font("Dialog", 0, 13); - this.removeButton.setFont(fButtons); - this.addButton.setFont(fButtons); - this.clearFilterButton.setFont(fButtons); - this.analysisButton.setFont(fButtons); - - this.addButton.setText("Add to Deck"); - this.removeButton.setText("Remove from Deck"); - this.clearFilterButton.setText("Clear Filter"); - this.analysisButton.setText("Deck Analysis"); - - this.removeButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorLimited.this.removeButtonClicked(e); - } - }); - this.addButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorLimited.this.addButtonActionPerformed(e); - } - }); - this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorLimited.this.clearFilterButtonActionPerformed(e); - } - }); - this.analysisButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorLimited.this.analysisButtonActionPerformed(e); - } - }); - - // Type filtering - final Font f = new Font("Tahoma", Font.PLAIN, 10); - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - box.setFont(f); - box.setOpaque(false); - } - - // Color filtering - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - box.setOpaque(false); - } - - // Do not lower statsLabel any lower, we want this to be visible at 1024 - // x 768 screen size - this.setTitle("Deck Editor"); - - final Container content = this.getContentPane(); - final MigLayout layout = new MigLayout("fill"); - content.setLayout(layout); - - boolean isFirst = true; - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - String growParameter = "grow"; - if (isFirst) { - growParameter = "cell 0 0, egx checkbox, grow, split 14"; - isFirst = false; - } - content.add(box, growParameter); - box.addItemListener(this.getItemListenerUpdatesDisplay()); - } - - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - content.add(box, "grow"); - box.addItemListener(this.getItemListenerUpdatesDisplay()); - } - - content.add(this.clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow"); - - content.add(this.filterNameTypeSet, "cell 0 1, grow"); - content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, push, grow"); - content.add(this.getTopTableWithCards().getLabel(), "cell 0 4"); - - content.add(this.addButton, "w 100, h 49, sg button, cell 0 5, split 5"); - content.add(this.removeButton, "w 100, h 49, sg button"); - // Label is used to push the analysis button to the right to separate - // analysis button from add/remove card ones - content.add(this.jLabelAnalysisGap, "wmin 75, growx"); - content.add(this.analysisButton, "w 100, h 49, wrap"); - - content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow"); - content.add(this.getBottomTableWithCards().getLabel(), "cell 0 7"); - - content.add(this.getCardView(), "cell 1 0 1 8, flowy, grow"); - - this.getTopTableWithCards().getTable().addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - if (e.getClickCount() == 2) { - DeckEditorLimited.this.addCardToDeck(); - } - } - }); - this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(final KeyEvent e) { - if (e.getKeyChar() == ' ') { - DeckEditorLimited.this.addCardToDeck(); - } - } - }); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#buildFilter() - */ - @Override - protected Predicate buildFilter() { - final Predicate cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(), - this.filterNameTypeSet.buildFilter()); - return Predicate.instanceOf(cardFilter, CardPrinted.class); - } - - /** - * Clear filter button_action performed. - * - * @param e - * the e - */ - void clearFilterButtonActionPerformed(final ActionEvent e) { - // disable automatic update triggered by listeners - this.setFiltersChangeFiringUpdate(false); - - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - if (!box.isSelected()) { - box.doClick(); - } - } - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - if (!box.isSelected()) { - box.doClick(); - } - } - - this.filterNameTypeSet.clearFilters(); - - this.setFiltersChangeFiringUpdate(true); - - this.getTopTableWithCards().setFilter(null); - } - - /** - * Adds the button_action performed. - * - * @param e - * the e - */ - void addButtonActionPerformed(final ActionEvent e) { - this.addCardToDeck(); - } - - /** - * Adds the card to deck. - */ - void addCardToDeck() { - final InventoryItem item = this.getTopTableWithCards().getSelectedCard(); - if ((item == null) || !(item instanceof CardPrinted)) { - return; - } - - // update view - final CardPrinted card = (CardPrinted) item; - this.getBottomTableWithCards().addCard(card); - this.getTopTableWithCards().removeCard(card); - - /* - * update model Deck model = - * getSelectedDeck(getController().getModel()); - * model.getMain().add(card); model.getSideboard().remove(card); - */ - - this.getController().notifyModelChanged(); - } - - /** - * TODO: Write javadoc for this method. - * - * @param model - * @return - */ - private Deck getSelectedDeck(final DeckGroup model) { - return model.getHumanDeck(); - } - - /** - * Removes the button clicked. - * - * @param e - * the e - */ - void removeButtonClicked(final ActionEvent e) { - final InventoryItem item = this.getBottomTableWithCards().getSelectedCard(); - if ((item == null) || !(item instanceof CardPrinted)) { - return; - } - - // update view - final CardPrinted card = (CardPrinted) item; - this.getBottomTableWithCards().removeCard(card); - this.getTopTableWithCards().addCard(card); - - /* - * update model Deck model = - * getSelectedDeck(getController().getModel()); - * model.getMain().remove(card); model.getSideboard().add(card); - */ - - this.getController().notifyModelChanged(); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#getController() - */ - @Override - public DeckController getController() { - return this.controller; - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#updateView() - */ - @Override - public void updateView() { - Deck toEdit = this.getSelectedDeck(this.controller.getModel()); - this.getTopTableWithCards().setDeck(toEdit.getSideboard()); - this.getBottomTableWithCards().setDeck(toEdit.getMain()); - } - -} diff --git a/src/main/java/forge/gui/deckeditor/DeckEditorQuest.java b/src/main/java/forge/gui/deckeditor/DeckEditorQuest.java deleted file mode 100644 index dac5ef7edd6..00000000000 --- a/src/main/java/forge/gui/deckeditor/DeckEditorQuest.java +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -// import java.awt.Font; -import java.awt.Container; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.List; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JLabel; -import javax.swing.JFrame; -import javax.swing.WindowConstants; - -import forge.Command; -import forge.Constant; -import forge.deck.Deck; -import forge.error.ErrorViewer; -import forge.gui.deckeditor.elements.CardPanelHeavy; -import forge.gui.deckeditor.elements.FilterCheckBoxes; -import forge.gui.deckeditor.elements.FilterNameTypeSetPanel; -import forge.gui.deckeditor.elements.ManaCostRenderer; -import forge.gui.deckeditor.elements.TableColumnInfo; -import forge.gui.deckeditor.elements.TableView; -import forge.item.CardPrinted; -import forge.item.InventoryItem; -import forge.item.ItemPool; -import forge.quest.QuestController; -import forge.util.closures.Lambda0; -import forge.util.closures.Predicate; -import net.miginfocom.swing.MigLayout; - -//import forge.quest.data.QuestBoosterPack; - -/** - *

- * Gui_Quest_DeckEditor class. - *

- * - * @author Forge - * @version $Id$ - */ -public final class DeckEditorQuest extends DeckEditorBase { - /** Constant serialVersionUID=152061168634545L. */ - private static final long serialVersionUID = 152061168634545L; - - /** The custom menu. */ - private final JButton clearFilterButton = new JButton(); - private final JButton addButton = new JButton(); - private final JButton removeButton = new JButton(); - private final JLabel jLabelAnalysisGap = new JLabel(""); - private final JButton analysisButton = new JButton(); - - private FilterNameTypeSetPanel filterNameTypeSet; - - private final QuestController questData; - private final DeckController controller; - - /** - * Show. - * - * @param exitCommand - * the exit command - */ - @Override - public void show(final Command exitCommand) { - final Command exit = new Command() { - private static final long serialVersionUID = -7428793574300520612L; - - @Override - public void execute() { - DeckEditorQuest.this.dispose(); - exitCommand.execute(); - } - }; - - this.setup(); - - final MenuQuest menu = new MenuQuest(this.getController(), exit); - this.setJMenuBar(menu); - - // do not change this!!!! - this.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent ev) { - menu.close(); - } - }); - - Deck deck = Constant.Runtime.HUMAN_DECK[0] == null ? null : this.questData.getMyDecks().get( - Constant.Runtime.HUMAN_DECK[0].getName()); - - if (deck == null) { - deck = new Deck(); - } - - // tell Gui_Quest_DeckEditor the name of the deck - - this.getController().setModel(deck); - - // this affects the card pool - this.getTopTableWithCards().sort(4, true); // sort by type - this.getTopTableWithCards().sort(3, true); // then sort by color - this.getBottomTableWithCards().sort(1, true); - } // show(Command) - - /** - *

- * setup. - *

- */ - public void setup() { - final List> columns = new ArrayList>(); - columns.add(new TableColumnInfo("Qty", 30, PresetColumns.FN_QTY_COMPARE, - PresetColumns.FN_QTY_GET)); - columns.add(new TableColumnInfo("Name", 180, PresetColumns.FN_NAME_COMPARE, - PresetColumns.FN_NAME_GET)); - columns.add(new TableColumnInfo("Cost", 70, PresetColumns.FN_COST_COMPARE, - PresetColumns.FN_COST_GET)); - columns.add(new TableColumnInfo("Color", 50, PresetColumns.FN_COLOR_COMPARE, - PresetColumns.FN_COLOR_GET)); - columns.add(new TableColumnInfo("Type", 100, PresetColumns.FN_TYPE_COMPARE, - PresetColumns.FN_TYPE_GET)); - columns.add(new TableColumnInfo("Stats", 40, PresetColumns.FN_STATS_COMPARE, - PresetColumns.FN_STATS_GET)); - columns.add(new TableColumnInfo("R", 35, PresetColumns.FN_RARITY_COMPARE, - PresetColumns.FN_RARITY_GET)); - columns.add(new TableColumnInfo("Set", 40, PresetColumns.FN_SET_COMPARE, - PresetColumns.FN_SET_GET)); - columns.add(new TableColumnInfo("New", 30, this.questData.getCards().getFnNewCompare(), - this.questData.getCards().getFnNewGet())); - - columns.get(2).setCellRenderer(new ManaCostRenderer()); - - this.getTopTableWithCards().setup(columns, this.getCardView()); - this.getBottomTableWithCards().setup(columns, this.getCardView()); - - this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay()); - - setSize(1024, 740); - } - - /** - * Instantiates a new deck editor quest. - * - * @param parent - * the parent frame for this deck editor instance - * @param questData2 - * the quest data2 - */ - public DeckEditorQuest(JFrame parent, final QuestController questData2) { - super(parent); - this.questData = questData2; - try { - this.setFilterBoxes(new FilterCheckBoxes(true)); - this.setTopTableWithCards(new TableView("All Cards", true, true, CardPrinted.class)); - this.setBottomTableWithCards(new TableView("Your deck", true, CardPrinted.class)); - this.setCardView(new CardPanelHeavy()); - this.filterNameTypeSet = new FilterNameTypeSetPanel(); - this.jbInit(); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - } - - final Lambda0 newCreator = new Lambda0() { - @Override - public Deck apply() { - return new Deck(); - } - }; - this.controller = new DeckController(questData2.getMyDecks(), this, newCreator); - } - - private void jbInit() throws Exception { - - this.setTitle("Deck Editor"); - this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - - final Font fButtons = new java.awt.Font("Dialog", 0, 13); - this.removeButton.setFont(fButtons); - this.addButton.setFont(fButtons); - this.clearFilterButton.setFont(fButtons); - this.analysisButton.setFont(fButtons); - - this.addButton.setText("Add to Deck"); - this.removeButton.setText("Remove from Deck"); - this.clearFilterButton.setText("Clear Filter"); - this.analysisButton.setText("Deck Analysis"); - - this.removeButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorQuest.this.removeButtonActionPerformed(e); - } - }); - this.addButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorQuest.this.addButtonActionPerformed(e); - } - }); - this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorQuest.this.clearFilterButtonActionPerformed(e); - } - }); - this.analysisButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckEditorQuest.this.analysisButtonActionPerformed(e); - } - }); - - // Type filtering - final Font f = new Font("Tahoma", Font.PLAIN, 10); - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - box.setFont(f); - box.setOpaque(false); - } - - // Color filtering - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - box.setOpaque(false); - } - - final Container content = this.getContentPane(); - final MigLayout layout = new MigLayout("fill"); - content.setLayout(layout); - - boolean isFirst = true; - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - String growParameter = "grow"; - if (isFirst) { - growParameter = "cell 0 0, egx checkbox, grow, split 14"; - isFirst = false; - } - content.add(box, growParameter); - box.addItemListener(this.getItemListenerUpdatesDisplay()); - } - - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - content.add(box, "grow"); - box.addItemListener(this.getItemListenerUpdatesDisplay()); - } - - content.add(this.clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow"); - - content.add(this.filterNameTypeSet, "cell 0 1, grow"); - content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, push, grow"); - content.add(this.getTopTableWithCards().getLabel(), "cell 0 4"); - - content.add(this.addButton, "w 100, h 49, sg button, cell 0 5, split 5"); - content.add(this.removeButton, "w 100, h 49, sg button"); - - content.add(this.jLabelAnalysisGap, "wmin 75, growx"); - content.add(this.analysisButton, "w 100, h 49, wrap"); - - content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow"); - content.add(this.getBottomTableWithCards().getLabel(), "cell 0 7"); - - content.add(this.getCardView(), "cell 1 0 1 8, flowy, growy"); - - this.getTopTableWithCards().getTable().addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - if (e.getClickCount() == 2) { - DeckEditorQuest.this.addCardToDeck(); - } - } - }); - this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(final KeyEvent e) { - if (e.getKeyChar() == ' ') { - DeckEditorQuest.this.addCardToDeck(); - } - } - }); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#buildFilter() - */ - @Override - protected Predicate buildFilter() { - final Predicate cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(), - this.filterNameTypeSet.buildFilter()); - return Predicate.instanceOf(cardFilter, CardPrinted.class); - } - - private void addButtonActionPerformed(final ActionEvent e) { - addCardToDeck(); - } - - /** - * Clear filter button_action performed. - * - * @param e - * the e - */ - void clearFilterButtonActionPerformed(final ActionEvent e) { - // disable automatic update triggered by listeners - this.setFiltersChangeFiringUpdate(false); - - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - if (!box.isSelected()) { - box.doClick(); - } - } - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - if (!box.isSelected()) { - box.doClick(); - } - } - - this.filterNameTypeSet.clearFilters(); - - this.setFiltersChangeFiringUpdate(true); - - this.getTopTableWithCards().setFilter(null); - } - - /** - * Adds the card to deck. - */ - void addCardToDeck() { - final InventoryItem item = this.getTopTableWithCards().getSelectedCard(); - if ((item == null) || !(item instanceof CardPrinted)) { - return; - } - - final CardPrinted card = (CardPrinted) item; - this.getTopTableWithCards().removeCard(card); - this.getBottomTableWithCards().addCard(card); - this.controller.notifyModelChanged(); - } - - private void removeButtonActionPerformed(final ActionEvent e) { - final InventoryItem item = this.getBottomTableWithCards().getSelectedCard(); - if ((item == null) || !(item instanceof CardPrinted)) { - return; - } - - final CardPrinted card = (CardPrinted) item; - this.getTopTableWithCards().addCard(card); - this.getBottomTableWithCards().removeCard(card); - } - - /** - * Adds the cheat card. - * - * @param card - * the card - */ - public void addCheatCard(final CardPrinted card) { - this.getTopTableWithCards().addCard(card); - this.questData.getCards().getCardpool().add(card); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#getController() - */ - @Override - public DeckController getController() { - return this.controller; - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#updateView() - */ - @Override - public void updateView() { - final Deck deck = this.controller.getModel(); - - final ItemPool cardpool = new ItemPool(CardPrinted.class); - cardpool.addAll(this.questData.getCards().getCardpool()); - // remove bottom cards that are in the deck from the card pool - cardpool.removeAll(deck.getMain()); - // show cards, makes this user friendly - this.getTopTableWithCards().setDeck(cardpool); - this.getBottomTableWithCards().setDeck(deck.getMain()); - } - -} diff --git a/src/main/java/forge/gui/deckeditor/DeckImport.java b/src/main/java/forge/gui/deckeditor/DeckImport.java index 2e5ff3060a2..a5d9880caf5 100644 --- a/src/main/java/forge/gui/deckeditor/DeckImport.java +++ b/src/main/java/forge/gui/deckeditor/DeckImport.java @@ -41,15 +41,22 @@ import javax.swing.text.ElementIterator; import net.miginfocom.swing.MigLayout; import forge.deck.Deck; +import forge.deck.DeckBase; import forge.deck.DeckRecognizer; import forge.deck.DeckRecognizer.TokenType; import forge.gui.GuiUtils; +import forge.gui.deckeditor.controllers.ACEditorBase; import forge.item.CardPrinted; +import forge.item.InventoryItem; /** + * * Dialog for quick import of decks. + * + * @param + * @param */ -public class DeckImport extends JDialog { +public class DeckImport extends JDialog { private static final long serialVersionUID = -5837776824284093004L; private final JTextArea txtInput = new JTextArea(); @@ -83,7 +90,7 @@ public class DeckImport extends JDialog { /** The tokens. */ private final List tokens = new ArrayList(); - private final DeckEditorConstructed host; + private final ACEditorBase host; /** * Instantiates a new deck import. @@ -91,7 +98,7 @@ public class DeckImport extends JDialog { * @param g * the g */ - public DeckImport(final DeckEditorConstructed g) { + public DeckImport(final ACEditorBase g) { this.host = g; final int wWidth = 600; @@ -136,6 +143,7 @@ public class DeckImport extends JDialog { }); this.cmdAccept.addActionListener(new ActionListener() { + @SuppressWarnings("unchecked") @Override public void actionPerformed(final ActionEvent e) { final String warning = "This will replace contents of your currently open deck with whatever you are importing. Proceed?"; @@ -145,7 +153,7 @@ public class DeckImport extends JDialog { return; } final Deck toSet = DeckImport.this.buildDeck(); - DeckImport.this.host.getController().setModel(toSet); + DeckImport.this.host.getDeckController().setModel((TModel) toSet); DeckImport.this.processWindowEvent(new WindowEvent(DeckImport.this, WindowEvent.WINDOW_CLOSING)); } }); diff --git a/src/main/java/forge/gui/deckeditor/DraftingProcess.java b/src/main/java/forge/gui/deckeditor/DraftingProcess.java deleted file mode 100644 index 28ce286948a..00000000000 --- a/src/main/java/forge/gui/deckeditor/DraftingProcess.java +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import java.awt.Rectangle; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.InputEvent; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.List; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JOptionPane; -import javax.swing.JTable; -import javax.swing.WindowConstants; - -import forge.Command; -import forge.Constant; -import forge.Singletons; -import forge.deck.Deck; -import forge.deck.DeckGroup; -import forge.error.ErrorViewer; -import forge.game.limited.IBoosterDraft; -import forge.gui.GuiUtils; -import forge.gui.SOverlayUtils; -import forge.gui.deckeditor.elements.CardPanelLite; -import forge.gui.deckeditor.elements.ManaCostRenderer; -import forge.gui.deckeditor.elements.TableColumnInfo; -import forge.gui.deckeditor.elements.TableView; -import forge.gui.home.sanctioned.CSubmenuDraft; -import forge.item.CardDb; -import forge.item.CardPrinted; -import forge.item.InventoryItem; -import forge.item.ItemPoolView; -import forge.properties.ForgeProps; -import forge.properties.NewConstants.Lang.GuiBoosterDraft; -import forge.util.closures.Predicate; - -/** - *

- * DeckEditorDraft class. - *

- * - * @author Forge - * @version $Id$ - */ -public class DraftingProcess extends DeckEditorBase { - /** - * Constant serialVersionUID=-6055633915602448260L. - */ - private static final long serialVersionUID = -6055633915602448260L; - - private IBoosterDraft boosterDraft; - - private final JButton jButtonPick = new JButton(); - - private CardPanelLite cardView = new CardPanelLite(); - - private final MouseListener pickWithMouse = new MouseAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - // Pick on left-button double click - if (((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) && (e.getClickCount() == 2)) { - DraftingProcess.this.jButtonPickClicked(null); - } else if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { - // pick on right click - final JTable table = DraftingProcess.this.getTopTableWithCards().getTable(); - final int rowNumber = table.rowAtPoint(e.getPoint()); - // after hittest - if it was outside of rows - discard this - // click - if (rowNumber == -1) { - return; - } - - // if row was not selected, select it. If it was, pick a card - if (rowNumber != table.getSelectedRow()) { - table.getSelectionModel().setSelectionInterval(rowNumber, rowNumber); - } else { - DraftingProcess.this.jButtonPickClicked(null); - } - } - } - }; - - /** - * Show gui. - * - * @param inBoosterDraft - * the in_booster draft - */ - public final void showGui(final IBoosterDraft inBoosterDraft) { - this.boosterDraft = inBoosterDraft; - this.show(null); - } - - /** - *

- * addListeners. - *

- */ - private void addListeners() { - this.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent ev) { - final int n = JOptionPane.showConfirmDialog(null, - ForgeProps.getLocalized(GuiBoosterDraft.CLOSE_MESSAGE), "", JOptionPane.YES_NO_OPTION); - if (n == JOptionPane.YES_OPTION) { - DraftingProcess.this.dispose(); - CSubmenuDraft.SINGLETON_INSTANCE.update(); - SOverlayUtils.hideOverlay(); - } - } // windowClosing() - }); - } // addListeners() - - /** - *

- * setup. - *

- */ - private void setup() { - this.addListeners(); - // setupMenu(); - - final List> columns = new ArrayList>(); - columns.add(new TableColumnInfo("Qty", 30, PresetColumns.FN_QTY_COMPARE, - PresetColumns.FN_QTY_GET)); - columns.add(new TableColumnInfo("Name", 180, PresetColumns.FN_NAME_COMPARE, - PresetColumns.FN_NAME_GET)); - columns.add(new TableColumnInfo("Cost", 70, PresetColumns.FN_COST_COMPARE, - PresetColumns.FN_COST_GET)); - columns.add(new TableColumnInfo("Color", 50, PresetColumns.FN_COLOR_COMPARE, - PresetColumns.FN_COLOR_GET)); - columns.add(new TableColumnInfo("Type", 100, PresetColumns.FN_TYPE_COMPARE, - PresetColumns.FN_TYPE_GET)); - columns.add(new TableColumnInfo("Stats", 40, PresetColumns.FN_STATS_COMPARE, - PresetColumns.FN_STATS_GET)); - columns.add(new TableColumnInfo("R", 35, PresetColumns.FN_RARITY_COMPARE, - PresetColumns.FN_RARITY_GET)); - columns.add(new TableColumnInfo("Set", 40, PresetColumns.FN_SET_COMPARE, - PresetColumns.FN_SET_GET)); - columns.add(new TableColumnInfo("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE, - PresetColumns.FN_AI_STATUS_GET)); - columns.get(2).setCellRenderer(new ManaCostRenderer()); - - this.getTopTableWithCards().setup(columns, this.cardView); - this.getBottomTableWithCards().setup(columns, this.cardView); - - this.setSize(980, 740); - GuiUtils.centerFrame(this); - this.setResizable(false); - - this.getTopTableWithCards().getTable().addMouseListener(this.pickWithMouse); - this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() { - @Override - public void keyPressed(final KeyEvent e) { - if (e.getKeyChar() == ' ') { - DraftingProcess.this.jButtonPickClicked(null); - } - } - }); - - } - - /** - * Instantiates a new deck editor draft. - */ - public DraftingProcess(JFrame parent) { - super(parent); - try { - this.setTopTableWithCards(new TableView("Choose one card", false, CardPrinted.class)); - this.setBottomTableWithCards(new TableView("Previously picked cards", true, CardPrinted.class)); - this.setFilterBoxes(null); - this.cardView = new CardPanelLite(); - this.jbInit(); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - } - } - - /** - *

- * jbInit. - *

- * - * @throws java.lang.Exception - * if any. - */ - private void jbInit() throws Exception { - this.getContentPane().setLayout(null); - - this.getTopTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 28, 680, 344)); - this.getBottomTableWithCards().getTableDecorated().setBounds(new Rectangle(19, 478, 680, 184)); - this.getBottomTableWithCards().getLabel().setBounds(new Rectangle(19, 680, 665, 31)); - - this.cardView.setBounds(new Rectangle(715, 23, 240, 666)); - - this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - this.setTitle("Booster Draft"); - - this.jButtonPick.setBounds(new Rectangle(238, 418, 147, 44)); - this.jButtonPick.setFont(new java.awt.Font("Dialog", 0, 16)); - this.jButtonPick.setText("Choose Card"); - this.jButtonPick.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DraftingProcess.this.jButtonPickClicked(e); - } - }); - - this.getContentPane().add(this.cardView, null); - this.getContentPane().add(this.getTopTableWithCards().getTableDecorated(), null); - this.getContentPane().add(this.getBottomTableWithCards().getLabel(), null); - this.getContentPane().add(this.getBottomTableWithCards().getTableDecorated(), null); - this.getContentPane().add(this.jButtonPick, null); - } - - /** - *

- * jButton1_actionPerformed. - *

- * - * @param e - * a {@link java.awt.event.ActionEvent} object. - */ - final void jButtonPickClicked(final ActionEvent e) { - final InventoryItem item = this.getTopTableWithCards().getSelectedCard(); - if ((item == null) || !(item instanceof CardPrinted)) { - return; - } - - final CardPrinted card = (CardPrinted) item; - - this.getBottomTableWithCards().addCard(card); - - // get next booster pack - this.boosterDraft.setChoice(card); - if (this.boosterDraft.hasNextChoice()) { - this.showChoices(this.boosterDraft.nextChoice()); - } else { - this.boosterDraft.finishedDrafting(); - - // quit - this.saveDraft(); - this.dispose(); - } - } /* OK Button */ - - /** - *

- * showChoices. - *

- * - * @param list - * a {@link forge.CardList} object. - */ - private void showChoices(final ItemPoolView list) { - this.getTopTableWithCards().setDeck(list); - this.cardView.showCard(null); - this.getTopTableWithCards().fixSelection(0); - } // showChoices() - - /** - *

- * getPlayersDeck. - *

- * - * @return a {@link forge.deck.Deck} object. - */ - private Deck getPlayersDeck() { - final Deck deck = new Deck(); - Constant.Runtime.HUMAN_DECK[0] = deck; - - // add sideboard to deck - deck.getSideboard().addAll(this.getBottomTableWithCards().getCards()); - - final String landSet = IBoosterDraft.LAND_SET_CODE[0]; - final int landsCount = 20; - deck.getSideboard().add(CardDb.instance().getCard("Forest", landSet), landsCount); - deck.getSideboard().add(CardDb.instance().getCard("Mountain", landSet), landsCount); - deck.getSideboard().add(CardDb.instance().getCard("Swamp", landSet), landsCount); - deck.getSideboard().add(CardDb.instance().getCard("Island", landSet), landsCount); - deck.getSideboard().add(CardDb.instance().getCard("Plains", landSet), landsCount); - - return deck; - } // getPlayersDeck() - - /** - *

- * saveDraft. - *

- */ - private void saveDraft() { - String s = ""; - while ((s == null) || (s.length() == 0)) { - s = JOptionPane.showInputDialog(null, ForgeProps.getLocalized(GuiBoosterDraft.SAVE_DRAFT_MESSAGE), - ForgeProps.getLocalized(GuiBoosterDraft.SAVE_DRAFT_TITLE), JOptionPane.QUESTION_MESSAGE); - } - // TODO: check if overwriting the same name, and let the user delete old - // drafts - - // construct computer's decks - // save draft - final Deck[] computer = this.boosterDraft.getDecks(); - - final DeckGroup finishedDraft = new DeckGroup(s); - finishedDraft.setHumanDeck((Deck) this.getPlayersDeck().copyTo(s)); - finishedDraft.addAiDecks(computer); - - // DeckManager deckManager = new - // DeckManager(ForgeProps.getFile(NEW_DECKS)); - Singletons.getModel().getDecks().getDraft().add(finishedDraft); // write - // file - // right - // here - - // close and open next screen - DraftingProcess.this.dispose(); - - // This should be handled in the exit command of the editor, not here. - CSubmenuDraft.SINGLETON_INSTANCE.update(); - SOverlayUtils.hideOverlay(); - } /* saveDraft() */ - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#buildFilter() - */ - @Override - protected final Predicate buildFilter() { - return Predicate.getTrue(CardPrinted.class); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#getController() - */ - @Override - public DeckController getController() { - return null; - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#updateView() - */ - @Override - public void updateView() { - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#show(forge.Command) - */ - @Override - public void show(final Command exitCommand) { - this.setup(); - this.showChoices(this.boosterDraft.nextChoice()); - this.getBottomTableWithCards().setDeck((Iterable) null); - - this.getTopTableWithCards().sort(1, true); - this.getBottomTableWithCards().sort(1, true); - - this.setVisible(true); - } -} diff --git a/src/main/java/forge/gui/deckeditor/MenuBase.java b/src/main/java/forge/gui/deckeditor/MenuBase.java deleted file mode 100644 index bc04ef9e7bc..00000000000 --- a/src/main/java/forge/gui/deckeditor/MenuBase.java +++ /dev/null @@ -1,454 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.List; - -import javax.swing.JMenu; -import javax.swing.JMenuBar; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; - -import org.apache.commons.lang3.StringUtils; - -import forge.Command; -import forge.deck.DeckBase; -import forge.error.ErrorViewer; -import forge.gui.GuiUtils; - -/** - *

- * Gui_DeckEditor_Menu class. - *

- * - * @param the generic type - * @author Forge - * @version $Id: DeckEditorCommonMenu.java 13590 2012-01-27 20:46:27Z Max mtg $ - */ -public class MenuBase extends JMenuBar { - - private static final long serialVersionUID = -4037993759604768755L; - private final Command exitCommand; - private final DeckController controller; - - /** - * Menu for Deck Editor. - * - * @param ctrl the ctrl - * @param exit a Command - */ - public MenuBase(final DeckController ctrl, final Command exit) { - this.controller = ctrl; - this.exitCommand = exit; - - this.setupMenu(); - } - - /** - * Gets the controller. - * - * @return the controller - */ - protected final DeckController getController() { - return this.controller; - } - - /** - * Setup menu. - */ - protected void setupMenu() { - this.add(this.getDefaultFileMenu()); - this.add(this.getSortMenu()); - } - - /** - * New constructed. - * - * @param careAboutOldDeck - * a boolean - */ - protected final void newDocument(final boolean careAboutOldDeck) { - if (careAboutOldDeck && !this.canLeaveCurrentDeck()) { - return; - } - - this.controller.newModel(); - } - - /** - * Gets the user input open deck. - * - * @return the user input open deck - */ - protected final String getUserInputOpenDeck() { - final List choices = this.controller.getSavedNames(); - if (choices.isEmpty()) { - JOptionPane.showMessageDialog(null, "No decks found", "Open Deck", JOptionPane.PLAIN_MESSAGE); - return null; - } - - final Object o = GuiUtils.chooseOneOrNone("Open Deck", choices.toArray()); - return o == null ? null : o.toString(); - } - - // deck.setName(currentDeckName); - - /** - * Open. - */ - protected final void open() { - if (!this.canLeaveCurrentDeck()) { - return; - } - final String name = this.getUserInputOpenDeck(); - if (StringUtils.isBlank(name)) { - return; - } - this.controller.load(name); - } - - /** - * Save. - */ - protected final void save() { - if (StringUtils.isBlank(this.controller.getModel().getName())) { - this.saveAs(); - return; - } - - this.controller.save(); - } - - /** - * Save as. - */ - protected final void saveAs() { - final String name = this.getDeckNameFromDialog(); - - if (StringUtils.isBlank(name)) { - final int n = JOptionPane.showConfirmDialog(null, "This name is incorrect. Enter another one?", - "Cannot save", JOptionPane.YES_NO_OPTION); - - if (n == JOptionPane.NO_OPTION) { - return; - } - } - - if (this.controller.fileExists(name)) { - final int m = JOptionPane.showConfirmDialog(null, "There is already saved an item named '" + name - + "'. Would you like to overwrite it?", "Confirm overwrite", JOptionPane.YES_NO_OPTION); - - if (m == JOptionPane.NO_OPTION) { - return; - } - } - - this.controller.saveAs(name); - } - - /** - * Delete. - */ - protected final void delete() { - if (!this.controller.isModelInStore()) { - return; - } - - final int n = JOptionPane.showConfirmDialog(null, "Do you want to delete this deck " - + this.controller.getModel().getName() + " ?", "Delete", JOptionPane.YES_NO_OPTION); - - if (n == JOptionPane.NO_OPTION) { - return; - } - - this.controller.delete(); - } - - /** - * - * close window. - */ - public final void close() { - if (!this.canLeaveCurrentDeck()) { - return; - } - this.exitCommand.execute(); - } - - /** - * Can leave current deck. - * - * @return true, if successful - */ - protected final boolean canLeaveCurrentDeck() { - if (this.controller.isSaved()) { - return true; - } - final String message = String.format("Do you wish to save changes you made to your current deck '%s'?", - this.controller.getModel().getName()); - final int choice = JOptionPane - .showConfirmDialog(this.controller.getOwnerWindow(), message, "You have unsaved changes in your deck", - JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); - if (JOptionPane.CANCEL_OPTION == choice) { - return false; - } - if (JOptionPane.NO_OPTION == choice) { - return true; - } - - this.save(); - return true; - } - - /** - *

- * getUserInput_GetDeckName. - *

- * - * @return a {@link java.lang.String} object. - */ - protected final String getDeckNameFromDialog() { - final Object o = JOptionPane.showInputDialog(null, "Save As", "Deck Name", JOptionPane.OK_CANCEL_OPTION); - - if (o == null) { - return ""; - } - - final String deckName = o.toString(); - final boolean isGoodName = this.controller.isGoodName(deckName); - - if (isGoodName) { - return deckName; - } - - JOptionPane.showMessageDialog(null, "Please pick another deck name, another deck currently has that name."); - return this.getDeckNameFromDialog(); - } - - /** - * Gets the default file menu. - * - * @return the default file menu - */ - protected JMenu getDefaultFileMenu() { - final JMenu fileMenu = new JMenu("Deck"); - - final JMenuItem newDoc = new JMenuItem("New"); - final JMenuItem open = new JMenuItem("Open"); - final JMenuItem save = new JMenuItem("Save"); - final JMenuItem saveAs = new JMenuItem("Save As..."); - final JMenuItem delete = new JMenuItem("Delete"); - - fileMenu.add(newDoc); - fileMenu.add(open); - fileMenu.addSeparator(); - - fileMenu.add(save); - fileMenu.add(saveAs); - fileMenu.add(delete); - - newDoc.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuBase.this.newDocument(true); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : newConstructed() error - " + ex); - } - } - }); - - open.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuBase.this.open(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : open() error - " + ex); - } - } - }); - - save.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuBase.this.save(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : save() error - " + ex); - } - } - }); - - saveAs.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuBase.this.saveAs(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : saveAs() error - " + ex); - } - } - }); - - delete.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuBase.this.delete(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : delete() error - " + ex); - } - } - }); - return fileMenu; - } - - /** - * Append close menu item to. - * - * @param fileMenu the file menu - */ - protected void appendCloseMenuItemTo(final JMenu fileMenu) { - final JMenuItem close = new JMenuItem("Close"); - fileMenu.addSeparator(); - fileMenu.add(close); - - close.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - try { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - MenuBase.this.close(); - } - }); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : close() error - " + ex); - } - } - }); - } // setupMenu() - - /** - *

- * setupSortMenu. - *

- * - * @return the sort menu - */ - protected final JMenuItem getSortMenu() { - final JMenuItem name = new JMenuItem("Card Name"); - final JMenuItem cost = new JMenuItem("Cost"); - final JMenuItem color = new JMenuItem("Color"); - final JMenuItem type = new JMenuItem("Type"); - final JMenuItem stats = new JMenuItem("Power/Toughness"); - final JMenuItem rarity = new JMenuItem("Rarity"); - - final JMenu menu = new JMenu("Sort By"); - menu.add(name); - menu.add(cost); - menu.add(color); - menu.add(type); - menu.add(stats); - menu.add(rarity); - - name.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - (MenuBase.this.controller).getView().getTopTableModel().sort(1, true); - } - }); - - // 0 1 2 3 4 5 6 - // private String column[] = {"Qty", "Name", "Cost", "Color", "Type", - // "Stats", "Rarity"}; - cost.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - (MenuBase.this.controller).getView().getTopTableModel().sort(4).sort(3).sort(2); - } - }); - - color.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - (MenuBase.this.controller).getView().getTopTableModel().sort(4).sort(2).sort(3); - } - }); - - type.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - (MenuBase.this.controller).getView().getTopTableModel().sort(2).sort(3).sort(4); - } - }); - - stats.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - (MenuBase.this.controller).getView().getTopTableModel().sort(4).sort(2).sort(3).sort(5); - } - }); - - rarity.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent ev) { - // sort by cost, type, color, rarity - (MenuBase.this.controller).getView().getTopTableModel().sort(2).sort(4).sort(3).sort(6); - } - }); - - return menu; - } // setupSortMenu() -} diff --git a/src/main/java/forge/gui/deckeditor/MenuCommon.java b/src/main/java/forge/gui/deckeditor/MenuCommon.java index c779f98778b..9d74f5fd588 100644 --- a/src/main/java/forge/gui/deckeditor/MenuCommon.java +++ b/src/main/java/forge/gui/deckeditor/MenuCommon.java @@ -17,24 +17,6 @@ */ package forge.gui.deckeditor; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import javax.swing.JFileChooser; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.SwingUtilities; - -import forge.Command; -import forge.card.CardRules; -import forge.deck.Deck; -import forge.deck.generate.Generate2ColorDeck; -import forge.deck.io.DeckSerializer; -import forge.error.ErrorViewer; -import forge.game.player.PlayerType; -import forge.item.CardDb; -import forge.item.CardPrinted; -import forge.util.closures.Predicate; /** *

@@ -44,11 +26,11 @@ import forge.util.closures.Predicate; * @author Forge * @version $Id$ */ -public final class MenuCommon extends MenuBase { +public final class MenuCommon { - /** Constant serialVersionUID=-4037993759604768755L. */ + /** Constant serialVersionUID=-4037993759604768755L. * private static final long serialVersionUID = -4037993759604768755L; - /** Constant previousDirectory. */ + /** Constant previousDirectory. * private static File previousDirectory = null; /** @@ -58,7 +40,7 @@ public final class MenuCommon extends MenuBase { * the ctrl * @param exit * a Command - */ + * public MenuCommon(final DeckController ctrl, final Command exit) { super(ctrl, exit); @@ -132,7 +114,7 @@ public final class MenuCommon extends MenuBase { *

* exportDeck. *

- */ + * private void exportDeck() { final File filename = this.getExportFilename(); if (filename == null) { @@ -168,7 +150,7 @@ public final class MenuCommon extends MenuBase { *

* Generate Proxy for a Deck. *

- */ + * private void generateProxies() { final File filename = this.getProxiesFilename(); if (filename == null) { @@ -206,7 +188,7 @@ public final class MenuCommon extends MenuBase { * (non-Javadoc) * * @see forge.gui.deckeditor.MenuBase#getDefaultFileMenu() - */ + * @Override protected JMenu getDefaultFileMenu() { final JMenu fileMenu = super.getDefaultFileMenu(); @@ -327,4 +309,5 @@ public final class MenuCommon extends MenuBase { return fileMenu; } // setupMenu() + */ } diff --git a/src/main/java/forge/gui/deckeditor/MenuLimited.java b/src/main/java/forge/gui/deckeditor/MenuLimited.java deleted file mode 100644 index b13a388e92d..00000000000 --- a/src/main/java/forge/gui/deckeditor/MenuLimited.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import forge.Command; -import forge.deck.DeckGroup; - -/** - *

- * Gui_DeckEditor_Menu class. - *

- * - * @author Forge - * @version $Id: DeckEditorCommonMenu.java 13590 2012-01-27 20:46:27Z Max mtg $ - */ -public final class MenuLimited extends MenuBase { - - /** Constant serialVersionUID=-4037993759604768755L. */ - private static final long serialVersionUID = -4037993759604768755L; - - /** - * Menu for Deck Editor. - * - * @param ctrl the ctrl - * @param exit a Command - */ - public MenuLimited(final DeckController ctrl, final Command exit) { - super(ctrl, exit); - } - - // deck.setName(currentDeckName); - -} diff --git a/src/main/java/forge/gui/deckeditor/MenuQuest.java b/src/main/java/forge/gui/deckeditor/MenuQuest.java deleted file mode 100644 index a4c9d89b0a5..00000000000 --- a/src/main/java/forge/gui/deckeditor/MenuQuest.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.swing.JFileChooser; -import javax.swing.JMenu; -import javax.swing.JMenuItem; - -import forge.Command; -import forge.Constant; -import forge.deck.Deck; -import forge.deck.io.DeckSerializer; -import forge.error.ErrorViewer; -import forge.gui.ListChooser; -import forge.item.CardDb; -import forge.item.CardPrinted; - -//presumes AllZone.getQuestData() is not null -/** - *

- * Gui_Quest_DeckEditor_Menu class. - *

- * - * @author Forge - * @version $Id$ - */ -public class MenuQuest extends MenuBase { - /** Constant serialVersionUID=-4052319220021158574L. */ - private static final long serialVersionUID = -4052319220021158574L; - - // used for import and export, try to made the gui user friendly - /** Constant previousDirectory. */ - private static File previousDirectory = null; - - /** - *

- * Constructor for Gui_Quest_DeckEditor_Menu. - *

- * - * @param d - * a {@link forge.gui.deckeditor.IDeckDisplay} object. - * @param exit - * a {@link forge.Command} object. - */ - public MenuQuest(final DeckController d, final Command exit) { - super(d, exit); - } - - /** - *

- * importDeck. - *

- */ - private void importDeck() { - final File file = this.getImportFilename(); - - if ((file != null) && file.getName().endsWith(".dck")) { - try { - final Deck newDeck = Deck.fromFile(file); - this.getController().importDeck(newDeck); - - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : importDeck() error, " + ex); - } - } - - } // importDeck() - - /** - *

- * getImportFilename. - *

- * - * @return a {@link java.io.File} object. - */ - private File getImportFilename() { - final JFileChooser chooser = new JFileChooser(MenuQuest.previousDirectory); - - chooser.addChoosableFileFilter(DeckSerializer.DCK_FILTER); - final int returnVal = chooser.showOpenDialog(null); - - if (returnVal == JFileChooser.APPROVE_OPTION) { - final File file = chooser.getSelectedFile(); - MenuQuest.previousDirectory = file.getParentFile(); - return file; - } - - return null; - } // openFileDialog() - - private final ActionListener addCardActionListener = new ActionListener() { - @Override - public void actionPerformed(final ActionEvent a) { - - // Provide a model here: all unique cards to be displayed by only - // name (unlike default toString) - final Iterable uniqueCards = CardDb.instance().getAllUniqueCards(); - final List cards = new ArrayList(); - for (final CardPrinted c : uniqueCards) { - cards.add(c.getName()); - } - Collections.sort(cards); - - // use standard forge's list selection dialog - final ListChooser c = new ListChooser("Cheat - Add Card to Your Cardpool", 0, 1, cards); - if (c.show()) { - ((DeckEditorQuest) MenuQuest.this.getController().getView()).addCheatCard(CardDb.instance().getCard( - c.getSelectedValue())); - } - } - }; - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.MenuBase#getDefaultFileMenu() - */ - @Override - protected JMenu getDefaultFileMenu() { - final JMenu deckMenu = super.getDefaultFileMenu(); - - final JMenuItem addCard = new JMenuItem("Cheat - Add Card"); - - addCard.addActionListener(this.addCardActionListener); - - if (Constant.Runtime.DEV_MODE[0]) { - deckMenu.addSeparator(); - deckMenu.add(addCard); - } - - deckMenu.addSeparator(); - this.addImportExport(deckMenu, true); - - this.appendCloseMenuItemTo(deckMenu); - return deckMenu; - - } - - /** - *

- * addImportExport. - *

- * - * @param menu - * a {@link javax.swing.JMenu} object. - * @param isHumanMenu - * a boolean. - */ - private void addImportExport(final JMenu menu, final boolean isHumanMenu) { - final JMenuItem import2 = new JMenuItem("Import"); - final JMenuItem export = new JMenuItem("Export"); - - import2.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent a) { - MenuQuest.this.importDeck(); // importDeck(isHumanMenu); - } - }); // import - - export.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent a) { - MenuQuest.this.exportDeck(); - } - }); // export - - menu.add(import2); - menu.add(export); - - } // addImportExport() - - private void exportDeck() { - final File filename = this.getExportFilename(); - if (filename == null) { - return; - } - - try { - DeckSerializer.writeDeck(this.getController().getModel(), filename); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - throw new RuntimeException("Gui_DeckEditor_Menu : exportDeck() error, " + ex); - } - } - - private File getExportFilename() { - final JFileChooser save = new JFileChooser(MenuQuest.previousDirectory); - save.setDialogTitle("Export Deck Filename"); - save.setDialogType(JFileChooser.SAVE_DIALOG); - save.setFileFilter(DeckSerializer.DCK_FILTER); - - if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { - final File file = save.getSelectedFile(); - final String check = file.getAbsolutePath(); - - MenuQuest.previousDirectory = file.getParentFile(); - - return check.endsWith(".dck") ? file : new File(check + ".dck"); - } - return null; - } - -} diff --git a/src/main/java/forge/gui/deckeditor/PresetColumns.java b/src/main/java/forge/gui/deckeditor/PresetColumns.java deleted file mode 100644 index 364039e3c68..00000000000 --- a/src/main/java/forge/gui/deckeditor/PresetColumns.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import java.util.Map.Entry; -import java.util.regex.Pattern; - -import forge.Singletons; -import forge.card.CardColor; -import forge.card.CardEdition; -import forge.card.CardManaCost; -import forge.card.CardRarity; -import forge.item.CardPrinted; -import forge.item.InventoryItem; -import forge.item.InventoryItemFromSet; -import forge.util.closures.Lambda1; - -/** - * TODO: Write javadoc for this type. - * - */ -public abstract class PresetColumns { - - private static final Pattern AE_FINDER = Pattern.compile("AE", Pattern.LITERAL); - - private static CardManaCost toManaCost(final InventoryItem i) { - return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getManaCost() : CardManaCost.EMPTY; - } - - private static CardColor toColor(final InventoryItem i) { - return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.getNullColor(); - } - - private static String toPTL(final InventoryItem i) { - return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getPTorLoyalty() : ""; - } - - private static CardRarity toRarity(final InventoryItem i) { - return i instanceof CardPrinted ? ((CardPrinted) i).getRarity() : CardRarity.Unknown; - } - - private static CardEdition toSetCmp(final InventoryItem i) { - return i instanceof InventoryItemFromSet ? Singletons.getModel().getEditions() - .get(((InventoryItemFromSet) i).getEdition()) : CardEdition.UNKNOWN; - } - - private static String toSetStr(final InventoryItem i) { - return i instanceof InventoryItemFromSet ? ((InventoryItemFromSet) i).getEdition() : "n/a"; - } - - private static Integer toAiCmp(final InventoryItem i) { - return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatusComparable() : Integer.valueOf(-1); - } - - private static String toAiStr(final InventoryItem i) { - return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatus() : "n/a"; - } - - /** The Constant fnQtyCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_QTY_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return from.getValue(); - } - }; - - /** The Constant fnQtyGet. */ - public static final Lambda1> FN_QTY_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return from.getValue(); - } - }; - - /** The Constant fnNameCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_NAME_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return from.getKey().getName(); - } - }; - - /** The Constant fnNameGet. */ - public static final Lambda1> FN_NAME_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - final String name = from.getKey().getName(); - return name.contains("AE") ? PresetColumns.AE_FINDER.matcher(name).replaceAll("\u00C6") : name; - } - }; - - /** The Constant fnCostCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_COST_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return PresetColumns.toManaCost(from.getKey()); - } - }; - - /** The Constant fnCostGet. */ - public static final Lambda1> FN_COST_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return PresetColumns.toManaCost(from.getKey()); - } - }; - - /** The Constant fnColorCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_COLOR_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return PresetColumns.toColor(from.getKey()); - } - }; - - /** The Constant fnColorGet. */ - public static final Lambda1> FN_COLOR_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return PresetColumns.toColor(from.getKey()); - } - }; - - /** The Constant fnTypeCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_TYPE_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return from.getKey().getType(); - } - }; - - /** The Constant fnTypeGet. */ - public static final Lambda1> FN_TYPE_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return from.getKey().getType(); - } - }; - - /** The Constant fnStatsCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_STATS_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return PresetColumns.toPTL(from.getKey()); - } - }; - - /** The Constant fnStatsGet. */ - public static final Lambda1> FN_STATS_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return PresetColumns.toPTL(from.getKey()); - } - }; - - /** The Constant fnRarityCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_RARITY_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return PresetColumns.toRarity(from.getKey()); - } - }; - - /** The Constant fnRarityGet. */ - public static final Lambda1> FN_RARITY_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return PresetColumns.toRarity(from.getKey()); - } - }; - - /** The Constant fnSetCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_SET_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return PresetColumns.toSetCmp(from.getKey()); - } - }; - - /** The Constant fnSetGet. */ - public static final Lambda1> FN_SET_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return PresetColumns.toSetStr(from.getKey()); - } - }; - - /** The Constant fnAiStatusCompare. */ - @SuppressWarnings("rawtypes") - public static final Lambda1> FN_AI_STATUS_COMPARE = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return PresetColumns.toAiCmp(from.getKey()); - } - }; - - /** The Constant fnAiStatusGet. */ - public static final Lambda1> FN_AI_STATUS_GET = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return PresetColumns.toAiStr(from.getKey()); - } - }; -} diff --git a/src/main/java/forge/gui/deckeditor/QuestCardShop.java b/src/main/java/forge/gui/deckeditor/QuestCardShop.java deleted file mode 100644 index f75354c505f..00000000000 --- a/src/main/java/forge/gui/deckeditor/QuestCardShop.java +++ /dev/null @@ -1,530 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor; - -import java.awt.Container; -import java.awt.Font; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.text.DecimalFormat; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JOptionPane; - - -import forge.Command; -import forge.deck.Deck; -import forge.deck.DeckBase; -import forge.error.ErrorViewer; -import forge.gui.CardListViewer; -import forge.gui.deckeditor.elements.CardPanelLite; -import forge.gui.deckeditor.elements.FilterCheckBoxes; -import forge.gui.deckeditor.elements.FilterNameTypeSetPanel; -import forge.gui.deckeditor.elements.ManaCostRenderer; -import forge.gui.deckeditor.elements.TableColumnInfo; -import forge.gui.deckeditor.elements.TableView; -import forge.item.BoosterPack; -import forge.item.CardPrinted; -import forge.item.FatPack; -import forge.item.InventoryItem; -import forge.item.ItemPool; -import forge.item.ItemPoolView; -import forge.item.ItemPredicate; -import forge.item.OpenablePack; -import forge.item.PreconDeck; -import forge.item.TournamentPack; -import forge.quest.QuestController; -import forge.quest.io.ReadPriceList; -import forge.util.closures.Lambda1; -import forge.util.closures.Predicate; -import net.miginfocom.swing.MigLayout; - -/** - *

- * Gui_CardShop class. - *

- * - * @author Forge - * @version $Id$ - */ -public final class QuestCardShop extends DeckEditorBase { - /** Constant serialVersionUID=3988857075791576483L. */ - private static final long serialVersionUID = 3988857075791576483L; - - private final JButton clearFilterButton = new JButton(); - private FilterNameTypeSetPanel filterNameTypeSet; - - private final JButton buyButton = new JButton(); - private final JButton sellButton = new JButton(); - - private final JLabel creditsLabel = new JLabel(); - private final JLabel sellPercentageLabel = new JLabel(); - - private double multiplier; - - private final QuestController questData; - - // get pricelist: - private final ReadPriceList r = new ReadPriceList(); - private final Map mapPrices = this.r.getPriceList(); - private Map decksUsingMyCards; - - /** - * Show. - * - * @param exitCommand - * the exit command - */ - @Override - public void show(final Command exitCommand) { - final Command exit = new Command() { - private static final long serialVersionUID = -7428793574300520612L; - - @Override - public void execute() { - QuestCardShop.this.dispose(); - exitCommand.execute(); - } - }; - - // do not change this!!!! - this.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent ev) { - exit.execute(); - } - }); - - this.setup(); - - this.decksUsingMyCards = this.countDecksForEachCard(); - - this.multiplier = this.questData.getCards().getSellMutliplier(); - - ItemPoolView forSale = this.questData.getCards().getShopList(); - if (forSale.isEmpty()) { - this.questData.getCards().generateCardsInShop(); - forSale = this.questData.getCards().getShopList(); - } - // newCardsList = questData.getCards().getNewCards(); - final ItemPool ownedItems = new ItemPool(InventoryItem.class); - ownedItems.addAll(this.questData.getCards().getCardpool().getView()); - - this.getTopTableModel().setDeck(forSale); - this.getBottomTableWithCards().setDeck(ownedItems); - - this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits()); - - final double multiPercent = this.multiplier * 100; - final NumberFormat formatter = new DecimalFormat("#0.00"); - String maxSellingPrice = ""; - final int maxSellPrice = this.questData.getCards().getSellPriceLimit(); - - if (maxSellPrice < Integer.MAX_VALUE) { - maxSellingPrice = String.format("Maximum selling price is %d credits.", maxSellPrice); - } - this.sellPercentageLabel.setText("Selling cards at " + formatter.format(multiPercent) - + "% of their value.
" + maxSellingPrice + ""); - - this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay()); - - this.getTopTableWithCards().sort(1, true); - this.getBottomTableWithCards().sort(1, true); - } // show(Command) - - // fills number of decks using each card - private Map countDecksForEachCard() { - final Map result = new HashMap(); - for (final Deck deck : this.questData.getMyDecks()) { - for (final Entry e : deck.getMain()) { - final CardPrinted card = e.getKey(); - final Integer amount = result.get(card); - result.put(card, Integer.valueOf(amount == null ? 1 : 1 + amount.intValue())); - } - } - return result; - } - - /** - *

- * setup. - *

- */ - private void setup() { - final List> columns = new ArrayList>(); - columns.add(new TableColumnInfo("Qty", 30, PresetColumns.FN_QTY_COMPARE, - PresetColumns.FN_QTY_GET)); - columns.add(new TableColumnInfo("Name", 176, PresetColumns.FN_NAME_COMPARE, - PresetColumns.FN_NAME_GET)); - columns.add(new TableColumnInfo("Cost", 70, PresetColumns.FN_COST_COMPARE, - PresetColumns.FN_COST_GET)); - columns.add(new TableColumnInfo("Color", 50, PresetColumns.FN_COLOR_COMPARE, - PresetColumns.FN_COLOR_GET)); - columns.add(new TableColumnInfo("Type", 100, PresetColumns.FN_TYPE_COMPARE, - PresetColumns.FN_TYPE_GET)); - columns.add(new TableColumnInfo("Stats", 40, PresetColumns.FN_STATS_COMPARE, - PresetColumns.FN_STATS_GET)); - columns.add(new TableColumnInfo("R", 25, PresetColumns.FN_RARITY_COMPARE, - PresetColumns.FN_RARITY_GET)); - columns.add(new TableColumnInfo("Set", 35, PresetColumns.FN_SET_COMPARE, - PresetColumns.FN_SET_GET)); - columns.get(2).setCellRenderer(new ManaCostRenderer()); - - final List> columnsBelow = new ArrayList>(columns); - columns.add(new TableColumnInfo("Price", 45, this.fnPriceCompare, this.fnPriceGet)); - this.getTopTableWithCards().setup(columns, this.getCardView()); - - columnsBelow.add(new TableColumnInfo("Dks", 30, this.fnDeckCompare, this.fnDeckGet)); - columnsBelow.add(new TableColumnInfo("New", 35, this.questData.getCards().getFnNewCompare(), - this.questData.getCards().getFnNewGet())); - columnsBelow.add(new TableColumnInfo("Price", 45, this.fnPriceCompare, this.fnPriceSellGet)); - this.getBottomTableWithCards().setup(columnsBelow, this.getCardView()); - - this.setSize(1024, 740); - } - - /** - *

- * Constructor for Gui_CardShop. - *

- * - * @param parent the parent frame for this deck editor instance - * @param qd - * a {@link forge.quest.data.QuestData} object. - */ - public QuestCardShop(JFrame parent, final QuestController qd) { - super(parent); - this.questData = qd; - try { - this.setFilterBoxes(new FilterCheckBoxes(true)); - this.setTopTableWithCards(new TableView("Cards for sale", false, false, InventoryItem.class)); - this.setBottomTableWithCards(new TableView("Owned Cards", false, InventoryItem.class)); - this.setCardView(new CardPanelLite()); - this.filterNameTypeSet = new FilterNameTypeSetPanel(); - this.jbInit(); - } catch (final Exception ex) { - ErrorViewer.showError(ex); - } - } - - /** - *

- * jbInit. - *

- * - * @throws java.lang.Exception - * if any. - */ - private void jbInit() throws Exception { - - final Font font = new java.awt.Font("Dialog", 0, 13); - this.clearFilterButton.setFont(font); - this.buyButton.setFont(font); - this.sellButton.setFont(font); - this.creditsLabel.setFont(font); - this.sellPercentageLabel.setFont(font); - - this.clearFilterButton.setText("Clear Filter"); - this.buyButton.setText("Buy Card"); - this.sellButton.setText("Sell Card"); - - this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - QuestCardShop.this.clearFilterButtonActionPerformed(e); - } - }); - this.buyButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - QuestCardShop.this.buyButtonActionPerformed(e); - } - }); - this.sellButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - QuestCardShop.this.sellButtonActionPerformed(e); - } - }); - - // Type filtering - final Font f = new Font("Tahoma", Font.PLAIN, 10); - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - box.setFont(f); - box.setOpaque(false); - } - - // Color filtering - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - box.setOpaque(false); - } - - this.setTitle("Card Shop"); - - final Container content = this.getContentPane(); - final MigLayout layout = new MigLayout("fill"); - content.setLayout(layout); - - boolean isFirst = true; - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - String growParameter = "grow"; - if (isFirst) { - growParameter = "cell 0 0, egx checkbox, grow, split 14"; - isFirst = false; - } - content.add(box, growParameter); - box.addItemListener(this.getItemListenerUpdatesDisplay()); - } - - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - content.add(box, "grow"); - box.addItemListener(this.getItemListenerUpdatesDisplay()); - } - - content.add(this.clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow"); - - content.add(this.filterNameTypeSet, "cell 0 1, grow"); - content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, push, grow"); - - content.add(this.buyButton, "w 100, h 49, sg button, cell 0 5, split 5"); - content.add(this.sellButton, "w 100, h 49, sg button"); - - content.add(this.creditsLabel, "w 100, h 49"); - content.add(this.sellPercentageLabel, "w 300, h 49, wrap"); - - content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow"); - - content.add(this.getCardView(), "cell 1 0 1 7, flowy, grow"); - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#buildFilter() - */ - @Override - protected Predicate buildFilter() { - final Predicate cardFilter = Predicate.and( - this.getFilterBoxes().buildFilter(), - this.filterNameTypeSet.buildFilter()); - - // Until this is filterable, always show packs and decks in the card shop - Predicate filter = Predicate.instanceOf(cardFilter, CardPrinted.class); - filter = Predicate.or(filter, ItemPredicate.Presets.IS_PACK); - filter = Predicate.or(filter, ItemPredicate.Presets.IS_DECK); - - return filter; - } - - /** - * Clear filter button_action performed. - * - * @param e - * the e - */ - void clearFilterButtonActionPerformed(final ActionEvent e) { - // disable automatic update triggered by listeners - this.setFiltersChangeFiringUpdate(false); - - for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) { - if (!box.isSelected()) { - box.doClick(); - } - } - for (final JCheckBox box : this.getFilterBoxes().getAllColors()) { - if (!box.isSelected()) { - box.doClick(); - } - } - - this.filterNameTypeSet.clearFilters(); - - this.setFiltersChangeFiringUpdate(true); - - this.getTopTableWithCards().setFilter(null); - } - - // TODO: move to cardshop - private Integer getCardValue(final InventoryItem card) { - if (this.mapPrices.containsKey(card.getName())) { - return this.mapPrices.get(card.getName()); - } else if (card instanceof CardPrinted) { - switch (((CardPrinted) card).getRarity()) { - case BasicLand: - return Integer.valueOf(4); - case Common: - return Integer.valueOf(6); - case Uncommon: - return Integer.valueOf(40); - case Rare: - return Integer.valueOf(120); - case MythicRare: - return Integer.valueOf(600); - default: - return Integer.valueOf(15); - } - } else if (card instanceof BoosterPack) { - return 395; - } else if (card instanceof TournamentPack) { - return 995; - } else if (card instanceof FatPack) { - return 2365; - } else if (card instanceof PreconDeck) { - return ((PreconDeck) card).getRecommendedDeals().getCost(); - } - return 1337; - } - - private void buyButtonActionPerformed(final ActionEvent e) { - final InventoryItem item = this.getTopTableWithCards().getSelectedCard(); - if (item == null) { - return; - } - - final int value = this.getCardValue(item); - - if (value <= this.questData.getAssets().getCredits()) { - - if (item instanceof CardPrinted) { - this.getTopTableWithCards().removeCard(item); - - final CardPrinted card = (CardPrinted) item; - this.getBottomTableWithCards().addCard(card); - this.questData.getCards().buyCard(card, value); - - } else if (item instanceof OpenablePack) { - this.getTopTableWithCards().removeCard(item); - - OpenablePack booster = null; - if (item instanceof BoosterPack) { - booster = (BoosterPack) ((BoosterPack) item).clone(); - } else if (item instanceof TournamentPack) { - booster = (TournamentPack) ((TournamentPack) item).clone(); - } else if (item instanceof FatPack) { - booster = (FatPack) ((FatPack) item).clone(); - } - this.questData.getCards().buyPack(booster, value); - final List newCards = booster.getCards(); - for (final CardPrinted card : newCards) { - this.getBottomTableWithCards().addCard(card); - } - final CardListViewer c = new CardListViewer(booster.getName(), - "You have found the following cards inside:", newCards); - c.show(); - } else if (item instanceof PreconDeck) { - this.getTopTableWithCards().removeCard(item); - final PreconDeck deck = (PreconDeck) item; - this.questData.getCards().buyPreconDeck(deck, value); - - for (final CardPrinted card : deck.getDeck().getMain().toFlatList()) { - this.getBottomTableWithCards().addCard(card); - } - JOptionPane.showMessageDialog(null, String.format( - "Deck '%s' was added to your decklist.%n%nCards from it were also added to your pool.", - deck.getName()), "Thanks for purchasing!", JOptionPane.INFORMATION_MESSAGE); - - } - - this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits()); - } else { - JOptionPane.showMessageDialog(null, "Not enough credits!"); - } - } - - private void sellButtonActionPerformed(final ActionEvent e) { - final InventoryItem item = this.getBottomTableWithCards().getSelectedCard(); - if ((item == null) || !(item instanceof CardPrinted)) { - return; - } - - final CardPrinted card = (CardPrinted) item; - this.getBottomTableWithCards().removeCard(card); - this.getTopTableWithCards().addCard(card); - - final int price = Math.min((int) (this.multiplier * this.getCardValue(card)), this.questData.getCards() - .getSellPriceLimit()); - this.questData.getCards().sellCard(card, price); - - this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits()); - } - - @SuppressWarnings("rawtypes") - private final Lambda1> fnPriceCompare = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - return QuestCardShop.this.getCardValue(from.getKey()); - } - }; - private final Lambda1> fnPriceGet = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return QuestCardShop.this.getCardValue(from.getKey()); - } - }; - private final Lambda1> fnPriceSellGet = new Lambda1>() { - @Override - public Object apply(final Entry from) { - return (int) (QuestCardShop.this.multiplier * QuestCardShop.this.getCardValue(from.getKey())); - } - }; - - @SuppressWarnings("rawtypes") - private final Lambda1> fnDeckCompare = new Lambda1>() { - @Override - public Comparable apply(final Entry from) { - final Integer iValue = QuestCardShop.this.decksUsingMyCards.get(from.getKey()); - return iValue == null ? Integer.valueOf(0) : iValue; - } - }; - private final Lambda1> fnDeckGet = new Lambda1>() { - @Override - public Object apply(final Entry from) { - final Integer iValue = QuestCardShop.this.decksUsingMyCards.get(from.getKey()); - return iValue == null ? "" : iValue.toString(); - } - }; - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#getController() - */ - @Override - public DeckController getController() { - return null; - } - - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.DeckEditorBase#updateView() - */ - @Override - public void updateView() { - } - -} diff --git a/src/main/java/forge/gui/deckeditor/SEditorIO.java b/src/main/java/forge/gui/deckeditor/SEditorIO.java new file mode 100644 index 00000000000..568556cc2cf --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/SEditorIO.java @@ -0,0 +1,303 @@ +package forge.gui.deckeditor; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.TreeMap; + +import javax.swing.JOptionPane; +import javax.xml.stream.XMLEventFactory; +import javax.xml.stream.XMLEventReader; +import javax.xml.stream.XMLEventWriter; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.events.Attribute; +import javax.xml.stream.events.StartElement; +import javax.xml.stream.events.XMLEvent; + +import forge.deck.DeckBase; +import forge.gui.deckeditor.tables.DeckController; +import forge.gui.deckeditor.tables.SColumnUtil; +import forge.gui.deckeditor.tables.SColumnUtil.ColumnName; +import forge.gui.deckeditor.tables.SColumnUtil.SortState; +import forge.gui.deckeditor.tables.TableColumnInfo; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.item.InventoryItem; +import forge.properties.NewConstants; + +/** + * Handles editor preferences saving and loading. + * + *

(S at beginning of class name denotes a static factory.) + */ +public class SEditorIO { + /** Used in the XML IO to extract properties from PREFS file. */ + private enum ColumnProperty { /** */ + enumval, /** */ + identifier, /** */ + index, /** */ + show, /** */ + sortpriority, /** */ + sortstate, /** */ + width + } + + /** Preferences (must match with PREFS file). */ + public enum EditorPreference { /** */ + stats_deck, /** */ + stats_catalog + } + + private static final XMLEventFactory EVENT_FACTORY = XMLEventFactory.newInstance(); + private static final XMLEvent NEWLINE = EVENT_FACTORY.createDTD("\n"); + private static final XMLEvent TAB = EVENT_FACTORY.createDTD("\t"); + + private static final Map PREFS + = new HashMap(); + + private static final Map> COLS + = new TreeMap>(); + + /** + * Retrieve a preference from the editor preference map. + * + * @param name0   {@link forge.gui.deckeditor.SEditorUtil.EditorPreference} + * @return TableColumnInfo + */ + public static boolean getPref(final EditorPreference name0) { + return PREFS.get(name0); + } + + /** + * Set a preference in the editor preference map. + * + * @param name0   {@link forge.gui.deckeditor.SEditorUtil.EditorPreference} + * @param val0   boolean + */ + public static void setPref(final EditorPreference name0, final boolean val0) { + PREFS.put(name0, val0); + } + + /** + * Retrieve a custom column. + * + * @param name0   {@link forge.gui.deckeditor.SEditorUtil.CatalogColumnName} + * @return TableColumnInfo + */ + public static TableColumnInfo getColumn(final ColumnName name0) { + return COLS.get(name0); + } + + /** + * Saves the current deck, with various prompts depending on the + * current save environment. + * + * @return boolean, true if success + */ + @SuppressWarnings("unchecked") + public static boolean saveDeck() { + final DeckController controller = (DeckController) CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController(); + final String name = VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().getText(); + + // Warn if no name + if (name.equals("[New Deck]") || name.isEmpty()) { + JOptionPane.showMessageDialog(null, + "Please name your deck using the 'Title' box.", + "Save Error!", + JOptionPane.ERROR_MESSAGE); + return false; + } + // Confirm if overwrite + else if (controller.fileExists(name)) { + final int m = JOptionPane.showConfirmDialog(null, + "There is already a deck named '" + name + "'. Overwrite?", + "Overwrite Deck?", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); + + if (m == JOptionPane.YES_OPTION) { controller.save(); } + VCurrentDeck.SINGLETON_INSTANCE.getTabLabel().setText("Current Deck"); + } + // Confirm if a new deck will be created + else { + final int m = JOptionPane.showConfirmDialog(null, + "This will create a new deck named '" + name + "'. Continue?", + "Create Deck?", + JOptionPane.YES_NO_OPTION, + JOptionPane.QUESTION_MESSAGE); + + if (m == JOptionPane.YES_OPTION) { controller.saveAs(name); } + VCurrentDeck.SINGLETON_INSTANCE.getTabLabel().setText("Current Deck"); + } + + return true; + } + + /** + * Prompts to save changes if necessary. + * + * @return boolean, true if success + */ + @SuppressWarnings("unchecked") + public static boolean confirmSaveChanges() { + if (!((DeckController) CDeckEditorUI + .SINGLETON_INSTANCE.getCurrentEditorController().getDeckController()).isSaved()) { + final int choice = JOptionPane.showConfirmDialog(null, + "Save changes to current deck?", + "Save Changes?", + JOptionPane.YES_NO_CANCEL_OPTION, + JOptionPane.QUESTION_MESSAGE); + + if (choice == JOptionPane.CANCEL_OPTION) { return false; } + + if (choice == JOptionPane.YES_OPTION && !saveDeck()) { return false; } + } + + return true; + } + + /** Publicly-accessible save method, to neatly handle exception handling. */ + public static void savePreferences() { + try { save(); } + catch (final Exception e) { e.printStackTrace(); } + } + + /** Publicly-accessible load method, to neatly handle exception handling. */ + public static void loadPreferences() { + try { load(); } + catch (final Exception e) { e.printStackTrace(); } + } + + /** + * + * TODO: Write javadoc for this method. + * + * @param extends InventoryItem + * @param extends DeckBase + */ + private static void save() throws Exception { + final XMLOutputFactory out = XMLOutputFactory.newInstance(); + final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(NewConstants.PREFERENCES_FILE_EDITOR)); + + writer.add(EVENT_FACTORY.createStartDocument()); + writer.add(NEWLINE); + writer.add(EVENT_FACTORY.createStartElement("", "", "preferences")); + writer.add(EVENT_FACTORY.createAttribute("type", "editor")); + writer.add(NEWLINE); + + for (final EditorPreference p : PREFS.keySet()) { + writer.add(TAB); + writer.add(EVENT_FACTORY.createStartElement("", "", "pref")); + writer.add(EVENT_FACTORY.createAttribute( + "name", p.toString())); + writer.add(EVENT_FACTORY.createAttribute( + "value", PREFS.get(p).toString())); + writer.add(EVENT_FACTORY.createEndElement("", "", "pref")); + writer.add(NEWLINE); + } + + for (final ColumnName c : COLS.keySet()) { + // If column is not in view, retain previous model index for the next time + // that the column will be in the view. + int index = SColumnUtil.getColumnViewIndex(c); + if (index == -1) { + index = COLS.get(c).getModelIndex(); + } + + writer.add(TAB); + writer.add(EVENT_FACTORY.createStartElement("", "", "col")); + writer.add(EVENT_FACTORY.createAttribute( + ColumnProperty.enumval.toString(), COLS.get(c).getEnumValue())); + writer.add(EVENT_FACTORY.createAttribute( + ColumnProperty.identifier.toString(), COLS.get(c).getIdentifier().toString())); + writer.add(EVENT_FACTORY.createAttribute( + ColumnProperty.index.toString(), String.valueOf(index))); + writer.add(EVENT_FACTORY.createAttribute( + ColumnProperty.show.toString(), String.valueOf(COLS.get(c).isShowing()))); + writer.add(EVENT_FACTORY.createAttribute( + ColumnProperty.sortpriority.toString(), String.valueOf(COLS.get(c).getSortPriority()))); + writer.add(EVENT_FACTORY.createAttribute( + ColumnProperty.sortstate.toString(), String.valueOf(COLS.get(c).getSortState()))); + writer.add(EVENT_FACTORY.createAttribute( + ColumnProperty.width.toString(), String.valueOf(COLS.get(c).getWidth()))); + writer.add(EVENT_FACTORY.createEndElement("", "", "col")); + writer.add(NEWLINE); + } + + writer.add(EVENT_FACTORY.createEndDocument()); + writer.flush(); + writer.close(); + } + + private static void load() throws Exception { + final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + final String fileAddress = NewConstants.PREFERENCES_FILE_EDITOR; + final XMLEventReader reader = inputFactory.createXMLEventReader(new FileInputStream(fileAddress)); + + PREFS.clear(); + COLS.clear(); + + XMLEvent event; + StartElement element; + Iterator attributes; + Attribute attribute; + EditorPreference pref; + TableColumnInfo tempcol; + String tagname; + + while (reader.hasNext()) { + event = reader.nextEvent(); + + if (event.isStartElement()) { + element = event.asStartElement(); + tagname = element.getName().getLocalPart(); + + // Assemble preferences + if (tagname.equals("pref")) { + // Retrieve name of pref + attributes = element.getAttributes(); + pref = EditorPreference.valueOf(((Attribute) attributes.next()).getValue()); + + // Add to map + PREFS.put(pref, Boolean.valueOf(((Attribute) attributes.next()).getValue())); + } + // Assemble columns + else if (tagname.equals("col")) { + attributes = element.getAttributes(); + tempcol = new TableColumnInfo(); + + while (attributes.hasNext()) { + attribute = (Attribute) attributes.next(); + if (attribute.getName().toString().equals(ColumnProperty.enumval.toString())) { + COLS.put(ColumnName.valueOf(attribute.getValue()), tempcol); + tempcol.setEnumValue(attribute.getValue()); + } + else if (attribute.getName().toString().equals(ColumnProperty.identifier.toString())) { + tempcol.setIdentifier(attribute.getValue()); + tempcol.setHeaderValue(attribute.getValue()); + } + else if (attribute.getName().toString().equals(ColumnProperty.width.toString())) { + tempcol.setPreferredWidth(Integer.valueOf(attribute.getValue())); + } + else if (attribute.getName().toString().equals(ColumnProperty.show.toString())) { + tempcol.setShowing(Boolean.valueOf(attribute.getValue())); + } + else if (attribute.getName().toString().equals(ColumnProperty.sortpriority.toString())) { + tempcol.setSortPriority(Integer.valueOf(attribute.getValue())); + } + else if (attribute.getName().toString().equals(ColumnProperty.sortstate.toString())) { + tempcol.setSortState(SortState.valueOf(attribute.getValue().toString())); + } + else if (attribute.getName().toString().equals(ColumnProperty.index.toString())) { + tempcol.setModelIndex(Integer.valueOf(attribute.getValue())); + } + } + } + } + } + + SColumnUtil.attachSortAndDisplayFunctions(); + } +} diff --git a/src/main/java/forge/gui/deckeditor/SEditorUtil.java b/src/main/java/forge/gui/deckeditor/SEditorUtil.java new file mode 100644 index 00000000000..081cfd21d71 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/SEditorUtil.java @@ -0,0 +1,149 @@ +package forge.gui.deckeditor; + +import javax.swing.ImageIcon; + +import forge.card.CardRules; +import forge.gui.deckeditor.views.ITableContainer; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.gui.toolbox.FSkin; +import forge.item.InventoryItem; +import forge.item.ItemPoolView; + +/** + * Static methods for working with top-level editor methods, + * included but not limited to preferences IO, icon generation, + * and stats analysis. + * + *

+ * (S at beginning of class name denotes a static factory.) + * + */ +public final class SEditorUtil { + /** Pre-cached resized version. */ + public static final ImageIcon ICO_ARTIFACT = + new ImageIcon(FSkin.getImage(FSkin.EditorImages.IMG_ARTIFACT, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_CREATURE = + new ImageIcon(FSkin.getImage(FSkin.EditorImages.IMG_CREATURE, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_ENCHANTMENT = + new ImageIcon(FSkin.getImage(FSkin.EditorImages.IMG_ENCHANTMENT, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_INSTANT = + new ImageIcon(FSkin.getImage(FSkin.EditorImages.IMG_INSTANT, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_LAND = + new ImageIcon(FSkin.getImage(FSkin.EditorImages.IMG_LAND, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_PLANESWALKER = + new ImageIcon(FSkin.getImage(FSkin.EditorImages.IMG_PLANESWALKER, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_SORCERY = + new ImageIcon(FSkin.getImage(FSkin.EditorImages.IMG_SORCERY, 18, 18)); + + /** Pre-cached resized version. */ + public static final ImageIcon ICO_TOTAL = + new ImageIcon(FSkin.getImage(FSkin.ZoneImages.ICO_HAND, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_MULTI = + new ImageIcon(FSkin.getImage(FSkin.EditorImages.IMG_MULTI, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_BLACK = + new ImageIcon(FSkin.getImage(FSkin.ManaImages.IMG_BLACK, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_BLUE = + new ImageIcon(FSkin.getImage(FSkin.ManaImages.IMG_BLUE, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_GREEN = + new ImageIcon(FSkin.getImage(FSkin.ManaImages.IMG_GREEN, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_RED = + new ImageIcon(FSkin.getImage(FSkin.ManaImages.IMG_RED, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_WHITE = + new ImageIcon(FSkin.getImage(FSkin.ManaImages.IMG_WHITE, 18, 18)); + /** Pre-cached resized version. */ + public static final ImageIcon ICO_COLORLESS = + new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_X, 18, 18)); + + /** + * Divides X by Y, multiplies by 100, rounds, returns. + * + * @param x0   Numerator (int) + * @param y0   Denominator (int) + * @return rounded result (int) + */ + public static int calculatePercentage(final int x0, final int y0) { + return (int) Math.round((double) x0 / (double) y0 * 100); + } + + /** + * setStats. + * + * @param   the generic type + * @param deck   ItemPoolView + * @param view   {@link forge.gui.deckeditor.views.ITableContainer} + */ + public static void setStats(final ItemPoolView deck, final ITableContainer view) { + view.getLblTotal().setText(String.valueOf(deck.countAll())); + + view.getLblCreature().setText(String.valueOf(CardRules.Predicates.Presets + .IS_CREATURE.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblLand().setText(String.valueOf(CardRules.Predicates.Presets + .IS_LAND.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblEnchantment().setText(String.valueOf(CardRules.Predicates.Presets + .IS_ENCHANTMENT.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblArtifact().setText(String.valueOf(CardRules.Predicates.Presets + .IS_ARTIFACT.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblInstant().setText(String.valueOf(CardRules.Predicates.Presets + .IS_INSTANT.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblSorcery().setText(String.valueOf(CardRules.Predicates.Presets + .IS_SORCERY.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblPlaneswalker().setText(String.valueOf(CardRules.Predicates.Presets + .IS_PLANESWALKER.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblColorless().setText(String.valueOf(CardRules.Predicates.Presets + .IS_COLORLESS.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblBlack().setText(String.valueOf(CardRules.Predicates.Presets + .IS_BLACK.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblBlue().setText(String.valueOf(CardRules.Predicates.Presets + .IS_BLUE.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblGreen().setText(String.valueOf(CardRules.Predicates.Presets + .IS_GREEN.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblRed().setText(String.valueOf(CardRules.Predicates.Presets + .IS_RED.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + + view.getLblWhite().setText(String.valueOf(CardRules.Predicates.Presets + .IS_WHITE.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()))); + } // getStats() + + /** + * Set all components visible that may have been hidden + * by various configurations of the deck editor. + */ + public static void resetUI() { + VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4().setVisible(true); + VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4().setVisible(true); + + VCurrentDeck.SINGLETON_INSTANCE.getBtnSaveAs().setVisible(true); + VCurrentDeck.SINGLETON_INSTANCE.getBtnNew().setVisible(true); + VCurrentDeck.SINGLETON_INSTANCE.getBtnOpen().setVisible(true); + + VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setEnabled(true); + VCardCatalog.SINGLETON_INSTANCE.getLblTitle().setText(""); + + VCurrentDeck.SINGLETON_INSTANCE.getPnlHeader().setVisible(true); + VCardCatalog.SINGLETON_INSTANCE.getPnlHeader().setVisible(true); + } +} diff --git a/src/main/java/forge/gui/deckeditor/SFilterUtil.java b/src/main/java/forge/gui/deckeditor/SFilterUtil.java new file mode 100644 index 00000000000..705bbb7e50f --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/SFilterUtil.java @@ -0,0 +1,515 @@ +package forge.gui.deckeditor; + +import java.awt.Graphics; +import java.awt.Image; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.swing.JCheckBox; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; + +import forge.card.CardEdition; +import forge.card.CardRules; +import forge.game.GameFormat; +import forge.gui.WrapLayout; +import forge.gui.deckeditor.controllers.CFilters; +import forge.gui.deckeditor.views.VFilters; +import forge.item.CardPrinted; +import forge.util.closures.Predicate; +import forge.util.closures.Predicate.ComparableOp; +import forge.util.closures.PredicateString.StringOp; + +/** + * Static factory; holds blocks of form elements and predicates + * which are used in various editing environments. + *

+ * (S at beginning of class name denotes a static factory.) + */ +public class SFilterUtil { + /** An enum to reference checkbox objects in their respective maps. */ + private enum FilterProperty { /** */ + BLACK, /** */ + BLUE, /** */ + COLORLESS, /** */ + GREEN, /** */ + MULTICOLOR, /** */ + RED, /** */ + WHITE, /** */ + + ARTIFACT, /** */ + CREATURE, /** */ + ENCHANTMENT, /** */ + INSTANT, /** */ + LAND, /** */ + PLANESWALKER, /** */ + SORCERY + } + + private static final Map MAP_COLOR_CHECKBOXES = + new HashMap(); + + private static final Map MAP_TYPE_CHECKBOXES = + new HashMap(); + + /** + + */ + private static boolean preventFiltering = false; + + /** + * This will prevent a filter event on a checkbox state change. + * It's used for programmatic changes to the checkboxes when rebuilding + * the filter each time is expensive. + * + * @return boolean   true if filtering is prevented + */ + public static boolean isFilteringPrevented() { + return preventFiltering; + } + + /** + * This will prevent a filter event on a checkbox state change. + * It's used for programmatic changes to the checkboxes when rebuilding + * the filter each time is expensive. + * + * @param bool0   true to prevent filtering + */ + public static void setPreventFiltering(final boolean bool0) { + preventFiltering = bool0; + } + + /** + * Fills and returns a JPanel with checkboxes for color filter set. + * + * @return {@link javax.swing.JPanel} + */ + public static JPanel populateColorFilters() { + MAP_COLOR_CHECKBOXES.clear(); + + MAP_COLOR_CHECKBOXES.put(FilterProperty.BLACK, + new ChbPnl(SEditorUtil.ICO_BLACK.getImage())); + MAP_COLOR_CHECKBOXES.put(FilterProperty.MULTICOLOR, + new ChbPnl(SEditorUtil.ICO_MULTI.getImage())); + MAP_COLOR_CHECKBOXES.put(FilterProperty.BLUE, + new ChbPnl(SEditorUtil.ICO_BLUE.getImage())); + MAP_COLOR_CHECKBOXES.put(FilterProperty.BLACK, + new ChbPnl(SEditorUtil.ICO_BLACK.getImage())); + MAP_COLOR_CHECKBOXES.put(FilterProperty.GREEN, + new ChbPnl(SEditorUtil.ICO_GREEN.getImage())); + MAP_COLOR_CHECKBOXES.put(FilterProperty.RED, + new ChbPnl(SEditorUtil.ICO_RED.getImage())); + MAP_COLOR_CHECKBOXES.put(FilterProperty.WHITE, + new ChbPnl(SEditorUtil.ICO_WHITE.getImage())); + MAP_COLOR_CHECKBOXES.put(FilterProperty.COLORLESS, + new ChbPnl(SEditorUtil.ICO_COLORLESS.getImage())); + + + final JPanel pnl = new JPanel(new WrapLayout(SwingConstants.CENTER, 10, 5)); + pnl.setOpaque(false); + + for (FilterProperty p : MAP_COLOR_CHECKBOXES.keySet()) { + pnl.add(MAP_COLOR_CHECKBOXES.get(p)); + } + return pnl; + } + + /** + * Fills and returns a JPanel with checkboxes for color filter set. + * + * @return {@link javax.swing.JPanel} + */ + public static JPanel populateTypeFilters() { + MAP_TYPE_CHECKBOXES.clear(); + + MAP_TYPE_CHECKBOXES.put(FilterProperty.ARTIFACT, + new ChbPnl(SEditorUtil.ICO_ARTIFACT.getImage())); + MAP_TYPE_CHECKBOXES.put(FilterProperty.CREATURE, + new ChbPnl(SEditorUtil.ICO_CREATURE.getImage())); + MAP_TYPE_CHECKBOXES.put(FilterProperty.ENCHANTMENT, + new ChbPnl(SEditorUtil.ICO_ENCHANTMENT.getImage())); + MAP_TYPE_CHECKBOXES.put(FilterProperty.INSTANT, + new ChbPnl(SEditorUtil.ICO_INSTANT.getImage())); + MAP_TYPE_CHECKBOXES.put(FilterProperty.LAND, + new ChbPnl(SEditorUtil.ICO_LAND.getImage())); + MAP_TYPE_CHECKBOXES.put(FilterProperty.PLANESWALKER, + new ChbPnl(SEditorUtil.ICO_PLANESWALKER.getImage())); + MAP_TYPE_CHECKBOXES.put(FilterProperty.SORCERY, + new ChbPnl(SEditorUtil.ICO_SORCERY.getImage())); + + + final JPanel pnl = new JPanel(new WrapLayout(SwingConstants.CENTER, 10, 5)); + pnl.setOpaque(false); + + for (FilterProperty p : MAP_TYPE_CHECKBOXES.keySet()) { + pnl.add(MAP_TYPE_CHECKBOXES.get(p)); + } + return pnl; + } + + /** Turns all type checkboxes off or on. + * @param select0   boolean */ + public static void toggleTypeCheckboxes(final boolean select0) { + for (FilterProperty p : MAP_TYPE_CHECKBOXES.keySet()) { + ((ChbPnl) MAP_TYPE_CHECKBOXES.get(p)).getCheckBox().setSelected(select0); + } + } + + /** Turns all type checkboxes off or on. + * @param select0   boolean */ + public static void toggleColorCheckboxes(final boolean select0) { + for (FilterProperty p : MAP_COLOR_CHECKBOXES.keySet()) { + ((ChbPnl) MAP_COLOR_CHECKBOXES.get(p)).getCheckBox().setSelected(select0); + } + } + + /** + * Assembles checkboxes for color and returns a filter predicate. + *

+ * Handles "multicolor" label, which is quite tricky. + * + * @return Predicate + */ + public static Predicate buildColorFilter() { + if (MAP_COLOR_CHECKBOXES.isEmpty()) { return Predicate.getTrue(CardPrinted.class); } + + final List> ors = new ArrayList>(); + JCheckBox chbTemp; + + chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.BLACK)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_BLACK); } + + chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.BLUE)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_BLUE); } + + chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.GREEN)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_GREEN); } + + chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.RED)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_RED); } + + chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.WHITE)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_WHITE); } + + chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.COLORLESS)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_COLORLESS); } + + // Multi-colored needs special XOR treatment, since "not multi" when OR-ed + // with any other of its colors except colorless, will return true. + // Careful when changing this. + chbTemp = ((ChbPnl) MAP_COLOR_CHECKBOXES.get(FilterProperty.MULTICOLOR)).getCheckBox(); + final Predicate preMulti; + if (chbTemp.isSelected()) { + preMulti = Predicate.getTrue(CardPrinted.class); + } + else { + preMulti = Predicate.not(Predicate.brigde( + CardRules.Predicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES)); + } + + final Predicate preColors = + Predicate.brigde(Predicate.or(ors), CardPrinted.FN_GET_RULES); + + // Corner case: if multi is checked, and the rest are empty, AND won't work. + // This still doesn't work perfectly :/ + boolean allEmptyExceptMulti = true; + for (FilterProperty p : MAP_COLOR_CHECKBOXES.keySet()) { + if (p.equals(FilterProperty.MULTICOLOR)) { continue; } + if (((ChbPnl) MAP_COLOR_CHECKBOXES.get(p)).getCheckBox().isSelected()) { + allEmptyExceptMulti = false; + break; + } + } + + if (allEmptyExceptMulti) { + return Predicate.brigde( + CardRules.Predicates.Presets.IS_MULTICOLOR, CardPrinted.FN_GET_RULES); + } + else { + return Predicate.and(preColors, preMulti); + } + } + + /** + * Filters the set/format combo box. + * + * @return Predicate + */ + public static Predicate buildSetAndFormatFilter() { + // Set/Format filter + if (VFilters.SINGLETON_INSTANCE.getCbxSets().getSelectedIndex() == 0) { + return Predicate.getTrue(CardPrinted.class); + } + + final Object selected = VFilters.SINGLETON_INSTANCE.getCbxSets().getSelectedItem(); + final Predicate filter; + if (selected instanceof CardEdition) { + filter = CardPrinted.Predicates.printedInSets(((CardEdition) selected).getCode()); + } + else { + filter = ((GameFormat) selected).getFilterRules(); + } + + return filter; + } + + /** + * Assembles checkboxes for type and returns a filter predicate. + * + * @return Predicate + */ + public static Predicate buildTypeFilter() { + if (MAP_TYPE_CHECKBOXES.isEmpty()) { return Predicate.getTrue(CardPrinted.class); } + + final List> ors = new ArrayList>(); + JCheckBox chbTemp; + + chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.ARTIFACT)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_ARTIFACT); } + + chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.CREATURE)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_CREATURE); } + + chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.ENCHANTMENT)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_ENCHANTMENT); } + + chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.INSTANT)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_INSTANT); } + + chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.LAND)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_LAND); } + + chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.PLANESWALKER)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_PLANESWALKER); } + + chbTemp = ((ChbPnl) MAP_TYPE_CHECKBOXES.get(FilterProperty.SORCERY)).getCheckBox(); + if (chbTemp.isSelected()) { ors.add(CardRules.Predicates.Presets.IS_SORCERY); } + + return Predicate.brigde(Predicate.or(ors), CardPrinted.FN_GET_RULES); + } + + /** + * Validates text field input (from txfContains and txfWithout), + * then assembles AND and NOT predicates accordingly, ANDs + * together, and returns. + * + * @return Predicate + */ + public static Predicate buildTextFilter() { + Predicate filterAnd = Predicate.getTrue(CardPrinted.class); + Predicate filterNot = Predicate.getTrue(CardPrinted.class); + + final String strContains = VFilters.SINGLETON_INSTANCE.getTxfContains().getText(); + final String strWithout = VFilters.SINGLETON_INSTANCE.getTxfWithout().getText(); + + if (!strContains.isEmpty()) { + final String[] splitContains = strContains + .replaceAll(",", "") + .replaceAll(" ", " ") + .toLowerCase().split(" "); + + final List> ands = new ArrayList>(); + + for (final String s : splitContains) { + final List> subands = new ArrayList>(); + subands.add(Predicate.brigde(CardRules.Predicates.name( + StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); + subands.add(Predicate.brigde(CardRules.Predicates.joinedType( + StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); + subands.add(Predicate.brigde(CardRules.Predicates.rules( + StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); + + ands.add(Predicate.or(subands)); + } + + filterAnd = Predicate.and(ands); + } + + if (!strWithout.isEmpty()) { + final String[] splitWithout = strWithout + .replaceAll(" ", " ") + .replaceAll(",", "") + .toLowerCase().split(" "); + + final List> nots = new ArrayList>(); + + for (final String s : splitWithout) { + final List> subnots = new ArrayList>(); + + subnots.add(Predicate.brigde(CardRules.Predicates.name( + StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); + subnots.add(Predicate.brigde(CardRules.Predicates.joinedType( + StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); + subnots.add(Predicate.brigde(CardRules.Predicates.rules( + StringOp.CONTAINS, s), CardPrinted.FN_GET_RULES)); + + nots.add(Predicate.or(subnots)); + } + + filterNot = Predicate.not(Predicate.or(nots)); + } + + return Predicate.and(filterAnd, filterNot); + } + + /** + * Validates combo box input, assembles predicate filters for each case, + * stacks them all together, and returns the predicate. + * + * @return Predicate + */ + public static Predicate buildIntervalFilter() { + final VFilters view = VFilters.SINGLETON_INSTANCE; + Predicate filter = Predicate.getTrue(CardPrinted.class); + + // Must include -1 so non-creatures are included by default. + final int plow = view.getCbxPLow().getSelectedItem().toString().equals("*") + ? -1 : Integer.valueOf(view.getCbxPLow().getSelectedItem().toString()); + final int tlow = view.getCbxTLow().getSelectedItem().toString().equals("*") + ? -1 : Integer.valueOf(view.getCbxTLow().getSelectedItem().toString()); + final int clow = view.getCbxCMCLow().getSelectedItem().toString().equals("*") + ? -1 : Integer.valueOf(view.getCbxCMCLow().getSelectedItem().toString()); + + // If a power, toughness, or CMC is higher than 100, that's bad. + final int phigh = view.getCbxPHigh().getSelectedItem().toString().equals("10+") + ? 100 : Integer.valueOf(view.getCbxPHigh().getSelectedItem().toString()); + final int thigh = view.getCbxTHigh().getSelectedItem().toString().equals("10+") + ? 100 : Integer.valueOf(view.getCbxTHigh().getSelectedItem().toString()); + final int chigh = view.getCbxCMCHigh().getSelectedItem().toString().equals("10+") + ? 100 : Integer.valueOf(view.getCbxCMCHigh().getSelectedItem().toString()); + + // Assemble final predicates + final Predicate prePower; + final Predicate preToughness; + final Predicate preCMC; + + // Power: CardRules returns null if no power, which means extra + // filtering must be applied to allow all cards to be shown if * is chosen. + // (Without this, lands and such would be filtered out by default.) + if (plow > phigh) { prePower = Predicate.getFalse(CardPrinted.class); } + else { + // If * is selected in the combo box, cards without power + // will be included in the filter. + final Predicate preNotCreature; + if (plow == -1) { + preNotCreature = Predicate.not( + Predicate.brigde(CardRules.Predicates.Presets.IS_CREATURE, + CardPrinted.FN_GET_RULES)); + } + // Otherwise, if 0 or higher is selected, cards without power + // are excluded. + else { + preNotCreature = Predicate.getFalse(CardPrinted.class); + } + + final Predicate prePowerTemp = Predicate.and( + Predicate.brigde(CardRules.Predicates.power( + ComparableOp.GT_OR_EQUAL, plow), CardPrinted.FN_GET_RULES), + Predicate.brigde(CardRules.Predicates.power( + ComparableOp.LT_OR_EQUAL, phigh), CardPrinted.FN_GET_RULES)); + + prePower = Predicate.or(preNotCreature, prePowerTemp); + } + + // Toughness: CardRules returns null if no toughness, which means extra + // filtering must be applied to allow all cards to be shown if * is chosen. + // (Without this, lands and such would be filtered out by default.) + if (tlow > thigh) { preToughness = Predicate.getFalse(CardPrinted.class); } + else { + // If * is selected in the combo box, cards without toughness + // will be included in the filter. + final Predicate preNotCreature; + if (tlow == -1) { + preNotCreature = Predicate.not( + Predicate.brigde(CardRules.Predicates.Presets.IS_CREATURE, + CardPrinted.FN_GET_RULES)); + } + // Otherwise, if 0 or higher is selected, cards without toughness + // are excluded. + else { + preNotCreature = Predicate.getFalse(CardPrinted.class); + } + + final Predicate preToughnessTemp = Predicate.and( + Predicate.brigde(CardRules.Predicates.toughness( + ComparableOp.GT_OR_EQUAL, tlow), CardPrinted.FN_GET_RULES), + Predicate.brigde(CardRules.Predicates.toughness( + ComparableOp.LT_OR_EQUAL, thigh), CardPrinted.FN_GET_RULES)); + + preToughness = Predicate.or(preNotCreature, preToughnessTemp); + } + + // CMC, thankfully, will return -1 if the card doesn't have a CMC, + // so it can be compared directly against the low value, and non-CMC + // cards will still be included if * is chosen. + if (clow > chigh) { preCMC = Predicate.getFalse(CardPrinted.class); } + else { + preCMC = Predicate.and( + Predicate.brigde(CardRules.Predicates.cmc( + ComparableOp.GT_OR_EQUAL, clow), CardPrinted.FN_GET_RULES), + Predicate.brigde(CardRules.Predicates.cmc( + ComparableOp.LT_OR_EQUAL, chigh), CardPrinted.FN_GET_RULES)); + } + + // Stack them all together and return. + filter = Predicate.and(preCMC, Predicate.and(prePower, preToughness)); + return filter; + } + + //========== Custom class handling + + /** + * A panel with a checkbox and an icon, which will toggle the + * checkbox when anywhere in the panel is clicked. + */ + @SuppressWarnings("serial") + private static class ChbPnl extends JPanel implements ItemListener { + private final JCheckBox checkBox = new JCheckBox(); + private final Image img; + + public ChbPnl(final Image img0) { + super(); + this.img = img0; + this.setOpaque(false); + checkBox.setBorder(new EmptyBorder(0, 20, 0, 0)); + checkBox.setOpaque(false); + checkBox.setSelected(true); + checkBox.addItemListener(this); + add(checkBox); + + this.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(final MouseEvent me) { + checkBox.doClick(); + } + }); + } + + public JCheckBox getCheckBox() { + return this.checkBox; + } + + @Override + protected void paintComponent(final Graphics g) { + super.paintComponent(g); + g.drawImage(img, 0, 0, null); + } + + /* (non-Javadoc) + * @see java.awt.event.ItemListener#itemStateChanged(java.awt.event.ItemEvent) + */ + @Override + public void itemStateChanged(final ItemEvent arg0) { + if (!preventFiltering) { + ((CFilters) VFilters.SINGLETON_INSTANCE.getControl()).buildFilter(); + } + } + } +} diff --git a/src/main/java/forge/gui/deckeditor/VDeckEditorUI.java b/src/main/java/forge/gui/deckeditor/VDeckEditorUI.java new file mode 100644 index 00000000000..3cba129f285 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/VDeckEditorUI.java @@ -0,0 +1,61 @@ +package forge.gui.deckeditor; + +import javax.swing.SwingWorker; + +import forge.gui.framework.IVTopLevelUI; +import forge.gui.framework.SLayoutIO; + +/** +/** + * Top level view class; instantiates and assembles + * tabs used in deck editor UI drag layout.
+ * + *

(V at beginning of class name denotes a view class.) + * + */ +public enum VDeckEditorUI implements IVTopLevelUI { + /** */ + SINGLETON_INSTANCE; + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVTopLevelUI#instantiate() + */ + @Override + public void instantiate() { + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVTopLevelUI#populate() + */ + @Override + public void populate() { + final SwingWorker w = new SwingWorker() { + @Override + public Void doInBackground() { + SLayoutIO.loadLayout(null); + + /* this can be used for toggling panels in and out of the view (e.g. dev mode) + + make are separate + layout states for each deck editor state. + however, the empty cells should still be removed. + + VFilters.SINGLETON_INSTANCE.getParentCell().removeDoc(VFilters.SINGLETON_INSTANCE); + VProbabilities.SINGLETON_INSTANCE.getParentCell().removeDoc(VProbabilities.SINGLETON_INSTANCE); + + System.out.println(FView.SINGLETON_INSTANCE.getDragCells().size()); + + for (final DragCell c : FView.SINGLETON_INSTANCE.getDragCells()) { + if (c.getDocs().size() == 0) { + SRearrangingUtil.fillGap(c); + FView.SINGLETON_INSTANCE.removeDragCell(c); + } + } */ + return null; + } + }; + w.execute(); + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java b/src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java new file mode 100644 index 00000000000..4c010d25833 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java @@ -0,0 +1,115 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.controllers; + +import forge.deck.DeckBase; +import forge.gui.deckeditor.tables.DeckController; +import forge.gui.deckeditor.tables.TableView; +import forge.item.InventoryItem; + +/** + * Maintains a generically typed architecture for various editing + * environments. A basic editor instance requires a card catalog, the + * current deck being edited, and optional filters on the catalog. + *

+ * These requirements are collected in this class and manipulated + * in subclasses for different environments. There are two generic + * types for all card display and filter predicates. + * + *

(A at beginning of class name denotes an abstract class.) + *

(C at beginning of class name denotes a control class.) + * + * @param extends {@link forge.item.InventoryItem} + * @param extends {@link forge.deck.DeckBase} + */ +public abstract class ACEditorBase { + + private TableView tblCatalog; + private TableView tblDeck; + /** + * Operation to add one of selected card to current deck. + */ + public abstract void addCard(); + + /** + * Operation to remove one of selected card from current deck. + */ + public abstract void removeCard(); + + /** + * Resets the cards in the catalog table and current deck table. + */ + public abstract void resetTables(); + + /** + * Gets controller responsible for the current deck being edited. + * + * @return {@link forge.gui.deckeditor.tables.DeckController} + */ + public abstract DeckController getDeckController(); + + /** + * Called when an editor wants to exit. Should confirm save options, + * update next UI screen, etc. + * + * @return boolean   true if safe to exit + */ + public abstract boolean exit(); + + /** + * Resets and initializes the current editor. + */ + public abstract void init(); + + /** + * Gets the TableView holding the cards in the current deck. + * + * @return {@link forge.gui.deckeditor.tables.TableView} + */ + public TableView getTableDeck() { + return this.tblDeck; + } + + /** + * Sets the TableView holding the cards in the current deck. + * + * @param table0   {@link forge.gui.deckeditor.tables.TableView} + */ + public void setTableDeck(final TableView table0) { + this.tblDeck = table0; + } + + /** + * Gets the TableView holding the cards in the current catalog. + * + * @return {@link forge.gui.deckeditor.tables.TableView} + */ + public TableView getTableCatalog() { + return this.tblCatalog; + } + + /** + * Sets the TableView holding the cards in the current catalog. + * + * @param table0   {@link forge.gui.deckeditor.tables.TableView} + */ + public void setTableCatalog(final TableView table0) { + this.tblCatalog = table0; + } + +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CAllDecks.java b/src/main/java/forge/gui/deckeditor/controllers/CAllDecks.java new file mode 100644 index 00000000000..c8a9c886374 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CAllDecks.java @@ -0,0 +1,68 @@ +package forge.gui.deckeditor.controllers; + +import java.awt.Dialog.ModalityType; + +import forge.Command; +import forge.Singletons; +import forge.deck.DeckBase; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.DeckImport; +import forge.gui.deckeditor.views.VAllDecks; +import forge.gui.framework.ICDoc; +import forge.gui.toolbox.FLabel; +import forge.item.InventoryItem; + +/** + * Controls the "all decks" panel in the deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CAllDecks implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @SuppressWarnings("serial") + @Override + public void initialize() { + VAllDecks.SINGLETON_INSTANCE.getLstDecks().setDecks( + Singletons.getModel().getDecks().getConstructed()); + + ((FLabel) VAllDecks.SINGLETON_INSTANCE.getBtnImport()) + .setCommand(new Command() { @Override + public void execute() { importDeck(); } }); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } + + /** + * Opens dialog for importing a deck from a different MTG software. + */ + @SuppressWarnings({ "unchecked", "rawtypes" }) + private void importDeck() { + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + final DeckImport dImport = new DeckImport(ed); + dImport.setModalityType(ModalityType.APPLICATION_MODAL); + dImport.setVisible(true); + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CCardCatalog.java b/src/main/java/forge/gui/deckeditor/controllers/CCardCatalog.java new file mode 100644 index 00000000000..ff785392165 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CCardCatalog.java @@ -0,0 +1,76 @@ +package forge.gui.deckeditor.controllers; + +import forge.Command; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.framework.ICDoc; +import forge.gui.toolbox.FLabel; +import forge.item.InventoryItem; + +/** + * Controls the "card catalog" panel in the deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CCardCatalog implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + // refresh analysis on add + + private CCardCatalog() { + } + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + @SuppressWarnings("serial") + public void initialize() { + // Add/remove buttons + ((FLabel) VCardCatalog.SINGLETON_INSTANCE.getBtnAdd()).setCommand(new Command() { + @Override + public void execute() { + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().addCard(); + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getTableCatalog().getTable().requestFocusInWindow(); + CStatistics.SINGLETON_INSTANCE.update(); + CProbabilities.SINGLETON_INSTANCE.update(); + } + }); + + ((FLabel) VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4()).setCommand(new Command() { + @Override + public void execute() { + final InventoryItem item = CDeckEditorUI.SINGLETON_INSTANCE + .getCurrentEditorController().getTableCatalog().getSelectedCard(); + + for (int i = 0; i < 4; i++) { + if (item.equals(CDeckEditorUI.SINGLETON_INSTANCE + .getCurrentEditorController().getTableCatalog().getSelectedCard())) { + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().addCard(); + } + } + CStatistics.SINGLETON_INSTANCE.update(); + CProbabilities.SINGLETON_INSTANCE.update(); + } + }); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CCurrentDeck.java b/src/main/java/forge/gui/deckeditor/controllers/CCurrentDeck.java new file mode 100644 index 00000000000..dd5c1b6ced3 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CCurrentDeck.java @@ -0,0 +1,202 @@ +package forge.gui.deckeditor.controllers; + +import java.awt.event.FocusAdapter; +import java.awt.event.FocusEvent; +import java.io.File; + +import javax.swing.JFileChooser; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +import forge.Command; +import forge.deck.Deck; +import forge.deck.DeckBase; +import forge.deck.io.DeckSerializer; +import forge.error.ErrorViewer; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.tables.DeckController; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.gui.framework.ICDoc; +import forge.gui.toolbox.FLabel; +import forge.item.InventoryItem; + +/** + * Controls the "current deck" panel in the deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CCurrentDeck implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + private static File previousDirectory = null; + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + @SuppressWarnings("serial") + public void initialize() { + ((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnSave()) + .setCommand(new Command() { @Override + public void execute() { SEditorIO.saveDeck(); } }); + + ((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnSaveAs()) + .setCommand(new Command() { @Override + public void execute() { exportDeck(); } }); + + ((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnOpen()) + .setCommand(new Command() { @Override + public void execute() { openDeck(); } }); + + ((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnNew()) + .setCommand(new Command() { @Override + public void execute() { newDeck(); } }); + + VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().addFocusListener(new FocusAdapter() { + @Override + public void focusGained(final FocusEvent e) { + if (((JTextField) e.getSource()).getText().equals("[New Deck]")) { + ((JTextField) e.getSource()).setText(""); + } + } + + @Override + public void focusLost(final FocusEvent e) { + if (((JTextField) e.getSource()).getText().isEmpty()) { + ((JTextField) e.getSource()).setText("[New Deck]"); + } + } + }); + + ((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove()).setCommand(new Command() { + @Override public void execute() { + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().removeCard(); + } }); + + ((FLabel) VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4()).setCommand(new Command() { + @Override public void execute() { + final InventoryItem item = CDeckEditorUI.SINGLETON_INSTANCE + .getCurrentEditorController().getTableDeck().getSelectedCard(); + + for (int i = 0; i < 4; i++) { + if (item.equals(CDeckEditorUI.SINGLETON_INSTANCE + .getCurrentEditorController().getTableDeck().getSelectedCard())) { + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().removeCard(); + } + } + } + }); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } + + // + + /** */ + @SuppressWarnings("unchecked") + private void newDeck() { + if (!SEditorIO.confirmSaveChanges()) { return; } + + try { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + ((DeckController) CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController()).newModel(); + VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setText(""); + VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().requestFocusInWindow(); + } + }); + } catch (final Exception ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("Error creating new deck. " + ex); + } + } + + /** */ + @SuppressWarnings("unchecked") + private void openDeck() { + if (!SEditorIO.confirmSaveChanges()) { return; } + + final File file = this.getImportFilename(); + + if (file != null && file.getName().endsWith(".dck")) { + try { + ((DeckController) CDeckEditorUI.SINGLETON_INSTANCE + .getCurrentEditorController().getDeckController()) + .setModel(Deck.fromFile(file)); + + } catch (final Exception ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("Error importing deck." + ex); + } + } + } + + /** */ + private File getImportFilename() { + final JFileChooser open = new JFileChooser(previousDirectory); + open.setDialogTitle("Import Deck"); + open.addChoosableFileFilter(DeckSerializer.DCK_FILTER); + final int returnVal = open.showOpenDialog(null); + + if (returnVal == JFileChooser.APPROVE_OPTION) { + final File file = open.getSelectedFile(); + previousDirectory = file.getParentFile(); + return file; + } + return null; + } + + /** */ + @SuppressWarnings("unchecked") + private void exportDeck() { + final File filename = this.getExportFilename(); + if (filename == null) { + return; + } + + try { + DeckSerializer.writeDeck( + ((DeckController) CDeckEditorUI.SINGLETON_INSTANCE + .getCurrentEditorController().getDeckController()).getModel(), filename); + } catch (final Exception ex) { + ErrorViewer.showError(ex); + throw new RuntimeException("Error exporting deck." + ex); + } + } + + private File getExportFilename() { + final JFileChooser save = new JFileChooser(previousDirectory); + save.setDialogTitle("Export Deck"); + save.setDialogType(JFileChooser.SAVE_DIALOG); + save.setFileFilter(DeckSerializer.DCK_FILTER); + + if (save.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) { + final File file = save.getSelectedFile(); + final String check = file.getAbsolutePath(); + + previousDirectory = file.getParentFile(); + + return check.endsWith(".dck") ? file : new File(check + ".dck"); + } + return null; + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java b/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java new file mode 100644 index 00000000000..720b5162498 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java @@ -0,0 +1,120 @@ +package forge.gui.deckeditor.controllers; + +import forge.Command; +import forge.card.CardRules; +import forge.deck.Deck; +import forge.deck.DeckBase; +import forge.deck.generate.Generate2ColorDeck; +import forge.deck.generate.Generate3ColorDeck; +import forge.deck.generate.Generate5ColorDeck; +import forge.game.player.PlayerType; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.views.VDeckgen; +import forge.gui.framework.ICDoc; +import forge.gui.toolbox.FLabel; +import forge.item.CardDb; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.util.closures.Predicate; + +/** + * Controls the "analysis" panel in the deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CDeckgen implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @SuppressWarnings("serial") + @Override + public void initialize() { + ((FLabel) VDeckgen.SINGLETON_INSTANCE.getBtnRandCardpool()).setCommand(new Command() { + @Override + public void execute() { + newRandomConstructed(); + } + }); + + ((FLabel) VDeckgen.SINGLETON_INSTANCE.getBtnRandDeck2()).setCommand(new Command() { + @Override public void execute() { newGenerateConstructed(2); } }); + + ((FLabel) VDeckgen.SINGLETON_INSTANCE.getBtnRandDeck3()).setCommand(new Command() { + @Override public void execute() { newGenerateConstructed(3); } }); + + ((FLabel) VDeckgen.SINGLETON_INSTANCE.getBtnRandDeck5()).setCommand(new Command() { + @Override public void execute() { newGenerateConstructed(5); } }); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } + + //========== Other methods + @SuppressWarnings("unchecked") + private void newRandomConstructed() { + if (!SEditorIO.confirmSaveChanges()) { return; } + + final Deck randomDeck = new Deck(); + + randomDeck.getMain().addAllFlat(Predicate.not(CardRules.Predicates.Presets.IS_BASIC_LAND) + .random(CardDb.instance().getAllUniqueCards(), CardPrinted.FN_GET_RULES, 15 * 5)); + randomDeck.getMain().add("Plains"); + randomDeck.getMain().add("Island"); + randomDeck.getMain().add("Swamp"); + randomDeck.getMain().add("Mountain"); + randomDeck.getMain().add("Forest"); + randomDeck.getMain().add("Terramorphic Expanse"); + + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + ed.getDeckController().setModel((TModel) randomDeck); + } + + @SuppressWarnings("unchecked") + private void newGenerateConstructed(final int colorCount0) { + if (!SEditorIO.confirmSaveChanges()) { return; } + + final Deck genConstructed = new Deck(); + + switch (colorCount0) { + case 2: + genConstructed.getMain().addAll( + (new Generate2ColorDeck("AI", "AI")).get2ColorDeck(60, PlayerType.HUMAN)); + break; + case 3: + genConstructed.getMain().addAll( + (new Generate3ColorDeck("AI", "AI", "AI")).get3ColorDeck(60, PlayerType.HUMAN)); + break; + case 5: + genConstructed.getMain().addAll( + (new Generate5ColorDeck()).get5ColorDeck(60, PlayerType.HUMAN)); + break; + default: + } + + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + ed.getDeckController().setModel((TModel) genConstructed); + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CEditorConstructed.java b/src/main/java/forge/gui/deckeditor/controllers/CEditorConstructed.java new file mode 100644 index 00000000000..2a58193b017 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CEditorConstructed.java @@ -0,0 +1,158 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.controllers; + +import java.util.List; + +import forge.Singletons; +import forge.deck.Deck; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.tables.DeckController; +import forge.gui.deckeditor.tables.SColumnUtil; +import forge.gui.deckeditor.tables.SColumnUtil.ColumnName; +import forge.gui.deckeditor.tables.TableColumnInfo; +import forge.gui.deckeditor.tables.TableView; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.item.CardDb; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.item.ItemPool; +import forge.util.closures.Lambda0; + +/** + * Child controller for constructed deck editor UI. + * This is the least restrictive mode; + * all cards are available. + * + *

(C at beginning of class name denotes a control class.) + * + * @author Forge + * @version $Id$ + */ +public final class CEditorConstructed extends ACEditorBase { + private final DeckController controller; + + //=========== Constructor + /** + * Child controller for constructed deck editor UI. + * This is the least restrictive mode; + * all cards are available. + */ + public CEditorConstructed() { + super(); + + final TableView tblCatalog = new TableView(true, CardPrinted.class); + final TableView tblDeck = new TableView(true, CardPrinted.class); + + VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable()); + VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable()); + + this.setTableCatalog(tblCatalog); + this.setTableDeck(tblDeck); + + final Lambda0 newCreator = new Lambda0() { + @Override + public Deck apply() { + return new Deck(); + } + }; + this.controller = new DeckController(Singletons.getModel().getDecks().getConstructed(), this, newCreator); + } + + //=========== Overridden from ACEditorBase + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#addCard() + */ + @Override + public void addCard() { + final InventoryItem item = this.getTableCatalog().getSelectedCard(); + if ((item == null) || !(item instanceof CardPrinted)) { + return; + } + + final CardPrinted card = (CardPrinted) item; + this.getTableDeck().addCard(card); + this.controller.notifyModelChanged(); + VCurrentDeck.SINGLETON_INSTANCE.getTabLabel().setText("*Current Deck"); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#removeCard() + */ + @Override + public void removeCard() { + final InventoryItem item = this.getTableDeck().getSelectedCard(); + if ((item == null) || !(item instanceof CardPrinted)) { + return; + } + + final CardPrinted card = (CardPrinted) item; + this.getTableDeck().removeCard(card); + this.controller.notifyModelChanged(); + VCurrentDeck.SINGLETON_INSTANCE.getTabLabel().setText("*Current Deck"); + } + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#updateView() + */ + @Override + public void resetTables() { + // Constructed mode can use all cards, no limitations. + this.getTableCatalog().setDeck(ItemPool.createFrom(CardDb.instance().getAllCards(), CardPrinted.class)); + this.getTableDeck().setDeck(this.controller.getModel().getMain()); + } + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#getController() + */ + @Override + public DeckController getDeckController() { + return this.controller; + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#show(forge.Command) + */ + @Override + public void init() { + final List> lstCatalogCols = SColumnUtil.getCatalogDefaultColumns(); + lstCatalogCols.remove(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); + + this.getTableCatalog().setup(VCardCatalog.SINGLETON_INSTANCE, lstCatalogCols); + this.getTableDeck().setup(VCurrentDeck.SINGLETON_INSTANCE, SColumnUtil.getDeckDefaultColumns()); + + SEditorUtil.resetUI(); + + this.controller.newModel(); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.controllers.ACEditorBase#exit() + */ + @Override + public boolean exit() { + return SEditorIO.confirmSaveChanges(); + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CEditorDraftingProcess.java b/src/main/java/forge/gui/deckeditor/controllers/CEditorDraftingProcess.java new file mode 100644 index 00000000000..80461fd50ec --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CEditorDraftingProcess.java @@ -0,0 +1,249 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.controllers; + +import javax.swing.JOptionPane; + +import forge.Constant; +import forge.Singletons; +import forge.control.FControl; +import forge.deck.Deck; +import forge.deck.DeckGroup; +import forge.game.limited.BoosterDraft; +import forge.game.limited.IBoosterDraft; +import forge.gui.deckeditor.tables.DeckController; +import forge.gui.deckeditor.tables.SColumnUtil; +import forge.gui.deckeditor.tables.TableView; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.gui.home.sanctioned.CSubmenuDraft; +import forge.item.CardDb; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.item.ItemPoolView; + +/** + * Updates the deck editor UI as necessary draft selection mode. + * + *

(C at beginning of class name denotes a control class.) + * + * @author Forge + * @version $Id$ + */ +public class CEditorDraftingProcess extends ACEditorBase { + private IBoosterDraft boosterDraft; + + //========== Constructor + + /** + * Updates the deck editor UI as necessary draft selection mode. + */ + public CEditorDraftingProcess() { + final TableView tblCatalog = new TableView(true, CardPrinted.class); + final TableView tblDeck = new TableView(true, CardPrinted.class); + + VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable()); + VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable()); + + this.setTableCatalog(tblCatalog); + this.setTableDeck(tblDeck); + } + + /** + * Show gui. + * + * @param inBoosterDraft + * the in_booster draft + */ + public final void showGui(final IBoosterDraft inBoosterDraft) { + this.boosterDraft = inBoosterDraft; + this.init(); + } + + /** + *

+ * setup. + *

+ */ + private void setup() { + this.getTableCatalog().setup(VCardCatalog.SINGLETON_INSTANCE, SColumnUtil.getCatalogDefaultColumns()); + this.getTableDeck().setup(VCurrentDeck.SINGLETON_INSTANCE, SColumnUtil.getDeckDefaultColumns()); + + /* + this.getTableCatalog().getTable().addMouseListener(this.pickWithMouse); + this.getTableCatalog().getTable().addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(final KeyEvent e) { + if (e.getKeyChar() == ' ') { + CEditorDraftingProcess.this.addCard(); + } + } + }); + */ + + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#addCard() + */ + @Override + public void addCard() { + final InventoryItem item = this.getTableCatalog().getSelectedCard(); + if ((item == null) || !(item instanceof CardPrinted)) { + return; + } + + final CardPrinted card = (CardPrinted) item; + + this.getTableDeck().addCard(card); + + // get next booster pack + this.boosterDraft.setChoice(card); + + if (this.boosterDraft.hasNextChoice()) { + this.showChoices(this.boosterDraft.nextChoice()); + } else { + this.boosterDraft.finishedDrafting(); + this.saveDraft(); + } + } + + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#removeCard() + */ + @Override + public void removeCard() { + } + + /** + *

+ * showChoices. + *

+ * + * @param list + * a {@link forge.CardList} object. + */ + private void showChoices(final ItemPoolView list) { + VCardCatalog.SINGLETON_INSTANCE.getLblTitle().setText("Select a card from pack number " + + (((BoosterDraft) boosterDraft).getCurrentBoosterIndex() + 1) + "."); + this.getTableCatalog().setDeck(list); + this.getTableCatalog().fixSelection(0); + } // showChoices() + + /** + *

+ * getPlayersDeck. + *

+ * + * @return a {@link forge.deck.Deck} object. + */ + private Deck getPlayersDeck() { + final Deck deck = new Deck(); + Constant.Runtime.HUMAN_DECK[0] = deck; + + // add sideboard to deck + deck.getSideboard().addAll(this.getTableDeck().getCards()); + + final String landSet = IBoosterDraft.LAND_SET_CODE[0]; + final int landsCount = 20; + deck.getSideboard().add(CardDb.instance().getCard("Forest", landSet), landsCount); + deck.getSideboard().add(CardDb.instance().getCard("Mountain", landSet), landsCount); + deck.getSideboard().add(CardDb.instance().getCard("Swamp", landSet), landsCount); + deck.getSideboard().add(CardDb.instance().getCard("Island", landSet), landsCount); + deck.getSideboard().add(CardDb.instance().getCard("Plains", landSet), landsCount); + + return deck; + } // getPlayersDeck() + + /** + *

+ * saveDraft. + *

+ */ + private void saveDraft() { + String s = ""; + while ((s == null) || (s.length() == 0)) { + s = JOptionPane.showInputDialog(null, + "Save this draft as:", + "Save draft", + JOptionPane.QUESTION_MESSAGE); + } + // TODO: check if overwriting the same name, and let the user delete old + // drafts + + // construct computer's decks + // save draft + final Deck[] computer = this.boosterDraft.getDecks(); + + final DeckGroup finishedDraft = new DeckGroup(s); + finishedDraft.setHumanDeck((Deck) this.getPlayersDeck().copyTo(s)); + finishedDraft.addAiDecks(computer); + + // DeckManager deckManager = new + // DeckManager(ForgeProps.getFile(NEW_DECKS)); + + // write the file + Singletons.getModel().getDecks().getDraft().add(finishedDraft); + + CSubmenuDraft.SINGLETON_INSTANCE.update(); + FControl.SINGLETON_INSTANCE.changeState(FControl.HOME_SCREEN); + } + + //========== Overridden from ACEditorBase + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#getController() + */ + @Override + public DeckController getDeckController() { + return null; + } + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#updateView() + */ + @Override + public void resetTables() { + } + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#show(forge.Command) + */ + @Override + public void init() { + this.setup(); + this.showChoices(this.boosterDraft.nextChoice()); + this.getTableDeck().setDeck((Iterable) null); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.controllers.ACEditorBase#exit() + */ + @Override + public boolean exit() { + CSubmenuDraft.SINGLETON_INSTANCE.update(); + return true; + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CEditorLimited.java b/src/main/java/forge/gui/deckeditor/controllers/CEditorLimited.java new file mode 100644 index 00000000000..364fc2cd17e --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CEditorLimited.java @@ -0,0 +1,183 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.controllers; + +import forge.deck.Deck; +import forge.deck.DeckGroup; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.tables.DeckController; +import forge.gui.deckeditor.tables.SColumnUtil; +import forge.gui.deckeditor.tables.TableView; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.gui.home.sanctioned.CSubmenuDraft; +import forge.gui.home.sanctioned.CSubmenuSealed; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.util.IStorage; +import forge.util.closures.Lambda0; + +/** + * Child controller for limited deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + * @author Forge + * @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $ + */ +public final class CEditorLimited extends ACEditorBase { + + private final DeckController controller; + + //========== Constructor + + /** + * Child controller for limited deck editor UI. + * + * @param deckMap0   {@link forge.deck.DeckGroup}<{@link forge.util.IStorage}> + */ + public CEditorLimited(final IStorage deckMap0) { + final TableView tblCatalog = new TableView(true, CardPrinted.class); + final TableView tblDeck = new TableView(true, CardPrinted.class); + + VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable()); + VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable()); + + this.setTableCatalog(tblCatalog); + this.setTableDeck(tblDeck); + + final Lambda0 newCreator = new Lambda0() { + @Override + public DeckGroup apply() { + return new DeckGroup(""); + } + }; + this.controller = new DeckController(deckMap0, this, newCreator); + } + + /** + * TODO: Write javadoc for this method. + * + * @param model + * @return + */ + private Deck getSelectedDeck(final DeckGroup model) { + return model.getHumanDeck(); + } + + //========== Overridden from ACEditorBase + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#addCard() + */ + @Override + public void addCard() { + final InventoryItem item = this.getTableCatalog().getSelectedCard(); + if ((item == null) || !(item instanceof CardPrinted)) { + return; + } + + // update view + final CardPrinted card = (CardPrinted) item; + this.getTableDeck().addCard(card); + this.getTableCatalog().removeCard(card); + + this.getDeckController().notifyModelChanged(); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#removeCard() + */ + @Override + public void removeCard() { + final InventoryItem item = this.getTableDeck().getSelectedCard(); + if ((item == null) || !(item instanceof CardPrinted)) { + return; + } + + // update view + final CardPrinted card = (CardPrinted) item; + this.getTableDeck().removeCard(card); + this.getTableCatalog().addCard(card); + + Deck model = getSelectedDeck(getDeckController().getModel()); + model.getMain().remove(card); model.getSideboard().add(card); + + this.getDeckController().notifyModelChanged(); + } + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#updateView() + */ + @Override + public void resetTables() { + final Deck toEdit = this.getSelectedDeck(this.controller.getModel()); + this.getTableCatalog().setDeck(toEdit.getSideboard()); + this.getTableDeck().setDeck(toEdit.getMain()); + } + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#getController() + */ + @Override + public DeckController getDeckController() { + return this.controller; + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#show(forge.Command) + */ + @Override + public void init() { + this.getTableCatalog().setup(VCardCatalog.SINGLETON_INSTANCE, SColumnUtil.getCatalogDefaultColumns()); + this.getTableDeck().setup(VCurrentDeck.SINGLETON_INSTANCE, SColumnUtil.getDeckDefaultColumns()); + + SEditorUtil.resetUI(); + + VCardCatalog.SINGLETON_INSTANCE.getBtnAdd4().setVisible(false); + VCurrentDeck.SINGLETON_INSTANCE.getBtnRemove4().setVisible(false); + + VCurrentDeck.SINGLETON_INSTANCE.getBtnSaveAs().setVisible(false); + VCurrentDeck.SINGLETON_INSTANCE.getBtnNew().setVisible(false); + VCurrentDeck.SINGLETON_INSTANCE.getBtnOpen().setVisible(false); + + VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setEnabled(false); + + VCardCatalog.SINGLETON_INSTANCE.getLblTitle().setText("Deck Editor: Limited Mode"); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.controllers.ACEditorBase#exit() + */ + @Override + public boolean exit() { + final boolean okToExit = SEditorIO.confirmSaveChanges(); + + if (okToExit) { + CSubmenuDraft.SINGLETON_INSTANCE.update(); + CSubmenuSealed.SINGLETON_INSTANCE.update(); + } + + return okToExit; + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CEditorPreferences.java b/src/main/java/forge/gui/deckeditor/controllers/CEditorPreferences.java new file mode 100644 index 00000000000..232d01703d1 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CEditorPreferences.java @@ -0,0 +1,151 @@ +package forge.gui.deckeditor.controllers; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import javax.swing.JCheckBox; + +import forge.Command; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.SEditorIO.EditorPreference; +import forge.gui.deckeditor.tables.SColumnUtil; +import forge.gui.deckeditor.tables.SColumnUtil.ColumnName; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.gui.deckeditor.views.VEditorPreferences; +import forge.gui.framework.ICDoc; + +/** + * Controls the "analysis" panel in the deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CEditorPreferences implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + SEditorIO.loadPreferences(); + + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogColor().setSelected( + SColumnUtil.getColumn(ColumnName.CAT_COLOR).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogRarity().setSelected( + SColumnUtil.getColumn(ColumnName.CAT_RARITY).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogCMC().setSelected( + SColumnUtil.getColumn(ColumnName.CAT_CMC).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogSet().setSelected( + SColumnUtil.getColumn(ColumnName.CAT_SET).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogAI().setSelected( + SColumnUtil.getColumn(ColumnName.CAT_AI).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckColor().setSelected( + SColumnUtil.getColumn(ColumnName.DECK_COLOR).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckRarity().setSelected( + SColumnUtil.getColumn(ColumnName.DECK_RARITY).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckCMC().setSelected( + SColumnUtil.getColumn(ColumnName.DECK_CMC).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckSet().setSelected( + SColumnUtil.getColumn(ColumnName.DECK_SET).isShowing()); + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckAI().setSelected( + SColumnUtil.getColumn(ColumnName.DECK_AI).isShowing()); + + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogStats().setSelected( + SEditorIO.getPref(EditorPreference.stats_catalog)); + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckStats().setSelected( + SEditorIO.getPref(EditorPreference.stats_deck)); + + if (!SEditorIO.getPref(EditorPreference.stats_deck)) { + VCurrentDeck.SINGLETON_INSTANCE.getPnlStats().setVisible(false); + } + if (!SEditorIO.getPref(EditorPreference.stats_catalog)) { + VCardCatalog.SINGLETON_INSTANCE.getPnlStats().setVisible(false); + } + + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogColor().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.CAT_COLOR)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogRarity().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.CAT_RARITY)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogCMC().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.CAT_CMC)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogSet().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.CAT_SET)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogAI().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.CAT_AI)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckColor().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.DECK_COLOR)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckRarity().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.DECK_RARITY)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckCMC().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.DECK_CMC)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckSet().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.DECK_SET)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckAI().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + SColumnUtil.toggleColumn(SColumnUtil.getColumn(ColumnName.DECK_AI)); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbCatalogStats().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + VCardCatalog.SINGLETON_INSTANCE.getPnlStats().setVisible( + ((JCheckBox) e.getSource()).isSelected()); + SEditorIO.setPref(EditorPreference.stats_catalog, ((JCheckBox) e.getSource()).isSelected()); + SEditorIO.savePreferences(); } }); + + VEditorPreferences.SINGLETON_INSTANCE.getChbDeckStats().addItemListener(new ItemListener() { + @Override public void itemStateChanged(final ItemEvent e) { + VCurrentDeck.SINGLETON_INSTANCE.getPnlStats().setVisible( + ((JCheckBox) e.getSource()).isSelected()); + SEditorIO.setPref(EditorPreference.stats_deck, ((JCheckBox) e.getSource()).isSelected()); + SEditorIO.savePreferences(); } }); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } + + //========== Other methods +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CEditorQuest.java b/src/main/java/forge/gui/deckeditor/controllers/CEditorQuest.java new file mode 100644 index 00000000000..2210e6ccc5e --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CEditorQuest.java @@ -0,0 +1,204 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.controllers; + +// import java.awt.Font; +import java.util.List; + +import forge.AllZone; +import forge.Constant; +import forge.deck.Deck; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.tables.DeckController; +import forge.gui.deckeditor.tables.SColumnUtil; +import forge.gui.deckeditor.tables.SColumnUtil.ColumnName; +import forge.gui.deckeditor.tables.TableColumnInfo; +import forge.gui.deckeditor.tables.TableView; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.gui.home.quest.CSubmenuQuestDecks; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.item.ItemPool; +import forge.quest.QuestController; +import forge.util.closures.Lambda0; + +//import forge.quest.data.QuestBoosterPack; + +/** + * Child controller for quest deck editor UI. + *

+ * Card catalog and decks are drawn from a QuestController object. + * + *

(C at beginning of class name denotes a control class.) + * + * @author Forge + * @version $Id$ + */ +public final class CEditorQuest extends ACEditorBase { + private final QuestController questData; + private final DeckController controller; + + /** + * Child controller for quest deck editor UI. + *

+ * Card catalog and decks are drawn from a QuestController object. + * + * @param questData0   {@link forge.quest.QuestController} + */ + public CEditorQuest(final QuestController questData0) { + this.questData = questData0; + + final TableView tblCatalog = new TableView(false, CardPrinted.class); + final TableView tblDeck = new TableView(false, CardPrinted.class); + + VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable()); + VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable()); + + this.setTableCatalog(tblCatalog); + this.setTableDeck(tblDeck); + + final Lambda0 newCreator = new Lambda0() { + @Override + public Deck apply() { + return new Deck(); + } + }; + this.controller = new DeckController(questData0.getMyDecks(), this, newCreator); + } + + /** + * Adds any card to the catalog and data pool. + * + * @param card {@link forge.item.CardPrinted} + */ + public void addCheatCard(final CardPrinted card) { + this.getTableCatalog().addCard(card); + this.questData.getCards().getCardpool().add(card); + } + + //=========== Overridden from ACEditorBase + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#addCard() + */ + @Override + public void addCard() { + final InventoryItem item = this.getTableCatalog().getSelectedCard(); + if ((item == null) || !(item instanceof CardPrinted)) { + return; + } + + final CardPrinted card = (CardPrinted) item; + this.getTableCatalog().removeCard(card); + this.getTableDeck().addCard(card); + this.controller.notifyModelChanged(); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#removeCard() + */ + @Override + public void removeCard() { + final InventoryItem item = this.getTableDeck().getSelectedCard(); + if ((item == null) || !(item instanceof CardPrinted)) { + return; + } + + final CardPrinted card = (CardPrinted) item; + this.getTableCatalog().addCard(card); + this.getTableDeck().removeCard(card); + } + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#updateView() + */ + @Override + public void resetTables() { + final Deck deck = this.controller.getModel(); + + final ItemPool cardpool = new ItemPool(CardPrinted.class); + cardpool.addAll(this.questData.getCards().getCardpool()); + // remove bottom cards that are in the deck from the card pool + cardpool.removeAll(deck.getMain()); + // show cards, makes this user friendly + this.getTableCatalog().setDeck(cardpool); + this.getTableDeck().setDeck(deck.getMain()); + } + + //=========== Overridden from ACEditorBase + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#getController() + */ + @Override + public DeckController getDeckController() { + return this.controller; + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#show(forge.Command) + */ + @Override + public void init() { + final List> columnsCatalog = SColumnUtil.getCatalogDefaultColumns(); + final List> columnsDeck = SColumnUtil.getDeckDefaultColumns(); + + // Add "new" column in catalog and deck + columnsCatalog.add(SColumnUtil.getColumn(ColumnName.CAT_NEW)); + + columnsCatalog.get(columnsCatalog.size() - 1).setSortAndDisplayFunctions( + this.questData.getCards().getFnNewCompare(), + this.questData.getCards().getFnNewGet()); + + columnsDeck.add(SColumnUtil.getColumn(ColumnName.DECK_NEW)); + + columnsDeck.get(columnsDeck.size() - 1).setSortAndDisplayFunctions( + this.questData.getCards().getFnNewCompare(), + this.questData.getCards().getFnNewGet()); + + this.getTableCatalog().setup(VCardCatalog.SINGLETON_INSTANCE, columnsCatalog); + this.getTableDeck().setup(VCurrentDeck.SINGLETON_INSTANCE, columnsDeck); + + Deck deck = Constant.Runtime.HUMAN_DECK[0] == null ? null : this.questData.getMyDecks().get( + Constant.Runtime.HUMAN_DECK[0].getName()); + + if (deck == null) { + deck = new Deck(); + } + + this.getDeckController().setModel(deck); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.controllers.ACEditorBase#exit() + */ + @Override + public boolean exit() { + final boolean okToExit = SEditorIO.confirmSaveChanges(); + if (okToExit) { + AllZone.getQuest().save(); + CSubmenuQuestDecks.SINGLETON_INSTANCE.update(); + } + return okToExit; + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CEditorQuestCardShop.java b/src/main/java/forge/gui/deckeditor/controllers/CEditorQuestCardShop.java new file mode 100644 index 00000000000..6b2496a7116 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CEditorQuestCardShop.java @@ -0,0 +1,368 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.controllers; + +import java.text.DecimalFormat; +import java.text.NumberFormat; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import javax.swing.JLabel; +import javax.swing.JOptionPane; + +import forge.AllZone; +import forge.deck.Deck; +import forge.deck.DeckBase; +import forge.gui.CardListViewer; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.tables.DeckController; +import forge.gui.deckeditor.tables.SColumnUtil; +import forge.gui.deckeditor.tables.SColumnUtil.ColumnName; +import forge.gui.deckeditor.tables.TableColumnInfo; +import forge.gui.deckeditor.tables.TableView; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.gui.home.quest.CSubmenuQuestDecks; +import forge.gui.home.quest.SSubmenuQuestUtil; +import forge.item.BoosterPack; +import forge.item.CardPrinted; +import forge.item.FatPack; +import forge.item.InventoryItem; +import forge.item.ItemPool; +import forge.item.ItemPoolView; +import forge.item.OpenablePack; +import forge.item.PreconDeck; +import forge.item.TournamentPack; +import forge.quest.QuestController; +import forge.quest.io.ReadPriceList; +import forge.util.closures.Lambda1; + +/** + * Child controller for quest card shop UI. + * + *

(C at beginning of class name denotes a control class.) + * + * @author Forge + * @version $Id: CEditorQuestCardShop.java 15088 2012-04-07 11:34:05Z Max mtg $ + */ +public final class CEditorQuestCardShop extends ACEditorBase { + private final JLabel creditsLabel = new JLabel(); + private final JLabel sellPercentageLabel = new JLabel(); + private double multiplier; + private final QuestController questData; + + // get pricelist: + private final ReadPriceList r = new ReadPriceList(); + private final Map mapPrices = this.r.getPriceList(); + private Map decksUsingMyCards; + + /** + * Child controller for quest card shop UI. + * + * @param qd + * a {@link forge.quest.data.QuestData} object. + */ + public CEditorQuestCardShop(final QuestController qd) { + this.questData = qd; + + final TableView tblCatalog = new TableView(false, InventoryItem.class); + final TableView tblDeck = new TableView(false, InventoryItem.class); + + VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable()); + VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable()); + + this.setTableCatalog(tblCatalog); + this.setTableDeck(tblDeck); + } + + /** + *

+ * setup. + *

+ */ + private void setup() { + final List> columnsCatalog = SColumnUtil.getCatalogDefaultColumns(); + final List> columnsDeck = SColumnUtil.getDeckDefaultColumns(); + + // Add "price", "decks", and "new" column in catalog and deck + columnsCatalog.add(SColumnUtil.getColumn(ColumnName.CAT_PURCHASE_PRICE)); + columnsCatalog.get(columnsCatalog.size() - 1).setSortAndDisplayFunctions( + this.fnPriceCompare, this.fnPriceGet); + + columnsCatalog.add(SColumnUtil.getColumn(ColumnName.CAT_DECKS)); + columnsCatalog.get(columnsCatalog.size() - 1).setSortAndDisplayFunctions( + this.fnDeckCompare, this.fnDeckGet); + + columnsCatalog.add(SColumnUtil.getColumn(ColumnName.CAT_NEW)); + columnsCatalog.get(columnsCatalog.size() - 1).setSortAndDisplayFunctions( + this.questData.getCards().getFnNewCompare(), this.questData.getCards().getFnNewGet()); + + columnsDeck.add(SColumnUtil.getColumn(ColumnName.DECK_SALE_PRICE)); + columnsDeck.get(columnsDeck.size() - 1).setSortAndDisplayFunctions( + this.fnPriceCompare, this.fnPriceSellGet); + + columnsDeck.add(SColumnUtil.getColumn(ColumnName.DECK_NEW)); + columnsDeck.get(columnsDeck.size() - 1).setSortAndDisplayFunctions( + this.questData.getCards().getFnNewCompare(), this.questData.getCards().getFnNewGet()); + + // Setup with current column set + this.getTableCatalog().setup(VCardCatalog.SINGLETON_INSTANCE, columnsCatalog); + this.getTableDeck().setup(VCurrentDeck.SINGLETON_INSTANCE, columnsDeck); + + SEditorUtil.resetUI(); + VCardCatalog.SINGLETON_INSTANCE.getPnlHeader().setVisible(false); + VCurrentDeck.SINGLETON_INSTANCE.getPnlHeader().setVisible(false); + } + + // fills number of decks using each card + private Map countDecksForEachCard() { + final Map result = new HashMap(); + for (final Deck deck : this.questData.getMyDecks()) { + for (final Entry e : deck.getMain()) { + final CardPrinted card = e.getKey(); + final Integer amount = result.get(card); + result.put(card, Integer.valueOf(amount == null ? 1 : 1 + amount.intValue())); + } + } + return result; + } + + private Integer getCardValue(final InventoryItem card) { + if (this.mapPrices.containsKey(card.getName())) { + return this.mapPrices.get(card.getName()); + } else if (card instanceof CardPrinted) { + switch (((CardPrinted) card).getRarity()) { + case BasicLand: + return Integer.valueOf(4); + case Common: + return Integer.valueOf(6); + case Uncommon: + return Integer.valueOf(40); + case Rare: + return Integer.valueOf(120); + case MythicRare: + return Integer.valueOf(600); + default: + return Integer.valueOf(15); + } + } else if (card instanceof BoosterPack) { + return 395; + } else if (card instanceof TournamentPack) { + return 995; + } else if (card instanceof FatPack) { + return 2365; + } else if (card instanceof PreconDeck) { + return ((PreconDeck) card).getRecommendedDeals().getCost(); + } + return 1337; + } + + @SuppressWarnings("rawtypes") + private final Lambda1> fnPriceCompare = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return CEditorQuestCardShop.this.getCardValue(from.getKey()); + } + }; + private final Lambda1> fnPriceGet = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return CEditorQuestCardShop.this.getCardValue(from.getKey()); + } + }; + private final Lambda1> fnPriceSellGet = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return (int) (CEditorQuestCardShop.this.multiplier * CEditorQuestCardShop.this.getCardValue(from.getKey())); + } + }; + + @SuppressWarnings("rawtypes") + private final Lambda1> fnDeckCompare = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + final Integer iValue = CEditorQuestCardShop.this.decksUsingMyCards.get(from.getKey()); + return iValue == null ? Integer.valueOf(0) : iValue; + } + }; + private final Lambda1> fnDeckGet = new Lambda1>() { + @Override + public Object apply(final Entry from) { + final Integer iValue = CEditorQuestCardShop.this.decksUsingMyCards.get(from.getKey()); + return iValue == null ? "" : iValue.toString(); + } + }; + + //=========== Overridden from ACEditorBase + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#addCard() + */ + @Override + public void addCard() { + final InventoryItem item = this.getTableCatalog().getSelectedCard(); + if (item == null) { + return; + } + + final int value = this.getCardValue(item); + + if (value <= this.questData.getAssets().getCredits()) { + + if (item instanceof CardPrinted) { + this.getTableCatalog().removeCard(item); + + final CardPrinted card = (CardPrinted) item; + this.getTableDeck().addCard(card); + this.questData.getCards().buyCard(card, value); + + } else if (item instanceof OpenablePack) { + this.getTableCatalog().removeCard(item); + + OpenablePack booster = null; + if (item instanceof BoosterPack) { + booster = (BoosterPack) ((BoosterPack) item).clone(); + } else if (item instanceof TournamentPack) { + booster = (TournamentPack) ((TournamentPack) item).clone(); + } else if (item instanceof FatPack) { + booster = (FatPack) ((FatPack) item).clone(); + } + this.questData.getCards().buyPack(booster, value); + final List newCards = booster.getCards(); + for (final CardPrinted card : newCards) { + this.getTableDeck().addCard(card); + } + final CardListViewer c = new CardListViewer(booster.getName(), + "You have found the following cards inside:", newCards); + c.show(); + } else if (item instanceof PreconDeck) { + this.getTableCatalog().removeCard(item); + final PreconDeck deck = (PreconDeck) item; + this.questData.getCards().buyPreconDeck(deck, value); + + for (final CardPrinted card : deck.getDeck().getMain().toFlatList()) { + this.getTableDeck().addCard(card); + } + JOptionPane.showMessageDialog(null, String.format( + "Deck '%s' was added to your decklist.%n%nCards from it were also added to your pool.", + deck.getName()), "Thanks for purchasing!", JOptionPane.INFORMATION_MESSAGE); + + } + + this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits()); + } else { + JOptionPane.showMessageDialog(null, "Not enough credits!"); + } + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#removeCard() + */ + @Override + public void removeCard() { + final InventoryItem item = this.getTableDeck().getSelectedCard(); + if ((item == null) || !(item instanceof CardPrinted)) { + return; + } + + final CardPrinted card = (CardPrinted) item; + this.getTableDeck().removeCard(card); + this.getTableCatalog().addCard(card); + + final int price = Math.min((int) (this.multiplier * this.getCardValue(card)), this.questData.getCards() + .getSellPriceLimit()); + this.questData.getCards().sellCard(card, price); + + this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits()); + } + + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#resetTables() + */ + @Override + public void resetTables() { + } + + /* + * (non-Javadoc) + * + * @see forge.gui.deckeditor.ACEditorBase#getController() + */ + @Override + public DeckController getDeckController() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.ACEditorBase#show(forge.Command) + */ + @Override + public void init() { + this.setup(); + + this.decksUsingMyCards = this.countDecksForEachCard(); + + this.multiplier = this.questData.getCards().getSellMultiplier(); + + ItemPoolView forSale = this.questData.getCards().getShopList(); + if (forSale.isEmpty()) { + this.questData.getCards().generateCardsInShop(); + forSale = this.questData.getCards().getShopList(); + } + + // newCardsList = questData.getCards().getNewCards(); + final ItemPool ownedItems = new ItemPool(InventoryItem.class); + ownedItems.addAll(this.questData.getCards().getCardpool().getView()); + + this.getTableCatalog().setDeck(forSale); + this.getTableDeck().setDeck(ownedItems); + + this.creditsLabel.setText("Credits: " + this.questData.getAssets().getCredits()); + + final double multiPercent = this.multiplier * 100; + final NumberFormat formatter = new DecimalFormat("#0.00"); + String maxSellingPrice = ""; + final int maxSellPrice = this.questData.getCards().getSellPriceLimit(); + + if (maxSellPrice < Integer.MAX_VALUE) { + maxSellingPrice = String.format("Maximum selling price is %d credits.", maxSellPrice); + } + this.sellPercentageLabel.setText("Selling cards at " + formatter.format(multiPercent) + + "% of their value.
" + maxSellingPrice + ""); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.controllers.ACEditorBase#exit() + */ + @Override + public boolean exit() { + final boolean okToExit = SEditorIO.confirmSaveChanges(); + if (okToExit) { + SSubmenuQuestUtil.updateStatsAndPet(); + AllZone.getQuest().save(); + CSubmenuQuestDecks.SINGLETON_INSTANCE.update(); + } + return okToExit; + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CFilters.java b/src/main/java/forge/gui/deckeditor/controllers/CFilters.java new file mode 100644 index 00000000000..4e26a9ca0e2 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CFilters.java @@ -0,0 +1,176 @@ +package forge.gui.deckeditor.controllers; + +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.ArrayList; +import java.util.List; + +import forge.Command; +import forge.deck.DeckBase; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.SFilterUtil; +import forge.gui.deckeditor.views.VFilters; +import forge.gui.framework.ICDoc; +import forge.gui.toolbox.FLabel; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.util.closures.Predicate; + +/** + * Controls the "filters" panel in the deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CFilters implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + private boolean filtersAllEnabled = true; + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @SuppressWarnings("serial") + @Override + public void initialize() { + final ItemListener iliFilter = new ItemListener() { + @Override + public void itemStateChanged(final ItemEvent arg0) { + if (!SFilterUtil.isFilteringPrevented()) { + buildFilter(); + } + } + }; + + VFilters.SINGLETON_INSTANCE.getCbxSets().addItemListener(iliFilter); + VFilters.SINGLETON_INSTANCE.getCbxPLow().addItemListener(iliFilter); + VFilters.SINGLETON_INSTANCE.getCbxPHigh().addItemListener(iliFilter); + VFilters.SINGLETON_INSTANCE.getCbxTLow().addItemListener(iliFilter); + VFilters.SINGLETON_INSTANCE.getCbxTHigh().addItemListener(iliFilter); + VFilters.SINGLETON_INSTANCE.getCbxCMCLow().addItemListener(iliFilter); + VFilters.SINGLETON_INSTANCE.getCbxCMCHigh().addItemListener(iliFilter); + + ((FLabel) VFilters.SINGLETON_INSTANCE.getBtnToggle()).setCommand(new Command() { + @Override + public void execute() { + SFilterUtil.setPreventFiltering(true); + toggleColorTypeSetFilter(); + SFilterUtil.setPreventFiltering(false); + buildFilter(); + } + }); + + ((FLabel) VFilters.SINGLETON_INSTANCE.getBtnResetIntervals()).setCommand(new Command() { + @Override + public void execute() { + SFilterUtil.setPreventFiltering(true); + VFilters.SINGLETON_INSTANCE.getCbxPLow().setSelectedIndex(0); + VFilters.SINGLETON_INSTANCE.getCbxTLow().setSelectedIndex(0); + VFilters.SINGLETON_INSTANCE.getCbxCMCLow().setSelectedIndex(0); + + VFilters.SINGLETON_INSTANCE.getCbxPHigh().setSelectedIndex( + VFilters.SINGLETON_INSTANCE.getCbxPHigh().getItemCount() - 1); + VFilters.SINGLETON_INSTANCE.getCbxTHigh().setSelectedIndex( + VFilters.SINGLETON_INSTANCE.getCbxTHigh().getItemCount() - 1); + VFilters.SINGLETON_INSTANCE.getCbxCMCHigh().setSelectedIndex( + VFilters.SINGLETON_INSTANCE.getCbxCMCHigh().getItemCount() - 1); + + SFilterUtil.setPreventFiltering(false); + buildFilter(); + } + }); + + ((FLabel) VFilters.SINGLETON_INSTANCE.getBtnResetText()).setCommand(new Command() { + @Override + public void execute() { + VFilters.SINGLETON_INSTANCE.getTxfContains().setText(""); + VFilters.SINGLETON_INSTANCE.getTxfWithout().setText(""); + buildFilter(); + } + }); + + VFilters.SINGLETON_INSTANCE.getTxfContains().addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(final KeyEvent e) { + if (e.getKeyCode() == 10) { buildFilter(); } + } + }); + + VFilters.SINGLETON_INSTANCE.getTxfWithout().addKeyListener(new KeyAdapter() { + @Override + public void keyReleased(final KeyEvent e) { + if (e.getKeyCode() == 10) { buildFilter(); } + } + }); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + } + + /** + * Clear filter button_action performed. + * + * @param e + * the e + */ + private void toggleColorTypeSetFilter() { + VFilters.SINGLETON_INSTANCE.getCbxSets().setSelectedIndex(0); + + if (filtersAllEnabled) { + filtersAllEnabled = false; + SFilterUtil.toggleColorCheckboxes(false); + SFilterUtil.toggleTypeCheckboxes(false); + } + else { + filtersAllEnabled = true; + SFilterUtil.toggleColorCheckboxes(true); + SFilterUtil.toggleTypeCheckboxes(true); + } + } + + //=========== + + /** + * + * Assembles filter from the ones available. To prevent a block + * of filters from being used, set its parent panel's visibility to false. + * + * @param   extends InventoryItem + * @param   extends DeckBase + */ + @SuppressWarnings("unchecked") + public void buildFilter() { + // The main trick here is to apply a CardPrinted predicate + // to the table. CardRules will lead to difficulties. + final List> lstFilters = new ArrayList>(); + + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + lstFilters.add(SFilterUtil.buildColorFilter()); + lstFilters.add(SFilterUtil.buildTypeFilter()); + lstFilters.add(SFilterUtil.buildSetAndFormatFilter()); + lstFilters.add(SFilterUtil.buildTextFilter()); + lstFilters.add(SFilterUtil.buildIntervalFilter()); + + // Apply to table + ed.getTableCatalog().setFilter((Predicate) Predicate.and(lstFilters)); + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CProbabilities.java b/src/main/java/forge/gui/deckeditor/controllers/CProbabilities.java new file mode 100644 index 00000000000..63241562caa --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CProbabilities.java @@ -0,0 +1,100 @@ +package forge.gui.deckeditor.controllers; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import forge.Command; +import forge.deck.DeckBase; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.views.VProbabilities; +import forge.gui.framework.ICDoc; +import forge.gui.toolbox.FLabel; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.item.ItemPool; +import forge.item.ItemPoolView; +import forge.util.MyRandom; + +/** + * Controls the "analysis" panel in the deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CProbabilities implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + @SuppressWarnings("serial") + public void initialize() { + ((FLabel) VProbabilities.SINGLETON_INSTANCE.getLblReshuffle()).setCommand( + new Command() { @Override public void execute() { update(); } }); + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + VProbabilities.SINGLETON_INSTANCE.rebuildLabels(analyze()); + } + + //========== Other methods + @SuppressWarnings("unchecked") + private List analyze() { + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + final ItemPoolView deck = ItemPool.createFrom( + ed.getTableDeck().getCards(), CardPrinted.class); + + final List cardProbabilities = new ArrayList(); + + final List shuffled = deck.toFlatList(); + Collections.shuffle(shuffled, MyRandom.getRandom()); + + // Log totals of each card for decrementing + final Map cardTotals = new HashMap(); + for (final CardPrinted c : shuffled) { + if (cardTotals.containsKey(c)) { cardTotals.put(c, cardTotals.get(c) + 1); } + else { cardTotals.put(c, 1); } + } + + // Run through shuffled deck and calculate probabilities. + // Formulas is (remaining instances of this card / total cards remaining) + final Iterator itr = shuffled.iterator(); + CardPrinted tmp; + int prob; + while (itr.hasNext()) { + tmp = itr.next(); + + prob = SEditorUtil.calculatePercentage( + cardTotals.get(tmp), shuffled.size()); + + cardTotals.put(tmp, cardTotals.get(tmp) - 1); + cardProbabilities.add(tmp.getName() + " (" + prob + "%)"); + itr.remove(); + } + + return cardProbabilities; + } +} diff --git a/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java b/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java new file mode 100644 index 00000000000..71e26e70f9f --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/controllers/CStatistics.java @@ -0,0 +1,191 @@ +package forge.gui.deckeditor.controllers; + +import java.util.Map.Entry; + +import forge.Command; +import forge.card.CardColor; +import forge.card.CardRules; +import forge.card.CardRules.Predicates; +import forge.deck.DeckBase; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.views.VStatistics; +import forge.gui.framework.ICDoc; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.item.ItemPool; +import forge.item.ItemPoolView; +import forge.util.closures.Predicate; + +/** + * Controls the "analysis" panel in the deck editor UI. + * + *

(C at beginning of class name denotes a control class.) + * + */ +public enum CStatistics implements ICDoc { + /** */ + SINGLETON_INSTANCE; + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#getCommandOnSelect() + */ + @Override + public Command getCommandOnSelect() { + return null; + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#initialize() + */ + @Override + public void initialize() { + } + + /* (non-Javadoc) + * @see forge.gui.framework.ICDoc#update() + */ + @Override + public void update() { + analyze(); + } + + //========== Other methods + @SuppressWarnings("unchecked") + private void analyze() { + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + if (ed == null) { return; } + + final ItemPoolView deck = ItemPool.createFrom( + ed.getTableDeck().getCards(), CardPrinted.class); + + int tmp = 0; + int total = deck.countAll(); + + // Hack-ish: avoid /0 cases, but still populate labels :) + if (total == 0) { total = 1; } + + tmp = CardRules.Predicates.Presets.IS_MULTICOLOR + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblMulti().setText(String.valueOf(tmp)); + + tmp = CardRules.Predicates.Presets.IS_CREATURE + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblCreature().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = CardRules.Predicates.Presets.IS_LAND + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblLand().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = CardRules.Predicates.Presets.IS_ENCHANTMENT + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblEnchantment().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = CardRules.Predicates.Presets.IS_ARTIFACT + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblArtifact().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = CardRules.Predicates.Presets.IS_INSTANT + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblInstant().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = CardRules.Predicates.Presets.IS_SORCERY + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblSorcery().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = CardRules.Predicates.Presets.IS_PLANESWALKER + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblPlaneswalker().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = CardRules.Predicates.Presets.IS_COLORLESS + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblColorless().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = Predicate.and( + Predicates.isColor(CardColor.BLACK), + Predicates.hasCntColors((byte) 1)) + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblBlack().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = Predicate.and( + Predicates.isColor(CardColor.BLUE), + Predicates.hasCntColors((byte) 1)) + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblBlue().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = Predicate.and( + Predicates.isColor(CardColor.GREEN), + Predicates.hasCntColors((byte) 1)) + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblGreen().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = Predicate.and( + Predicates.isColor(CardColor.RED), + Predicates.hasCntColors((byte) 1)) + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblRed().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + tmp = Predicate.and( + Predicates.isColor(CardColor.WHITE), + Predicates.hasCntColors((byte) 1)) + .aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); + VStatistics.SINGLETON_INSTANCE.getLblWhite().setText( + tmp + " (" + SEditorUtil.calculatePercentage(tmp, total) + "%)"); + + int cmc0 = 0, cmc1 = 0, cmc2 = 0, cmc3 = 0, cmc4 = 0, cmc5 = 0, cmc6 = 0; + int tmc = 0; + + for (final Entry e : deck) { + final CardRules cardRules = e.getKey().getCard(); + final int count = e.getValue(); + final int cmc = cardRules.getManaCost().getCMC(); + + if (cmc == 0) { cmc0 += count; } + else if (cmc == 1) { cmc1 += count; } + else if (cmc == 2) { cmc2 += count; } + else if (cmc == 3) { cmc3 += count; } + else if (cmc == 4) { cmc4 += count; } + else if (cmc == 5) { cmc5 += count; } + else if (cmc >= 6) { cmc6 += count; } + + tmc += (cmc * count); + } + + VStatistics.SINGLETON_INSTANCE.getLblCMC0().setText( + cmc0 + " (" + SEditorUtil.calculatePercentage(cmc0, total) + "%)"); + VStatistics.SINGLETON_INSTANCE.getLblCMC1().setText( + cmc1 + " (" + SEditorUtil.calculatePercentage(cmc1, total) + "%)"); + VStatistics.SINGLETON_INSTANCE.getLblCMC2().setText( + cmc2 + " (" + SEditorUtil.calculatePercentage(cmc2, total) + "%)"); + VStatistics.SINGLETON_INSTANCE.getLblCMC3().setText( + cmc3 + " (" + SEditorUtil.calculatePercentage(cmc3, total) + "%)"); + VStatistics.SINGLETON_INSTANCE.getLblCMC4().setText( + cmc4 + " (" + SEditorUtil.calculatePercentage(cmc4, total) + "%)"); + VStatistics.SINGLETON_INSTANCE.getLblCMC5().setText( + cmc5 + " (" + SEditorUtil.calculatePercentage(cmc5, total) + "%)"); + VStatistics.SINGLETON_INSTANCE.getLblCMC6().setText( + cmc6 + " (" + SEditorUtil.calculatePercentage(cmc6, total) + "%)"); + + double amc = (double) Math.round((double) tmc / (double) total * 100) / 100.0d; + + VStatistics.SINGLETON_INSTANCE.getLblTotal().setText("TOTAL CARDS: " + deck.countAll()); + VStatistics.SINGLETON_INSTANCE.getLblTMC().setText("TOTAL MANA COST: " + tmc); + VStatistics.SINGLETON_INSTANCE.getLblAMC().setText("AVERAGE MANA COST: " + amc); + } +} diff --git a/src/main/java/forge/gui/deckeditor/elements/CardPanelBase.java b/src/main/java/forge/gui/deckeditor/elements/CardPanelBase.java deleted file mode 100644 index 046831f4a48..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/CardPanelBase.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import javax.swing.JPanel; - -import forge.item.InventoryItem; - -/** - * Base class for any cardView panel. - * - */ -public abstract class CardPanelBase extends JPanel { - private static final long serialVersionUID = -2230733670423143126L; - - /** - * - * showCard. - * - * @param card - * an InventoryItem - */ - public abstract void showCard(InventoryItem card); - -} diff --git a/src/main/java/forge/gui/deckeditor/elements/CardPanelHeavy.java b/src/main/java/forge/gui/deckeditor/elements/CardPanelHeavy.java deleted file mode 100644 index c43ad008062..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/CardPanelHeavy.java +++ /dev/null @@ -1,251 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import java.awt.event.ActionEvent; -import java.io.File; - -import javax.swing.JButton; -import javax.swing.JOptionPane; - -import net.miginfocom.swing.MigLayout; -import forge.Card; -import forge.CardCharactersticName; -import forge.gui.CardDetailPanel; -import forge.gui.GuiDisplayUtil; -import forge.item.CardPrinted; -import forge.item.InventoryItem; -import forge.properties.ForgeProps; -import forge.properties.NewConstants; -import forge.view.arcane.CardPanel; -import forge.view.arcane.ViewPanel; - -/** - * This panel is to be placed in the right part of a deck editor. - */ -public class CardPanelHeavy extends CardPanelBase { - - private static final long serialVersionUID = -7134546689397508597L; - - private final JButton changeStateButton = new JButton(); - - /* - * Removed Oct 25 2011 - Hellfish private JButton changePictureButton = new - * JButton(); private JButton removePictureButton = new JButton(); - */ - - // Controls to show card details - /** The detail. */ - private final CardDetailPanel detail = new CardDetailPanel(null); - - /** The picture. */ - private final CardPanel picture = new CardPanel(null); - - /** The picture view panel. */ - private final ViewPanel pictureViewPanel = new ViewPanel(); - - // fake card to allow picture changes - /** The c card hq. */ - private Card cCardHQ; - - /** Constant previousDirectory. */ - // private static File previousDirectory = null; - - /** - * Instantiates a new card panel heavy. - */ - public CardPanelHeavy() { - this.changeStateButton.setVisible(false); - this.changeStateButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - CardPanelHeavy.this.changeStateButtonActionPerformed(e); - } - }); - this.changeStateButton.setFont(new java.awt.Font("Dialog", 0, 10)); - - /* - * Removed Oct 25 2011 - Hellfish - * changePictureButton.setText("Change picture..."); - * changePictureButton.addActionListener(new - * java.awt.event.ActionListener() { public void - * actionPerformed(ActionEvent e) { - * changePictureButton_actionPerformed(e); } }); if - * (!Singletons.getModel().getPreferences().lafFonts) - * changePictureButton.setFont(new java.awt.Font("Dialog", 0, 10)); - * - * removePictureButton.setText("Remove picture..."); - * removePictureButton.addActionListener(new - * java.awt.event.ActionListener() { public void - * actionPerformed(ActionEvent e) { - * removePictureButton_actionPerformed(e); } }); if - * (!Singletons.getModel().getPreferences().lafFonts) - * removePictureButton.setFont(new java.awt.Font("Dialog", 0, 10)); - */ - - this.pictureViewPanel.setCardPanel(this.picture); - - this.setLayout(new MigLayout("fill, ins 0")); - this.add(this.detail, "w 239, h 323, grow, flowy, wrap"); - /* - * Removed Oct 25 2011 - Hellfish this.add(changeStateButton, - * "align 50% 0%, split 3, flowx"); this.add(changePictureButton, - * "align 50% 0%"); this.add(removePictureButton, "align 50% 0%, wrap"); - */ - this.add(this.changeStateButton, "align 50% 0%, flowx, wrap"); - this.add(this.pictureViewPanel, "wmin 239, hmin 323, grow"); - } - - /* - * (non-Javadoc) - * - * @see - * forge.gui.deckeditor.CardPanelBase#showCard(forge.item.InventoryItem) - */ - @Override - public final void showCard(final InventoryItem card) { - final Card card2 = card instanceof CardPrinted ? ((CardPrinted) card).toForgeCard() : null; - this.detail.setCard(card2); - this.setCard(card2); - } - - /** - * Sets the card. - * - * @param c - * the new card - */ - public final void setCard(final Card c) { - if (this.picture.getCard() != null) { - if (this.picture.getCard().isInAlternateState()) { - this.picture.getCard().setState(CardCharactersticName.Original); - } - } - this.picture.setCard(c); - - if (c.isFlip()) { - this.changeStateButton.setVisible(true); - this.changeStateButton.setText("Flip"); - } else if (c.isDoubleFaced()) { - this.changeStateButton.setVisible(true); - this.changeStateButton.setText("Transform"); - } else { - this.changeStateButton.setVisible(false); - } - } - - /** - *

- * changeStateButton_actionPerformed. - *

- * - * @param e - * a {@link java.awt.event.ActionEvent} object. - */ - final void changeStateButtonActionPerformed(final ActionEvent e) { - final Card cur = this.picture.getCard(); - if (cur.isInAlternateState()) { - cur.setState(CardCharactersticName.Original); - } else { - if (cur.isFlip()) { - cur.setState(CardCharactersticName.Flipped); - } - if (cur.isDoubleFaced()) { - cur.setState(CardCharactersticName.Transformed); - } - } - - this.picture.setCard(cur); - this.detail.setCard(cur); - } - - /** - *

- * getImportFilename. - *

- * - * @param e - * the e - * @return a {@link java.io.File} object. - */ - /* - * private File getImportFilename() { final JFileChooser chooser = new - * JFileChooser(CardPanelHeavy.previousDirectory); final ImagePreviewPanel - * preview = new ImagePreviewPanel(); chooser.setAccessory(preview); - * chooser.addPropertyChangeListener(preview); - * chooser.addChoosableFileFilter(this.dckFilter); final int returnVal = - * chooser.showOpenDialog(null); - * - * if (returnVal == JFileChooser.APPROVE_OPTION) { final File file = - * chooser.getSelectedFile(); CardPanelHeavy.previousDirectory = - * file.getParentFile(); return file; } - * - * return null; - * - * } - */ - - /** The dck filter. */ - /* - * private final FileFilter dckFilter = new FileFilter() { - * - * @Override public boolean accept(final File f) { return - * f.getName().endsWith(".jpg") || f.isDirectory(); } - * - * @Override public String getDescription() { return "*.jpg"; } - * - * }; - */ - - /** - *

- * removePictureButton_actionPerformed - *

- * . Removed Oct 25 2011 - Hellfish - * - * @param e - * the e - */ - final void removePictureButtonActionPerformed(final ActionEvent e) { - if (this.cCardHQ != null) { - final String[] options = { "Yes", "No" }; - final int value = JOptionPane.showOptionDialog(null, "Do you want delete " + this.cCardHQ.getName() - + " picture?", "Delete picture", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, - options, options[1]); - if (value == 0) { - final String fileName = GuiDisplayUtil.cleanString(this.cCardHQ.getName()) + ".jpg"; - final File base = ForgeProps.getFile(NewConstants.IMAGE_BASE); - final File f = new File(base, fileName); - f.delete(); - JOptionPane.showMessageDialog(null, "Picture " + this.cCardHQ.getName() + " deleted.", - "Delete picture", JOptionPane.INFORMATION_MESSAGE); - this.setCard(this.cCardHQ); - } - } - } - - /** - * Gets the card. - * - * @return the card - */ - public final Card getCard() { - return this.detail.getCard(); - } - -} diff --git a/src/main/java/forge/gui/deckeditor/elements/CardPanelLite.java b/src/main/java/forge/gui/deckeditor/elements/CardPanelLite.java deleted file mode 100644 index b6f927819bd..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/CardPanelLite.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JScrollPane; -import javax.swing.JTextPane; - -import net.miginfocom.swing.MigLayout; - -import org.apache.commons.lang3.StringUtils; - -import forge.Card; -import forge.CardCharactersticName; -import forge.Singletons; -import forge.card.CardEdition; -import forge.gui.CardDetailPanel; -import forge.gui.CardPicturePanel; -import forge.item.CardPrinted; -import forge.item.InventoryItem; -import forge.item.OpenablePack; -import forge.item.PreconDeck; - -/** - * This panel is to be placed in the right part of a deck editor. - * - */ -public class CardPanelLite extends CardPanelBase { - - private static final long serialVersionUID = -7134546689397508597L; - - // Controls to show card details - /** The detail. */ - private final CardDetailPanel detail = new CardDetailPanel(null); - private final CardPicturePanel picture = new CardPicturePanel(null); - private final JButton bChangeState = new JButton(); - private final JTextPane description = new JTextPane(); - private final JScrollPane descrScroll; - - /** - * - * Constructor. - */ - public CardPanelLite() { - this.bChangeState.setVisible(false); - this.bChangeState.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - CardPanelLite.this.bChangeStateActionPerformed(e); - } - }); - this.bChangeState.setFont(new java.awt.Font("Dialog", 0, 10)); - - this.descrScroll = new JScrollPane(this.description); - - this.setLayout(new MigLayout("fill, ins 0")); - this.add(this.detail, "w 239, h 303, grow, flowy, wrap"); - this.add(this.descrScroll, "w 239, h 303, grow, flowy, wrap"); - this.add(this.bChangeState, "align 50% 0%, wrap"); - this.add(this.picture, "wmin 239, hmin 323, grow"); - - this.description.setEditable(false); - this.description.setCursor(null); - this.description.setOpaque(false); - this.description.setFocusable(false); - } - - private static Dimension shrinkedComponent = new Dimension(239, 0); - private static Dimension expandedComponent = new Dimension(239, 303); - - /** - * - * ShowCard. - * - * @param card - * an InventoryItem - */ - @Override - public final void showCard(final InventoryItem card) { - this.picture.setCard(card); - final boolean isCard = (card != null) && (card instanceof CardPrinted); - this.detail.setVisible(isCard); - this.description.setVisible(!isCard); - this.descrScroll.setMaximumSize(isCard ? CardPanelLite.shrinkedComponent : CardPanelLite.expandedComponent); - this.detail.setMaximumSize(!isCard ? CardPanelLite.shrinkedComponent : CardPanelLite.expandedComponent); - if (isCard) { - final Card toSet = ((CardPrinted) card).toForgeCard(); - - this.detail.setCard(toSet); - if (toSet.hasAlternateState()) { - this.bChangeState.setVisible(true); - if (toSet.isFlip()) { - this.bChangeState.setText("Flip"); - } else { - this.bChangeState.setText("Transform"); - } - } - } else { - if (card instanceof OpenablePack) { - final OpenablePack booster = (OpenablePack) card; - final CardEdition set = Singletons.getModel().getEditions().getEditionByCodeOrThrow(booster.getEdition()); - final String tpl = "%s %s.%n%nContains %d cards.%n%nBuy it to reveal the cards and add them to your inventory."; - this.description.setText(String.format(tpl, set.getName(), booster.getType(), booster.getTotalCards())); - } else if (card instanceof PreconDeck) { - final PreconDeck deck = (PreconDeck) card; - final String desc = deck.getDescription(); - final String tpl = "%s%n%n%s%n%nThis deck contains the following cards:%n%s"; - final String decklist = StringUtils.join(deck.getDeck().getMain().toItemListString(), "\n"); - this.description.setText(String.format(tpl, deck.getName(), desc, decklist)); - this.description.setCaretPosition(0); - - } - } - } - - /** - * Sets the card. - * - * @param c - * the new card - */ - public final void setCard(final Card c) { - this.picture.setCard(c); - if (c != null) { - this.detail.setCard(c); - - if (c.isFlip()) { - this.bChangeState.setVisible(true); - this.bChangeState.setText("Flip"); - } else if (c.isDoubleFaced()) { - this.bChangeState.setVisible(true); - this.bChangeState.setText("Transform"); - } else { - this.bChangeState.setVisible(false); - } - } - } - - /** - * - * getCard. - * - * @return Card - */ - public final Card getCard() { - return this.detail.getCard(); - } - - private void bChangeStateActionPerformed(final ActionEvent e) { - final Card cur = this.detail.getCard(); - if (cur != null) { - if (cur.isDoubleFaced()) { - if (cur.getCurState() == CardCharactersticName.Transformed) { - cur.setState(CardCharactersticName.Original); - } else { - cur.setState(CardCharactersticName.Transformed); - } - } - - this.setCard(cur); - } - } - -} diff --git a/src/main/java/forge/gui/deckeditor/elements/CheckBoxWithIcon.java b/src/main/java/forge/gui/deckeditor/elements/CheckBoxWithIcon.java deleted file mode 100644 index 040481d1e1c..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/CheckBoxWithIcon.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.ImageIcon; -import javax.swing.JCheckBox; - -/** - * Custom check box class for filter icon. - */ -public class CheckBoxWithIcon extends JCheckBox { - /* CHOPPIC */ - /* Custom check box class for filter icons */ - private static final long serialVersionUID = -8099263807219520120L; - - private final String imagePath = "res/images/deckeditor/"; - private final String iconYes; - private final String iconNo; - private final CheckBoxWithIcon cb; - - /** - * Instantiates a new check box with icon. - * - * @param filterName - * the filter name - * @param toolTip - * the tool tip - */ - CheckBoxWithIcon(final String filterName, final String toolTip) { - super("", true); - this.cb = this; - this.iconYes = this.imagePath + "filter_" + filterName + "_y.png"; - this.iconNo = this.imagePath + "filter_" + filterName + "_n.png"; - this.setIcon(new ImageIcon(this.iconYes)); - this.setToolTipText(toolTip); - this.addActionListener(new ActionListener() { - @Override - public void actionPerformed(final ActionEvent actionEvent) { - if (CheckBoxWithIcon.this.cb.isSelected()) { - CheckBoxWithIcon.this.cb.setIcon(new ImageIcon(CheckBoxWithIcon.this.iconYes)); - } else { - CheckBoxWithIcon.this.cb.setIcon(new ImageIcon(CheckBoxWithIcon.this.iconNo)); - } - } - }); - } -} diff --git a/src/main/java/forge/gui/deckeditor/elements/DeckAnalysis.java b/src/main/java/forge/gui/deckeditor/elements/DeckAnalysis.java deleted file mode 100644 index 2d447c15627..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/DeckAnalysis.java +++ /dev/null @@ -1,1357 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.MouseEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.math.BigDecimal; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map.Entry; -import javax.swing.BorderFactory; -import javax.swing.DefaultComboBoxModel; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSeparator; -import javax.swing.JTable; -import javax.swing.ListModel; -import javax.swing.SwingConstants; -import javax.swing.border.BevelBorder; -import javax.swing.event.MouseInputAdapter; -import javax.swing.table.DefaultTableModel; - -import forge.card.CardRules; -import forge.card.CardType; -import forge.item.CardPrinted; -import forge.item.ItemPoolView; -import forge.util.MyRandom; -import net.miginfocom.swing.MigLayout; - -/** - * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI - * Builder, which is free for non-commercial use. If Jigloo is being used - * commercially (ie, by a corporation, company or business for any purpose - * whatever) then you should purchase a license for each developer using Jigloo. - * Please visit www.cloudgarden.com for details. Use of Jigloo implies - * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN - * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR - * ANY CORPORATE OR COMMERCIAL PURPOSE. - * - * @author Forge - * @version $Id$ - */ -public class DeckAnalysis extends javax.swing.JDialog { - - /** Constant serialVersionUID=-8475271235196182185L. */ - private static final long serialVersionUID = -8475271235196182185L; - private JPanel jPanel1; - private JLabel jLabelColorless; - private JLabel jLabelMultiColor; - private JLabel jLabelWhite; - private JLabel jLabelSixMana; - private JLabel jLabelFiveMana; - private JLabel jLabelFourMana; - private JLabel jLabelThreeMana; - private JLabel jLabel1; - private JScrollPane jScrollPane1; - private JTable jTable1; - private JPanel jPanel5; - private JButton jButtonRegenerate; - private JLabel jLabel4; - private JSeparator jSeparator4; - private JPanel jPanel4; - private JList jListFirstHand; - private JLabel jLabelTwoMana; - private JLabel jLabelOneMana; - private JLabel jLabelManaCost; - private JSeparator jSeparator3; - private JLabel jLabelZeroMana; - private JPanel jPanel3; - private JLabel jLabelSorcery; - private JLabel jLabelPlaneswalker; - private JLabel jLabelRed; - private JLabel jLabelGreen; - private JLabel jLabelBlue; - private JLabel jLabelBlack; - private JLabel jLabelEnchant; - private JLabel jLabelLandType; - private JLabel jLabelInstant; - private JLabel jLabelCreature; - private JLabel jLabel3; - private JSeparator jSeparator2; - private JLabel jLabelArtifact; - private JPanel jPanel2; - private JLabel jLabelTotal; - private JLabel jLabelLand; - private JSeparator jSeparator1; - private JLabel jLabel2; - private JButton jButtonOk; - private final JDialog parentDialog; - - /** The deck. */ - private final ItemPoolView deck; - - /** - *

- * Constructor for GUI_DeckAnalysis. - *

- * - * @param g - * a {@link javax.swing.JFrame} object. - * @param deckView - * the deck view - */ - public DeckAnalysis(final JDialog g, final ItemPoolView deckView) { - super(g); - this.deck = deckView; - - this.parentDialog = g; - this.initGUI(); - } - - /** - *

- * initGUI. - *

- */ - private void initGUI() { - try { - - this.getContentPane().setLayout(null); - this.setVisible(true); - final int wWidth = 600; - final int wHeight = 600; - this.setPreferredSize(new java.awt.Dimension(wWidth, wHeight)); - - final Dimension screen = this.getToolkit().getScreenSize(); - final int x = (screen.width - wWidth) / 2; - final int y = (screen.height - wHeight) / 2; - this.setBounds(x, y, wWidth, wHeight); - this.setResizable(false); - this.setTitle("Deck Analysis"); - this.pack(); - // this.setIconImage(null); - - this.addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(final WindowEvent arg0) { - DeckAnalysis.this.parentDialog.setEnabled(true); - } - - @Override - public void windowOpened(final WindowEvent arg0) { - - int cBlack, cBlue, cGreen, cRed, cWhite, cMulticolor, cColorless, cLand; - int cArtifact, cCreature, cEnchant, cInstant, cLandType, cPlaneswalker, cSorcery; - int mZero, mOne, mTwo, mThree, mFour, mFive, mSixMore; - float tManaCost; - CardRules c; - cBlack = 0; - cBlue = 0; - cGreen = 0; - cRed = 0; - cWhite = 0; - cMulticolor = 0; - cColorless = 0; - cLand = 0; - cArtifact = 0; - cCreature = 0; - cEnchant = 0; - cInstant = 0; - cLandType = 0; - cPlaneswalker = 0; - cSorcery = 0; - mZero = 0; - mOne = 0; - mTwo = 0; - mThree = 0; - mFour = 0; - mFive = 0; - mSixMore = 0; - tManaCost = 0; - - for (final Entry e : DeckAnalysis.this.deck) { - c = e.getKey().getCard(); - final int cnt = e.getValue(); - - if (c.getColor().isMulticolor()) { - cMulticolor = cMulticolor + cnt; - } else { - if (c.getColor().isBlack()) { - cBlack = cBlack + cnt; - } - if (c.getColor().isBlue()) { - cBlue = cBlue + cnt; - } - if (c.getColor().isGreen()) { - cGreen = cGreen + cnt; - } - if (c.getColor().isRed()) { - cRed = cRed + cnt; - } - if (c.getColor().isWhite()) { - cWhite = cWhite + cnt; - } - if (c.getColor().isColorless()) { - if (c.getType().isLand()) { - cLand = cLand + cnt; - } else { - cColorless = cColorless + cnt; - } - } - } - - // count card types - final CardType cType = c.getType(); - if (cType.isArtifact()) { - cArtifact = cArtifact + cnt; - } - if (cType.isCreature()) { - cCreature = cCreature + cnt; - } - if (cType.isEnchantment()) { - cEnchant = cEnchant + cnt; - } - if (cType.isInstant()) { - cInstant = cInstant + cnt; - } - if (cType.isLand()) { - cLandType = cLandType + cnt; - } - if (cType.isPlaneswalker()) { - cPlaneswalker = cPlaneswalker + cnt; - } - if (cType.isSorcery()) { - cSorcery = cSorcery + cnt; - } - - final int cmc = c.getManaCost().getCMC(); - if (cmc == 0) { - mZero = mZero + cnt; - } else if (cmc == 1) { - mOne = mOne + cnt; - } else if (cmc == 2) { - mTwo = mTwo + cnt; - } else if (cmc == 3) { - mThree = mThree + cnt; - } else if (cmc == 4) { - mFour = mFour + cnt; - } else if (cmc == 5) { - mFive = mFive + 1; - } else if (cmc >= 6) { - mSixMore = mSixMore + 1; - } - - tManaCost = tManaCost + (cmc * cnt); - } - final int total = DeckAnalysis.this.deck.countAll(); - BigDecimal aManaCost = new BigDecimal(tManaCost / total); - aManaCost = aManaCost.setScale(2, BigDecimal.ROUND_HALF_UP); - - DeckAnalysis.this.jLabelTotal.setText("Information about deck (total cards: " + total + "):"); - DeckAnalysis.this.jLabelManaCost.setText("Mana cost (ACC:" + aManaCost + ")"); - final Color cr = new Color(100, 100, 100); - - if (cBlack == 0) { - DeckAnalysis.this.jLabelBlack.setForeground(cr); - } - DeckAnalysis.this.jLabelBlack.setText(DeckAnalysis.this.formatStat("Black", cBlack, total)); - if (cBlue == 0) { - DeckAnalysis.this.jLabelBlue.setForeground(cr); - } - DeckAnalysis.this.jLabelBlue.setText(DeckAnalysis.this.formatStat("Blue", cBlue, total)); - if (cGreen == 0) { - DeckAnalysis.this.jLabelGreen.setForeground(cr); - } - DeckAnalysis.this.jLabelGreen.setText(DeckAnalysis.this.formatStat("Green", cGreen, total)); - if (cRed == 0) { - DeckAnalysis.this.jLabelRed.setForeground(cr); - } - DeckAnalysis.this.jLabelRed.setText(DeckAnalysis.this.formatStat("Red", cRed, total)); - if (cWhite == 0) { - DeckAnalysis.this.jLabelWhite.setForeground(cr); - } - DeckAnalysis.this.jLabelWhite.setText(DeckAnalysis.this.formatStat("White", cWhite, total)); - if (cMulticolor == 0) { - DeckAnalysis.this.jLabelMultiColor.setForeground(cr); - } - DeckAnalysis.this.jLabelMultiColor.setText(DeckAnalysis.this.formatStat("Multicolor", cMulticolor, - total)); - if (cColorless == 0) { - DeckAnalysis.this.jLabelColorless.setForeground(cr); - } - DeckAnalysis.this.jLabelColorless.setText(DeckAnalysis.this.formatStat("Colorless", cColorless, - total)); - - if (cLand == 0) { - DeckAnalysis.this.jLabelLand.setForeground(cr); - } - DeckAnalysis.this.jLabelLand.setText(DeckAnalysis.this.formatStat("Land", cLand, total)); - if (cArtifact == 0) { - DeckAnalysis.this.jLabelArtifact.setForeground(cr); - } - DeckAnalysis.this.jLabelArtifact.setText(DeckAnalysis.this.formatStat("Artifact", cArtifact, total)); - if (cCreature == 0) { - DeckAnalysis.this.jLabelCreature.setForeground(cr); - } - DeckAnalysis.this.jLabelCreature.setText(DeckAnalysis.this.formatStat("Creature", cCreature, total)); - if (cEnchant == 0) { - DeckAnalysis.this.jLabelEnchant.setForeground(cr); - } - DeckAnalysis.this.jLabelEnchant.setText(DeckAnalysis.this.formatStat("Enchant", cEnchant, total)); - if (cInstant == 0) { - DeckAnalysis.this.jLabelInstant.setForeground(cr); - } - DeckAnalysis.this.jLabelInstant.setText(DeckAnalysis.this.formatStat("Instant", cInstant, total)); - if (cLandType == 0) { - DeckAnalysis.this.jLabelLandType.setForeground(cr); - } - DeckAnalysis.this.jLabelLandType.setText(DeckAnalysis.this.formatStat("Land", cLandType, total)); - if (cPlaneswalker == 0) { - DeckAnalysis.this.jLabelPlaneswalker.setForeground(cr); - } - DeckAnalysis.this.jLabelPlaneswalker.setText(DeckAnalysis.this.formatStat("Planeswalker", - cPlaneswalker, total)); - - if (cSorcery == 0) { - DeckAnalysis.this.jLabelSorcery.setForeground(cr); - } - DeckAnalysis.this.jLabelSorcery.setText(DeckAnalysis.this.formatStat("Sorcery", cSorcery, total)); - if (mZero == 0) { - DeckAnalysis.this.jLabelZeroMana.setForeground(cr); - } - DeckAnalysis.this.jLabelZeroMana.setText(DeckAnalysis.this.formatStat("Zero mana", mZero, total)); - if (mOne == 0) { - DeckAnalysis.this.jLabelOneMana.setForeground(cr); - } - DeckAnalysis.this.jLabelOneMana.setText(DeckAnalysis.this.formatStat("One mana", mOne, total)); - if (mTwo == 0) { - DeckAnalysis.this.jLabelTwoMana.setForeground(cr); - } - DeckAnalysis.this.jLabelTwoMana.setText(DeckAnalysis.this.formatStat("Two mana", mTwo, total)); - if (mThree == 0) { - DeckAnalysis.this.jLabelThreeMana.setForeground(cr); - } - DeckAnalysis.this.jLabelThreeMana.setText(DeckAnalysis.this.formatStat("Three mana", mThree, total)); - if (mFour == 0) { - DeckAnalysis.this.jLabelFourMana.setForeground(cr); - } - DeckAnalysis.this.jLabelFourMana.setText(DeckAnalysis.this.formatStat("Four mana", mFour, total)); - if (mFive == 0) { - DeckAnalysis.this.jLabelFiveMana.setForeground(cr); - } - DeckAnalysis.this.jLabelFiveMana.setText(DeckAnalysis.this.formatStat("Five mana", mFive, total)); - if (mSixMore == 0) { - DeckAnalysis.this.jLabelSixMana.setForeground(cr); - } - DeckAnalysis.this.jLabelSixMana.setText(DeckAnalysis.this.formatStat("Six and more", mSixMore, - total)); - } - }); - - this.getContentPane().add(this.getJButton1()); - this.getContentPane().add(this.getJLabel1xx()); - this.getContentPane().add(this.getJButtonOk()); - this.getContentPane().add(this.getJPanel1()); - this.getContentPane().add(this.getJPanel2()); - this.getContentPane().add(this.getJPanel3()); - this.getContentPane().add(this.getJPanel4()); - this.getContentPane().add(this.getJPanel5()); - this.getContentPane().add(this.getJLabel1xxxxx()); - - } catch (final Exception e) { - e.printStackTrace(); - } - } - - private String formatStat(final String statName, final int value, final int deckSize) { - return String.format("%s: %d (%f%%)", statName, value, (100f * value) / deckSize); - } - - /** - *

- * Getter for the field jPanel1. - *

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel getJPanel1() { - if (this.jPanel1 == null) { - this.jPanel1 = new JPanel(); - - this.jPanel1.setLayout(null); - this.jPanel1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); - this.jPanel1.setBackground(new java.awt.Color(192, 192, 192)); - this.jPanel1.setBounds(5, 35, 137, 203); - this.jPanel1.add(this.getJLabel1()); - this.jPanel1.add(this.getJSeparator1()); - this.jPanel1.add(this.getJLabel2()); - this.jPanel1.add(this.getJLabel3()); - this.jPanel1.add(this.getJLabel4()); - this.jPanel1.add(this.getJLabel5()); - this.jPanel1.add(this.getJLabel6()); - this.jPanel1.add(this.getJLabel7()); - this.jPanel1.add(this.getJLabel8()); - this.jPanel1.add(this.getJLabel1x()); - } - return this.jPanel1; - } - - /** - *

- * Getter for the field jLabel2. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel2() { - if (this.jLabel2 == null) { - this.jLabel2 = new JLabel(); - this.jLabel2.setText("Color"); - this.jLabel2.setHorizontalAlignment(SwingConstants.CENTER); - this.jLabel2.setFont(new java.awt.Font("Segoe UI", 0, 14)); - this.jLabel2.setPreferredSize(new java.awt.Dimension(152, 39)); - this.jLabel2.setLayout(null); - this.jLabel2.setBounds(2, -3, 135, 26); - } - return this.jLabel2; - } - - /** - *

- * Getter for the field jSeparator1. - *

- * - * @return a {@link javax.swing.JSeparator} object. - */ - private JSeparator getJSeparator1() { - if (this.jSeparator1 == null) { - this.jSeparator1 = new JSeparator(); - this.jSeparator1.setPreferredSize(new java.awt.Dimension(117, 6)); - this.jSeparator1.setLayout(null); - this.jSeparator1.setBounds(1, 20, 136, 5); - } - return this.jSeparator1; - } - - /** - *

- * Getter for the field jButtonOk. - *

- * - * @return a {@link javax.swing.JButton} object. - */ - private JButton getJButtonOk() { - if (this.jButtonOk == null) { - this.jButtonOk = new JButton(); - this.jButtonOk.setLayout(null); - this.jButtonOk.setText("OK"); - this.jButtonOk.setBounds(206, 536, 168, 31); - this.jButtonOk.addMouseListener(new MouseInputAdapter() { - @Override - public void mouseClicked(final MouseEvent e) { - DeckAnalysis.this.parentDialog.setEnabled(true); - DeckAnalysis.this.dispose(); - } - }); - } - return this.jButtonOk; - } - - /** - *

- * Getter for the field jLabel1. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel1() { - if (this.jLabelBlack == null) { - this.jLabelBlack = new JLabel(); - this.jLabelBlack.setText("Black:"); - this.jLabelBlack.setPreferredSize(new java.awt.Dimension(105, 12)); - this.jLabelBlack.setLayout(null); - this.jLabelBlack.setBounds(10, 28, 127, 13); - } - return this.jLabelBlack; - } - - /** - *

- * Getter for the field jLabel3. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel3() { - if (this.jLabelBlue == null) { - this.jLabelBlue = new JLabel(); - this.jLabelBlue.setText("Blue:"); - this.jLabelBlue.setLayout(null); - this.jLabelBlue.setBounds(10, 50, 127, 13); - } - return this.jLabelBlue; - } - - /** - *

- * Getter for the field jLabel4. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel4() { - if (this.jLabelGreen == null) { - this.jLabelGreen = new JLabel(); - this.jLabelGreen.setText("Green:"); - this.jLabelGreen.setLayout(null); - this.jLabelGreen.setBounds(10, 72, 127, 13); - } - return this.jLabelGreen; - } - - /** - *

- * getJLabel5. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel5() { - if (this.jLabelRed == null) { - this.jLabelRed = new JLabel(); - this.jLabelRed.setText("Red:"); - this.jLabelRed.setLayout(null); - this.jLabelRed.setBounds(10, 94, 127, 14); - } - return this.jLabelRed; - } - - /** - *

- * getJLabel6. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel6() { - if (this.jLabelWhite == null) { - this.jLabelWhite = new JLabel(); - this.jLabelWhite.setText("White:"); - this.jLabelWhite.setLayout(null); - this.jLabelWhite.setBounds(10, 116, 127, 13); - } - return this.jLabelWhite; - } - - /** - *

- * getJLabel7. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel7() { - if (this.jLabelMultiColor == null) { - this.jLabelMultiColor = new JLabel(); - this.jLabelMultiColor.setText("Multicolor:"); - this.jLabelMultiColor.setLayout(null); - this.jLabelMultiColor.setBounds(10, 138, 127, 12); - } - return this.jLabelMultiColor; - } - - /** - *

- * getJLabel8. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel8() { - if (this.jLabelColorless == null) { - this.jLabelColorless = new JLabel(); - this.jLabelColorless.setText("Colorless:"); - this.jLabelColorless.setLayout(null); - this.jLabelColorless.setBounds(10, 160, 128, 11); - } - return this.jLabelColorless; - } - - /** - *

- * getJLabel1x. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel1x() { - if (this.jLabelLand == null) { - this.jLabelLand = new JLabel(); - this.jLabelLand.setText("Land: "); - this.jLabelLand.setLayout(null); - this.jLabelLand.setBounds(10, 182, 129, 10); - } - return this.jLabelLand; - } - - /** - *

- * getJLabel1xx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel1xx() { - if (this.jLabelTotal == null) { - this.jLabelTotal = new JLabel(); - this.jLabelTotal.setText("Information about deck:"); - this.jLabelTotal.setLayout(null); - this.jLabelTotal.setBounds(5, 0, 454, 35); - } - return this.jLabelTotal; - } - - /** - *

- * Getter for the field jPanel2. - *

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel getJPanel2() { - if (this.jPanel2 == null) { - this.jPanel2 = new JPanel(); - - this.jPanel2.setBackground(new java.awt.Color(192, 192, 192)); - this.jPanel2.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); - this.jPanel2.setLayout(null); - this.jPanel2.setBounds(153, 35, 137, 203); - this.jPanel2.add(this.getJLabel1xxx()); - this.jPanel2.add(this.getJSeparator2()); - this.jPanel2.add(this.getJLabel3x()); - this.jPanel2.add(this.getJLabel4x()); - this.jPanel2.add(this.getJLabel5x()); - this.jPanel2.add(this.getJLabel6x()); - this.jPanel2.add(this.getJLabel7x()); - this.jPanel2.add(this.getJLabel8x()); - this.jPanel2.add(this.getJLabel10()); - } - return this.jPanel2; - } - - /** - *

- * getJLabel1xxx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel1xxx() { - if (this.jLabelArtifact == null) { - this.jLabelArtifact = new JLabel(); - this.jLabelArtifact.setText("Artifact:"); - this.jLabelArtifact.setPreferredSize(new java.awt.Dimension(105, 12)); - this.jLabelArtifact.setLayout(null); - this.jLabelArtifact.setBounds(10, 28, 127, 13); - } - return this.jLabelArtifact; - } - - /** - *

- * Getter for the field jSeparator2. - *

- * - * @return a {@link javax.swing.JSeparator} object. - */ - private JSeparator getJSeparator2() { - if (this.jSeparator2 == null) { - this.jSeparator2 = new JSeparator(); - this.jSeparator2.setPreferredSize(new java.awt.Dimension(117, 6)); - this.jSeparator2.setLayout(null); - this.jSeparator2.setBounds(1, 20, 136, 5); - } - return this.jSeparator2; - } - - /** - *

- * getJLabel3x. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel3x() { - if (this.jLabel3 == null) { - this.jLabel3 = new JLabel(); - this.jLabel3.setText("Type"); - this.jLabel3.setHorizontalAlignment(SwingConstants.CENTER); - this.jLabel3.setFont(new java.awt.Font("Segoe UI", 0, 14)); - this.jLabel3.setPreferredSize(new java.awt.Dimension(152, 39)); - this.jLabel3.setLayout(null); - this.jLabel3.setBounds(2, -3, 135, 26); - } - return this.jLabel3; - } - - /** - *

- * getJLabel4x. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel4x() { - if (this.jLabelCreature == null) { - this.jLabelCreature = new JLabel(); - this.jLabelCreature.setText("Creature:"); - this.jLabelCreature.setLayout(null); - this.jLabelCreature.setBounds(10, 53, 127, 13); - } - return this.jLabelCreature; - } - - /** - *

- * getJLabel5x. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel5x() { - if (this.jLabelEnchant == null) { - this.jLabelEnchant = new JLabel(); - this.jLabelEnchant.setText("Enchant:"); - this.jLabelEnchant.setLayout(null); - this.jLabelEnchant.setBounds(10, 79, 127, 13); - } - return this.jLabelEnchant; - } - - /** - *

- * getJLabel6x. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel6x() { - if (this.jLabelInstant == null) { - this.jLabelInstant = new JLabel(); - this.jLabelInstant.setText("Instant:"); - this.jLabelInstant.setLayout(null); - this.jLabelInstant.setBounds(10, 105, 127, 14); - } - return this.jLabelInstant; - } - - /** - *

- * getJLabel7x. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel7x() { - if (this.jLabelLandType == null) { - this.jLabelLandType = new JLabel(); - this.jLabelLandType.setText("Land:"); - this.jLabelLandType.setLayout(null); - this.jLabelLandType.setBounds(10, 130, 127, 13); - } - return this.jLabelLandType; - } - - /** - *

- * getJLabel8x. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel8x() { - if (this.jLabelPlaneswalker == null) { - this.jLabelPlaneswalker = new JLabel(); - this.jLabelPlaneswalker.setText("Planeswalker:"); - this.jLabelPlaneswalker.setLayout(null); - this.jLabelPlaneswalker.setBounds(10, 156, 127, 13); - } - return this.jLabelPlaneswalker; - } - - /** - *

- * getJLabel10. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel10() { - if (this.jLabelSorcery == null) { - this.jLabelSorcery = new JLabel(); - this.jLabelSorcery.setText("Sorcery:"); - this.jLabelSorcery.setLayout(null); - this.jLabelSorcery.setBounds(10, 182, 127, 11); - } - return this.jLabelSorcery; - } - - /** - *

- * Getter for the field jPanel3. - *

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel getJPanel3() { - if (this.jPanel3 == null) { - this.jPanel3 = new JPanel(); - this.jPanel3.setBackground(new java.awt.Color(192, 192, 192)); - this.jPanel3.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); - this.jPanel3.setLayout(null); - this.jPanel3.setBounds(302, 35, 137, 203); - this.jPanel3.add(this.getJLabel1xxxx()); - this.jPanel3.add(this.getJSeparator3()); - this.jPanel3.add(this.getJLabel4xx()); - this.jPanel3.add(this.getJLabel5xx()); - this.jPanel3.add(this.getJLabel6xx()); - this.jPanel3.add(this.getJLabel7xx()); - this.jPanel3.add(this.getJLabel8xx()); - this.jPanel3.add(this.getJLabel9()); - this.jPanel3.add(this.getJLabel10x()); - } - return this.jPanel3; - } - - /** - *

- * getJLabel1xxxx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel1xxxx() { - if (this.jLabelZeroMana == null) { - this.jLabelZeroMana = new JLabel(); - this.jLabelZeroMana.setText("Zero mana:"); - this.jLabelZeroMana.setPreferredSize(new java.awt.Dimension(105, 12)); - this.jLabelZeroMana.setLayout(null); - this.jLabelZeroMana.setBounds(10, 28, 127, 13); - } - return this.jLabelZeroMana; - } - - /** - *

- * Getter for the field jSeparator3. - *

- * - * @return a {@link javax.swing.JSeparator} object. - */ - private JSeparator getJSeparator3() { - if (this.jSeparator3 == null) { - this.jSeparator3 = new JSeparator(); - this.jSeparator3.setPreferredSize(new java.awt.Dimension(117, 6)); - this.jSeparator3.setLayout(null); - this.jSeparator3.setBounds(1, 20, 136, 5); - } - return this.jSeparator3; - } - - /** - *

- * getJLabel4xx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel4xx() { - if (this.jLabelManaCost == null) { - this.jLabelManaCost = new JLabel(); - this.jLabelManaCost.setText("Mana cost"); - this.jLabelManaCost.setHorizontalAlignment(SwingConstants.CENTER); - this.jLabelManaCost.setFont(new java.awt.Font("Segoe UI", 0, 14)); - this.jLabelManaCost.setPreferredSize(new java.awt.Dimension(152, 39)); - this.jLabelManaCost.setLayout(null); - this.jLabelManaCost.setBounds(2, -3, 135, 26); - } - return this.jLabelManaCost; - } - - /** - *

- * getJLabel5xx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel5xx() { - if (this.jLabelOneMana == null) { - this.jLabelOneMana = new JLabel(); - this.jLabelOneMana.setText("One mana:"); - this.jLabelOneMana.setLayout(null); - this.jLabelOneMana.setBounds(10, 53, 127, 13); - } - return this.jLabelOneMana; - } - - /** - *

- * getJLabel6xx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel6xx() { - if (this.jLabelTwoMana == null) { - this.jLabelTwoMana = new JLabel(); - this.jLabelTwoMana.setText("Two mana:"); - this.jLabelTwoMana.setLayout(null); - this.jLabelTwoMana.setBounds(10, 79, 127, 13); - } - return this.jLabelTwoMana; - } - - /** - *

- * getJLabel7xx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel7xx() { - if (this.jLabelThreeMana == null) { - this.jLabelThreeMana = new JLabel(); - this.jLabelThreeMana.setText("Three mana:"); - this.jLabelThreeMana.setLayout(null); - this.jLabelThreeMana.setBounds(10, 105, 127, 14); - } - return this.jLabelThreeMana; - } - - /** - *

- * getJLabel8xx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel8xx() { - if (this.jLabelFourMana == null) { - this.jLabelFourMana = new JLabel(); - this.jLabelFourMana.setText("Four mana:"); - this.jLabelFourMana.setLayout(null); - this.jLabelFourMana.setBounds(10, 130, 127, 13); - } - return this.jLabelFourMana; - } - - /** - *

- * getJLabel9. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel9() { - if (this.jLabelFiveMana == null) { - this.jLabelFiveMana = new JLabel(); - this.jLabelFiveMana.setText("Five mana:"); - this.jLabelFiveMana.setLayout(null); - this.jLabelFiveMana.setBounds(10, 156, 127, 13); - } - return this.jLabelFiveMana; - } - - /** - *

- * getJLabel10x. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel10x() { - if (this.jLabelSixMana == null) { - this.jLabelSixMana = new JLabel(); - this.jLabelSixMana.setText("Six and more:"); - this.jLabelSixMana.setLayout(null); - this.jLabelSixMana.setBounds(10, 182, 127, 11); - } - return this.jLabelSixMana; - } - - /** - *

- * getJList1. - *

- * - * @return a {@link javax.swing.JList} object. - */ - private JList getJList1() { - final List rList = this.deck.toFlatList(); - - Collections.shuffle(rList, MyRandom.getRandom()); - Collections.shuffle(rList, MyRandom.getRandom()); - - ListModel jList1Model; - if (this.jListFirstHand == null) { - this.jListFirstHand = new JList(); - } - - if (rList.size() >= 40) { - jList1Model = new DefaultComboBoxModel(new String[] { rList.get(0).getName(), rList.get(1).getName(), - rList.get(2).getName(), rList.get(3).getName(), rList.get(4).getName(), rList.get(5).getName(), - rList.get(6).getName() }); - - } else { - jList1Model = new DefaultComboBoxModel(new String[] { "Few cards." }); - } - - this.jListFirstHand.setModel(jList1Model); - this.jListFirstHand.setLayout(null); - this.jListFirstHand.setBackground(new java.awt.Color(192, 192, 192)); - this.jListFirstHand.setSelectionBackground(new java.awt.Color(192, 192, 192)); - this.jListFirstHand.setSelectionForeground(new java.awt.Color(0, 0, 0)); - this.jListFirstHand.setFixedCellHeight(24); - this.jListFirstHand.setBounds(2, 21, 133, 167); - - return this.jListFirstHand; - } - - /** - *

- * Getter for the field jPanel4. - *

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel getJPanel4() { - if (this.jPanel4 == null) { - this.jPanel4 = new JPanel(); - this.jPanel4.setBackground(new java.awt.Color(192, 192, 192)); - this.jPanel4.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); - this.jPanel4.setLayout(null); - this.jPanel4.setBounds(451, 35, 137, 202); - this.jPanel4.add(this.getJSeparator4()); - this.jPanel4.add(this.getJLabel4xxx()); - this.jPanel4.add(this.getJList1()); - this.jPanel4.add(this.getJButton1()); - } else { - this.jPanel4.removeAll(); - final MigLayout jPanel4Layout = new MigLayout(); - this.jPanel4.setBackground(new java.awt.Color(192, 192, 192)); - this.jPanel4.setPreferredSize(new java.awt.Dimension(139, 201)); - this.jPanel4.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); - this.jPanel4.setLayout(jPanel4Layout); - this.jPanel4.add(this.getJSeparator4()); - this.jPanel4.add(this.getJLabel4xxx()); - this.jPanel4.add(this.getJList1()); - this.jPanel4.add(this.getJButton1()); - } - return this.jPanel4; - - } - - /** - *

- * Getter for the field jSeparator4. - *

- * - * @return a {@link javax.swing.JSeparator} object. - */ - private JSeparator getJSeparator4() { - if (this.jSeparator4 == null) { - this.jSeparator4 = new JSeparator(); - this.jSeparator4.setPreferredSize(new java.awt.Dimension(138, 8)); - this.jSeparator4.setLayout(null); - this.jSeparator4.setBounds(0, 19, 137, 7); - } - return this.jSeparator4; - } - - /** - *

- * getJLabel4xxx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel4xxx() { - if (this.jLabel4 == null) { - this.jLabel4 = new JLabel(); - this.jLabel4.setText("Random start hand"); - this.jLabel4.setHorizontalAlignment(SwingConstants.CENTER); - this.jLabel4.setFont(new java.awt.Font("Segoe UI", 0, 14)); - this.jLabel4.setPreferredSize(new java.awt.Dimension(136, 24)); - this.jLabel4.setLayout(null); - this.jLabel4.setBounds(2, 0, 135, 20); - } - return this.jLabel4; - } - - /** - *

- * getJButton1. - *

- * - * @return a {@link javax.swing.JButton} object. - */ - private JButton getJButton1() { - - if (this.jButtonRegenerate == null) { - if (this.deck.countAll() >= 40) { - this.jButtonRegenerate = new JButton(); - this.jButtonRegenerate.setLayout(null); - this.jButtonRegenerate.setText("Regenerate hand"); - this.jButtonRegenerate.setPreferredSize(new java.awt.Dimension(139, 21)); - this.jButtonRegenerate.setBounds(2, 189, 133, 13); - this.jButtonRegenerate.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(final ActionEvent e) { - DeckAnalysis.this.jButtonRegenerateActionPerformed(e); - } - }); - } else { - this.jButtonRegenerate = new JButton(); - this.jButtonRegenerate.setBounds(2, 189, 133, 13); - this.jButtonRegenerate.setVisible(false); - } - } - return this.jButtonRegenerate; - } - - /** - *

- * jButtonRegenerate_actionPerformed. - *

- * - * @param e - * a {@link java.awt.event.ActionEvent} object. - */ - final void jButtonRegenerateActionPerformed(final ActionEvent e) { - this.getContentPane().removeAll(); - this.getContentPane().add(this.getJPanel5()); - this.getContentPane().add(this.getJLabel1xx()); - this.getContentPane().add(this.getJButtonOk()); - this.getContentPane().add(this.getJPanel1()); - this.getContentPane().add(this.getJPanel2()); - this.getContentPane().add(this.getJPanel3()); - this.getContentPane().add(this.getJPanel4()); - this.getContentPane().add(this.getJPanel5()); - this.getContentPane().add(this.getJLabel1xxxxx()); - this.getContentPane().repaint(); - - } - - /** - *

- * Getter for the field jPanel5. - *

- * - * @return a {@link javax.swing.JPanel} object. - */ - private JPanel getJPanel5() { - if (this.jPanel5 == null) { - this.jPanel5 = new JPanel(); - this.jPanel5.setLayout(null); - this.jPanel5.setBounds(5, 262, 583, 270); - this.jPanel5.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED)); - this.jPanel5.add(this.getJScrollPane1()); - } - return this.jPanel5; - } - - /** - *

- * Getter for the field jTable1. - *

- * - * @return a {@link javax.swing.JTable} object. - */ - private JTable getJTable1() { - if (this.jTable1 == null) { - final DefaultTableModel dm = new DefaultTableModel(); - dm.setDataVector(new Object[][] { {} }, new Object[] { "Card", "Qty", "1st", "2nd", "3rd", "4th", "5th", - "6th", "7th" }); - - this.jTable1 = new JTable(dm); - final List rList = this.deck.toFlatList(); - final String[] cardsName = new String[rList.size()]; - int cCount; - float fCount; - float firstTurnF, secondTurnF, thirdTurnF, fourthTurnF, fivethTurnF, sixthTurnF, seventhTurnF; - - for (int i = 0; i < rList.size(); i++) { - cardsName[i] = rList.get(i).getName(); - } - Arrays.sort(cardsName); - this.jTable1.setValueAt("Few cards.", 0, 0); - - if (rList.size() >= 40) { - this.jTable1.setValueAt(cardsName[0], 0, 0); - cCount = 1; - for (int i = 1; i < cardsName.length; i++) { - if (cardsName[i].equals(cardsName[i - 1])) { - cCount = cCount + 1; - - } else { - dm.addRow(new Object[][] { {} }); - this.jTable1.setValueAt(cardsName[i], dm.getRowCount() - 1, 0); - this.jTable1.setValueAt(cCount, dm.getRowCount() - 2, 1); - fCount = cCount; - - firstTurnF = fCount / rList.size(); - BigDecimal firstTurn = new BigDecimal(firstTurnF * 100); - firstTurn = firstTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(firstTurn.toString() + " %", dm.getRowCount() - 2, 2); - - secondTurnF = (((1 - firstTurnF) * fCount) / (rList.size() - 1)) + firstTurnF; - BigDecimal secondTurn = new BigDecimal(secondTurnF * 100); - secondTurn = secondTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(secondTurn.toString() + " %", dm.getRowCount() - 2, 3); - - thirdTurnF = (((1 - secondTurnF) * fCount) / (rList.size() - 2)) + secondTurnF; - BigDecimal thirdTurn = new BigDecimal(thirdTurnF * 100); - thirdTurn = thirdTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(thirdTurn.toString() + " %", dm.getRowCount() - 2, 4); - - fourthTurnF = (((1 - thirdTurnF) * fCount) / (rList.size() - 3)) + thirdTurnF; - BigDecimal fourthTurn = new BigDecimal(fourthTurnF * 100); - fourthTurn = fourthTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(fourthTurn.toString() + " %", dm.getRowCount() - 2, 5); - - fivethTurnF = (((1 - fourthTurnF) * fCount) / (rList.size() - 4)) + fourthTurnF; - BigDecimal fivethTurn = new BigDecimal(fivethTurnF * 100); - fivethTurn = fivethTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(fivethTurn.toString() + " %", dm.getRowCount() - 2, 6); - - sixthTurnF = (((1 - fivethTurnF) * fCount) / (rList.size() - 5)) + fivethTurnF; - BigDecimal sixthTurn = new BigDecimal(sixthTurnF * 100); - sixthTurn = sixthTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(sixthTurn.toString() + " %", dm.getRowCount() - 2, 7); - - seventhTurnF = (((1 - sixthTurnF) * fCount) / (rList.size() - 6)) + sixthTurnF; - BigDecimal seventhTurn = new BigDecimal(seventhTurnF * 100); - seventhTurn = seventhTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(seventhTurn.toString() + " %", dm.getRowCount() - 2, 8); - - cCount = 1; - } - if (i == (cardsName.length - 1)) { - this.jTable1.setValueAt(cCount, dm.getRowCount() - 1, 1); - fCount = cCount; - - firstTurnF = fCount / rList.size(); - BigDecimal firstTurn = new BigDecimal(firstTurnF * 100); - firstTurn = firstTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(firstTurn.toString() + " %", dm.getRowCount() - 1, 2); - - secondTurnF = (((1 - firstTurnF) * fCount) / (rList.size() - 1)) + firstTurnF; - BigDecimal secondTurn = new BigDecimal(secondTurnF * 100); - secondTurn = secondTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(secondTurn.toString() + " %", dm.getRowCount() - 1, 3); - - thirdTurnF = (((1 - secondTurnF) * fCount) / (rList.size() - 2)) + secondTurnF; - BigDecimal thirdTurn = new BigDecimal(thirdTurnF * 100); - thirdTurn = thirdTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(thirdTurn.toString() + " %", dm.getRowCount() - 1, 4); - - fourthTurnF = (((1 - thirdTurnF) * fCount) / (rList.size() - 3)) + thirdTurnF; - BigDecimal fourthTurn = new BigDecimal(fourthTurnF * 100); - fourthTurn = fourthTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(fourthTurn.toString() + " %", dm.getRowCount() - 1, 5); - - fivethTurnF = (((1 - fourthTurnF) * fCount) / (rList.size() - 4)) + fourthTurnF; - BigDecimal fivethTurn = new BigDecimal(fivethTurnF * 100); - fivethTurn = fivethTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(fivethTurn.toString() + " %", dm.getRowCount() - 1, 6); - - sixthTurnF = (((1 - fivethTurnF) * fCount) / (rList.size() - 5)) + fivethTurnF; - BigDecimal sixthTurn = new BigDecimal(sixthTurnF * 100); - sixthTurn = sixthTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(sixthTurn.toString() + " %", dm.getRowCount() - 1, 7); - - seventhTurnF = (((1 - sixthTurnF) * fCount) / (rList.size() - 6)) + sixthTurnF; - BigDecimal seventhTurn = new BigDecimal(seventhTurnF * 100); - seventhTurn = seventhTurn.setScale(1, BigDecimal.ROUND_HALF_UP); - this.jTable1.setValueAt(seventhTurn.toString() + " %", dm.getRowCount() - 1, 8); - - } - - } - } - - this.jTable1.getColumn("Qty").setMaxWidth(50); - this.jTable1.getColumn("1st").setMaxWidth(50); - this.jTable1.getColumn("2nd").setMaxWidth(50); - this.jTable1.getColumn("3rd").setMaxWidth(50); - this.jTable1.getColumn("4th").setMaxWidth(50); - this.jTable1.getColumn("5th").setMaxWidth(50); - this.jTable1.getColumn("6th").setMaxWidth(50); - this.jTable1.getColumn("7th").setMaxWidth(50); - this.jTable1.setRowHeight(18); - this.jTable1.setPreferredSize(new java.awt.Dimension(576, (18 * dm.getRowCount()) + 3)); - } - return this.jTable1; - } - - /** - *

- * Getter for the field jScrollPane1. - *

- * - * @return a {@link javax.swing.JScrollPane} object. - */ - private JScrollPane getJScrollPane1() { - if (this.jScrollPane1 == null) { - this.jScrollPane1 = new JScrollPane(); - this.jScrollPane1.setBounds(2, 2, 582, 268); - this.jScrollPane1.setSize(580, 268); - this.jScrollPane1.setViewportView(this.getJTable1()); - } - return this.jScrollPane1; - } - - /** - *

- * getJLabel1xxxxx. - *

- * - * @return a {@link javax.swing.JLabel} object. - */ - private JLabel getJLabel1xxxxx() { - if (this.jLabel1 == null) { - this.jLabel1 = new JLabel(); - this.jLabel1.setText("Draw Probabilities:"); - this.jLabel1.setLayout(null); - this.jLabel1.setBounds(7, 237, 447, 25); - } - return this.jLabel1; - } - -} diff --git a/src/main/java/forge/gui/deckeditor/elements/FilterCheckBoxes.java b/src/main/java/forge/gui/deckeditor/elements/FilterCheckBoxes.java deleted file mode 100644 index e3b45d7977d..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/FilterCheckBoxes.java +++ /dev/null @@ -1,327 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.swing.JCheckBox; - - -import forge.card.CardRules; -import forge.item.CardPrinted; -import forge.util.closures.Predicate; - -/** - * A structural class for some checkboxes need for a deck editor, contains no - * JPanel to store boxes on Checkboxes are public so the using class should - * place them in some container. - */ -public class FilterCheckBoxes { - - /** The white. */ - private final JCheckBox white; - - /** The blue. */ - private final JCheckBox blue; - - /** The black. */ - private final JCheckBox black; - - /** The red. */ - private final JCheckBox red; - - /** The green. */ - private final JCheckBox green; - - /** The colorless. */ - private final JCheckBox colorless; - - /** The land. */ - private final JCheckBox land; - - /** The creature. */ - private final JCheckBox creature; - - /** The sorcery. */ - private final JCheckBox sorcery; - - /** The instant. */ - private final JCheckBox instant; - - /** The planeswalker. */ - private final JCheckBox planeswalker; - - /** The artifact. */ - private final JCheckBox artifact; - - /** The enchantment. */ - private final JCheckBox enchantment; - - // Very handy for classes using mass operations on an array of checkboxes - /** The all colors. */ - private final List allColors; - - /** The all types. */ - private final List allTypes; - - /** - * Instantiates a new filter check boxes. - * - * @param useGraphicalBoxes - * the use graphical boxes - */ - public FilterCheckBoxes(final boolean useGraphicalBoxes) { - if (useGraphicalBoxes) { - this.white = new CheckBoxWithIcon("white", "White"); - this.blue = new CheckBoxWithIcon("blue", "Blue"); - this.black = new CheckBoxWithIcon("black", "Black"); - this.red = new CheckBoxWithIcon("red", "Red"); - this.green = new CheckBoxWithIcon("green", "Green"); - this.colorless = new CheckBoxWithIcon("colorless", "Colorless"); - - this.land = new CheckBoxWithIcon("land", "Land"); - this.creature = new CheckBoxWithIcon("creature", "Creature"); - this.sorcery = new CheckBoxWithIcon("sorcery", "Sorcery"); - this.instant = new CheckBoxWithIcon("instant", "Instant"); - this.planeswalker = new CheckBoxWithIcon("planeswalker", "Planeswalker"); - this.artifact = new CheckBoxWithIcon("artifact", "Artifact"); - this.enchantment = new CheckBoxWithIcon("enchant", "Enchantment"); - } else { - // We moved the filters and now have room for the full name. - // this.white = new JCheckBox("W", true); - // this.blue = new JCheckBox("U", true); - // this.black = new JCheckBox("B", true); - // this.red = new JCheckBox("R", true); - // this.green = new JCheckBox("G", true); - // this.colorless = new JCheckBox("C", true); - this.white = new JCheckBox("White", true); - this.blue = new JCheckBox("Blue", true); - this.black = new JCheckBox("Black", true); - this.red = new JCheckBox("Red", true); - this.green = new JCheckBox("Green", true); - this.colorless = new JCheckBox("Colorless", true); - - this.land = new JCheckBox("Land", true); - this.creature = new JCheckBox("Creature", true); - this.sorcery = new JCheckBox("Sorcery", true); - this.instant = new JCheckBox("Instant", true); - this.planeswalker = new JCheckBox("Planeswalker", true); - this.artifact = new JCheckBox("Artifact", true); - this.enchantment = new JCheckBox("Enchantment", true); - } - - this.allColors = Arrays.asList(new JCheckBox[] { this.getWhite(), this.getBlue(), this.getBlack(), - this.getRed(), this.getGreen(), this.getColorless() }); - this.allTypes = Arrays.asList(new JCheckBox[] { this.getLand(), this.getCreature(), this.getSorcery(), - this.getInstant(), this.getPlaneswalker(), this.getArtifact(), this.getEnchantment() }); - } - - /** - * Builds the filter. - * - * @return the predicate - */ - public final Predicate buildFilter() { - final List> colors = new ArrayList>(); - if (this.getWhite().isSelected()) { - colors.add(CardRules.Predicates.Presets.IS_WHITE); - } - if (this.getBlue().isSelected()) { - colors.add(CardRules.Predicates.Presets.IS_BLUE); - } - if (this.getBlack().isSelected()) { - colors.add(CardRules.Predicates.Presets.IS_BLACK); - } - if (this.getRed().isSelected()) { - colors.add(CardRules.Predicates.Presets.IS_RED); - } - if (this.getGreen().isSelected()) { - colors.add(CardRules.Predicates.Presets.IS_GREEN); - } - if (this.getColorless().isSelected()) { - colors.add(CardRules.Predicates.Presets.IS_COLORLESS); - } - final Predicate filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.CONSTANT_TRUE - : Predicate.or(colors); - - final List> types = new ArrayList>(); - if (this.getLand().isSelected()) { - types.add(CardRules.Predicates.Presets.IS_LAND); - } - if (this.getCreature().isSelected()) { - types.add(CardRules.Predicates.Presets.IS_CREATURE); - } - if (this.getSorcery().isSelected()) { - types.add(CardRules.Predicates.Presets.IS_SORCERY); - } - if (this.getInstant().isSelected()) { - types.add(CardRules.Predicates.Presets.IS_INSTANT); - } - if (this.getPlaneswalker().isSelected()) { - types.add(CardRules.Predicates.Presets.IS_PLANESWALKER); - } - if (this.getArtifact().isSelected()) { - types.add(CardRules.Predicates.Presets.IS_ARTIFACT); - } - if (this.getEnchantment().isSelected()) { - types.add(CardRules.Predicates.Presets.IS_ENCHANTMENT); - } - final Predicate filterByType = types.size() == 7 ? CardRules.Predicates.Presets.CONSTANT_TRUE - : Predicate.or(types); - - return Predicate.brigde(Predicate.and(filterByColor, filterByType), CardPrinted.FN_GET_RULES); - } - - /** - * Gets the all types. - * - * @return the allTypes - */ - public List getAllTypes() { - return this.allTypes; - } - - /** - * Gets the white. - * - * @return the white - */ - public JCheckBox getWhite() { - return this.white; - } - - /** - * Gets the blue. - * - * @return the blue - */ - public JCheckBox getBlue() { - return this.blue; - } - - /** - * Gets the black. - * - * @return the black - */ - public JCheckBox getBlack() { - return this.black; - } - - /** - * Gets the red. - * - * @return the red - */ - public JCheckBox getRed() { - return this.red; - } - - /** - * Gets the colorless. - * - * @return the colorless - */ - public JCheckBox getColorless() { - return this.colorless; - } - - /** - * Gets the green. - * - * @return the green - */ - public JCheckBox getGreen() { - return this.green; - } - - /** - * Gets the land. - * - * @return the land - */ - public JCheckBox getLand() { - return this.land; - } - - /** - * Gets the all colors. - * - * @return the allColors - */ - public List getAllColors() { - return this.allColors; - } - - /** - * Gets the creature. - * - * @return the creature - */ - public JCheckBox getCreature() { - return this.creature; - } - - /** - * Gets the sorcery. - * - * @return the sorcery - */ - public JCheckBox getSorcery() { - return this.sorcery; - } - - /** - * Gets the instant. - * - * @return the instant - */ - public JCheckBox getInstant() { - return this.instant; - } - - /** - * Gets the planeswalker. - * - * @return the planeswalker - */ - public JCheckBox getPlaneswalker() { - return this.planeswalker; - } - - /** - * Gets the artifact. - * - * @return the artifact - */ - public JCheckBox getArtifact() { - return this.artifact; - } - - /** - * Gets the enchantment. - * - * @return the enchantment - */ - public JCheckBox getEnchantment() { - return this.enchantment; - } - -} diff --git a/src/main/java/forge/gui/deckeditor/elements/FilterNameTypeSetPanel.java b/src/main/java/forge/gui/deckeditor/elements/FilterNameTypeSetPanel.java deleted file mode 100644 index b9e1cb29e1c..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/FilterNameTypeSetPanel.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import java.awt.event.ItemListener; -import java.util.ArrayList; -import java.util.List; - -import javax.swing.JComboBox; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JTextField; -import javax.swing.event.DocumentListener; - -import net.miginfocom.swing.MigLayout; - -import org.apache.commons.lang3.StringUtils; - -import forge.Singletons; -import forge.card.CardRules; -import forge.card.CardEdition; -import forge.game.GameFormat; -import forge.item.CardPrinted; -import forge.util.closures.Predicate; -import forge.util.closures.PredicateString.StringOp; - -/** - * A panel that holds Name, Type, Rules text fields aligned horizontally - * together with set filter. - */ -public class FilterNameTypeSetPanel extends JComponent { - - private static final long serialVersionUID = -6409564625432765430L; - - /** The label filter name. */ - private final JLabel labelFilterName = new JLabel(); - - /** The label filter type. */ - private final JLabel labelFilterType = new JLabel(); - - /** The label filter rules. */ - private final JLabel labelFilterRules = new JLabel(); - - /** The txt card name. */ - private final JTextField txtCardName = new JTextField(); - - /** The txt card type. */ - private final JTextField txtCardType = new JTextField(); - - /** The txt card rules. */ - private final JTextField txtCardRules = new JTextField(); - - /** The search set combo. */ - private final JComboBox searchSetCombo = new JComboBox(); - - /** - * Instantiates a new filter name type set panel. - */ - public FilterNameTypeSetPanel() { - this.setLayout(new MigLayout("fill, ins 0")); - - this.labelFilterName.setText("Name:"); - this.labelFilterName.setToolTipText("Card names must include the text in this field"); - this.add(this.labelFilterName, "cell 0 1, split 7"); - this.add(this.txtCardName, "wmin 100, grow"); - - this.labelFilterType.setText("Type:"); - this.labelFilterType.setToolTipText("Card types must include the text in this field"); - this.add(this.labelFilterType, ""); - this.add(this.txtCardType, "wmin 100, grow"); - - this.labelFilterRules.setText("Text:"); - this.labelFilterRules.setToolTipText("Card descriptions must include the text in this field"); - this.add(this.labelFilterRules, ""); - this.add(this.txtCardRules, "wmin 200, grow"); - - this.searchSetCombo.removeAllItems(); - this.searchSetCombo.addItem("(all sets and formats)"); - for (final GameFormat s : Singletons.getModel().getFormats()) { - this.searchSetCombo.addItem(s); - } - for (final CardEdition s : Singletons.getModel().getEditions()) { - this.searchSetCombo.addItem(s); - } - - this.add(this.searchSetCombo, "wmin 150, grow"); - } - - /** - * Sets the listeners. - * - * @param onTextChange - * the on text change - * @param onComboChange - * the on combo change - */ - public final void setListeners(final DocumentListener onTextChange, final ItemListener onComboChange) { - this.txtCardType.getDocument().addDocumentListener(onTextChange); - this.txtCardRules.getDocument().addDocumentListener(onTextChange); - this.txtCardName.getDocument().addDocumentListener(onTextChange); - this.searchSetCombo.addItemListener(onComboChange); - } - - /** - * Builds the filter. - * - * @return the predicate - */ - public final Predicate buildFilter() { - final List> rules = new ArrayList>(4); - if (StringUtils.isNotBlank(this.txtCardName.getText())) { - rules.add(CardPrinted.Predicates.name(StringOp.CONTAINS, this.txtCardName.getText())); - } - - if (StringUtils.isNotBlank(this.txtCardType.getText())) { - rules.add(Predicate.brigde(CardRules.Predicates.joinedType(StringOp.CONTAINS, this.txtCardType.getText()), - CardPrinted.FN_GET_RULES)); - } - - if (StringUtils.isNotBlank(this.txtCardRules.getText())) { - rules.add(Predicate.brigde(CardRules.Predicates.rules(StringOp.CONTAINS, this.txtCardRules.getText()), - CardPrinted.FN_GET_RULES)); - } - - if (this.searchSetCombo.getSelectedIndex() != 0) { - final Object selected = this.searchSetCombo.getSelectedItem(); - if (selected instanceof CardEdition) { - rules.add(CardPrinted.Predicates.printedInSets(((CardEdition) selected).getCode())); - } else if (selected instanceof GameFormat) { - rules.add(((GameFormat) selected).getFilterRules()); - } - } - - switch (rules.size()) { - case 0: - return Predicate.getTrue(CardPrinted.class); - case 1: - return rules.get(0); - case 2: - return Predicate.and(rules.get(0), rules.get(1)); - default: - return Predicate.and(rules); - } - } - - /** - * TODO: Write javadoc for this method. - */ - public final void clearFilters() { - this.txtCardName.setText(""); - this.txtCardType.setText(""); - this.txtCardRules.setText(""); - this.searchSetCombo.setSelectedIndex(0); - } -} diff --git a/src/main/java/forge/gui/deckeditor/elements/TableColumnInfo.java b/src/main/java/forge/gui/deckeditor/elements/TableColumnInfo.java deleted file mode 100644 index 4db0f5d82ed..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/TableColumnInfo.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import java.util.Map.Entry; - -import javax.swing.table.TableCellRenderer; - -import forge.util.closures.Lambda1; - - -/** - * Holds single column set up for TableModel. Contains name, width + functions - * to retrieve column's value for compare and for display (they are different, - * in case of sets for instance) - * - * @param - * the generic type - */ - -@SuppressWarnings("rawtypes") -public class TableColumnInfo { - private final String name; - - /** The min width. */ - private int minWidth; - - /** The max width. */ - private int maxWidth; - - /** The nominal width. */ - private int nominalWidth; - - /** The is min max applied. */ - private boolean isMinMaxApplied = true; - - /** The fn sort. */ - private final Lambda1> fnSort; // this will be - // used for - // sorting - - /** The fn display. */ - private final Lambda1> fnDisplay; // this is used - // to display - - private TableCellRenderer cellRenderer = null; - - /** - * Gets the name. - * - * @return the name - */ - public final String getName() { - return this.name; - } - - /** - * Instantiates a new table column info. - * - * @param colName - * the col name - * @param fieldSort - * the field sort - * @param fieldDisplay - * the field display - */ - public TableColumnInfo(final String colName, final Lambda1> fieldSort, - final Lambda1> fieldDisplay) { - this.fnSort = fieldSort; - this.fnDisplay = fieldDisplay; - this.name = colName; - } - - /** - * Instantiates a new table column info. - * - * @param colName - * the col name - * @param width - * the width - * @param fieldSort - * the field sort - * @param fieldDisplay - * the field display - */ - public TableColumnInfo(final String colName, final int width, - final Lambda1> fieldSort, - final Lambda1> fieldDisplay) { - this(colName, fieldSort, fieldDisplay); - this.setMaxWidth(width); - this.setMinWidth(width); - this.setNominalWidth(width); - } - - /** - * Instantiates a new table column info. - * - * @param colName - * the col name - * @param wMin - * the w min - * @param width - * the width - * @param wMax - * the w max - * @param fieldSort - * the field sort - * @param fieldDisplay - * the field display - */ - public TableColumnInfo(final String colName, final int wMin, final int width, final int wMax, - final Lambda1> fieldSort, - final Lambda1> fieldDisplay) { - this(colName, fieldSort, fieldDisplay); - this.setMaxWidth(wMax); - this.setMinWidth(wMin); - this.setNominalWidth(width); - } - - /** - * Sets the cell renderer. - * - * @param renderer - * the new cell renderer - */ - public final void setCellRenderer(final TableCellRenderer renderer) { - this.cellRenderer = renderer; - } - - /** - * Gets the cell renderer. - * - * @return the cell renderer - */ - public final TableCellRenderer getCellRenderer() { - return this.cellRenderer; - } - - /** - * Gets the min width. - * - * @return the minWidth - */ - public int getMinWidth() { - return this.minWidth; - } - - /** - * Sets the min width. - * - * @param minWidth0 - * the minWidth to set - */ - public void setMinWidth(final int minWidth0) { - this.minWidth = minWidth0; - } - - /** - * Gets the max width. - * - * @return the maxWidth - */ - public int getMaxWidth() { - return this.maxWidth; - } - - /** - * Sets the max width. - * - * @param maxWidth0 - * the maxWidth to set - */ - public void setMaxWidth(final int maxWidth0) { - this.maxWidth = maxWidth0; - } - - /** - * Gets the nominal width. - * - * @return the nominalWidth - */ - public int getNominalWidth() { - return this.nominalWidth; - } - - /** - * Sets the nominal width. - * - * @param nominalWidth0 - * the nominalWidth to set - */ - public void setNominalWidth(final int nominalWidth0) { - this.nominalWidth = nominalWidth0; - } - - /** - * Checks if is min max applied. - * - * @return the isMinMaxApplied - */ - public boolean isMinMaxApplied() { - return this.isMinMaxApplied; - } - - /** - * Sets the min max applied. - * - * @param isMinMaxApplied0 - * the isMinMaxApplied to set - */ - public void setMinMaxApplied(final boolean isMinMaxApplied0) { - this.isMinMaxApplied = isMinMaxApplied0; - } - - /** - * Gets the fn sort. - * - * @return the fnSort - */ - public Lambda1> getFnSort() { - return this.fnSort; - } - - /** - * Gets the fn display. - * - * @return the fnDisplay - */ - public Lambda1> getFnDisplay() { - return this.fnDisplay; - } -} diff --git a/src/main/java/forge/gui/deckeditor/elements/TableModel.java b/src/main/java/forge/gui/deckeditor/elements/TableModel.java deleted file mode 100644 index 04f48d0ffee..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/TableModel.java +++ /dev/null @@ -1,451 +0,0 @@ -/* - * Forge: Play Magic: the Gathering. - * Copyright (C) 2011 Forge Team - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package forge.gui.deckeditor.elements; - -import java.awt.event.FocusEvent; -import java.awt.event.FocusListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Map.Entry; - -import javax.swing.JTable; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.event.TableModelEvent; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumn; -import javax.swing.table.TableColumnModel; - -import forge.item.InventoryItem; -import forge.item.ItemPool; -import forge.item.ItemPoolView; - -/** - *

- * TableModel class. - *

- * - * @param - * the generic type - * @author Forge - * @version $Id$ - */ -public final class TableModel extends AbstractTableModel { - /** - * - */ - private static final long serialVersionUID = -6896726613116254828L; - - private final class SortOrders { - private class Order { - private final int sortColumn; - private boolean isSortAsc = true; - - public Order(final int col) { - this.sortColumn = col; - } - }; - - private final int maxDepth = 3; - private final List orders = new ArrayList(3); - private TableSorterCascade sorter = null; - private boolean isSorterReady = false; - - private int indexOfColumn(final int column) { - int posColumn = this.orders.size() - 1; - for (; posColumn >= 0; posColumn--) { - if ((this.orders.get(posColumn) != null) && (this.orders.get(posColumn).sortColumn == column)) { - break; - } - } - return posColumn; - } - - // index of column to sort by, desired direction - public void add(final int column, final boolean wantAsc) { - this.add(column); - this.orders.get(0).isSortAsc = wantAsc; - this.isSorterReady = false; - } - - // puts desired direction on top, set "asc"; if already was on top, - // inverts direction; - public void add(final int column) { - final int posColumn = this.indexOfColumn(column); - switch (posColumn) { - case -1: // no such column here - let's add then - this.orders.add(0, new Order(column)); - break; - case 0: // found at top-level, should invert - this.orders.get(0).isSortAsc ^= true; // invert - break; - default: // found somewhere, move down others, set this one onto - // top; - this.orders.remove(posColumn); - this.orders.add(0, new Order(column)); - break; - } - if (this.orders.size() > this.maxDepth) { - this.orders.remove(this.maxDepth); - } - this.isSorterReady = false; - } - - public TableSorterCascade getSorter() { - if (!this.isSorterReady) { - final List> oneColSorters = new ArrayList>(this.maxDepth); - for (final Order order : this.orders) { - oneColSorters.add(new TableSorter(TableModel.this.columns.get(order.sortColumn).getFnSort(), - order.isSortAsc)); - } - this.sorter = new TableSorterCascade(oneColSorters); - } - return this.sorter; - } - } - - private final ItemPool data; - private final CardPanelBase cardDisplay; - private final List> columns; - private final SortOrders sortOrders = new SortOrders(); - - /** - * Instantiates a new table model. - * - * @param cd - * the cd - * @param columnsToShow - * the columns to show - * @param cls - * the cls - */ - public TableModel(final CardPanelBase cd, final List> columnsToShow, final Class cls) { - this.data = new ItemPool(cls); - this.cardDisplay = cd; - this.columns = columnsToShow; - this.columns.get(4).setMinMaxApplied(false); - } - - /** - * Resize cols. - * - * @param table - * the table - */ - public void resizeCols(final JTable table) { - TableColumn tableColumn = null; - for (int i = 0; i < table.getColumnCount(); i++) { - tableColumn = table.getColumnModel().getColumn(i); - final TableColumnInfo colInfo = this.columns.get(i); - - tableColumn.setPreferredWidth(colInfo.getNominalWidth()); - if (colInfo.isMinMaxApplied()) { - tableColumn.setMinWidth(colInfo.getMinWidth()); - tableColumn.setMaxWidth(colInfo.getMaxWidth()); - } - } - } - - /** - * Clear. - */ - public void clear() { - this.data.clear(); - } - - /** - * Gets the cards. - * - * @return the cards - */ - public ItemPoolView getCards() { - return this.data.getView(); - } - - /** - *

- * removeCard. - *

- * - * @param c - * a {@link forge.Card} object. - */ - public void removeCard(final T c) { - final boolean wasThere = this.data.count(c) > 0; - if (wasThere) { - this.data.remove(c); - this.fireTableDataChanged(); - } - } - - /** - * Adds the card. - * - * @param c - * the c - */ - public void addCard(final T c) { - this.data.add(c); - this.fireTableDataChanged(); - } - - /** - * Adds the card. - * - * @param c - * the c - * @param count - * the count - */ - public void addCard(final T c, final int count) { - this.data.add(c, count); - this.fireTableDataChanged(); - } - - /** - * Adds the card. - * - * @param e - * the e - */ - public void addCard(final Entry e) { - this.data.add(e.getKey(), e.getValue()); - this.fireTableDataChanged(); - } - - /** - * Adds the cards. - * - * @param c - * the c - */ - public void addCards(final Iterable> c) { - this.data.addAll(c); - this.fireTableDataChanged(); - } - - /** - * Adds the all cards. - * - * @param c - * the c - */ - public void addAllCards(final Iterable c) { - this.data.addAllFlat(c); - this.fireTableDataChanged(); - } - - /** - * Row to card. - * - * @param row - * the row - * @return the entry - */ - public Entry rowToCard(final int row) { - final List> model = this.data.getOrderedList(); - return (row >= 0) && (row < model.size()) ? model.get(row) : null; - } - - /* - * (non-Javadoc) - * - * @see javax.swing.table.TableModel#getRowCount() - */ - /** - * Gets the row count. - * - * @return int - */ - @Override - public int getRowCount() { - return this.data.countDistinct(); - } - - /* - * (non-Javadoc) - * - * @see javax.swing.table.TableModel#getColumnCount() - */ - /** - * Gets the column count. - * - * @return int - */ - @Override - public int getColumnCount() { - return this.columns.size(); - } - - /** {@inheritDoc} */ - @Override - public String getColumnName(final int n) { - return this.columns.get(n).getName(); - } - - /** {@inheritDoc} */ - @SuppressWarnings("unchecked") - @Override - public Object getValueAt(final int row, final int column) { - return this.columns.get(column).getFnDisplay().apply((Entry) this.rowToCard(row)); - } - - /** - * The listener interface for receiving column events. The class that is - * interested in processing a column event implements this interface, and - * the object created with that class is registered with a component using - * the component's addColumnListener method. When the column event occurs, - * that object's appropriate method is invoked. - * - */ - class ColumnListener extends MouseAdapter { - - /** The table. */ - private final JTable table; - - /** - * Instantiates a new column listener. - * - * @param t - * the t - */ - public ColumnListener(final JTable t) { - this.table = t; - } - - /* - * (non-Javadoc) - * - * @see - * java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent) - */ - /** - * Mouse clicked. - * - * @param e - * MouseEvent - */ - @Override - public void mouseClicked(final MouseEvent e) { - final TableColumnModel colModel = this.table.getColumnModel(); - final int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); - final int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex(); - - if (modelIndex < 0) { - return; - } - - // This will invert if needed - TableModel.this.sortOrders.add(modelIndex); - - for (int i = 0; i < TableModel.this.columns.size(); i++) { - final TableColumn column = colModel.getColumn(i); - column.setHeaderValue(TableModel.this.getColumnName(column.getModelIndex())); - } - this.table.getTableHeader().repaint(); - - TableModel.this.resort(); - this.table.tableChanged(new TableModelEvent(TableModel.this)); - this.table.repaint(); - } - } - - /** - * Show selected card. - * - * @param table - * the table - */ - public void showSelectedCard(final JTable table) { - final int row = table.getSelectedRow(); - if (row != -1) { - final T cp = this.rowToCard(row).getKey(); - this.cardDisplay.showCard(cp); - } - } - - /** - *

- * addListeners. - *

- * - * @param table - * a {@link javax.swing.JTable} object. - */ - public void addListeners(final JTable table) { - // updates card detail, listens to any key strokes - table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { - - @Override - public void valueChanged(final ListSelectionEvent arg0) { - TableModel.this.showSelectedCard(table); - } - }); - table.addFocusListener(new FocusListener() { - - @Override - public void focusLost(final FocusEvent e) { - } - - @Override - public void focusGained(final FocusEvent e) { - TableModel.this.showSelectedCard(table); - } - }); - - table.getTableHeader().addMouseListener(new ColumnListener(table)); - - } // addCardListener() - - private class MyComparator implements Comparator> { - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - private TableSorterCascade sorter = TableModel.this.sortOrders.getSorter(); - @SuppressWarnings("unchecked") - @Override - public int compare(Entry o1, Entry o2) { - return sorter.compare((Entry) o1, (Entry) o2); - } - } - - /** - * Resort. - */ - public void resort() { - Collections.sort(this.data.getOrderedList(), new MyComparator()); - } - - /** - * Sort. - * - * @param iCol - * the i col - * @param isAsc - * the is asc - */ - public void sort(final int iCol, final boolean isAsc) { - this.sortOrders.add(iCol, isAsc); - this.resort(); - } - -} // CardTableModel diff --git a/src/main/java/forge/gui/deckeditor/elements/package-info.java b/src/main/java/forge/gui/deckeditor/elements/package-info.java deleted file mode 100644 index 00dba87a7f2..00000000000 --- a/src/main/java/forge/gui/deckeditor/elements/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -/** Forge Card Game. */ -package forge.gui.deckeditor.elements; - diff --git a/src/main/java/forge/gui/deckeditor/DeckController.java b/src/main/java/forge/gui/deckeditor/tables/DeckController.java similarity index 83% rename from src/main/java/forge/gui/deckeditor/DeckController.java rename to src/main/java/forge/gui/deckeditor/tables/DeckController.java index 132ca046c2f..197984b0cd7 100644 --- a/src/main/java/forge/gui/deckeditor/DeckController.java +++ b/src/main/java/forge/gui/deckeditor/tables/DeckController.java @@ -15,15 +15,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.gui.deckeditor; +package forge.gui.deckeditor.tables; -import java.awt.Component; import java.util.ArrayList; - import org.apache.commons.lang3.StringUtils; import forge.deck.DeckBase; +import forge.gui.deckeditor.controllers.ACEditorBase; +import forge.gui.deckeditor.controllers.CProbabilities; +import forge.gui.deckeditor.controllers.CStatistics; +import forge.gui.deckeditor.views.VCurrentDeck; import forge.util.IStorage; import forge.util.closures.Lambda0; @@ -38,7 +40,7 @@ public class DeckController { private boolean saved; private boolean modelInStore; private final IStorage folder; - private final DeckEditorBase view; + private final ACEditorBase view; private final Lambda0 newModelCreator; /** @@ -48,7 +50,7 @@ public class DeckController { * @param view0 the view0 * @param newModelCreator0 the new model creator0 */ - public DeckController(final IStorage folder0, final DeckEditorBase view0, + public DeckController(final IStorage folder0, final ACEditorBase view0, final Lambda0 newModelCreator0) { this.folder = folder0; this.view = view0; @@ -85,7 +87,12 @@ public class DeckController { public void setModel(final T document, final boolean isStored) { this.modelInStore = isStored; this.model = document; - this.view.updateView(); + this.view.resetTables(); + + VCurrentDeck.SINGLETON_INSTANCE.getTxfTitle().setText(model.getName()); + CStatistics.SINGLETON_INSTANCE.update(); + CProbabilities.SINGLETON_INSTANCE.update(); + this.saved = true; // unless set to false in notify if (!this.isModelInSyncWithFolder()) { this.notifyModelChanged(); @@ -110,7 +117,7 @@ public class DeckController { * * @return the view */ - public DeckEditorBase getView() { + public ACEditorBase getView() { return this.view; } @@ -127,20 +134,6 @@ public class DeckController { // view.setTitle(); } - /* - * (non-Javadoc) - * - * @see forge.gui.deckeditor.IDeckController#getOwnerWindow() - */ - /** - * Gets the owner window. - * - * @return the owner window - */ - public Component getOwnerWindow() { - return this.getView(); - } - /* * (non-Javadoc) * @@ -187,6 +180,7 @@ public class DeckController { if (null == model) { return; } + this.folder.add(this.model); // copy to new instance which will be edited and left if unsaved this.setModel((T) this.model.copyTo(this.model.getName()), true); @@ -258,20 +252,6 @@ public class DeckController { return !this.folder.isUnique(deckName); } - /* (non-Javadoc) - * @see forge.gui.deckeditor.IDeckController#isGoodName(java.lang.String) - */ - - /** - * Checks if is good name. - * - * @param deckName the deck name - * @return true, if is good name - */ - public boolean isGoodName(final String deckName) { - return StringUtils.isNotBlank(deckName) && this.folder.isUnique(deckName); - } - /* * (non-Javadoc) * @@ -314,6 +294,6 @@ public class DeckController { public void newModel() { this.model = this.newModelCreator.apply(); this.saved = true; - this.view.updateView(); + this.view.resetTables(); } } diff --git a/src/main/java/forge/gui/deckeditor/tables/IntegerRenderer.java b/src/main/java/forge/gui/deckeditor/tables/IntegerRenderer.java new file mode 100644 index 00000000000..de1fcb9b2f0 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/tables/IntegerRenderer.java @@ -0,0 +1,44 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.tables; + +import java.awt.Component; + +import javax.swing.JTable; +import javax.swing.table.DefaultTableCellRenderer; + +/** + * A quick converter to avoid -1 being displayed for unapplicable values. + */ +@SuppressWarnings("serial") +public class IntegerRenderer extends DefaultTableCellRenderer { + /* + * (non-Javadoc) + * + * @see + * javax.swing.table.DefaultTableCellRenderer#getTableCellRendererComponent + * (javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) + */ + @Override + public final Component getTableCellRendererComponent(final JTable table, Object value0, + final boolean isSelected, final boolean hasFocus, final int row, final int column) { + + if ((Integer) value0 == -1) { value0 = "-"; } + return super.getTableCellRendererComponent(table, value0, isSelected, hasFocus, row, column); + } +} diff --git a/src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java b/src/main/java/forge/gui/deckeditor/tables/ManaCostRenderer.java similarity index 95% rename from src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java rename to src/main/java/forge/gui/deckeditor/tables/ManaCostRenderer.java index 25a9536c35f..c0f90471380 100644 --- a/src/main/java/forge/gui/deckeditor/elements/ManaCostRenderer.java +++ b/src/main/java/forge/gui/deckeditor/tables/ManaCostRenderer.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.gui.deckeditor.elements; +package forge.gui.deckeditor.tables; import java.awt.Component; import java.awt.Graphics; diff --git a/src/main/java/forge/gui/deckeditor/tables/SColumnUtil.java b/src/main/java/forge/gui/deckeditor/tables/SColumnUtil.java new file mode 100644 index 00000000000..cbac7c9b425 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/tables/SColumnUtil.java @@ -0,0 +1,530 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.tables; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.regex.Pattern; + +import javax.swing.JTable; +import javax.swing.table.TableColumnModel; + +import forge.Singletons; +import forge.card.CardColor; +import forge.card.CardEdition; +import forge.card.CardManaCost; +import forge.card.CardRarity; +import forge.deck.DeckBase; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.controllers.ACEditorBase; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.item.InventoryItemFromSet; +import forge.util.closures.Lambda1; + +/** + * A collection of methods pertaining to columns in card catalog and + * current deck tables, for use in the deck editor. + *

+ * (S at beginning of class name denotes a static factory.) + * + */ +public final class SColumnUtil { + /** + * Each catalog column identified in the XML file is + * referenced using these names. Its name in the XML + * should match the name in the enum. Underscores + * will be replaced with spaces in the display. + *

+ * Note: To add a new column, put an enum here, and also add in the XML prefs file. + */ + public enum ColumnName { /** */ + CAT_QUANTITY, /** */ + CAT_NAME, /** */ + CAT_COST, /** */ + CAT_COLOR, /** */ + CAT_TYPE, /** */ + CAT_POWER, /** */ + CAT_TOUGHNESS, /** */ + CAT_CMC, /** */ + CAT_RARITY, /** */ + CAT_SET, /** */ + CAT_AI, /** */ + CAT_NEW, /** */ + CAT_PURCHASE_PRICE, /** */ + CAT_DECKS, /** */ + DECK_QUANTITY, /** */ + DECK_NAME, /** */ + DECK_COST, /** */ + DECK_COLOR, /** */ + DECK_TYPE, /** */ + DECK_POWER, /** */ + DECK_TOUGHNESS, /** */ + DECK_CMC, /** */ + DECK_RARITY, /** */ + DECK_SET, /** */ + DECK_AI, /** */ + DECK_NEW, /** */ + DECK_SALE_PRICE; + } + + /** Possible states of data sorting in a column: none, ascending, or descending. */ + public enum SortState { /** */ + NONE, /** */ + ASC, /** */ + DESC + } + + /** @return List> */ + public static List> getCatalogDefaultColumns() { + final List> columns = new ArrayList>(); + + columns.add(SColumnUtil.getColumn(ColumnName.CAT_QUANTITY)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_NAME)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_COST)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_COLOR)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_TYPE)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_POWER)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_TOUGHNESS)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_CMC)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_RARITY)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_SET)); + columns.add(SColumnUtil.getColumn(ColumnName.CAT_AI)); + + return columns; + } + + /** @return List> */ + public static List> getDeckDefaultColumns() { + final List> columns = new ArrayList>(); + + columns.add(SColumnUtil.getColumn(ColumnName.DECK_QUANTITY)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_NAME)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_COST)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_COLOR)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_TYPE)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_POWER)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_TOUGHNESS)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_CMC)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_RARITY)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_SET)); + columns.add(SColumnUtil.getColumn(ColumnName.DECK_AI)); + + return columns; + } + + /** Should be called after column preferences has run, which has created a new column list. */ + public static void attachSortAndDisplayFunctions() { + SColumnUtil.getColumn(ColumnName.CAT_QUANTITY).setSortAndDisplayFunctions( + SColumnUtil.FN_QTY_COMPARE, SColumnUtil.FN_QTY_GET); + SColumnUtil.getColumn(ColumnName.CAT_NAME).setSortAndDisplayFunctions( + SColumnUtil.FN_NAME_COMPARE, SColumnUtil.FN_NAME_GET); + SColumnUtil.getColumn(ColumnName.CAT_COST).setSortAndDisplayFunctions( + SColumnUtil.FN_COST_COMPARE, SColumnUtil.FN_COST_GET); + SColumnUtil.getColumn(ColumnName.CAT_COLOR).setSortAndDisplayFunctions( + SColumnUtil.FN_COLOR_COMPARE, SColumnUtil.FN_COLOR_GET); + SColumnUtil.getColumn(ColumnName.CAT_TYPE).setSortAndDisplayFunctions( + SColumnUtil.FN_TYPE_COMPARE, SColumnUtil.FN_TYPE_GET); + SColumnUtil.getColumn(ColumnName.CAT_POWER).setSortAndDisplayFunctions( + SColumnUtil.FN_POWER_COMPARE, SColumnUtil.FN_POWER_GET); + SColumnUtil.getColumn(ColumnName.CAT_TOUGHNESS).setSortAndDisplayFunctions( + SColumnUtil.FN_TOUGHNESS_COMPARE, SColumnUtil.FN_TOUGHNESS_GET); + SColumnUtil.getColumn(ColumnName.CAT_CMC).setSortAndDisplayFunctions( + SColumnUtil.FN_CMC_COMPARE, SColumnUtil.FN_CMC_GET); + SColumnUtil.getColumn(ColumnName.CAT_RARITY).setSortAndDisplayFunctions( + SColumnUtil.FN_RARITY_COMPARE, SColumnUtil.FN_RARITY_GET); + SColumnUtil.getColumn(ColumnName.CAT_SET).setSortAndDisplayFunctions( + SColumnUtil.FN_SET_COMPARE, SColumnUtil.FN_SET_GET); + SColumnUtil.getColumn(ColumnName.CAT_AI).setSortAndDisplayFunctions( + SColumnUtil.FN_AI_STATUS_COMPARE, SColumnUtil.FN_AI_STATUS_GET); + + SColumnUtil.getColumn(ColumnName.DECK_QUANTITY).setSortAndDisplayFunctions( + SColumnUtil.FN_QTY_COMPARE, SColumnUtil.FN_QTY_GET); + SColumnUtil.getColumn(ColumnName.DECK_NAME).setSortAndDisplayFunctions( + SColumnUtil.FN_NAME_COMPARE, SColumnUtil.FN_NAME_GET); + SColumnUtil.getColumn(ColumnName.DECK_COST).setSortAndDisplayFunctions( + SColumnUtil.FN_COST_COMPARE, SColumnUtil.FN_COST_GET); + SColumnUtil.getColumn(ColumnName.DECK_COLOR).setSortAndDisplayFunctions( + SColumnUtil.FN_COLOR_COMPARE, SColumnUtil.FN_COLOR_GET); + SColumnUtil.getColumn(ColumnName.DECK_TYPE).setSortAndDisplayFunctions( + SColumnUtil.FN_TYPE_COMPARE, SColumnUtil.FN_TYPE_GET); + SColumnUtil.getColumn(ColumnName.DECK_POWER).setSortAndDisplayFunctions( + SColumnUtil.FN_POWER_COMPARE, SColumnUtil.FN_POWER_GET); + SColumnUtil.getColumn(ColumnName.DECK_TOUGHNESS).setSortAndDisplayFunctions( + SColumnUtil.FN_TOUGHNESS_COMPARE, SColumnUtil.FN_TOUGHNESS_GET); + SColumnUtil.getColumn(ColumnName.DECK_CMC).setSortAndDisplayFunctions( + SColumnUtil.FN_CMC_COMPARE, SColumnUtil.FN_CMC_GET); + SColumnUtil.getColumn(ColumnName.DECK_RARITY).setSortAndDisplayFunctions( + SColumnUtil.FN_RARITY_COMPARE, SColumnUtil.FN_RARITY_GET); + SColumnUtil.getColumn(ColumnName.DECK_SET).setSortAndDisplayFunctions( + SColumnUtil.FN_SET_COMPARE, SColumnUtil.FN_SET_GET); + SColumnUtil.getColumn(ColumnName.DECK_AI).setSortAndDisplayFunctions( + SColumnUtil.FN_AI_STATUS_COMPARE, SColumnUtil.FN_AI_STATUS_GET); + + SColumnUtil.getColumn(ColumnName.CAT_COST).setCellRenderer(new ManaCostRenderer()); + SColumnUtil.getColumn(ColumnName.CAT_POWER).setCellRenderer(new IntegerRenderer()); + SColumnUtil.getColumn(ColumnName.CAT_TOUGHNESS).setCellRenderer(new IntegerRenderer()); + SColumnUtil.getColumn(ColumnName.CAT_CMC).setCellRenderer(new IntegerRenderer()); + + SColumnUtil.getColumn(ColumnName.DECK_COST).setCellRenderer(new ManaCostRenderer()); + SColumnUtil.getColumn(ColumnName.DECK_POWER).setCellRenderer(new IntegerRenderer()); + SColumnUtil.getColumn(ColumnName.DECK_TOUGHNESS).setCellRenderer(new IntegerRenderer()); + SColumnUtil.getColumn(ColumnName.DECK_CMC).setCellRenderer(new IntegerRenderer()); + } + + /** + * Hides/shows a table column. + * + * @param col0 TableColumnInfo + * @param extends InventoryItem + * @param extends DeckBase + */ + @SuppressWarnings("unchecked") + public static + void toggleColumn(final TableColumnInfo col0) { + + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + final JTable tbl = (col0.getEnumValue().substring(0, 4).equals("DECK")) + ? ed.getTableDeck().getTable() + : ed.getTableCatalog().getTable(); + + final TableColumnModel colmodel = tbl.getColumnModel(); + + if (col0.isShowing()) { + col0.setShowing(false); + colmodel.removeColumn(col0); + } + else { + col0.setShowing(true); + colmodel.addColumn(col0); + if (col0.getModelIndex() < colmodel.getColumnCount()) { + colmodel.moveColumn(colmodel.getColumnIndex(col0.getIdentifier()), col0.getModelIndex()); + } + } + } + + /** + * Retrieve a custom column (uses identical method in SEditorIO). + * + * @param id0   {@link forge.gui.deckeditor.SEditorUtil.CatalogColumnName} + * @return TableColumnInfo + */ + public static TableColumnInfo getColumn(final ColumnName id0) { + return SEditorIO.getColumn(id0); + } + + /** + * Convenience method to get a column's index in the view (that is, + * in the TableColumnModel). + * + * @param id0   {@link forge.gui.deckeditor.SEditorUtil.CatalogColumnName} + * @return int + * @param extends InventoryItem + * @param extends InventoryItem + */ + @SuppressWarnings("unchecked") + public static + int getColumnViewIndex(final ColumnName id0) { + + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + final JTable tbl = (id0.toString().substring(0, 4).equals("DECK")) + ? ed.getTableDeck().getTable() + : ed.getTableCatalog().getTable(); + + int index = -1; + + try { + index = tbl.getColumnModel().getColumnIndex(SColumnUtil.getColumn(id0).getIdentifier()); + } + catch (final Exception e) { } + + return index; + } + + /** + * Convenience method to get a column's index in the model (that is, + * in the TableModel, NOT the TableColumnModel). + * + * @param id0   {@link forge.gui.deckeditor.SEditorUtil.CatalogColumnName} + * @return int + * @param extends InventoryItem + * @param extends InventoryItem + */ + @SuppressWarnings("unchecked") + public static + int getColumnModelIndex(final ColumnName id0) { + + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + final JTable tbl = (id0.toString().substring(0, 4) == "DECK") + ? ed.getTableDeck().getTable() + : ed.getTableCatalog().getTable(); + + return tbl.getColumn(SColumnUtil.getColumn(id0).getIdentifier()).getModelIndex(); + } + + //========== Display functions + + private static final Pattern AE_FINDER = Pattern.compile("AE", Pattern.LITERAL); + + private static CardManaCost toManaCost(final InventoryItem i) { + return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getManaCost() : CardManaCost.EMPTY; + } + + private static CardColor toColor(final InventoryItem i) { + return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getColor() : CardColor.getNullColor(); + } + + private static Integer toPower(final InventoryItem i) { + Integer result = -1; + if (i instanceof CardPrinted) { + result = ((CardPrinted) i).getCard().getIntPower(); + if (result == null) { + result = Integer.valueOf(((CardPrinted) i).getCard().getLoyalty()); + if (result == null) { result = -1; } + } + } + return result; + } + + private static Integer toToughness(final InventoryItem i) { + return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getIntToughness() : -1; + } + + private static Integer toCMC(final InventoryItem i) { + return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getManaCost().getCMC() : -1; + } + + private static CardRarity toRarity(final InventoryItem i) { + return i instanceof CardPrinted ? ((CardPrinted) i).getRarity() : CardRarity.Unknown; + } + + private static CardEdition toSetCmp(final InventoryItem i) { + return i instanceof InventoryItemFromSet ? Singletons.getModel().getEditions() + .get(((InventoryItemFromSet) i).getEdition()) : CardEdition.UNKNOWN; + } + + private static String toSetStr(final InventoryItem i) { + return i instanceof InventoryItemFromSet ? ((InventoryItemFromSet) i).getEdition() : "n/a"; + } + + private static Integer toAiCmp(final InventoryItem i) { + return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatusComparable() : Integer.valueOf(-1); + } + + private static String toAiStr(final InventoryItem i) { + return i instanceof CardPrinted ? ((CardPrinted) i).getCard().getAiStatus() : "n/a"; + } + + //========== + + /** Lamda sort fnQtyCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_QTY_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return from.getValue(); + } + }; + + /** Lamda sort fnQtyGet. */ + private static final Lambda1> FN_QTY_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return from.getValue(); + } + }; + + /** Lamda sort fnNameCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_NAME_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return from.getKey().getName(); + } + }; + + /** Lamda sort fnNameGet. */ + private static final Lambda1> FN_NAME_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + final String name = from.getKey().getName(); + return name.contains("AE") ? SColumnUtil.AE_FINDER.matcher(name).replaceAll("\u00C6") : name; + } + }; + + /** Lamda sort fnCostCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_COST_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return SColumnUtil.toManaCost(from.getKey()); + } + }; + + /** Lamda sort fnCostGet. */ + private static final Lambda1> FN_COST_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return SColumnUtil.toManaCost(from.getKey()); + } + }; + + /** Lamda sort fnColorCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_COLOR_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return SColumnUtil.toColor(from.getKey()); + } + }; + + /** Lamda sort fnColorGet. */ + private static final Lambda1> FN_COLOR_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return SColumnUtil.toColor(from.getKey()); + } + }; + + /** Lamda sort fnTypeCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_TYPE_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return from.getKey().getType(); + } + }; + + /** Lamda sort fnTypeGet. */ + private static final Lambda1> FN_TYPE_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return from.getKey().getType(); + } + }; + + /** Lamda sort fnPowerCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_POWER_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return SColumnUtil.toPower(from.getKey()); + } + }; + + /** Lamda sort fnPowerGet. */ + private static final Lambda1> FN_POWER_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return SColumnUtil.toPower(from.getKey()); + } + }; + + /** Lamda sort fnToughnessCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_TOUGHNESS_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return SColumnUtil.toToughness(from.getKey()); + } + }; + + /** Lamda sort fnToughnessGet. */ + private static final Lambda1> FN_TOUGHNESS_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return SColumnUtil.toToughness(from.getKey()); + } + }; + + /** Lamda sort fnCMCCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_CMC_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return SColumnUtil.toCMC(from.getKey()); + } + }; + + /** Lamda sort fnCMCGet. */ + private static final Lambda1> FN_CMC_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return SColumnUtil.toCMC(from.getKey()); + } + }; + + /** Lamda sort fnRarityCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_RARITY_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return SColumnUtil.toRarity(from.getKey()); + } + }; + + /** Lamda sort fnRarityGet. */ + private static final Lambda1> FN_RARITY_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return SColumnUtil.toRarity(from.getKey()); + } + }; + + /** Lamda sort fnSetCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_SET_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return SColumnUtil.toSetCmp(from.getKey()); + } + }; + + /** Lamda sort fnSetGet. */ + private static final Lambda1> FN_SET_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return SColumnUtil.toSetStr(from.getKey()); + } + }; + + /** Lamda sort fnAiStatusCompare. */ + @SuppressWarnings("rawtypes") + private static final Lambda1> FN_AI_STATUS_COMPARE = new Lambda1>() { + @Override + public Comparable apply(final Entry from) { + return SColumnUtil.toAiCmp(from.getKey()); + } + }; + + /** Lamda sort fnAiStatusGet. */ + private static final Lambda1> FN_AI_STATUS_GET = new Lambda1>() { + @Override + public Object apply(final Entry from) { + return SColumnUtil.toAiStr(from.getKey()); + } + }; +} diff --git a/src/main/java/forge/gui/deckeditor/tables/TableColumnInfo.java b/src/main/java/forge/gui/deckeditor/tables/TableColumnInfo.java new file mode 100644 index 00000000000..2af9cb02aff --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/tables/TableColumnInfo.java @@ -0,0 +1,142 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.tables; + +import java.util.Map.Entry; + +import javax.swing.table.TableColumn; + +import forge.gui.deckeditor.tables.SColumnUtil.SortState; +import forge.util.closures.Lambda1; + +/** + * A column object in a TableModel in the card editor. + * Requires a sorting function and a display function + * (to extract information as appropriate for table row data). + * + * @param a generic type + */ + +@SuppressWarnings({ "rawtypes", "serial" }) +public class TableColumnInfo extends TableColumn { + private SortState sortstate = SortState.NONE; + private int sortPriority = 0; + private boolean show = true; + private String enumval; + + private Lambda1> fnSort; + private Lambda1> fnDisplay; + + /** */ + public TableColumnInfo() { + super(); + } + + /** + * Unique identifier in SColumnUtil.ColumnName enum. + * + * @return {@link java.lang.String} + */ + public String getEnumValue() { + return enumval; + } + + /** + * Unique identifier in SColumnUtil.ColumnName enum. + * + * @param val0   {@link java.lang.String} + */ + public void setEnumValue(final String val0) { + this.enumval = val0; + } + + /** + * Position in sort cascade, 0 for no priority. + * + * @return int + */ + public int getSortPriority() { + return sortPriority; + } + + /** + * Position in sort cascade, 0 for no priority. + * + * @param position0   int + */ + public void setSortPriority(final int position0) { + this.sortPriority = position0; + } + + /** @return {@link forge.gui.deckeditor.tables.TableModel.SortState} */ + public SortState getSortState() { + return this.sortstate; + } + + /** @param state0   {@link forge.gui.deckeditor.tables.TableColumnInfo.SortState} */ + public void setSortState(final SortState state0) { + this.sortstate = state0; + } + + /** @return boolean */ + public boolean isShowing() { + return this.show; + } + + /** @param boolean0   show/hide this column */ + public void setShowing(final boolean boolean0) { + this.show = boolean0; + } + + /** + * Lambda closure used to sort this column. + * + * @return the fnSort + */ + public Lambda1> getFnSort() { + if (fnSort.equals(null)) { + throw new NullPointerException("A sort function hasn't been set for " + + "Column " + TableColumnInfo.this.getIdentifier()); + } + return this.fnSort; + } + + /** + * Gets the fn display. + * + * @return the fnDisplay + */ + public Lambda1> getFnDisplay() { + if (fnSort.equals(null)) { + throw new NullPointerException("A display function hasn't been set for " + + "Column " + TableColumnInfo.this.getIdentifier()); + } + return this.fnDisplay; + } + + /** + * Lambda closure used to sort this column, and fn display. + * + * @param lambda0 the fnSort + * @param lambda1 the fnDisplay + */ + public void setSortAndDisplayFunctions(final Lambda1> lambda0, final Lambda1> lambda1) { + this.fnSort = lambda0; + this.fnDisplay = lambda1; + } +} diff --git a/src/main/java/forge/gui/deckeditor/tables/TableModel.java b/src/main/java/forge/gui/deckeditor/tables/TableModel.java new file mode 100644 index 00000000000..e9f171a9f10 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/tables/TableModel.java @@ -0,0 +1,373 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 +import forge.gui.deckeditor.views.VDeckEditorUI; +Forge Team + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.gui.deckeditor.tables; + +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Enumeration; +import java.util.List; +import java.util.Map.Entry; + +import javax.swing.JTable; +import javax.swing.event.ListSelectionEvent; +import javax.swing.event.ListSelectionListener; +import javax.swing.event.TableModelEvent; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; + +import org.apache.commons.lang3.ArrayUtils; + +import forge.Card; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.SEditorIO; +import forge.gui.deckeditor.tables.SColumnUtil.ColumnName; +import forge.gui.deckeditor.tables.SColumnUtil.SortState; +import forge.item.CardPrinted; +import forge.item.InventoryItem; +import forge.item.ItemPool; +import forge.item.ItemPoolView; + +/** + *

+ * TableModel class. + *

+ * + * @param + * the generic type + * @author Forge + * @version $Id$ + */ +@SuppressWarnings("serial") +public final class TableModel extends AbstractTableModel { + private final ItemPool data; + private final JTable table; + private final CascadeManager cascadeManager = new CascadeManager(); + private final int maxSortDepth = 3; + + /** + * Instantiates a new table model, using a JTable, + * a column set, and a data set of generic type . + * + * @param table0   {@link javax.swing.JTable} + * @param class0   Generic type + */ + public TableModel(final JTable table0, final Class class0) { + this.table = table0; + this.data = new ItemPool(class0); + } + + /** */ + @SuppressWarnings("unchecked") + public void setup() { + final Enumeration e = table.getColumnModel().getColumns(); + final TableColumn[] sortcols = new TableColumn[table.getColumnCount()]; + + // Assemble priority sort. + while (e.hasMoreElements()) { + final TableColumnInfo col = (TableColumnInfo) e.nextElement(); + + if (col.getSortPriority() > 0) { + sortcols[col.getSortPriority()] = col; + } + } + + final boolean isDeckTable = ((TableColumnInfo) table.getColumnModel() + .getColumn(0)).getEnumValue().substring(0, 4).equals("DECK") + ? true : false; + + if (sortcols[1] == null) { + if (isDeckTable) { + cascadeManager.add((TableColumnInfo) SColumnUtil.getColumn(ColumnName.DECK_NAME)); + } + else { + cascadeManager.add((TableColumnInfo) SColumnUtil.getColumn(ColumnName.CAT_NAME)); + } + } + else { + ArrayUtils.reverse(sortcols); + for (int i = 1; i < sortcols.length; i++) { + if (sortcols[i] != null) { + cascadeManager.add((TableColumnInfo) sortcols[i]); + } + } + } + } + + /** + * Clears all data in the model. + */ + public void clear() { + this.data.clear(); + } + + /** + * Gets all cards in the model. + * + * @return the cards + */ + public ItemPoolView getCards() { + return this.data.getView(); + } + + /** + * Removes a card from the model. + * + * @param card0   {@link forge.Card} object + */ + public void removeCard(final T card0) { + final boolean wasThere = this.data.count(card0) > 0; + if (wasThere) { + this.data.remove(card0); + this.fireTableDataChanged(); + } + } + + /** + * Adds a card to the model. + * + * @param card0   {@link forge.Card} object. + */ + public void addCard(final T card0) { + this.data.add(card0); + this.fireTableDataChanged(); + } + + /** + * Adds multiple copies of multiple cards to the model. + * + * @param cards0   {@link java.lang.Iterable}> + */ + public void addCards(final Iterable> cards0) { + this.data.addAll(cards0); + this.fireTableDataChanged(); + } + + /** + * Row to card. + * + * @param row + * the row + * @return the entry + */ + public Entry rowToCard(final int row) { + final List> model = this.data.getOrderedList(); + return (row >= 0) && (row < model.size()) ? model.get(row) : null; + } + + /** + * Show selected card. + * + * @param table + * the table + */ + public void showSelectedCard(final JTable table) { + final int row = table.getSelectedRow(); + if (row != -1) { + final T cp = this.rowToCard(row).getKey(); + + final Card card2 = cp instanceof CardPrinted ? ((CardPrinted) cp).toForgeCard() : null; + + CDeckEditorUI.SINGLETON_INSTANCE.setCard(card2); + } + } + + /** + *

+ * addListeners. + *

+ */ + public void addListeners() { + // updates card detail, listens to any key strokes + table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { + + @Override + public void valueChanged(final ListSelectionEvent arg0) { + TableModel.this.showSelectedCard(table); + } + }); + table.addFocusListener(new FocusListener() { + + @Override + public void focusLost(final FocusEvent e) { + } + + @Override + public void focusGained(final FocusEvent e) { + TableModel.this.showSelectedCard(table); + } + }); + + table.getTableHeader().addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(final MouseEvent e) { + headerClicked(e); + } + + @Override + public void mouseReleased(MouseEvent e) { + SEditorIO.savePreferences(); + } + }); + } // addCardListener() + + /** + * Resort. + */ + public void refreshSort() { + if (this.data.getOrderedList().size() == 0) { return; } + + Collections.sort(this.data.getOrderedList(), new MyComparator()); + } + + @SuppressWarnings("unchecked") + private void headerClicked(final MouseEvent e) { + final TableColumnModel colModel = TableModel.this.table.getColumnModel(); + final int columnModelIndex = colModel.getColumnIndexAtX(e.getX()); + final int modelIndex = colModel.getColumn(columnModelIndex).getModelIndex(); + + if (modelIndex < 0) { + return; + } + + // This will invert if needed + TableModel.this.cascadeManager.add((TableColumnInfo) this.table.getColumnModel().getColumn(modelIndex)); + TableModel.this.refreshSort(); + TableModel.this.table.tableChanged(new TableModelEvent(TableModel.this)); + TableModel.this.table.repaint(); + TableModel.this.table.setRowSelectionInterval(0, 0); + SEditorIO.savePreferences(); + } + + //========== Overridden from AbstractTableModel + /** {@inheritDoc} */ + @Override + public int findColumn(final String name0) { + return table.getColumnModel().getColumnIndex(name0); + } + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getColumnCount() + */ + @Override + public int getColumnCount() { + return table.getColumnCount(); + } + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getRowCount() + */ + @Override + public int getRowCount() { + return this.data.countDistinct(); + } + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getValueAt(int, int) + */ + @Override + @SuppressWarnings("unchecked") + public Object getValueAt(int iRow, int iCol) { + return ((TableColumnInfo) table.getColumnModel().getColumn(table.convertColumnIndexToView(iCol))).getFnDisplay().apply((Entry) this.rowToCard(iRow)); + } + + //========= Custom class handling + + /** + * Manages sorting orders for multiple depths of sorting. + */ + private final class CascadeManager { + private final List> colsToSort = new ArrayList>(3); + private TableSorterCascade sorter = null; + + // Adds a column to sort cascade list. + // If column is first in the cascade, inverts direction of sort. + // Otherwise, sorts in ascending direction. + @SuppressWarnings("unchecked") + public void add(final TableColumnInfo col0) { + // Found at top level, should invert + if (colsToSort.size() > 0 && colsToSort.get(0).equals(col0)) { + this.colsToSort.get(0).setSortState( + this.colsToSort.get(0).getSortState() == SortState.ASC + ? SortState.DESC : SortState.ASC); + this.colsToSort.get(0).setSortPriority(1); + } + // Found somewhere: move down others, this one to top. + else if (colsToSort.contains(col0)) { + col0.setSortState(SortState.ASC); + this.colsToSort.remove(col0); + this.colsToSort.add(0, (TableColumnInfo) col0); + } + // No column in list; add directly. + else { + col0.setSortState(SortState.ASC); + this.colsToSort.add(0, (TableColumnInfo) col0); + this.colsToSort.get(0).setSortPriority(1); + } + + // Decrement sort priority on remaining columns + for (int i = 1; i < maxSortDepth; i++) { + if (colsToSort.size() == i) { break; } + + if (colsToSort.get(i).getSortPriority() != 0) { + colsToSort.get(i).setSortPriority(i + 1); + } + } + + // Unset and remove boundary columns. + if (this.colsToSort.size() > maxSortDepth) { + this.colsToSort.get(maxSortDepth).setSortState(SortState.NONE); + this.colsToSort.get(maxSortDepth).setSortPriority(0); + this.colsToSort.remove(maxSortDepth); + } + } + + public TableSorterCascade getSorter() { + final List> oneColSorters + = new ArrayList>(maxSortDepth); + + for (final TableColumnInfo col : this.colsToSort) { + oneColSorters.add(new TableSorter( + col.getFnSort(), + col.getSortState().equals(SortState.ASC) ? true : false)); + } + + this.sorter = new TableSorterCascade(oneColSorters); + return this.sorter; + } + } + + private class MyComparator implements Comparator> { + /* (non-Javadoc) + * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) + */ + @SuppressWarnings("unchecked") + @Override + public int compare(Entry o1, Entry o2) { + return TableModel.this.cascadeManager.getSorter().compare( + (Entry) o1, (Entry) o2); + } + } +} // CardTableModel diff --git a/src/main/java/forge/gui/deckeditor/elements/TableSorter.java b/src/main/java/forge/gui/deckeditor/tables/TableSorter.java similarity index 98% rename from src/main/java/forge/gui/deckeditor/elements/TableSorter.java rename to src/main/java/forge/gui/deckeditor/tables/TableSorter.java index 9504a987fee..620ee1ddccf 100644 --- a/src/main/java/forge/gui/deckeditor/elements/TableSorter.java +++ b/src/main/java/forge/gui/deckeditor/tables/TableSorter.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.gui.deckeditor.elements; +package forge.gui.deckeditor.tables; import java.util.Comparator; import java.util.Map.Entry; diff --git a/src/main/java/forge/gui/deckeditor/elements/TableSorterCascade.java b/src/main/java/forge/gui/deckeditor/tables/TableSorterCascade.java similarity index 95% rename from src/main/java/forge/gui/deckeditor/elements/TableSorterCascade.java rename to src/main/java/forge/gui/deckeditor/tables/TableSorterCascade.java index 9165df95145..83614cd00eb 100644 --- a/src/main/java/forge/gui/deckeditor/elements/TableSorterCascade.java +++ b/src/main/java/forge/gui/deckeditor/tables/TableSorterCascade.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.gui.deckeditor.elements; +package forge.gui.deckeditor.tables; import java.util.Comparator; import java.util.List; diff --git a/src/main/java/forge/gui/deckeditor/elements/TableView.java b/src/main/java/forge/gui/deckeditor/tables/TableView.java similarity index 52% rename from src/main/java/forge/gui/deckeditor/elements/TableView.java rename to src/main/java/forge/gui/deckeditor/tables/TableView.java index bb588a1d2d5..32fbd4043cc 100644 --- a/src/main/java/forge/gui/deckeditor/elements/TableView.java +++ b/src/main/java/forge/gui/deckeditor/tables/TableView.java @@ -15,24 +15,23 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package forge.gui.deckeditor.elements; +package forge.gui.deckeditor.tables; import java.awt.Color; +import java.util.ArrayList; import java.util.List; -import javax.swing.BorderFactory; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JScrollPane; import javax.swing.JTable; -import javax.swing.border.TitledBorder; import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; -import javax.swing.table.TableCellRenderer; +import javax.swing.table.DefaultTableColumnModel; +import javax.swing.table.TableColumn; - -import forge.Constant; import forge.card.CardRules; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.views.ITableContainer; +import forge.gui.toolbox.FSkin; +import forge.item.CardPrinted; import forge.item.InventoryItem; import forge.item.ItemPool; import forge.item.ItemPoolView; @@ -45,44 +44,14 @@ import forge.util.closures.Predicate; * the generic type */ public final class TableView { - - /** The pool. */ private ItemPool pool; - - /** The model. */ private TableModel model; - - /** The table. */ private final JTable table = new JTable(); - - /** The j scroll pane. */ - private final JScrollPane jScrollPane = new JScrollPane(); - - /** The stats label. */ - private final JLabel statsLabel = new JLabel(); - - /** The filter. */ private Predicate filter = null; - - /** The is tracking stats. */ - private boolean isTrackingStats = false; - - /** The want unique. */ private boolean wantUnique = false; private final Class genericType; - // need this to allow users place its contents - /** - * - * getTableDecorated. - * - * @return JComponent - */ - public JComponent getTableDecorated() { - return this.jScrollPane; - } - /** * * getTable. @@ -93,149 +62,104 @@ public final class TableView { return this.table; } - /** - * - * getLabel. - * - * @return JComponent - */ - public JComponent getLabel() { - return this.statsLabel; - } - /** * TableWithCards. * - * @param title - * a String - * @param showStats - * a boolean * @param cls * the cls */ - public TableView(final String title, final boolean showStats, final Class cls) { - this(title, showStats, false, cls); + public TableView(final Class cls) { + this(false, cls); } /** * TableWithCards Constructor. * - * @param title - * a String - * @param showStats - * a boolean * @param forceUnique * a boolean - * @param cls - * the cls + * @param type0 the cls */ - public TableView(final String title, final boolean showStats, final boolean forceUnique, final Class cls) { - // components - this.genericType = cls; - - final Color gray = new Color(148, 145, 140); - final TitledBorder titledBorder = new TitledBorder(BorderFactory.createEtchedBorder(Color.white, gray), title); - - final String tableToolTip = "Click on the column name (like name or color) to sort the cards"; - this.jScrollPane.setBorder(titledBorder); - this.jScrollPane.setToolTipText(tableToolTip); - this.jScrollPane.getViewport().add(this.table, null); - - this.statsLabel.setFont(new java.awt.Font("Dialog", 0, 13)); - this.statsLabel.setText("Total: 0, Creatures: 0, Land: 0"); - - // class data - this.isTrackingStats = showStats; + public TableView(final boolean forceUnique, final Class type0) { + this.genericType = type0; this.wantUnique = forceUnique; + + table.setFont(FSkin.getFont(12)); + table.setBorder(null); + table.getTableHeader().setBorder(null); + table.setRowHeight(18); } /** + * Applies a TableModel and a model listener to this instance's JTable. * - * setup. - * - * @param columns - * a List> - * @param cardView - * a CardPanelBase + * @param view0   the {@link javax.gui.deckeditor.views.ITableCOntainer} + * @param cols0   List> of additional columns for this */ - public void setup(final List> columns, final CardPanelBase cardView) { - this.model = new TableModel(cardView, columns, this.genericType); - this.model.addListeners(this.table); - this.table.setModel(this.model); - this.model.resizeCols(this.table); + @SuppressWarnings("unchecked") + public void setup(final ITableContainer view0, final List> cols0) { + final DefaultTableColumnModel colmodel = new DefaultTableColumnModel(); - for (int idx = columns.size() - 1; idx >= 0; idx--) { - final TableCellRenderer renderer = columns.get(idx).getCellRenderer(); - if (null != renderer) { - this.table.getColumnModel().getColumn(idx).setCellRenderer(renderer); + // Add columns whose indices are inside the view indices, as long as there's not one there already. + final TableColumn[] knownCols = new TableColumn[cols0.size()]; + final List unknownCols = new ArrayList(); + + for (final TableColumn c : cols0) { + if (!((TableColumnInfo) c).isShowing()) { continue; } + if (c.getModelIndex() < knownCols.length && knownCols[c.getModelIndex()] == null) { + knownCols[c.getModelIndex()] = c; + } + else { + unknownCols.add(c); } } - if (this.isTrackingStats) { - // get stats from deck - this.model.addTableModelListener(new TableModelListener() { - @Override - public void tableChanged(final TableModelEvent ev) { - final ItemPoolView deck = TableView.this.model.getCards(); - TableView.this.statsLabel.setText(TableView.getStats(deck)); + // Columns outside the bounds of the view indices must be + // resolved by inserting into empty slots. + for (final TableColumn c : unknownCols) { + for (int i = 0; i < knownCols.length; i++) { + if (knownCols[i] == null) { + knownCols[i] = c; + break; } - }); - } - } - - // This should not be here, but still found no better place - /** - * getStats. - * - * @param - * the generic type - * @param deck - * an ItemPoolView - * @return String - */ - public static String getStats(final ItemPoolView deck) { - final int total = deck.countAll(); - final int creature = CardRules.Predicates.Presets.IS_CREATURE.aggregate(deck, deck.getFnToCard(), - deck.getFnToCount()); - final int land = CardRules.Predicates.Presets.IS_LAND.aggregate(deck, deck.getFnToCard(), deck.getFnToCount()); - - final StringBuffer show = new StringBuffer(); - show.append("Total - ").append(total).append(", Creatures - ").append(creature).append(", Land - ") - .append(land); - final String[] color = Constant.Color.ONLY_COLORS; - final List> predicates = CardRules.Predicates.Presets.COLORS; - for (int i = 0; i < color.length; ++i) { - show.append(String.format(", %s - %d", color[i], predicates.get(i).count(deck, deck.getFnToCard()))); + } } - return show.toString(); - } // getStats() + // Put columns into model in preferred order (much easier than moving dynamically). + for (final TableColumn c : knownCols) { + if (c == null) { continue; } + c.setMinWidth(15); + c.setPreferredWidth(c.getPreferredWidth()); + c.setMaxWidth(350); + colmodel.addColumn(c); + } - /** - * - * sort. - * - * @param iCol - * an int - * @return TableWithCards - */ - public TableView sort(final int iCol) { - return this.sort(iCol, true); - } + this.model = new TableModel(this.table, this.genericType); + this.model.addListeners(); + this.table.setModel(this.model); + this.table.setColumnModel(colmodel); - /** - * - * sort. - * - * @param iCol - * an int - * @param isAsc - * a boolean - * @return TableWithCards - */ - public TableView sort(final int iCol, final boolean isAsc) { - this.model.sort(iCol, isAsc); - return this; + this.model.setup(); + this.model.refreshSort(); + + this.table.getTableHeader().setBackground(new Color(200, 200, 200)); + + // Update stats each time table changes + this.model.addTableModelListener(new TableModelListener() { + @Override + public void tableChanged(final TableModelEvent ev) { + final List deck = TableView.this.model.getCards().toFlatList(); + final ItemPool filteredDeck = new ItemPool((Class) CardPrinted.class); + + // Filter out non-card items (booster packs, etc.) + for (T item : deck) { + if (item instanceof CardPrinted) { + filteredDeck.add(item); + } + } + + SEditorUtil.setStats(filteredDeck, view0); + } + }); } /** @@ -388,7 +312,7 @@ public final class TableView { this.model.addCards(this.pool); } - this.model.resort(); + this.model.refreshSort(); } /** diff --git a/src/main/java/forge/gui/deckeditor/tables/package-info.java b/src/main/java/forge/gui/deckeditor/tables/package-info.java new file mode 100644 index 00000000000..5eccba35a34 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/tables/package-info.java @@ -0,0 +1,3 @@ +/** Forge Card Game. */ +package forge.gui.deckeditor.tables; + diff --git a/src/main/java/forge/gui/deckeditor/views/ITableContainer.java b/src/main/java/forge/gui/deckeditor/views/ITableContainer.java new file mode 100644 index 00000000000..f96d1ba5923 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/ITableContainer.java @@ -0,0 +1,65 @@ +package forge.gui.deckeditor.views; + +import javax.swing.JLabel; +import javax.swing.JTable; + +/** + * Dictates methods needed for a class to act as a container for + * a TableView deck editing component. + * + *

(I at beginning of class name denotes an interface.) + * + */ +public interface ITableContainer { + /** + * Sets the table used for displaying cards in this + * deck editor container. + * + * @param tbl0   {@link forge.gui.deckeditor.tables.TableView} + */ + void setTableView(JTable tbl0); + + // Various card count total labels + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblTotal(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblBlack(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblBlue(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblGreen(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblRed(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblWhite(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblColorless(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblArtifact(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblEnchantment(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblCreature(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblSorcery(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblInstant(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblPlaneswalker(); + + /** @return {@link javax.swing.JLabel} */ + JLabel getLblLand(); +} diff --git a/src/main/java/forge/gui/deckeditor/views/VAllDecks.java b/src/main/java/forge/gui/deckeditor/views/VAllDecks.java new file mode 100644 index 00000000000..850eda35a9d --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/VAllDecks.java @@ -0,0 +1,110 @@ +package forge.gui.deckeditor.views; + +import javax.swing.JLabel; +import javax.swing.JScrollPane; + +import net.miginfocom.swing.MigLayout; +import forge.game.GameType; +import forge.gui.deckeditor.controllers.CAllDecks; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.toolbox.DeckLister; +import forge.gui.toolbox.FLabel; + +/** + * Assembles Swing components of all deck viewer in deck editor. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VAllDecks implements IVDoc { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("All Decks"); + + private final DeckLister lstDecks = new DeckLister(GameType.Constructed); + private JScrollPane scroller = new JScrollPane(lstDecks); + + private final JLabel btnImport = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .text("Import Deck").tooltip("Attempt to import a deck from a non-Forge format") + .opaque(true).hoverable(true).build(); + + //========== Constructor + private VAllDecks() { + scroller.setOpaque(false); + scroller.getViewport().setOpaque(false); + scroller.setBorder(null); + scroller.getViewport().setBorder(null); + } + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.EDITOR_ALLDECKS; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CAllDecks.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, wrap, ax center")); + + parentCell.getBody().add(btnImport, "w 120px!, h 30px!, gap 0 0 5px 5px"); + + //parentCell.getBody().add(scroller, "w 96%!, h 96%!, gap 2% 0 2% 0"); + } + + //========== Retrieval methods + /** @return {@link javax.swing.JPanel} */ + public DeckLister getLstDecks() { + return lstDecks; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnImport() { + return btnImport; + } +} diff --git a/src/main/java/forge/gui/deckeditor/views/VCardCatalog.java b/src/main/java/forge/gui/deckeditor/views/VCardCatalog.java new file mode 100644 index 00000000000..d02ea373e65 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/VCardCatalog.java @@ -0,0 +1,315 @@ +package forge.gui.deckeditor.views; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; + +import net.miginfocom.swing.MigLayout; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.controllers.CCardCatalog; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FSkin; + +/** + * Assembles Swing components of card catalog in deck editor. + * + *

(V at beginning of class name denotes a view class.) + * + */ +public enum VCardCatalog implements IVDoc, ITableContainer { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Card Catalog"); + + // Total and color count labels + private final JPanel pnlStats = new JPanel(); + private final JLabel lblTotal = buildLabel(SEditorUtil.ICO_TOTAL); + private final JLabel lblBlack = buildLabel(SEditorUtil.ICO_BLACK); + private final JLabel lblBlue = buildLabel(SEditorUtil.ICO_BLUE); + private final JLabel lblGreen = buildLabel(SEditorUtil.ICO_GREEN); + private final JLabel lblRed = buildLabel(SEditorUtil.ICO_RED); + private final JLabel lblWhite = buildLabel(SEditorUtil.ICO_WHITE); + private final JLabel lblColorless = buildLabel(SEditorUtil.ICO_COLORLESS); + + // Card type labels + private final JLabel lblArtifact = buildLabel(SEditorUtil.ICO_ARTIFACT); + private final JLabel lblCreature = buildLabel(SEditorUtil.ICO_CREATURE); + private final JLabel lblEnchantment = buildLabel(SEditorUtil.ICO_ENCHANTMENT); + private final JLabel lblInstant = buildLabel(SEditorUtil.ICO_INSTANT); + private final JLabel lblLand = buildLabel(SEditorUtil.ICO_LAND); + private final JLabel lblPlaneswalker = buildLabel(SEditorUtil.ICO_PLANESWALKER); + private final JLabel lblSorcery = buildLabel(SEditorUtil.ICO_SORCERY); + + private final JLabel lblTitle = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14).build(); + + private final JPanel pnlHeader = new JPanel(new MigLayout("insets 0, gap 0")); + + private final JPanel pnlAddButtons = + new JPanel(new MigLayout("insets 0, gap 0, ax center, hidemode 3")); + + private final JLabel btnAdd = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .text("Add card") + .tooltip("Add selected card to current deck (or double click the row)") + .icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_PLUS)) + .iconScaleAuto(false).hoverable(true).build(); + + private final JLabel btnAdd4 = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .text("Add 4 of card") + .tooltip("Add up to 4 of selected card to current deck") + .icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_PLUS)) + .iconScaleAuto(false).hoverable(true).build(); + + private JTable tblCards = null; + private final JScrollPane scroller = new JScrollPane(); + + //========== Constructor + /** */ + private VCardCatalog() { + scroller.setOpaque(false); + scroller.getViewport().setOpaque(false); + scroller.setBorder(null); + scroller.getViewport().setBorder(null); + + lblTotal.setToolTipText("Total Card Count"); + lblBlack.setToolTipText("Black Card Count"); + lblBlue.setToolTipText("Blue Card Count"); + lblGreen.setToolTipText("Green Card Count"); + lblRed.setToolTipText("Red Card Count"); + lblWhite.setToolTipText("White Card Count"); + lblColorless.setToolTipText("Total Card Count"); + lblArtifact.setToolTipText("Artiface Card Count"); + lblCreature.setToolTipText("Creature Card Count"); + lblColorless.setToolTipText("Colorless Card Count"); + lblEnchantment.setToolTipText("Enchantment Card Count"); + lblInstant.setToolTipText("Instant Card Count"); + lblLand.setToolTipText("Land Card Count"); + lblPlaneswalker.setToolTipText("Planeswalker Card Count"); + lblSorcery.setToolTipText("Sorcery Card Count"); + + pnlStats.setOpaque(false); + pnlStats.setLayout(new MigLayout("insets 0, gap 5px, ax center, wrap 7")); + + final String constraints = "w 55px!, h 20px!"; + pnlStats.add(lblTotal, constraints); + pnlStats.add(lblBlack, constraints); + pnlStats.add(lblBlue, constraints); + pnlStats.add(lblGreen, constraints); + pnlStats.add(lblRed, constraints); + pnlStats.add(lblWhite, constraints); + pnlStats.add(lblColorless, constraints); + + pnlStats.add(lblArtifact, constraints); + pnlStats.add(lblCreature, constraints); + pnlStats.add(lblEnchantment, constraints); + pnlStats.add(lblInstant, constraints); + pnlStats.add(lblLand, constraints); + pnlStats.add(lblPlaneswalker, constraints); + pnlStats.add(lblSorcery, constraints); + + pnlAddButtons.setOpaque(false); + pnlAddButtons.add(btnAdd, "w 42%!, h 30px!, gap 0 0 5px 5px"); + pnlAddButtons.add(btnAdd4, "w 42%!, h 30px!, gap 5% 5% 5px 5px"); + + pnlHeader.setOpaque(false); + pnlHeader.add(lblTitle, "w 100%!, h 100%!"); + } + + //========== Overridden from IVDoc + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.EDITOR_CATALOG; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CCardCatalog.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, wrap, hidemode 3")); + parentCell.getBody().add(pnlHeader, "w 98%!, h 30px!, gap 1% 0 1% 10px"); + parentCell.getBody().add(pnlStats, "w 96%, h 50px!, gap 2% 0 1% 1%"); + parentCell.getBody().add(pnlAddButtons, "w 96%!, gap 2% 0 0 0"); + parentCell.getBody().add(scroller, "w 98%!, h 100% - 35px, gap 1% 0 1% 1%"); + } + + //========== Overridden from ITableContainer + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#setTableView() + */ + @Override + public void setTableView(final JTable tbl0) { + this.tblCards = tbl0; + scroller.setViewportView(tblCards); + } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblTotal() + */ + @Override + public JLabel getLblTotal() { return lblTotal; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblBlack() + */ + @Override + public JLabel getLblBlack() { return lblBlack; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblBlue() + */ + @Override + public JLabel getLblBlue() { return lblBlue; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblGreen() + */ + @Override + public JLabel getLblGreen() { return lblGreen; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblRed() + */ + @Override + public JLabel getLblRed() { return lblRed; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblWhite() + */ + @Override + public JLabel getLblWhite() { return lblWhite; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblColorless() + */ + @Override + public JLabel getLblColorless() { return lblColorless; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblArtifact() + */ + @Override + public JLabel getLblArtifact() { return lblArtifact; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblEnchantment() + */ + @Override + public JLabel getLblEnchantment() { return lblEnchantment; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblCreature() + */ + @Override + public JLabel getLblCreature() { return lblCreature; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblSorcery() + */ + @Override + public JLabel getLblSorcery() { return lblSorcery; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblInstant() + */ + @Override + public JLabel getLblInstant() { return lblInstant; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblPlaneswalker() + */ + @Override + public JLabel getLblPlaneswalker() { return lblPlaneswalker; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblLand() + */ + @Override + public JLabel getLblLand() { return lblLand; } + + //========== Accessor/mutator methods + + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblTitle() { + return lblTitle; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnAdd() { + return btnAdd; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnAdd4() { + return btnAdd4; + } + + /** @return {@link javax.swing.JPanel} */ + public JPanel getPnlHeader() { + return pnlHeader; + } + + /** @return {@link javax.swing.JPanel} */ + public JPanel getPnlStats() { + return pnlStats; + } + + //========== Other methods + + private JLabel buildLabel(final ImageIcon icon0) { + final JLabel lbl = new FLabel.Builder().text("0") + .icon(icon0).iconScaleAuto(false) + .fontSize(11).fontScaleAuto(false) + .build(); + + return lbl; + } +} diff --git a/src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java b/src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java new file mode 100644 index 00000000000..039efe3d44e --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java @@ -0,0 +1,406 @@ +package forge.gui.deckeditor.views; + +import java.awt.Insets; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +import net.miginfocom.swing.MigLayout; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.controllers.CCurrentDeck; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FTextField; + + +/** + * Assembles Swing components of current deck being edited in deck editor. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VCurrentDeck implements IVDoc, ITableContainer { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Current Deck"); + + // Other fields + + private final JLabel btnSave = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .tooltip("Save (in default directory)") + .iconInBackground(true) + .iconAlignX(SwingConstants.CENTER).iconAlpha(1.0f) + .icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_SAVE)) + .text(" ").hoverable(true).build(); + + private final JLabel btnExport = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .tooltip("Export...") + .iconInBackground(true) + .iconAlignX(SwingConstants.CENTER).iconAlpha(1.0f) + .icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_SAVEAS)) + .text(" ").hoverable(true).build(); + + private final JLabel btnImport = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .tooltip("Import...") + .iconInBackground(true) + .iconAlignX(SwingConstants.CENTER).iconAlpha(1.0f) + .icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_OPEN)) + .text(" ").hoverable(true).build(); + + private final JLabel btnNew = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .tooltip("New Deck") + .iconInBackground(true) + .iconAlignX(SwingConstants.CENTER).iconAlpha(1.0f) + .icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_NEW)) + .text(" ").hoverable(true).build(); + + private final JPanel pnlRemoveButtons = + new JPanel(new MigLayout("insets 0, gap 0, ax center, hidemode 3")); + + private final JLabel btnRemove = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .text("Remove card") + .tooltip("Remove selected card to current deck (or double click the row)") + .icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_MINUS)) + .iconScaleAuto(false).hoverable(true).build(); + + private final JLabel btnRemove4 = new FLabel.Builder() + .fontScaleAuto(false).fontSize(14) + .text("Remove 4 of card") + .tooltip("Remove up to 4 of selected card to current deck") + .icon(FSkin.getIcon(FSkin.ForgeIcons.ICO_MINUS)) + .iconScaleAuto(false).hoverable(true).build(); + + private final JTextField txfTitle = new FTextField(); + + private final JPanel pnlRemove = new JPanel(); + private final JPanel pnlHeader = new JPanel(); + + private final JLabel lblTitle = new FLabel.Builder().text("Title") + .fontScaleAuto(false).fontSize(14).build(); + + private final JPanel pnlStats = new JPanel(); + private final JLabel lblTotal = buildLabel(SEditorUtil.ICO_TOTAL); + private final JLabel lblBlack = buildLabel(SEditorUtil.ICO_BLACK); + private final JLabel lblBlue = buildLabel(SEditorUtil.ICO_BLUE); + private final JLabel lblGreen = buildLabel(SEditorUtil.ICO_GREEN); + private final JLabel lblRed = buildLabel(SEditorUtil.ICO_RED); + private final JLabel lblWhite = buildLabel(SEditorUtil.ICO_WHITE); + private final JLabel lblColorless = buildLabel(SEditorUtil.ICO_COLORLESS); + + private final JLabel lblArtifact = buildLabel(SEditorUtil.ICO_ARTIFACT); + private final JLabel lblCreature = buildLabel(SEditorUtil.ICO_CREATURE); + private final JLabel lblEnchantment = buildLabel(SEditorUtil.ICO_ENCHANTMENT); + private final JLabel lblInstant = buildLabel(SEditorUtil.ICO_INSTANT); + private final JLabel lblLand = buildLabel(SEditorUtil.ICO_LAND); + private final JLabel lblPlaneswalker = buildLabel(SEditorUtil.ICO_PLANESWALKER); + private final JLabel lblSorcery = buildLabel(SEditorUtil.ICO_SORCERY); + + private JTable tblCards = null; + private final JScrollPane scroller = new JScrollPane(tblCards); + + //========== Constructor + + private VCurrentDeck() { + // Title text area + txfTitle.setText("[New Deck]"); + txfTitle.setMargin(new Insets(5, 5, 5, 5)); + txfTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + txfTitle.setOpaque(true); + txfTitle.setEditable(true); + txfTitle.setFocusable(true); + txfTitle.setOpaque(true); + txfTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + + // Header area + pnlHeader.setOpaque(false); + pnlHeader.setLayout(new MigLayout("insets 0, gap 0, ax center, hidemode 3")); + + pnlHeader.add(lblTitle, "w 80px!, h 30px!, gap 5px 5px 0 0"); + pnlHeader.add(txfTitle, "pushx, growx, gap 0 5px 0 0"); + pnlHeader.add(btnSave, "w 26px!, h 26px!, gap 0 5px 0 0"); + pnlHeader.add(btnNew, "w 26px!, h 26px!, gap 0 5px 0 0"); + + pnlHeader.add(btnImport, "w 26px!, h 26px!, gap 0 5px 0 0"); + pnlHeader.add(btnExport, "w 26px!, h 26px!, gap 0 20px 0 0"); + + pnlRemove.setOpaque(false); + pnlRemove.setLayout(new MigLayout("insets 0, gap 0, ax center")); + pnlRemove.add(btnRemove, "w 40%!, h 100%!, gap 5% 5% 0 0"); + pnlRemove.add(btnRemove4, "w 40%!, h 100%!"); + + scroller.setOpaque(false); + scroller.getViewport().setOpaque(false); + scroller.setBorder(null); + scroller.getViewport().setBorder(null); + + lblTotal.setToolTipText("Total Card Count"); + lblBlack.setToolTipText("Black Card Count"); + lblBlue.setToolTipText("Blue Card Count"); + lblGreen.setToolTipText("Green Card Count"); + lblRed.setToolTipText("Red Card Count"); + lblWhite.setToolTipText("White Card Count"); + lblColorless.setToolTipText("Total Card Count"); + lblArtifact.setToolTipText("Artiface Card Count"); + lblCreature.setToolTipText("Creature Card Count"); + lblColorless.setToolTipText("Colorless Card Count"); + lblEnchantment.setToolTipText("Enchantment Card Count"); + lblInstant.setToolTipText("Instant Card Count"); + lblLand.setToolTipText("Land Card Count"); + lblPlaneswalker.setToolTipText("Planeswalker Card Count"); + lblSorcery.setToolTipText("Sorcery Card Count"); + + pnlStats.setOpaque(false); + pnlStats.setLayout(new MigLayout("insets 0, gap 5px, ax center, wrap 7")); + + final String constraints = "w 55px!, h 20px!"; + pnlStats.add(lblTotal, constraints); + pnlStats.add(lblBlack, constraints); + pnlStats.add(lblBlue, constraints); + pnlStats.add(lblGreen, constraints); + pnlStats.add(lblRed, constraints); + pnlStats.add(lblWhite, constraints); + pnlStats.add(lblColorless, constraints); + + pnlStats.add(lblArtifact, constraints); + pnlStats.add(lblCreature, constraints); + pnlStats.add(lblEnchantment, constraints); + pnlStats.add(lblInstant, constraints); + pnlStats.add(lblLand, constraints); + pnlStats.add(lblPlaneswalker, constraints); + pnlStats.add(lblSorcery, constraints); + + pnlRemoveButtons.setOpaque(false); + pnlRemoveButtons.add(btnRemove, "w 42%!, h 30px!, gap 0 0 5px 5px"); + pnlRemoveButtons.add(btnRemove4, "w 42%!, h 30px!, gap 5% 5% 5px 5px"); + } + + //========== Overridden from IVDoc + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.EDITOR_CURRENTDECK; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CCurrentDeck.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + final JPanel pnl = parentCell.getBody(); + pnl.setLayout(new MigLayout("insets 0, gap 0, wrap, hidemode 3")); + + parentCell.getBody().add(pnlHeader, "w 98%!, h 30px!, gap 1% 0 1% 10px"); + parentCell.getBody().add(pnlStats, "w 96%, h 50px!, gap 2% 0 1% 1%"); + parentCell.getBody().add(pnlRemoveButtons, "w 96%!, gap 2% 0 0 0"); + parentCell.getBody().add(scroller, "w 98%!, h 100% - 35px, gap 1% 0 1% 1%"); + } + + //========== Retrieval methods + + //========== Custom class handling + + //========== Overridden from ITableContainer + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#setTableView() + */ + @Override + public void setTableView(final JTable tbl0) { + this.tblCards = tbl0; + scroller.setViewportView(tblCards); + } + + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblTotal() + */ + @Override + public JLabel getLblTotal() { return lblTotal; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblBlack() + */ + @Override + public JLabel getLblBlack() { return lblBlack; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblBlue() + */ + @Override + public JLabel getLblBlue() { return lblBlue; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblGreen() + */ + @Override + public JLabel getLblGreen() { return lblGreen; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblRed() + */ + @Override + public JLabel getLblRed() { return lblRed; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblWhite() + */ + @Override + public JLabel getLblWhite() { return lblWhite; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblColorless() + */ + @Override + public JLabel getLblColorless() { return lblColorless; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblArtifact() + */ + @Override + public JLabel getLblArtifact() { return lblArtifact; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblEnchantment() + */ + @Override + public JLabel getLblEnchantment() { return lblEnchantment; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblCreature() + */ + @Override + public JLabel getLblCreature() { return lblCreature; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblSorcery() + */ + @Override + public JLabel getLblSorcery() { return lblSorcery; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblInstant() + */ + @Override + public JLabel getLblInstant() { return lblInstant; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblPlaneswalker() + */ + @Override + public JLabel getLblPlaneswalker() { return lblPlaneswalker; } + + /* (non-Javadoc) + * @see forge.gui.deckeditor.views.ITableContainer#getLblLand() + */ + @Override + public JLabel getLblLand() { return lblLand; } + + //========== Retrieval + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnRemove() { + return btnRemove; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnRemove4() { + return btnRemove4; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnSave() { + return btnSave; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnSaveAs() { + return btnExport; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnOpen() { + return btnImport; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnNew() { + return btnNew; + } + + /** @return {@link javax.swing.JTextField} */ + public JTextField getTxfTitle() { + return txfTitle; + } + + /** @return {@link javax.swing.JPanel} */ + public JPanel getPnlHeader() { + return pnlHeader; + } + + /** @return {@link javax.swing.JPanel} */ + public JPanel getPnlStats() { + return pnlStats; + } + + //========== Other methods + + private JLabel buildLabel(final ImageIcon icon0) { + final JLabel lbl = new FLabel.Builder().text("0") + .icon(icon0).iconScaleAuto(false) + .fontSize(11).fontScaleAuto(false) + .build(); + + return lbl; + } +} diff --git a/src/main/java/forge/gui/deckeditor/views/VDeckgen.java b/src/main/java/forge/gui/deckeditor/views/VDeckgen.java new file mode 100644 index 00000000000..1be730d1dc1 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/VDeckgen.java @@ -0,0 +1,128 @@ +package forge.gui.deckeditor.views; + +import javax.swing.JLabel; + +import net.miginfocom.swing.MigLayout; +import forge.gui.deckeditor.controllers.CDeckgen; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.toolbox.FLabel; + +/** + * Assembles Swing components of deck editor analysis tab. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VDeckgen implements IVDoc { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Deck Generation"); + + // Deckgen buttons + private final JLabel btnRandCardpool = new FLabel.Builder() + .tooltip("Generate random constructed cardpool in current deck area") + .text("Random Cardpool").fontScaleAuto(false).fontSize(14) + .opaque(true).hoverable(true).build(); + + private final JLabel btnRandDeck2 = new FLabel.Builder() + .tooltip("Generate 2 color constructed deck in current deck area") + .text("Constructed (2 color)").fontScaleAuto(false).fontSize(14) + .opaque(true).hoverable(true).build(); + + private final JLabel btnRandDeck3 = new FLabel.Builder() + .tooltip("Generate 3 color constructed deck in current deck area") + .text("Constructed (3 color)").fontScaleAuto(false).fontSize(14) + .opaque(true).hoverable(true).build(); + + private final JLabel btnRandDeck5 = new FLabel.Builder() + .tooltip("Generate 5 color constructed deck in current deck area") + .text("Constructed (5 color)").fontScaleAuto(false).fontSize(14) + .opaque(true).hoverable(true).build(); + + //========== Constructor + private VDeckgen() { + } + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.EDITOR_DECKGEN; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CDeckgen.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, wrap, ax center")); + + final String constraints = "w 80%!, h 30px!, gap 0 0 10px 0"; + parentCell.getBody().add(btnRandCardpool, constraints); + parentCell.getBody().add(btnRandDeck2, constraints); + parentCell.getBody().add(btnRandDeck3, constraints); + parentCell.getBody().add(btnRandDeck5, constraints); + } + + //========== Retrieval methods + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnRandCardpool() { + return btnRandCardpool; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnRandDeck2() { + return btnRandDeck2; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnRandDeck3() { + return btnRandDeck3; + } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getBtnRandDeck5() { + return btnRandDeck5; + } +} diff --git a/src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java b/src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java new file mode 100644 index 00000000000..4d60ee515b5 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java @@ -0,0 +1,225 @@ +package forge.gui.deckeditor.views; + +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.border.MatteBorder; + +import net.miginfocom.swing.MigLayout; +import forge.gui.deckeditor.controllers.CEditorPreferences; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.toolbox.FCheckBox; +import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FSkin; + +/** + * Assembles Swing components of deck editor analysis tab. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VEditorPreferences implements IVDoc { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Preferences"); + + private JLabel lblStats = new FLabel.Builder() + .text("Stat Bars").tooltip("Toggle statistics bars") + .fontScaleAuto(false).fontSize(12).build(); + + private JLabel lblCatalog = new FLabel.Builder() + .text("Card Catalog Columns").tooltip("Toggle columns in card catalog panel") + .fontScaleAuto(false).fontSize(12).build(); + + private JLabel lblDeck = new FLabel.Builder() + .text("Current Deck Columns").tooltip("Toggle columns in current deck panel") + .fontScaleAuto(false).fontSize(12).build(); + + private JCheckBox chbCatalogColor = new FCheckBox("Color"); + private JCheckBox chbCatalogRarity = new FCheckBox("Rarity"); + private JCheckBox chbCatalogCMC = new FCheckBox("CMC"); + private JCheckBox chbCatalogSet = new FCheckBox("Set"); + private JCheckBox chbCatalogAI = new FCheckBox("AI"); + + private JCheckBox chbDeckColor = new FCheckBox("Color"); + private JCheckBox chbDeckRarity = new FCheckBox("Rarity"); + private JCheckBox chbDeckCMC = new FCheckBox("CMC"); + private JCheckBox chbDeckSet = new FCheckBox("Set"); + private JCheckBox chbDeckAI = new FCheckBox("AI"); + + private JCheckBox chbDeckStats = new FCheckBox("Show stats in current deck"); + private JCheckBox chbCatalogStats = new FCheckBox("Show stats in card catalog"); + + private JPanel pnl = new JPanel(new MigLayout("insets 0, gap 0, wrap 2, ax center")); + private JScrollPane scroller = new JScrollPane(pnl); + + //========== Constructor + private VEditorPreferences() { + lblStats.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + lblCatalog.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + lblDeck.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + + chbCatalogColor.setFont(FSkin.getFont(12)); + chbCatalogRarity.setFont(FSkin.getFont(12)); + chbCatalogCMC.setFont(FSkin.getFont(12)); + chbCatalogSet.setFont(FSkin.getFont(12)); + chbCatalogAI.setFont(FSkin.getFont(12)); + + chbDeckColor.setFont(FSkin.getFont(12)); + chbDeckRarity.setFont(FSkin.getFont(12)); + chbDeckCMC.setFont(FSkin.getFont(12)); + chbDeckSet.setFont(FSkin.getFont(12)); + chbDeckAI.setFont(FSkin.getFont(12)); + + chbDeckStats.setFont(FSkin.getFont(12)); + chbCatalogStats.setFont(FSkin.getFont(12)); + chbDeckStats.setSelected(true); + chbCatalogStats.setSelected(true); + + pnl.add(lblStats, "h 25px!, gap 5px 5px 5px 5px, ax center, span 2 1"); + pnl.add(chbCatalogStats, "h 25px!, gap 5px 5px 5px 5px, ax center, span 2 1"); + pnl.add(chbDeckStats, "h 25px!, gap 5px 5px 5px 5px, ax center, span 2 1"); + + final String constraints = "w 75px, h 25px!, gap 5px 5px 5px 5px, ax center"; + pnl.add(lblCatalog, constraints + ", span 2 1"); + pnl.add(chbCatalogColor, constraints); + pnl.add(chbCatalogRarity, constraints); + pnl.add(chbCatalogCMC, constraints); + pnl.add(chbCatalogSet, constraints); + pnl.add(chbCatalogAI, constraints + ", wrap"); + + pnl.add(lblDeck, constraints + ", span 2 1"); + pnl.add(chbDeckColor, constraints); + pnl.add(chbDeckRarity, constraints); + pnl.add(chbDeckCMC, constraints); + pnl.add(chbDeckSet, constraints); + pnl.add(chbDeckAI, constraints); + + pnl.setOpaque(false); + scroller.setOpaque(false); + scroller.getViewport().setOpaque(false); + scroller.setBorder(null); + scroller.getViewport().setBorder(null); + } + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.EDITOR_PREFERENCES; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CEditorPreferences.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, wrap")); + parentCell.getBody().add(scroller, "w 96%!, h 96%, gap 2% 0 2% 0"); + } + + //========== Retrieval methods + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbCatalogColor() { + return chbCatalogColor; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbCatalogRarity() { + return chbCatalogRarity; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbCatalogCMC() { + return chbCatalogCMC; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbCatalogSet() { + return chbCatalogSet; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbCatalogAI() { + return chbCatalogAI; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbDeckColor() { + return chbDeckColor; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbDeckRarity() { + return chbDeckRarity; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbDeckCMC() { + return chbDeckCMC; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbDeckSet() { + return chbDeckSet; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbDeckAI() { + return chbDeckAI; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbDeckStats() { + return chbDeckStats; + } + + /** @return {@link javax.swing.JCheckBox} */ + public JCheckBox getChbCatalogStats() { + return chbCatalogStats; + } + //========== Other methods + +} diff --git a/src/main/java/forge/gui/deckeditor/views/VFilters.java b/src/main/java/forge/gui/deckeditor/views/VFilters.java new file mode 100644 index 00000000000..51217423478 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/VFilters.java @@ -0,0 +1,306 @@ +package forge.gui.deckeditor.views; + +import java.awt.Insets; + +import javax.swing.JComboBox; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.border.MatteBorder; + +import net.miginfocom.swing.MigLayout; +import forge.Singletons; +import forge.card.CardEdition; +import forge.game.GameFormat; +import forge.gui.deckeditor.SFilterUtil; +import forge.gui.deckeditor.controllers.CFilters; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FSkin; +import forge.gui.toolbox.FTextField; + +/** + * Assembles Swing components of deck editor filter tab. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VFilters implements IVDoc { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Filters"); + + // Text filter components + private final JTextField txfContains = new FTextField(); + private final JTextField txfWithout = new FTextField(); + private final JLabel lblContains = new FLabel.Builder() + .text("Contains:").fontScaleAuto(false).fontSize(14).build(); + private final JLabel lblWithout = new FLabel.Builder() + .text("Without:").fontScaleAuto(false).fontSize(14).build(); + + // Interval filter components + private final JComboBox cbxSets = new JComboBox(); + private final JComboBox cbxPLow = new JComboBox(); + private final JComboBox cbxPHigh = new JComboBox(); + private final JComboBox cbxTLow = new JComboBox(); + private final JComboBox cbxTHigh = new JComboBox(); + private final JComboBox cbxCMCLow = new JComboBox(); + private final JComboBox cbxCMCHigh = new JComboBox(); + + private final JLabel lblP = new FLabel.Builder() + .fontScaleAuto(false).fontSize(12).text(" <= Power <= ").build(); + + private final JLabel lblT = new FLabel.Builder() + .fontScaleAuto(false).fontSize(12).text(" <= Toughness <= ").build(); + + private final JLabel lblCMC = new FLabel.Builder() + .fontScaleAuto(false).fontSize(12).text(" <= CMC <= ").build(); + + // Title labels + private final JLabel lblProperties = new FLabel.Builder() + .text("Properties").tooltip("Filter by color, type, set, or format. Click to toggle.") + .hoverable(true).fontScaleAuto(false).fontSize(14).build(); + + private final JLabel lblText = new FLabel.Builder() + .text("Card Text").tooltip("Filter by card name, type, and text, space delimited. Click to reset.") + .hoverable(true).fontScaleAuto(false).fontSize(14).build(); + + private final JLabel lblIntervals = new FLabel.Builder() + .text("Intervals").tooltip("Filter by power, toughness, or converted mana cost. Click to reset.") + .hoverable(true).fontScaleAuto(false).fontSize(14).build(); + + // Container components + private final JPanel pnlText = new JPanel(new MigLayout( + "insets 0, gap 0, wrap 2, ax center")); + private final JPanel pnlIntervals = new JPanel(new MigLayout( + "insets 0, gap 0, wrap 3, ax center")); + + private JPanel pnlContainer = new JPanel(new MigLayout("insets 0, gap 0, wrap")); + private JScrollPane scroller = new JScrollPane(pnlContainer); + + //========== Constructor + private VFilters() { + String constraints = ""; + + // Sets/formats combo box + cbxSets.addItem("All sets and formats"); + for (final GameFormat s : Singletons.getModel().getFormats()) { + cbxSets.addItem(s); + } + for (final CardEdition s : Singletons.getModel().getEditions()) { + cbxSets.addItem(s); + } + + // Color/type searches + lblProperties.setBorder(new MatteBorder(0, 0, 1, 0, + FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + lblText.setBorder(new MatteBorder(0, 0, 1, 0, + FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + lblIntervals.setBorder(new MatteBorder(0, 0, 1, 0, + FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + + // Text search + txfContains.setMargin(new Insets(5, 5, 5, 5)); + txfContains.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + txfContains.setOpaque(true); + txfContains.setEditable(true); + txfContains.setFocusable(true); + txfContains.setOpaque(true); + txfContains.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + + txfWithout.setMargin(new Insets(5, 5, 5, 5)); + txfWithout.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + txfWithout.setOpaque(true); + txfWithout.setEditable(true); + txfWithout.setFocusable(true); + txfWithout.setOpaque(true); + txfWithout.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + + pnlText.setOpaque(false); + pnlText.add(lblText, "w 210px!, span 2 1, h 25px!"); + pnlText.add(lblContains, "w 80px!, h 30px!"); + pnlText.add(txfContains, "pushx, growx, gap 5px 5px 2px 2px, h 30px!"); + pnlText.add(lblWithout, "w 80px!, h 30px!"); + pnlText.add(txfWithout, "pushx, growx, gap 5px 5px 2px 2px, h 30px!"); + + cbxPLow.addItem("*"); + cbxTLow.addItem("*"); + cbxCMCLow.addItem("*"); + + // Interval search + for (int i = 0; i < 10; i++) { + cbxPLow.addItem(i); + cbxTLow.addItem(i); + cbxCMCLow.addItem(i); + cbxPHigh.addItem(i); + cbxTHigh.addItem(i); + cbxCMCHigh.addItem(i); + } + + cbxPHigh.addItem("10+"); + cbxTHigh.addItem("10+"); + cbxCMCHigh.addItem("10+"); + + cbxPLow.setSelectedItem("*"); + cbxTLow.setSelectedItem("*"); + cbxCMCLow.setSelectedItem("*"); + cbxPHigh.setSelectedItem("10+"); + cbxTHigh.setSelectedItem("10+"); + cbxCMCHigh.setSelectedItem("10+"); + + constraints = "w 60px!, h 25px!, gap 0 0 0 0"; + pnlIntervals.add(cbxPLow, constraints); + pnlIntervals.add(lblP, "w 100px!, h 25px!"); + pnlIntervals.add(cbxPHigh, constraints); + + pnlIntervals.add(cbxTLow, constraints); + pnlIntervals.add(lblT, "w 100px!, h 25px!"); + pnlIntervals.add(cbxTHigh, constraints); + + pnlIntervals.add(cbxCMCLow, constraints); + pnlIntervals.add(lblCMC, "w 100px!, h 25px!"); + pnlIntervals.add(cbxCMCHigh, constraints); + + pnlIntervals.setOpaque(false); + + // Core layout + final String constraints2 = "w 90%!, gap 5% 0 1% 0"; + pnlContainer.add(lblProperties, "w 90%!, h 25px!, gap 5% 0 1% 0"); + pnlContainer.add(SFilterUtil.populateColorFilters(), constraints2); + pnlContainer.add(SFilterUtil.populateTypeFilters(), constraints2); + pnlContainer.add(cbxSets, constraints2 + ", h 25px!"); + + pnlContainer.add(lblText, "w 90%!, h 25px!, gap 5% 0 15px 0"); + pnlContainer.add(pnlText, constraints2); + + pnlContainer.add(lblIntervals, "w 90%!, h 25px!, gap 5% 0 15px 0"); + pnlContainer.add(pnlIntervals, constraints2); + + pnlContainer.setOpaque(false); + scroller.setOpaque(false); + scroller.getViewport().setOpaque(false); + scroller.setBorder(null); + scroller.getViewport().setBorder(null); + } + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.EDITOR_FILTERS; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CFilters.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0, wrap")); + parentCell.getBody().add(scroller, "w 96%!, h 96%, gap 2% 0 2% 0"); + } + + //========== Retrieval methods + /** @return {javax.swing.JLabel} */ + public JLabel getBtnToggle() { + return lblProperties; + } + + /** @return {javax.swing.JLabel} */ + public JLabel getBtnResetText() { + return lblText; + } + + /** @return {javax.swing.JLabel} */ + public JLabel getBtnResetIntervals() { + return lblIntervals; + } + + /** @return {javax.swing.JComboBox} */ + public JComboBox getCbxSets() { + return cbxSets; + } + + /** @return {javax.swing.JTextField} */ + public JTextField getTxfContains() { + return txfContains; + } + + /** @return {javax.swing.JTextField} */ + public JTextField getTxfWithout() { + return txfWithout; + } + + /** @return {javax.swing.JComboBox} */ + public JComboBox getCbxPLow() { + return cbxPLow; + } + + /** @return {javax.swing.JComboBox} */ + public JComboBox getCbxPHigh() { + return cbxPHigh; + } + + /** @return {javax.swing.JComboBox} */ + public JComboBox getCbxTLow() { + return cbxTLow; + } + + /** @return {javax.swing.JComboBox} */ + public JComboBox getCbxTHigh() { + return cbxTHigh; + } + + /** @return {javax.swing.JComboBox} */ + public JComboBox getCbxCMCLow() { + return cbxCMCLow; + } + + /** @return {javax.swing.JComboBox} */ + public JComboBox getCbxCMCHigh() { + return cbxCMCHigh; + } + //========== Custom class handling + +} diff --git a/src/main/java/forge/gui/deckeditor/views/VProbabilities.java b/src/main/java/forge/gui/deckeditor/views/VProbabilities.java new file mode 100644 index 00000000000..98433d93a91 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/VProbabilities.java @@ -0,0 +1,198 @@ +package forge.gui.deckeditor.views; + +import java.awt.Font; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.util.List; + +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.SwingConstants; +import javax.swing.border.MatteBorder; + +import net.miginfocom.swing.MigLayout; +import forge.deck.DeckBase; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.controllers.ACEditorBase; +import forge.gui.deckeditor.controllers.CProbabilities; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FSkin; +import forge.item.CardPrinted; +import forge.item.InventoryItem; + +/** + * Assembles Swing components of deck editor analysis tab. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VProbabilities implements IVDoc { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Draw Order"); + + // Title labels + private final JLabel lblReshuffle = new FLabel.Builder() + .hoverable(true).text("RE-SHUFFLE").tooltip("See a new sample shuffle") + .fontScaleAuto(false).fontSize(12).build(); + private final JLabel lblSampleHand = new FLabel.Builder().fontStyle(Font.BOLD) + .fontSize(14).fontScaleAuto(false).text("SAMPLE HAND").build(); + private final JLabel lblRemainingDraws = new FLabel.Builder().fontStyle(Font.BOLD) + .fontSize(14).fontScaleAuto(false).text("REMAINING DRAWS").build(); + private final JLabel lblExplanation = new FLabel.Builder() + .fontSize(11).fontScaleAuto(false).text("XX % = frequency that card will appear at that position").build(); + + // Layout containers + private final JPanel pnlContent = new JPanel(new MigLayout("insets 0, gap 0, wrap")); + private final JScrollPane scroller = new JScrollPane(pnlContent); + private final JPanel pnlHand = new JPanel(new MigLayout("insets 0, gap 0, wrap")); + private final JPanel pnlLibrary = new JPanel(new MigLayout("insets 0, gap 0, wrap")); + + //========== Constructor + private VProbabilities() { + pnlContent.setOpaque(false); + pnlHand.setOpaque(false); + pnlLibrary.setOpaque(false); + scroller.setOpaque(false); + scroller.getViewport().setOpaque(false); + scroller.setBorder(null); + scroller.getViewport().setBorder(null); + scroller.getVerticalScrollBar().setUnitIncrement(16); + + // Sample hand + lblExplanation.setBorder(new MatteBorder(0, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + lblRemainingDraws.setBorder(new MatteBorder(1, 0, 1, 0, FSkin.getColor(FSkin.Colors.CLR_BORDERS))); + + // Core layout + final String constraints = "w 96%!, h 25px!, gap 2% 0 0 0"; + + pnlContent.add(lblReshuffle, constraints); + pnlContent.add(lblSampleHand, constraints); + pnlContent.add(lblExplanation, constraints); + pnlContent.add(pnlHand, "w 96%!, gap 2% 0 0 0"); + pnlContent.add(lblRemainingDraws, constraints); + pnlContent.add(pnlLibrary, "w 96%!, gap 2% 0 0 0"); + } + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.EDITOR_PROBABILITIES; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CProbabilities.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0")); + parentCell.getBody().add(scroller, "w 96%!, h 96%!, gap 2% 0 2% 0"); + } + + //========== Retrieval methods + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblReshuffle() { + return lblReshuffle; + } + + //========== Other methods + /** @param shuffledVals   A map of card names and their positional probability. */ + public void rebuildLabels(final List shuffledVals) { + pnlHand.removeAll(); + pnlLibrary.removeAll(); + + JLabel lbl; + final String constraints = "w 96%, h 25px!, gap 2% 0 0 0"; + + for (int i = 0; i < shuffledVals.size(); i++) { + lbl = (i % 2 == 1 ? buildLabel(true) : buildLabel(false)); + lbl.setText(shuffledVals.get(i)); + + if (i < 7) { pnlHand.add(lbl, constraints); } + else { pnlLibrary.add(lbl, constraints); } + } + + pnlHand.validate(); + pnlLibrary.validate(); + } + + private JLabel buildLabel(final boolean zebra) { + final JLabel lbl = new FLabel.Builder().text("--") + .fontAlign(SwingConstants.CENTER).fontSize(13).fontScaleAuto(false) + .build(); + + lbl.addMouseListener(new MouseAdapter() { + @Override + @SuppressWarnings("unchecked") + public void mouseEntered(final MouseEvent e) { + final ACEditorBase ed = (ACEditorBase) + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController(); + + final List cards = (List) ed.getTableDeck().getCards().toFlatList(); + final String name1 = lbl.getText(); + String name2; + + for (CardPrinted c : cards) { + name2 = c.getName(); + if (name2.length() > name1.length()) { continue; } + + if (name2.equals(name1.substring(0, name2.length()))) { + CDeckEditorUI.SINGLETON_INSTANCE.setCard(c.toForgeCard()); + break; + } + } + } + }); + + if (zebra) { + lbl.setOpaque(true); + lbl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + } + + return lbl; + } +} diff --git a/src/main/java/forge/gui/deckeditor/views/VStatistics.java b/src/main/java/forge/gui/deckeditor/views/VStatistics.java new file mode 100644 index 00000000000..0b8b3cfb298 --- /dev/null +++ b/src/main/java/forge/gui/deckeditor/views/VStatistics.java @@ -0,0 +1,271 @@ +package forge.gui.deckeditor.views; + +import java.awt.Font; + +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import net.miginfocom.swing.MigLayout; +import forge.gui.deckeditor.SEditorUtil; +import forge.gui.deckeditor.controllers.CStatistics; +import forge.gui.framework.DragCell; +import forge.gui.framework.DragTab; +import forge.gui.framework.EDocID; +import forge.gui.framework.ICDoc; +import forge.gui.framework.IVDoc; +import forge.gui.toolbox.FLabel; +import forge.gui.toolbox.FSkin; + +/** + * Assembles Swing components of deck editor analysis tab. + * + *

(V at beginning of class name denotes a view class.) + */ +public enum VStatistics implements IVDoc { + /** */ + SINGLETON_INSTANCE; + + // Fields used with interface IVDoc + private DragCell parentCell; + private final DragTab tab = new DragTab("Statistics"); + + // Global stats + private JLabel lblTotal = new FLabel.Builder() + .text("Total cards: 0").tooltip("TOTAL CARDS") + .fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD) + .fontScaleAuto(false).build(); + private JLabel lblTMC = new FLabel.Builder() + .text("Total mana cost: 0").tooltip("TOTAL MANA COST") + .fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD) + .fontScaleAuto(false).build(); + private JLabel lblAMC = new FLabel.Builder() + .text("Average mana cost: 0.00").tooltip("AVERAGE MANA COST") + .fontStyle(Font.BOLD).fontSize(11).fontStyle(Font.BOLD) + .fontScaleAuto(false).build(); + + // Total and color count labels + private final JPanel pnlStats = new JPanel(); + private final JLabel lblMulti = buildLabel(SEditorUtil.ICO_MULTI, true); + private final JLabel lblBlack = buildLabel(SEditorUtil.ICO_BLACK, false); + private final JLabel lblBlue = buildLabel(SEditorUtil.ICO_BLUE, true); + private final JLabel lblGreen = buildLabel(SEditorUtil.ICO_GREEN, false); + private final JLabel lblRed = buildLabel(SEditorUtil.ICO_RED, true); + private final JLabel lblWhite = buildLabel(SEditorUtil.ICO_WHITE, false); + private final JLabel lblColorless = buildLabel(SEditorUtil.ICO_COLORLESS, true); + + // Card type labels + private final JLabel lblArtifact = buildLabel(SEditorUtil.ICO_ARTIFACT, true); + private final JLabel lblCreature = buildLabel(SEditorUtil.ICO_CREATURE, false); + private final JLabel lblEnchantment = buildLabel(SEditorUtil.ICO_ENCHANTMENT, true); + private final JLabel lblInstant = buildLabel(SEditorUtil.ICO_INSTANT, false); + private final JLabel lblLand = buildLabel(SEditorUtil.ICO_LAND, true); + private final JLabel lblPlaneswalker = buildLabel(SEditorUtil.ICO_PLANESWALKER, false); + private final JLabel lblSorcery = buildLabel(SEditorUtil.ICO_SORCERY, true); + + // CMC labels + private final JLabel lblCMC0 = buildLabel( + new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_0, 16, 16)), true); + private final JLabel lblCMC1 = buildLabel( + new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_1, 16, 16)), false); + private final JLabel lblCMC2 = buildLabel( + new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_2, 16, 16)), true); + private final JLabel lblCMC3 = buildLabel( + new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_3, 16, 16)), false); + private final JLabel lblCMC4 = buildLabel( + new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_4, 16, 16)), true); + private final JLabel lblCMC5 = buildLabel( + new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_5, 16, 16)), false); + private final JLabel lblCMC6 = buildLabel( + new ImageIcon(FSkin.getImage(FSkin.ColorlessManaImages.IMG_6, 16, 16)), true); + + // Layout containers + private final JScrollPane scroller = new JScrollPane(pnlStats); + + //========== Constructor + private VStatistics() { + scroller.setOpaque(false); + scroller.getViewport().setOpaque(false); + scroller.setBorder(null); + scroller.getViewport().setBorder(null); + scroller.getVerticalScrollBar().setUnitIncrement(16); + + // Color stats + lblMulti.setToolTipText("Total Card Count"); + lblBlack.setToolTipText("Black Card Count"); + lblBlue.setToolTipText("Blue Card Count"); + lblGreen.setToolTipText("Green Card Count"); + lblRed.setToolTipText("Red Card Count"); + lblWhite.setToolTipText("White Card Count"); + lblColorless.setToolTipText("Total Card Count"); + + // Type stats + lblArtifact.setToolTipText("Artiface Card Count"); + lblCreature.setToolTipText("Creature Card Count"); + lblColorless.setToolTipText("Colorless Card Count"); + lblEnchantment.setToolTipText("Enchantment Card Count"); + lblInstant.setToolTipText("Instant Card Count"); + lblLand.setToolTipText("Land Card Count"); + lblPlaneswalker.setToolTipText("Planeswalker Card Count"); + lblSorcery.setToolTipText("Sorcery Card Count"); + + // Stats container + pnlStats.setOpaque(false); + pnlStats.setLayout(new MigLayout("insets 0, gap 0, ax center, wrap 3")); + + pnlStats.add(lblTotal, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0"); + pnlStats.add(lblTMC, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0"); + pnlStats.add(lblAMC, "w 96%!, h 20px!, span 3 1, gap 2% 0 0 0"); + + // Add labels to container + final String constraints = "w 32%!, h 35px!"; + pnlStats.add(lblMulti, constraints); + pnlStats.add(lblArtifact, constraints); + pnlStats.add(lblCMC0, constraints); + + pnlStats.add(lblBlack, constraints); + pnlStats.add(lblCreature, constraints); + pnlStats.add(lblCMC1, constraints); + + pnlStats.add(lblBlue, constraints); + pnlStats.add(lblEnchantment, constraints); + pnlStats.add(lblCMC2, constraints); + + pnlStats.add(lblGreen, constraints); + pnlStats.add(lblInstant, constraints); + pnlStats.add(lblCMC3, constraints); + + pnlStats.add(lblRed, constraints); + pnlStats.add(lblLand, constraints); + pnlStats.add(lblCMC4, constraints); + + pnlStats.add(lblWhite, constraints); + pnlStats.add(lblPlaneswalker, constraints); + pnlStats.add(lblCMC5, constraints); + + pnlStats.add(lblColorless, constraints); + pnlStats.add(lblSorcery, constraints); + pnlStats.add(lblCMC6, constraints); + } + + //========== Overridden methods + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getDocumentID() + */ + @Override + public EDocID getDocumentID() { + return EDocID.EDITOR_STATISTICS; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getTabLabel() + */ + @Override + public DragTab getTabLabel() { + return tab; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getControl() + */ + @Override + public ICDoc getControl() { + return CStatistics.SINGLETON_INSTANCE; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#setParentCell(forge.gui.framework.DragCell) + */ + @Override + public void setParentCell(final DragCell cell0) { + this.parentCell = cell0; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#getParentCell() + */ + @Override + public DragCell getParentCell() { + return this.parentCell; + } + + /* (non-Javadoc) + * @see forge.gui.framework.IVDoc#populate() + */ + @Override + public void populate() { + parentCell.getBody().setLayout(new MigLayout("insets 0, gap 0")); + parentCell.getBody().add(scroller, "w 96%!, h 96%!, gap 2% 0 2% 0"); + } + + //========== Retrieval methods + + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblMulti() { return lblMulti; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblBlack() { return lblBlack; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblBlue() { return lblBlue; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblGreen() { return lblGreen; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblRed() { return lblRed; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblWhite() { return lblWhite; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblColorless() { return lblColorless; } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblArtifact() { return lblArtifact; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblEnchantment() { return lblEnchantment; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblCreature() { return lblCreature; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblSorcery() { return lblSorcery; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblInstant() { return lblInstant; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblPlaneswalker() { return lblPlaneswalker; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblLand() { return lblLand; } + + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblCMC0() { return lblCMC0; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblCMC1() { return lblCMC1; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblCMC2() { return lblCMC2; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblCMC3() { return lblCMC3; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblCMC4() { return lblCMC4; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblCMC5() { return lblCMC5; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblCMC6() { return lblCMC6; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblTotal() { return lblTotal; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblTMC() { return lblTMC; } + /** @return {@link javax.swing.JLabel} */ + public JLabel getLblAMC() { return lblAMC; } + + //========== Other methods + + private JLabel buildLabel(final ImageIcon icon0, final boolean zebra) { + final JLabel lbl = new FLabel.Builder().text("0") + .icon(icon0).iconScaleAuto(false) + .fontSize(11).fontScaleAuto(false) + .build(); + + if (zebra) { + lbl.setOpaque(true); + lbl.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + } + + return lbl; + } +} diff --git a/src/main/java/forge/gui/framework/DragCell.java b/src/main/java/forge/gui/framework/DragCell.java index 504e98aa5cc..8b788a47e70 100644 --- a/src/main/java/forge/gui/framework/DragCell.java +++ b/src/main/java/forge/gui/framework/DragCell.java @@ -147,7 +147,12 @@ public final class DragCell extends JPanel implements ILocalRepaint { * @return int */ public int getAbsX() { - return (int) this.getLocationOnScreen().getX(); + int i = 0; + + try { i = (int) this.getLocationOnScreen().getX(); } + catch (final Exception e) { } + + return i; } /** @@ -155,7 +160,12 @@ public final class DragCell extends JPanel implements ILocalRepaint { * @return int */ public int getAbsX2() { - return this.getAbsX() + this.getW(); + int i = 0; + + try { i = this.getAbsX() + this.getW(); } + catch (final Exception e) { } + + return i; } /** @@ -163,7 +173,12 @@ public final class DragCell extends JPanel implements ILocalRepaint { * @return int */ public int getAbsY() { - return (int) this.getLocationOnScreen().getY(); + int i = 0; + + try { i = (int) this.getLocationOnScreen().getY(); } + catch (final Exception e) { } + + return i; } /** @@ -171,7 +186,12 @@ public final class DragCell extends JPanel implements ILocalRepaint { * @return int */ public int getAbsY2() { - return this.getAbsY() + this.getH(); + int i = 0; + + try { i = this.getAbsY() + this.getH(); } + catch (final Exception e) { } + + return i; } /** diff --git a/src/main/java/forge/gui/framework/EDocID.java b/src/main/java/forge/gui/framework/EDocID.java index 3e68ad6de2e..ed395026456 100644 --- a/src/main/java/forge/gui/framework/EDocID.java +++ b/src/main/java/forge/gui/framework/EDocID.java @@ -3,6 +3,14 @@ */ package forge.gui.framework; +import forge.gui.deckeditor.views.VAllDecks; +import forge.gui.deckeditor.views.VCardCatalog; +import forge.gui.deckeditor.views.VCurrentDeck; +import forge.gui.deckeditor.views.VDeckgen; +import forge.gui.deckeditor.views.VEditorPreferences; +import forge.gui.deckeditor.views.VFilters; +import forge.gui.deckeditor.views.VProbabilities; +import forge.gui.deckeditor.views.VStatistics; import forge.gui.match.views.VAntes; import forge.gui.match.views.VCombat; import forge.gui.match.views.VDetail; @@ -21,6 +29,15 @@ import forge.gui.match.views.VStack; *

(E at beginning of class name denotes an enum.) */ public enum EDocID { /** */ + EDITOR_FILTERS (VFilters.SINGLETON_INSTANCE), /** */ + EDITOR_PREFERENCES (VEditorPreferences.SINGLETON_INSTANCE), /** */ + EDITOR_ALLDECKS (VAllDecks.SINGLETON_INSTANCE), /** */ + EDITOR_STATISTICS (VStatistics.SINGLETON_INSTANCE), /** */ + EDITOR_PROBABILITIES (VProbabilities.SINGLETON_INSTANCE), /** */ + EDITOR_CATALOG (VCardCatalog.SINGLETON_INSTANCE), /** */ + EDITOR_CURRENTDECK (VCurrentDeck.SINGLETON_INSTANCE), /** */ + EDITOR_DECKGEN (VDeckgen.SINGLETON_INSTANCE), /** */ + CARD_PICTURE (VPicture.SINGLETON_INSTANCE), /** */ CARD_DETAIL (VDetail.SINGLETON_INSTANCE), /** */ CARD_ANTES (VAntes.SINGLETON_INSTANCE), /** */ @@ -61,7 +78,7 @@ public enum EDocID { /** */ /** @return {@link forge.gui.framework.IVDoc} */ public IVDoc getDoc() { - if (vDoc == null) { throw new NullPointerException("No document found!"); } + if (vDoc == null) { throw new NullPointerException("No document found for " + this.name() + "."); } return vDoc; } } diff --git a/src/main/java/forge/gui/framework/ICDoc.java b/src/main/java/forge/gui/framework/ICDoc.java index 9dc42a9c282..162f1b4b932 100644 --- a/src/main/java/forge/gui/framework/ICDoc.java +++ b/src/main/java/forge/gui/framework/ICDoc.java @@ -20,10 +20,10 @@ public interface ICDoc { Command getCommandOnSelect(); /** - * Call this method after the view singleton has been fully realized + * This method is called once, after the view singleton has been fully realized * for the first time. It should execute operations which should only - * be done once, but require non-null view components.

- * + * be done once, but require non-null view components. + *

* This method should only be called once, in FView, after singletons are populated. */ void initialize(); diff --git a/src/main/java/forge/gui/framework/IVTopLevelUI.java b/src/main/java/forge/gui/framework/IVTopLevelUI.java index 651de1ef11b..076750cd2f3 100644 --- a/src/main/java/forge/gui/framework/IVTopLevelUI.java +++ b/src/main/java/forge/gui/framework/IVTopLevelUI.java @@ -10,14 +10,18 @@ package forge.gui.framework; */ public interface IVTopLevelUI { /** Called during the preload sequence, this method caches - * all of the children singletons and instances. */ + * all of the view singletons and component instances, + * before any operations are performed on them. + *

+ * Although this is sometimes empty, it's important, since in many cases + * non-lazy components must be prepared before each panel is populated. + */ void instantiate(); /** * Removes all children and (re)populates top level content, * independent of constructor. Expected to provide * a completely fresh layout on the component. - * */ void populate(); } diff --git a/src/main/java/forge/gui/framework/SIOUtil.java b/src/main/java/forge/gui/framework/SLayoutIO.java similarity index 73% rename from src/main/java/forge/gui/framework/SIOUtil.java rename to src/main/java/forge/gui/framework/SLayoutIO.java index caf5cf34482..8f661d6700e 100644 --- a/src/main/java/forge/gui/framework/SIOUtil.java +++ b/src/main/java/forge/gui/framework/SLayoutIO.java @@ -18,6 +18,8 @@ import javax.xml.stream.events.Attribute; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; +import forge.control.FControl; +import forge.properties.NewConstants; import forge.view.FView; @@ -26,7 +28,7 @@ import forge.view.FView; * *

(S at beginning of class name denotes a static factory.) */ -public final class SIOUtil { +public final class SLayoutIO { /** Each cell must save these elements of its display. */ private enum Property { x, @@ -36,15 +38,22 @@ public final class SIOUtil { doc }; - /** */ - public static final String FILE_DEFAULT = "res/layouts/match_default.xml"; - public static final String FILE_PREFERRED = "res/layouts/match_preferred.xml"; + private static String fileDefault = null; + private static String filePreferred = null; private static final XMLEventFactory EF = XMLEventFactory.newInstance(); private static final XMLEvent NEWLINE = EF.createDTD("\n"); private static final XMLEvent TAB = EF.createDTD("\t"); + /** + * Gets preferred layout file corresponding to current state of UI. + * @return {@link java.lang.String} + */ + public static String getFilePreferred() { + return filePreferred; + } + /** Publicly-accessible save method, to neatly handle exception handling. - * @param f0 file to save layout to, if null, saves to FILE_PREFERRED + * @param f0 file to save layout to, if null, saves to filePreferred * * */ @@ -52,9 +61,9 @@ public final class SIOUtil { if (SwingUtilities.isEventDispatchThread()) { throw new IllegalThreadStateException("This operation should be independent of the EDT."); } - - try { save(f0); } - catch (final Exception e) { e.printStackTrace(); } + + try { save(f0); } + catch (final Exception e) { e.printStackTrace(); } } @@ -72,15 +81,16 @@ public final class SIOUtil { } private static void save(final File f0) throws Exception { - final String fWriteTo; - if (f0==null) { - fWriteTo = FILE_PREFERRED; + SLayoutIO.setFilesForState(); + + if (f0 == null) { + fWriteTo = filePreferred; } else { fWriteTo = f0.getPath(); - } - + } + final XMLOutputFactory out = XMLOutputFactory.newInstance(); final XMLEventWriter writer = out.createXMLEventWriter(new FileOutputStream(fWriteTo)); final List cells = FView.SINGLETON_INSTANCE.getDragCells(); @@ -125,16 +135,17 @@ public final class SIOUtil { private static void load(final File f) throws Exception { final FView view = FView.SINGLETON_INSTANCE; final XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + SLayoutIO.setFilesForState(); final XMLEventReader reader; if (f != null && f.exists()) { reader = inputFactory.createXMLEventReader(new FileInputStream(f)); } - else if (new File(FILE_PREFERRED).exists()) { - reader = inputFactory.createXMLEventReader(new FileInputStream(FILE_PREFERRED)); + else if (new File(filePreferred).exists()) { + reader = inputFactory.createXMLEventReader(new FileInputStream(filePreferred)); } else { - reader = inputFactory.createXMLEventReader(new FileInputStream(FILE_DEFAULT)); + reader = inputFactory.createXMLEventReader(new FileInputStream(fileDefault)); } view.removeAllDragCells(); @@ -149,7 +160,6 @@ public final class SIOUtil { event = reader.nextEvent(); if (event.isStartElement()) { - //&& event.asStartElement().getName().getLocalPart().equals("cell")) { element = event.asStartElement(); if (element.getName().getLocalPart().equals("cell")) { @@ -195,4 +205,37 @@ public final class SIOUtil { writer0.add(EF.createEndElement("", "", name0.toString())); writer0.add(NEWLINE); } + + /** + * Updates preferred / default layout addresses particular to each UI state. + * Always called before a load or a save, to ensure file addresses are correct. + */ + private static void setFilesForState() { + final String dir = NewConstants.LAYOUT_DIR; + + switch(FControl.SINGLETON_INSTANCE.getState()) { + case FControl.HOME_SCREEN: + fileDefault = dir + "home_default.xml"; + filePreferred = dir + "home_preferred.xml"; + break; + case FControl.MATCH_SCREEN: + fileDefault = dir + "match_default.xml"; + filePreferred = dir + "match_preferred.xml"; + break; + case FControl.DECK_EDITOR_CONSTRUCTED: + case FControl.DECK_EDITOR_LIMITED: + case FControl.DECK_EDITOR_QUEST: + case FControl.DRAFTING_PROCESS: + case FControl.QUEST_CARD_SHOP: + fileDefault = dir + "editor_default.xml"; + filePreferred = dir + "editor_preferred.xml"; + break; + case FControl.QUEST_BAZAAR: + fileDefault = dir + "bazaar_default.xml"; + filePreferred = dir + "bazaar_preferred.xml"; + break; + default: + throw new IllegalStateException("Layout load failed; UI state unknown."); + } + } } diff --git a/src/main/java/forge/gui/framework/SRearrangingUtil.java b/src/main/java/forge/gui/framework/SRearrangingUtil.java index 22f8732deea..50d6a23f484 100644 --- a/src/main/java/forge/gui/framework/SRearrangingUtil.java +++ b/src/main/java/forge/gui/framework/SRearrangingUtil.java @@ -307,7 +307,7 @@ public final class SRearrangingUtil { updateBorders(); final Thread t = new Thread() { @Override - public void run() { SIOUtil.saveLayout(null); } }; + public void run() { SLayoutIO.saveLayout(null); } }; t.start(); } @@ -439,6 +439,19 @@ public final class SRearrangingUtil { throw new UnsupportedOperationException("Gap was not filled."); } + /** + * Fills a gap left by a source cell. + *

+ * Cell will not be removed, but its coordinates will be filled + * by its neighbors. + * + * @param sourceCell0   {@link forge.gui.framework.DragCell} + */ + public static void fillGap(final DragCell sourceCell0) { + cellSrc = sourceCell0; + fillGap(); + } + /** Hides outer borders for components on edges, * preventing illegal resizing (and misleading cursor). */ public static void updateBorders() { diff --git a/src/main/java/forge/gui/framework/SResizingUtil.java b/src/main/java/forge/gui/framework/SResizingUtil.java index d59630a7524..50c5eb9074c 100644 --- a/src/main/java/forge/gui/framework/SResizingUtil.java +++ b/src/main/java/forge/gui/framework/SResizingUtil.java @@ -332,7 +332,7 @@ public final class SResizingUtil { /** */ public static void endResize() { final Thread t = new Thread() { @Override - public void run() { SIOUtil.saveLayout(null); } }; + public void run() { SLayoutIO.saveLayout(null); } }; t.start(); } diff --git a/src/main/java/forge/gui/home/VHomeUI.java b/src/main/java/forge/gui/home/VHomeUI.java index 6429ae72cf6..015e405a180 100644 --- a/src/main/java/forge/gui/home/VHomeUI.java +++ b/src/main/java/forge/gui/home/VHomeUI.java @@ -202,16 +202,7 @@ public enum VHomeUI implements IVTopLevelUI { pnlParent.addComponentListener(new ComponentAdapter() { @Override public void componentResized(final ComponentEvent e) { - final int w = pnlParent.getWidth(); - final int h = pnlParent.getHeight(); - pnlRight.setBounds(new Rectangle( - 2 * insets + leftWidthPx, insets, - w - leftWidthPx - 3 * insets, h - 2 * insets)); - pnlLeft.setBounds(new Rectangle( - insets, insets, - leftWidthPx, h - 2 * insets - )); - pnlParent.revalidate(); + updateLayout(); } }); } @@ -313,4 +304,18 @@ public enum VHomeUI implements IVTopLevelUI { public JPanel getPanel() { return pnlParent; } + + /** Updates the null layout percentage dimensions. */ + public void updateLayout() { + final int w = pnlParent.getWidth(); + final int h = pnlParent.getHeight(); + pnlRight.setBounds(new Rectangle( + 2 * insets + leftWidthPx, insets, + w - leftWidthPx - 3 * insets, h - 2 * insets)); + pnlLeft.setBounds(new Rectangle( + insets, insets, + leftWidthPx, h - 2 * insets + )); + pnlParent.revalidate(); + } } diff --git a/src/main/java/forge/gui/home/quest/CSubmenuChallenges.java b/src/main/java/forge/gui/home/quest/CSubmenuChallenges.java index d6998d03836..46534ed609f 100644 --- a/src/main/java/forge/gui/home/quest/CSubmenuChallenges.java +++ b/src/main/java/forge/gui/home/quest/CSubmenuChallenges.java @@ -13,7 +13,7 @@ import forge.Command; import forge.gui.home.EMenuItem; import forge.gui.home.ICSubmenu; import forge.gui.home.VHomeUI; -import forge.gui.home.quest.SubmenuQuestUtil.SelectablePanel; +import forge.gui.home.quest.SSubmenuQuestUtil.SelectablePanel; import forge.gui.toolbox.FLabel; import forge.quest.QuestController; import forge.quest.QuestEventChallenge; @@ -59,15 +59,15 @@ public enum CSubmenuChallenges implements ICSubmenu { view.getBtnSpellShop().setCommand( new Command() { @Override - public void execute() { SubmenuQuestUtil.showSpellShop(); } }); + public void execute() { SSubmenuQuestUtil.showSpellShop(); } }); view.getBtnBazaar().setCommand( new Command() { @Override - public void execute() { SubmenuQuestUtil.showBazaar(); } }); + public void execute() { SSubmenuQuestUtil.showBazaar(); } }); view.getBtnStart().addActionListener( new ActionListener() { @Override - public void actionPerformed(final ActionEvent e) { SubmenuQuestUtil.startGame(); } }); + public void actionPerformed(final ActionEvent e) { SSubmenuQuestUtil.startGame(); } }); ((FLabel) view.getLblZep()).setCommand( new Command() { @@ -111,7 +111,7 @@ public enum CSubmenuChallenges implements ICSubmenu { */ @Override public void update() { - SubmenuQuestUtil.updateStatsAndPet(); + SSubmenuQuestUtil.updateStatsAndPet(); final VSubmenuChallenges view = VSubmenuChallenges.SINGLETON_INSTANCE; final QuestController qCtrl = AllZone.getQuest(); diff --git a/src/main/java/forge/gui/home/quest/CSubmenuDuels.java b/src/main/java/forge/gui/home/quest/CSubmenuDuels.java index e4d0e083ab4..925bc9dc0a2 100644 --- a/src/main/java/forge/gui/home/quest/CSubmenuDuels.java +++ b/src/main/java/forge/gui/home/quest/CSubmenuDuels.java @@ -9,7 +9,7 @@ import forge.Command; import forge.gui.home.EMenuItem; import forge.gui.home.ICSubmenu; import forge.gui.home.VHomeUI; -import forge.gui.home.quest.SubmenuQuestUtil.SelectablePanel; +import forge.gui.home.quest.SSubmenuQuestUtil.SelectablePanel; import forge.quest.QuestController; import forge.quest.QuestEventDuel; import forge.quest.bazaar.QuestPetController; @@ -52,15 +52,15 @@ public enum CSubmenuDuels implements ICSubmenu { view.getBtnSpellShop().setCommand( new Command() { @Override - public void execute() { SubmenuQuestUtil.showSpellShop(); } }); + public void execute() { SSubmenuQuestUtil.showSpellShop(); } }); view.getBtnBazaar().setCommand( new Command() { @Override - public void execute() { SubmenuQuestUtil.showBazaar(); } }); + public void execute() { SSubmenuQuestUtil.showBazaar(); } }); view.getBtnStart().addActionListener( new ActionListener() { @Override - public void actionPerformed(final ActionEvent e) { SubmenuQuestUtil.startGame(); } }); + public void actionPerformed(final ActionEvent e) { SSubmenuQuestUtil.startGame(); } }); view.getBtnCurrentDeck().setCommand( new Command() { @Override @@ -94,7 +94,7 @@ public enum CSubmenuDuels implements ICSubmenu { */ @Override public void update() { - SubmenuQuestUtil.updateStatsAndPet(); + SSubmenuQuestUtil.updateStatsAndPet(); final VSubmenuDuels view = VSubmenuDuels.SINGLETON_INSTANCE; diff --git a/src/main/java/forge/gui/home/quest/CSubmenuQuestData.java b/src/main/java/forge/gui/home/quest/CSubmenuQuestData.java index 78cf30dfbea..6566217b4ff 100644 --- a/src/main/java/forge/gui/home/quest/CSubmenuQuestData.java +++ b/src/main/java/forge/gui/home/quest/CSubmenuQuestData.java @@ -189,7 +189,7 @@ public enum CSubmenuQuestData implements ICSubmenu { AllZone.getQuest().getName() + ".dat"); Singletons.getModel().getQuestPreferences().save(); - SubmenuQuestUtil.updateStatsAndPet(); + SSubmenuQuestUtil.updateStatsAndPet(); CSubmenuDuels.SINGLETON_INSTANCE.update(); CSubmenuChallenges.SINGLETON_INSTANCE.update(); diff --git a/src/main/java/forge/gui/home/quest/CSubmenuQuestDecks.java b/src/main/java/forge/gui/home/quest/CSubmenuQuestDecks.java index 90915a50dbc..81c5afb7db2 100644 --- a/src/main/java/forge/gui/home/quest/CSubmenuQuestDecks.java +++ b/src/main/java/forge/gui/home/quest/CSubmenuQuestDecks.java @@ -5,9 +5,10 @@ import java.util.ArrayList; import forge.AllZone; import forge.Command; import forge.Singletons; +import forge.control.FControl; import forge.deck.Deck; -import forge.gui.SOverlayUtils; -import forge.gui.deckeditor.DeckEditorQuest; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.controllers.CEditorQuest; import forge.gui.home.EMenuItem; import forge.gui.home.ICSubmenu; import forge.gui.home.VHomeUI; @@ -26,15 +27,6 @@ public enum CSubmenuQuestDecks implements ICSubmenu { private Deck currentDeck; - private final Command cmdDeckExit = new Command() { - @Override - public void execute() { - AllZone.getQuest().save(); - SOverlayUtils.hideOverlay(); - update(); - } - }; - private final Command cmdDeckSelect = new Command() { @Override public void execute() { @@ -76,11 +68,8 @@ public enum CSubmenuQuestDecks implements ICSubmenu { VSubmenuQuestDecks.SINGLETON_INSTANCE.getBtnNewDeck().setCommand(new Command() { @Override public void execute() { - final DeckEditorQuest editor = - new DeckEditorQuest(Singletons.getView().getFrame(), AllZone.getQuest()); - editor.show(cmdDeckExit); - SOverlayUtils.showOverlay(); - editor.setVisible(true); + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(new CEditorQuest(AllZone.getQuest())); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_QUEST); } }); } @@ -116,7 +105,6 @@ public enum CSubmenuQuestDecks implements ICSubmenu { view.getLstDecks().setSelectCommand(cmdDeckSelect); view.getLstDecks().setDeleteCommand(cmdDeckDelete); - view.getLstDecks().setExitCommand(cmdDeckExit); if (view.getLstDecks().getSelectedDeck() != null) { Singletons.getModel().getQuestPreferences().setPreference(QPref.CURRENT_DECK, view.getLstDecks().getSelectedDeck().getName()); diff --git a/src/main/java/forge/gui/home/quest/SubmenuQuestUtil.java b/src/main/java/forge/gui/home/quest/SSubmenuQuestUtil.java similarity index 93% rename from src/main/java/forge/gui/home/quest/SubmenuQuestUtil.java rename to src/main/java/forge/gui/home/quest/SSubmenuQuestUtil.java index 45337c82ad6..6e192c0d871 100644 --- a/src/main/java/forge/gui/home/quest/SubmenuQuestUtil.java +++ b/src/main/java/forge/gui/home/quest/SSubmenuQuestUtil.java @@ -20,7 +20,8 @@ import forge.deck.Deck; import forge.game.GameNew; import forge.game.GameType; import forge.gui.SOverlayUtils; -import forge.gui.deckeditor.QuestCardShop; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.controllers.CEditorQuestCardShop; import forge.gui.toolbox.FLabel; import forge.gui.toolbox.FPanel; import forge.gui.toolbox.FSkin; @@ -41,8 +42,10 @@ import forge.quest.data.QuestPreferences.QPref; /** * Utilities for the quest submenu, all over the MVC spectrum. * If a piece of code can be reused, it's dumped here. + * + *

(S at beginning of class name denotes a static factory.) */ -public class SubmenuQuestUtil { +public class SSubmenuQuestUtil { private static SelectablePanel selectedOpponent; /** @@ -140,7 +143,7 @@ public class SubmenuQuestUtil { view.getLblLosses().setText("Losses: " + qA.getLost()); view.updateCurrentDeckStatus(); - final int num = SubmenuQuestUtil.nextChallengeInWins(); + final int num = SSubmenuQuestUtil.nextChallengeInWins(); if (num == 0) { view.getLblNextChallengeInWins().setText("Next challenge available now."); } @@ -186,19 +189,10 @@ public class SubmenuQuestUtil { } /** */ - @SuppressWarnings("serial") public static void showSpellShop() { - final Command exit = new Command() { - @Override - public void execute() { - AllZone.getQuest().save(); - updateStatsAndPet(); - } - }; - - final QuestCardShop g = new QuestCardShop(Singletons.getView().getFrame(), AllZone.getQuest()); - g.show(exit); - g.setVisible(true); + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController( + new CEditorQuestCardShop(AllZone.getQuest())); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_QUEST); } /** */ @@ -223,7 +217,7 @@ public class SubmenuQuestUtil { final SwingWorker worker = new SwingWorker() { @Override public Object doInBackground() { - Constant.Runtime.HUMAN_DECK[0] = SubmenuQuestUtil.getCurrentDeck(); + Constant.Runtime.HUMAN_DECK[0] = SSubmenuQuestUtil.getCurrentDeck(); Constant.Runtime.COMPUTER_DECK[0] = event.getEventDeck(); Constant.Runtime.setGameType(GameType.Quest); @@ -255,7 +249,7 @@ public class SubmenuQuestUtil { event.getIconFilename()); } // End isFantasy else { - GameNew.newGame(SubmenuQuestUtil.getCurrentDeck(), event.getEventDeck()); + GameNew.newGame(SSubmenuQuestUtil.getCurrentDeck(), event.getEventDeck()); } return null; } @@ -297,7 +291,7 @@ public class SubmenuQuestUtil { VSubmenuChallenges.SINGLETON_INSTANCE.getBtnStart().setEnabled(true); } - selectedOpponent = SubmenuQuestUtil.SelectablePanel.this; + selectedOpponent = SSubmenuQuestUtil.SelectablePanel.this; } }); diff --git a/src/main/java/forge/gui/home/quest/VSubmenuChallenges.java b/src/main/java/forge/gui/home/quest/VSubmenuChallenges.java index 51088dbbec5..7a1e371b3b8 100644 --- a/src/main/java/forge/gui/home/quest/VSubmenuChallenges.java +++ b/src/main/java/forge/gui/home/quest/VSubmenuChallenges.java @@ -144,14 +144,14 @@ public enum VSubmenuChallenges implements IVSubmenu, IStatsAndPet { @Override public void updateCurrentDeckStatus() { final JLabel btnCurrentDeck = VSubmenuChallenges.SINGLETON_INSTANCE.getBtnCurrentDeck(); - if (SubmenuQuestUtil.getCurrentDeck() == null) { + if (SSubmenuQuestUtil.getCurrentDeck() == null) { btnCurrentDeck.setBackground(Color.red.darker()); btnCurrentDeck.setText(" Build, then select a deck in the \"Decks\" submenu. "); } else { btnCurrentDeck.setBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); btnCurrentDeck.setText("Current deck: " - + SubmenuQuestUtil.getCurrentDeck().getName()); + + SSubmenuQuestUtil.getCurrentDeck().getName()); } } diff --git a/src/main/java/forge/gui/home/quest/VSubmenuDuels.java b/src/main/java/forge/gui/home/quest/VSubmenuDuels.java index 978cbfd39f8..f9959cda2ed 100644 --- a/src/main/java/forge/gui/home/quest/VSubmenuDuels.java +++ b/src/main/java/forge/gui/home/quest/VSubmenuDuels.java @@ -144,14 +144,14 @@ public enum VSubmenuDuels implements IVSubmenu, IStatsAndPet { @Override public void updateCurrentDeckStatus() { final JLabel btnCurrentDeck = VSubmenuDuels.SINGLETON_INSTANCE.getBtnCurrentDeck(); - if (SubmenuQuestUtil.getCurrentDeck() == null) { + if (SSubmenuQuestUtil.getCurrentDeck() == null) { btnCurrentDeck.setBackground(Color.red.darker()); btnCurrentDeck.setText(" Build, then select a deck in the \"Decks\" submenu. "); } else { btnCurrentDeck.setBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); btnCurrentDeck.setText("Current deck: " - + SubmenuQuestUtil.getCurrentDeck().getName()); + + SSubmenuQuestUtil.getCurrentDeck().getName()); } } diff --git a/src/main/java/forge/gui/home/sanctioned/CSubmenuDraft.java b/src/main/java/forge/gui/home/sanctioned/CSubmenuDraft.java index a10b9e10460..4122a4bd4e7 100644 --- a/src/main/java/forge/gui/home/sanctioned/CSubmenuDraft.java +++ b/src/main/java/forge/gui/home/sanctioned/CSubmenuDraft.java @@ -13,6 +13,7 @@ import javax.swing.SwingWorker; import forge.Command; import forge.Constant; import forge.Singletons; +import forge.control.FControl; import forge.deck.Deck; import forge.deck.DeckGroup; import forge.game.GameNew; @@ -21,7 +22,8 @@ import forge.game.limited.BoosterDraft; import forge.game.limited.CardPoolLimitation; import forge.gui.GuiUtils; import forge.gui.SOverlayUtils; -import forge.gui.deckeditor.DraftingProcess; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.controllers.CEditorDraftingProcess; import forge.gui.home.ICSubmenu; import forge.gui.toolbox.FSkin; @@ -77,14 +79,6 @@ public enum CSubmenuDraft implements ICSubmenu { "Walter", "Wilfred", "William", "Winston" }; - private final Command cmdDeckExit = new Command() { - @Override - public void execute() { - update(); - SOverlayUtils.hideOverlay(); - } - }; - private final Command cmdDeckSelect = new Command() { @Override public void execute() { @@ -102,7 +96,6 @@ public enum CSubmenuDraft implements ICSubmenu { view.populate(); CSubmenuDraft.SINGLETON_INSTANCE.update(); - view.getLstHumanDecks().setExitCommand(cmdDeckExit); view.getLstHumanDecks().setSelectCommand(cmdDeckSelect); view.getBtnBuildDeck().addMouseListener( @@ -220,9 +213,7 @@ public enum CSubmenuDraft implements ICSubmenu { /** */ private void setupDraft() { - SOverlayUtils.showOverlay(); - - final DraftingProcess draft = new DraftingProcess(Singletons.getView().getFrame()); + final CEditorDraftingProcess draft = new CEditorDraftingProcess(); // Determine what kind of booster draft to run final ArrayList draftTypes = new ArrayList(); @@ -244,6 +235,9 @@ public enum CSubmenuDraft implements ICSubmenu { else if (o.toString().equals(draftTypes.get(2))) { draft.showGui(new BoosterDraft(CardPoolLimitation.Custom)); } + + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(draft); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_LIMITED); } private String[] generateNames() { diff --git a/src/main/java/forge/gui/home/sanctioned/CSubmenuSealed.java b/src/main/java/forge/gui/home/sanctioned/CSubmenuSealed.java index 0e6cfe5b4a0..0d6f6640025 100644 --- a/src/main/java/forge/gui/home/sanctioned/CSubmenuSealed.java +++ b/src/main/java/forge/gui/home/sanctioned/CSubmenuSealed.java @@ -16,6 +16,7 @@ import org.apache.commons.lang3.StringUtils; import forge.Command; import forge.Constant; import forge.Singletons; +import forge.control.FControl; import forge.deck.Deck; import forge.deck.DeckBase; import forge.deck.DeckGroup; @@ -23,8 +24,9 @@ import forge.game.GameNew; import forge.game.limited.SealedDeck; import forge.gui.GuiUtils; import forge.gui.SOverlayUtils; -import forge.gui.deckeditor.DeckEditorBase; -import forge.gui.deckeditor.DeckEditorLimited; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.controllers.ACEditorBase; +import forge.gui.deckeditor.controllers.CEditorLimited; import forge.gui.home.ICSubmenu; import forge.gui.toolbox.FSkin; import forge.item.CardPrinted; @@ -46,14 +48,6 @@ public enum CSubmenuSealed implements ICSubmenu { private Map aiDecks; - private final Command cmdExit = new Command() { - @Override - public void execute() { - update(); - SOverlayUtils.hideOverlay(); - } - }; - private final Command cmdDeckSelect = new Command() { @Override public void execute() { @@ -71,7 +65,6 @@ public enum CSubmenuSealed implements ICSubmenu { view.populate(); CSubmenuSealed.SINGLETON_INSTANCE.update(); - VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().setExitCommand(cmdExit); VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().setSelectCommand(cmdDeckSelect); VSubmenuSealed.SINGLETON_INSTANCE.getBtnBuildDeck().addMouseListener( @@ -225,15 +218,13 @@ public enum CSubmenuSealed implements ICSubmenu { final DeckGroup sealed = new DeckGroup(sDeckName); sealed.setHumanDeck(deck); sealed.addAiDeck(sd.buildAIDeck(sDeck.toForgeCardList())); - Singletons.getModel().getDecks().getSealed().add(sealed); + Singletons.getModel().getDecks().getSealed().add(sealed); - final DeckEditorBase editor = (DeckEditorBase) new DeckEditorLimited( - Singletons.getView().getFrame(), + final ACEditorBase editor = (ACEditorBase) new CEditorLimited( Singletons.getModel().getDecks().getSealed()); - editor.show(cmdExit); - editor.getController().setModel((T) sealed); - editor.setAlwaysOnTop(true); - editor.setVisible(true); + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(editor); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_LIMITED); + editor.getDeckController().setModel((T) sealed); } } diff --git a/src/main/java/forge/gui/home/utilities/CSubmenuDeckEditor.java b/src/main/java/forge/gui/home/utilities/CSubmenuDeckEditor.java index 0e3c35af824..492a0e9d8b8 100644 --- a/src/main/java/forge/gui/home/utilities/CSubmenuDeckEditor.java +++ b/src/main/java/forge/gui/home/utilities/CSubmenuDeckEditor.java @@ -1,10 +1,9 @@ package forge.gui.home.utilities; import forge.Command; -import forge.Singletons; -import forge.deck.DeckBase; -import forge.gui.deckeditor.DeckEditorBase; -import forge.gui.deckeditor.DeckEditorConstructed; +import forge.control.FControl; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.controllers.CEditorConstructed; import forge.gui.home.ICSubmenu; /** @@ -44,13 +43,9 @@ public enum CSubmenuDeckEditor implements ICSubmenu { /** * Shows constructed mode editor. - * @param extends DeckBase */ - @SuppressWarnings("unchecked") - private void showDeckEditor() { - DeckEditorBase editor = - (DeckEditorBase) new DeckEditorConstructed(Singletons.getView().getFrame()); - editor.show(null); - editor.setVisible(true); + private void showDeckEditor() { + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(new CEditorConstructed()); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_CONSTRUCTED); } } diff --git a/src/main/java/forge/gui/match/VMatchUI.java b/src/main/java/forge/gui/match/VMatchUI.java index 95ee255085c..8e67b545dea 100644 --- a/src/main/java/forge/gui/match/VMatchUI.java +++ b/src/main/java/forge/gui/match/VMatchUI.java @@ -10,7 +10,7 @@ import forge.gui.framework.DragCell; import forge.gui.framework.EDocID; import forge.gui.framework.IVDoc; import forge.gui.framework.IVTopLevelUI; -import forge.gui.framework.SIOUtil; +import forge.gui.framework.SLayoutIO; import forge.gui.framework.SResizingUtil; import forge.gui.match.nonsingleton.VField; import forge.gui.match.nonsingleton.VHand; @@ -71,7 +71,7 @@ public enum VMatchUI implements IVTopLevelUI { if (isPopulated) { return; } else { isPopulated = true; } - SIOUtil.loadLayout(null); + SLayoutIO.loadLayout(null); } /** NEVER ACTUALLY CALLED; could be removed... */ diff --git a/src/main/java/forge/gui/match/controllers/CDock.java b/src/main/java/forge/gui/match/controllers/CDock.java index e54ed4109cd..a995809ab71 100644 --- a/src/main/java/forge/gui/match/controllers/CDock.java +++ b/src/main/java/forge/gui/match/controllers/CDock.java @@ -39,7 +39,7 @@ import forge.deck.Deck; import forge.gui.ForgeAction; import forge.gui.SOverlayUtils; import forge.gui.framework.ICDoc; -import forge.gui.framework.SIOUtil; +import forge.gui.framework.SLayoutIO; import forge.gui.match.views.VDock; import forge.gui.toolbox.SaveOpenDialog; import forge.gui.toolbox.SaveOpenDialog.Filetypes; @@ -76,7 +76,7 @@ public enum CDock implements ICDoc { final SwingWorker w = new SwingWorker() { @Override public Void doInBackground() { - SIOUtil.loadLayout(new File(SIOUtil.FILE_DEFAULT)); + SLayoutIO.loadLayout(null); SOverlayUtils.hideOverlay(); return null; } @@ -89,10 +89,10 @@ public enum CDock implements ICDoc { @Override public Void doInBackground() { final SaveOpenDialog dlgSave = new SaveOpenDialog(); - final File defFile = new File(SIOUtil.FILE_PREFERRED); + final File defFile = new File(SLayoutIO.getFilePreferred()); final File saveFile = dlgSave.SaveDialog(defFile, Filetypes.LAYOUT); if (saveFile != null) { - SIOUtil.saveLayout(saveFile); + SLayoutIO.saveLayout(saveFile); } return null; } @@ -108,12 +108,12 @@ public enum CDock implements ICDoc { @Override public Void doInBackground() { final SaveOpenDialog dlgOpen = new SaveOpenDialog(); - final File defFile = new File(SIOUtil.FILE_PREFERRED); + final File defFile = new File(SLayoutIO.getFilePreferred()); final File loadFile = dlgOpen.OpenDialog(defFile, Filetypes.LAYOUT); if (loadFile != null) { - SIOUtil.loadLayout(loadFile); - SIOUtil.saveLayout(null); + SLayoutIO.loadLayout(loadFile); + SLayoutIO.saveLayout(null); } SOverlayUtils.hideOverlay(); diff --git a/src/main/java/forge/gui/toolbox/DeckLister.java b/src/main/java/forge/gui/toolbox/DeckLister.java index 3b7d7115040..af48ece66d3 100644 --- a/src/main/java/forge/gui/toolbox/DeckLister.java +++ b/src/main/java/forge/gui/toolbox/DeckLister.java @@ -2,7 +2,9 @@ * Forge: Play Magic: the Gathering. * Copyright (C) 2011 Nate * - * This program is free software: you can redistribute it and/or modify + * This prog +import forge.gui.deckeditor.CDeckEditorUI; +ram is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. @@ -24,27 +26,31 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; + import javax.swing.ImageIcon; import javax.swing.JButton; -import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.MatteBorder; +import net.miginfocom.swing.MigLayout; import forge.AllZone; import forge.Command; import forge.Constant; import forge.Singletons; +import forge.control.FControl; import forge.deck.CardCollections; import forge.deck.Deck; +import forge.deck.DeckBase; import forge.game.GameType; -import forge.gui.SOverlayUtils; -import forge.gui.deckeditor.DeckEditorConstructed; -import forge.gui.deckeditor.DeckEditorLimited; -import forge.gui.deckeditor.DeckEditorQuest; -import net.miginfocom.swing.MigLayout; +import forge.gui.deckeditor.CDeckEditorUI; +import forge.gui.deckeditor.controllers.ACEditorBase; +import forge.gui.deckeditor.controllers.CEditorConstructed; +import forge.gui.deckeditor.controllers.CEditorLimited; +import forge.gui.deckeditor.controllers.CEditorQuest; +import forge.gui.framework.ILocalRepaint; /** * Creates deck list for selected decks for quick deleting, editing, and basic @@ -52,7 +58,7 @@ import net.miginfocom.swing.MigLayout; * */ @SuppressWarnings("serial") -public class DeckLister extends JPanel { +public class DeckLister extends JPanel implements ILocalRepaint { private final ImageIcon icoDelete; private final ImageIcon icoDeleteOver; private final ImageIcon icoEdit; @@ -60,7 +66,7 @@ public class DeckLister extends JPanel { private RowPanel previousSelect; private RowPanel[] rows; private final GameType gametype; - private Command cmdEditorExit, cmdDelete, cmdRowSelect; + private Command cmdDelete, cmdRowSelect; private final Color clrDefault, clrHover, clrActive, clrBorders; /** @@ -87,7 +93,6 @@ public class DeckLister extends JPanel { public DeckLister(final GameType gt0, final Command cmd0) { super(); this.gametype = gt0; - this.cmdEditorExit = cmd0; this.clrDefault = new Color(0, 0, 0, 0); this.clrHover = FSkin.getColor(FSkin.Colors.CLR_HOVER); @@ -118,18 +123,22 @@ public class DeckLister extends JPanel { // scroll panes will have difficulty dynamically resizing if 100% width // is set. final JPanel rowTitle = new TitlePanel(); - rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA)); + rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); rowTitle.setLayout(new MigLayout("insets 0, gap 0")); rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER).build(), "w 10%!, h 20px!, gaptop 5px"); - rowTitle.add(new FLabel.Builder().text("Edit").fontAlign(SwingConstants.CENTER).build(), + rowTitle.add(new FLabel.Builder().text("Edit") + .fontScaleAuto(false).fontSize(14).fontAlign(SwingConstants.CENTER).build(), "w 10%!, h 20px!, gaptop 5px"); - rowTitle.add(new FLabel.Builder().text("Deck Name").fontAlign(SwingConstants.CENTER).build(), - "w 60%!, h 20px!, gaptop 5px"); - rowTitle.add(new FLabel.Builder().text("Main").fontAlign(SwingConstants.CENTER).build(), + rowTitle.add(new FLabel.Builder().text("Deck Name") + .fontScaleAuto(false).fontSize(14).fontAlign(SwingConstants.CENTER).build(), + "w 58%!, h 20px!, gaptop 5px"); + rowTitle.add(new FLabel.Builder().text("Main") + .fontScaleAuto(false).fontSize(14).fontAlign(SwingConstants.CENTER).build(), "w 10%!, h 20px!, gaptop 5px"); - rowTitle.add(new FLabel.Builder().text("Side").fontAlign(SwingConstants.CENTER).build(), + rowTitle.add(new FLabel.Builder().text("Side") + .fontScaleAuto(false).fontSize(14).fontAlign(SwingConstants.CENTER).build(), "w 10%!, h 20px!, gaptop 5px"); this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%"); @@ -142,7 +151,7 @@ public class DeckLister extends JPanel { row = new RowPanel(d); row.add(new DeleteButton(row), "w 10%!, h 20px!, gaptop 5px"); row.add(new EditButton(row), "w 10%!, h 20px!, gaptop 5px"); - row.add(new GenericLabel(d.getName()), "w 60%!, h 20px!, gaptop 5px"); + row.add(new GenericLabel(d.getName()), "w 58%!, h 20px!, gaptop 5px"); row.add(new MainLabel(String.valueOf(d.getMain().countAll())), "w 10%, h 20px!, gaptop 5px"); row.add(new GenericLabel(String.valueOf(d.getSideboard().countAll())), "w 10%!, h 20px!, gaptop 5px"); this.add(row, "w 98%!, h 30px!, gapleft 1%"); @@ -169,7 +178,8 @@ public class DeckLister extends JPanel { } /** Prevent panel from repainting the whole screen. */ - public void repaintOnlyThisPanel() { + @Override + public void repaintThis() { final Dimension d = DeckLister.this.getSize(); this.repaint(0, 0, d.width, d.height); } @@ -400,15 +410,6 @@ public class DeckLister extends JPanel { this.cmdRowSelect = c0; } - /** - * Sets the exit command. - * - * @param c0   {@link forge.Command} command executed on editor exit. - */ - public void setExitCommand(final Command c0) { - this.cmdEditorExit = c0; - } - private void selectHandler(final RowPanel r0) { if (this.previousSelect != null) { this.previousSelect.setSelected(false); @@ -420,41 +421,39 @@ public class DeckLister extends JPanel { this.cmdRowSelect.execute(); } } - - private void editDeck(final Deck d0) { - SOverlayUtils.showOverlay(); - - JFrame mainFrame = Singletons.getView().getFrame(); + @SuppressWarnings("unchecked") + private void editDeck(final Deck d0) { switch (this.gametype) { case Quest: - Constant.Runtime.HUMAN_DECK[0] = d0; - final DeckEditorQuest editor = new DeckEditorQuest(mainFrame, AllZone.getQuest()); - editor.show(this.cmdEditorExit); - editor.setVisible(true); - break; + Constant.Runtime.HUMAN_DECK[0] = d0; + final CEditorQuest qEditor = new CEditorQuest(AllZone.getQuest()); + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(qEditor); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_QUEST); + break; case Constructed: - final DeckEditorConstructed cEditor = - new DeckEditorConstructed(mainFrame); - cEditor.show(this.cmdEditorExit); - cEditor.getController().load(d0.getName()); - cEditor.setVisible(true); - break; - case Sealed: - final DeckEditorLimited sEditor = - new DeckEditorLimited(mainFrame, Singletons.getModel().getDecks().getSealed()); - sEditor.show(this.cmdEditorExit); - sEditor.getController().load(d0.getName()); - sEditor.setVisible(true); - break; - case Draft: - final DeckEditorLimited dEditor = - new DeckEditorLimited(mainFrame, Singletons.getModel().getDecks().getDraft()); - dEditor.show(this.cmdEditorExit); - dEditor.getController().load(d0.getName()); - dEditor.setVisible(true); - break; - default: - break; + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(new CEditorConstructed()); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_CONSTRUCTED); + CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController().getDeckController().load(d0.getName()); + break; + case Sealed: + final ACEditorBase sEditor = (ACEditorBase) + new CEditorLimited(Singletons.getModel().getDecks().getSealed()); + + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(sEditor); + + sEditor.getDeckController().load(d0.getName()); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_LIMITED); + break; + case Draft: + final ACEditorBase dEditor = (ACEditorBase) + new CEditorLimited(Singletons.getModel().getDecks().getDraft()); + CDeckEditorUI.SINGLETON_INSTANCE.setCurrentEditorController(dEditor); + + dEditor.getDeckController().load(d0.getName()); + FControl.SINGLETON_INSTANCE.changeState(FControl.DECK_EDITOR_LIMITED); + break; + default: + break; } } @@ -482,7 +481,7 @@ public class DeckLister extends JPanel { } this.remove(r0); - this.repaintOnlyThisPanel(); + this.repaintThis(); this.revalidate(); if (this.cmdDelete != null) { diff --git a/src/main/java/forge/gui/toolbox/FLabel.java b/src/main/java/forge/gui/toolbox/FLabel.java index 3129295760a..90724d6c3ed 100644 --- a/src/main/java/forge/gui/toolbox/FLabel.java +++ b/src/main/java/forge/gui/toolbox/FLabel.java @@ -7,6 +7,7 @@ import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; +import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; @@ -54,6 +55,8 @@ public class FLabel extends JLabel { private int bldFontStyle = Font.PLAIN; private int bldFontSize = 14; private float bldIconAlpha = 1.0f; + private int bldIconAlignX = SwingConstants.LEFT; + private Point bldIconInsets = new Point(0, 0); private boolean bldSelectable = false; private boolean bldHoverable = false; @@ -74,71 +77,81 @@ public class FLabel extends JLabel { // Begin builder methods. /**@param s0   {@link java.lang.String} * @return {@link forge.gui.toolbox.Builder} */ - public Builder text(String s0) { this.bldText = s0; return this; } + public Builder text(final String s0) { this.bldText = s0; return this; } /**@param s0   {@link java.lang.String} * @return {@link forge.gui.toolbox.Builder} */ - public Builder tooltip(String s0) { this.bldToolTip = s0; return this; } + public Builder tooltip(final String s0) { this.bldToolTip = s0; return this; } /**@param i0   {@link javax.swing.ImageIcon} * @return {@link forge.gui.toolbox.Builder} */ - public Builder icon(ImageIcon i0) { this.bldIcon = i0; return this; } + public Builder icon(final ImageIcon i0) { this.bldIcon = i0; return this; } /**@param i0   SwingConstants.CENTER, .LEFT, or .RIGHT * @return {@link forge.gui.toolbox.Builder} */ - public Builder fontAlign(int i0) { this.bldFontAlign = i0; return this; } + public Builder fontAlign(final int i0) { this.bldFontAlign = i0; return this; } /**@param b0   boolean * @return {@link forge.gui.toolbox.Builder} */ - public Builder opaque(boolean b0) { this.bldOpaque = b0; return this; } + public Builder opaque(final boolean b0) { this.bldOpaque = b0; return this; } /**@param b0   boolean * @return {@link forge.gui.toolbox.Builder} */ - public Builder hoverable(boolean b0) { this.bldHoverable = b0; return this; } + public Builder hoverable(final boolean b0) { this.bldHoverable = b0; return this; } /**@param b0   boolean * @return {@link forge.gui.toolbox.Builder} */ - public Builder selectable(boolean b0) { this.bldSelectable = b0; return this; } + public Builder selectable(final boolean b0) { this.bldSelectable = b0; return this; } /**@param c0   {@link forge.Command} to execute if clicked * @return {@link forge.gui.toolbox.Builder} */ - public Builder cmdClick(Command c0) { this.bldCmd = c0; return this; } + public Builder cmdClick(final Command c0) { this.bldCmd = c0; return this; } /**@param i0   int * @return {@link forge.gui.toolbox.Builder} */ - public Builder fontSize(int i0) { this.bldFontSize = i0; return this; } + public Builder fontSize(final int i0) { this.bldFontSize = i0; return this; } /**@param i0   Font.PLAIN, Font.BOLD, or Font.ITALIC * @return {@link forge.gui.toolbox.Builder} */ - public Builder fontStyle(int i0) { this.bldFontStyle = i0; return this; } + public Builder fontStyle(final int i0) { this.bldFontStyle = i0; return this; } /**@param b0   boolean * @return {@link forge.gui.toolbox.Builder} */ - public Builder fontScaleAuto(boolean b0) { this.bldFontScaleAuto = b0; return this; } + public Builder fontScaleAuto(final boolean b0) { this.bldFontScaleAuto = b0; return this; } /**@param d0   double between 0 and 1, 0.6 by default * @return {@link forge.gui.toolbox.Builder} */ - public Builder fontScaleFactor(double d0) { this.bldFontScaleFactor = d0; return this; } + public Builder fontScaleFactor(final double d0) { this.bldFontScaleFactor = d0; return this; } /**@param i0   SwingConstants.HORIZONTAL or .VERTICAL * @return {@link forge.gui.toolbox.Builder} */ - public Builder fontScaleBy(int i0) { this.bldFontScaleBy = i0; return this; } + public Builder fontScaleBy(final int i0) { this.bldFontScaleBy = i0; return this; } /**@param b0   boolean * @return {@link forge.gui.toolbox.Builder} */ - public Builder iconScaleAuto(boolean b0) { this.bldIconScaleAuto = b0; return this; } + public Builder iconScaleAuto(final boolean b0) { this.bldIconScaleAuto = b0; return this; } /**@param d0   double between 0 and 1, 0.8 by default * @return {@link forge.gui.toolbox.Builder} */ - public Builder iconScaleFactor(double d0) { this.bldIconScaleFactor = d0; return this; } + public Builder iconScaleFactor(final double d0) { this.bldIconScaleFactor = d0; return this; } /**@param b0   boolean, icon will be drawn independent of text * @return {@link forge.gui.toolbox.Builder} */ - public Builder iconInBackground(boolean b0) { this.bldIconInBackground = b0; return this; } + public Builder iconInBackground(final boolean b0) { this.bldIconInBackground = b0; return this; } /**@param f0   0.0f - 1.0f. If icon is in background, this alpha is applied. * @return {@link forge.gui.toolbox.Builder} */ - public Builder iconAlpha(float f0) { this.bldIconAlpha = f0; return this; } + public Builder iconAlpha(final float f0) { this.bldIconAlpha = f0; return this; } + + /**@param i0   Int. Only available for background icon. + * SwingConstants.HORIZONTAL .VERTICAL or .CENTER + * @return {@link forge.gui.toolbox.Builder} */ + public Builder iconAlignX(final int i0) { this.bldIconAlignX = i0; return this; } + + /**@param i0   Point. Only available for background icon. + * Additional padding to top left corner of icon, after alignX. + * @return {@link forge.gui.toolbox.Builder} */ + public Builder iconInsets(final Point i0) { this.bldIconInsets = i0; return this; } } //========== Constructors @@ -146,7 +159,7 @@ public class FLabel extends JLabel { protected FLabel() { } // Call this using FLabel.Builder()... - private FLabel(Builder b0) { + private FLabel(final Builder b0) { super(b0.bldText); // Init fields from builder @@ -158,6 +171,8 @@ public class FLabel extends JLabel { this.fontScaleAuto = b0.bldFontScaleAuto; this.iconScaleAuto = b0.bldIconScaleAuto; this.selectable = b0.bldSelectable; + this.iconAlignX = b0.bldIconAlignX; + this.iconInsets = b0.bldIconInsets; this.setFontScaleBy(b0.bldFontScaleBy); this.setFontStyle(b0.bldFontStyle); @@ -194,9 +209,10 @@ public class FLabel extends JLabel { // Custom properties, assigned either at realization (using builder) // or dynamically (using methods below). private double fontScaleFactor, iconScaleFactor; - private int fontScaleBy, fontStyle; + private int fontScaleBy, fontStyle, iconAlignX; private boolean selectable, selected, hoverable, hovered, opaque, iconInBackground, fontScaleAuto, iconScaleAuto; + private Point iconInsets; // Various variables used in image rendering. private Image img; @@ -209,30 +225,30 @@ public class FLabel extends JLabel { private final ActionListener fireResize = new ActionListener() { @Override - public void actionPerformed(ActionEvent evt) { resize(); resizeTimer.stop(); } + public void actionPerformed(final ActionEvent evt) { resize(); resizeTimer.stop(); } }; - private Timer resizeTimer = new Timer(10, fireResize); + private final Timer resizeTimer = new Timer(10, fireResize); // Resize adapter; on a timer to prevent resizing while "sliding" between sizes private final ComponentAdapter cadResize = new ComponentAdapter() { @Override - public void componentResized(ComponentEvent e) { resizeTimer.restart(); } + public void componentResized(final ComponentEvent e) { resizeTimer.restart(); } }; // Mouse event handler private final MouseAdapter madEvents = new MouseAdapter() { @Override - public void mouseEntered(MouseEvent e) { + public void mouseEntered(final MouseEvent e) { hovered = true; repaintOnlyThisLabel(); } @Override - public void mouseExited(MouseEvent e) { + public void mouseExited(final MouseEvent e) { hovered = false; repaintOnlyThisLabel(); } @Override - public void mouseClicked(MouseEvent e) { + public void mouseClicked(final MouseEvent e) { if (cmdClick != null && FLabel.this.isEnabled()) { cmdClick.execute(); } if (!selectable) { return; } if (selected) { setSelected(false); } @@ -243,7 +259,7 @@ public class FLabel extends JLabel { //========== Methods /** @param b0   boolean */ // Must be public. - public void setHoverable(boolean b0) { + public void setHoverable(final boolean b0) { this.hoverable = b0; if (!b0) { this.removeMouseListener(madEvents); } else { this.addMouseListener(madEvents); } @@ -251,7 +267,7 @@ public class FLabel extends JLabel { /** @param b0   boolean */ // Must be public. - public void setSelected(boolean b0) { + public void setSelected(final boolean b0) { this.selected = b0; repaintOnlyThisLabel(); } @@ -259,14 +275,14 @@ public class FLabel extends JLabel { /** Sets alpha if icon is in background. * @param f0   float */ // NOT public; must be set when label is built. - private void setIconAlpha(float f0) { + private void setIconAlpha(final float f0) { this.alphaDim = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, f0); this.alphaStrong = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f); } /** @param i0   int, must be SwingConstants.HORIZONTAL or VERTICAL */ // NOT public; must be set when label is built. - private void setFontScaleBy(int i0) { + private void setFontScaleBy(final int i0) { if (i0 != SwingConstants.HORIZONTAL && i0 != SwingConstants.VERTICAL) { throw new IllegalArgumentException("FLabel$setScaleBy " + "must be passed either SwingConstants.HORIZONTAL " @@ -276,7 +292,7 @@ public class FLabel extends JLabel { this.fontScaleBy = i0; } - private void setFontSize(int i0) { + private void setFontSize(final int i0) { switch(this.fontStyle) { case Font.BOLD: this.setFont(FSkin.getBoldFont(i0)); break; case Font.ITALIC: this.setFont(FSkin.getItalicFont(i0)); break; @@ -286,7 +302,7 @@ public class FLabel extends JLabel { /** @param i0   Font.PLAIN, .BOLD, or .ITALIC */ // NOT public; must be set when label is built. - private void setFontStyle(int i0) { + private void setFontStyle(final int i0) { if (i0 != Font.PLAIN && i0 != Font.BOLD && i0 != Font.ITALIC) { throw new IllegalArgumentException("FLabel$setFontStyle " + "must be passed either Font.PLAIN, Font.BOLD, or Font.ITALIC."); @@ -296,7 +312,7 @@ public class FLabel extends JLabel { /** @param i0   SwingConstants.CENTER, .LEFT or .RIGHT */ // NOT public; must be set when label is built. - private void setFontAlign(int i0) { + private void setFontAlign(final int i0) { if (i0 != SwingConstants.CENTER && i0 != SwingConstants.LEFT && i0 != SwingConstants.RIGHT) { throw new IllegalArgumentException("FLabel$setFontStyle " + "must be passed either SwingConstants.CENTER, " @@ -345,7 +361,7 @@ public class FLabel extends JLabel { } /** @param c0   {@link forge.Command} on click */ - public void setCommand(Command c0) { + public void setCommand(final Command c0) { this.cmdClick = c0; } @@ -363,7 +379,7 @@ public class FLabel extends JLabel { } @Override - public void paintComponent(Graphics g) { + public void paintComponent(final Graphics g) { g2d = (Graphics2D) g.create(); w = getWidth(); h = getHeight(); @@ -388,10 +404,16 @@ public class FLabel extends JLabel { // Icon in background if (iconInBackground) { - x = 3; - sh = (int) ((h - 2 * x) * iconScaleFactor); + sh = (int) (h * iconScaleFactor); sw = (int) (sh * iar); - y = (int) ((h - sh) / 2); + + if (iconAlignX == SwingConstants.CENTER) { + x = (int) ((w - sw) / 2 + iconInsets.getX()); + } + else { + x = (int) iconInsets.getX(); + } + y = (int) (((h - sh) / 2) + iconInsets.getY()); if (hoverable && hovered && !selected) { g2d.setComposite(alphaStrong); @@ -423,7 +445,7 @@ public class FLabel extends JLabel { // Non-background icon if (img != null && iconScaleAuto && !iconInBackground) { h = (int) (getHeight() * iconScaleFactor); - w = (int) (h * iar * iconScaleFactor); + w = (int) (h * iar); if (w == 0 || h == 0) { return; } FLabel.super.setIcon(new ImageIcon(img.getScaledInstance(w, h, Image.SCALE_SMOOTH))); diff --git a/src/main/java/forge/gui/toolbox/FSkin.java b/src/main/java/forge/gui/toolbox/FSkin.java index 2d5ec0dbdb1..c3feb9e69d4 100644 --- a/src/main/java/forge/gui/toolbox/FSkin.java +++ b/src/main/java/forge/gui/toolbox/FSkin.java @@ -214,8 +214,8 @@ public enum FSkin { ICO_ENDTURN (new int[] {320, 640, 80, 80}), /** */ ICO_CONCEDE (new int[] {240, 640, 80, 80}), /** */ ICO_REVERTLAYOUT (new int[] {400, 720, 80, 80}), /** */ - ICO_OPENLAYOUT (new int[] {480, 640, 80, 80}), - ICO_SAVELAYOUT (new int[] {480, 720, 80, 80}), + ICO_OPENLAYOUT (new int[] {480, 640, 80, 80}), /** */ + ICO_SAVELAYOUT (new int[] {480, 720, 80, 80}), /** */ ICO_DECKLIST (new int[] {400, 640, 80, 80}); private int[] coords; @@ -258,10 +258,16 @@ public enum FSkin { /** */ public enum ForgeIcons implements SkinProp { /** */ - ICO_EDIT (new int[] {640, 500, 20, 20}), /** */ - ICO_EDIT_OVER (new int[] {660, 500, 20, 20}), /** */ ICO_DELETE (new int[] {640, 480, 20, 20}), /** */ ICO_DELETE_OVER (new int[] {660, 480, 20, 20}), /** */ + ICO_EDIT (new int[] {640, 500, 20, 20}), /** */ + ICO_EDIT_OVER (new int[] {660, 500, 20, 20}), /** */ + ICO_OPEN (new int[] {660, 520, 20, 20}), /** */ + ICO_MINUS (new int[] {660, 620, 20, 20}), /** */ + ICO_NEW (new int[] {660, 540, 20, 20}), /** */ + ICO_PLUS (new int[] {660, 600, 20, 20}), /** */ + ICO_SAVE (new int[] {660, 560, 20, 20}), /** */ + ICO_SAVEAS (new int[] {660, 580, 20, 20}), /** */ ICO_UNKNOWN (new int[] {80, 720, 80, 80}), /** */ ICO_LOGO (new int[] {480, 0, 200, 200}), /** */ ICO_DEFAULT_MAGE (new int[] {0, 720, 80, 80}), /** */ @@ -277,11 +283,11 @@ public enum FSkin { /** */ public enum LayoutImages implements SkinProp { /** */ IMG_HANDLE (new int[] {320, 450, 80, 20}), /** */ - IMG_CUR_L (new int[] {644, 524, 32, 32}), /** */ - IMG_CUR_R (new int[] {644, 564, 32, 32}), /** */ - IMG_CUR_T (new int[] {644, 604, 32, 32}), /** */ - IMG_CUR_B (new int[] {644, 644, 32, 32}), /** */ - IMG_CUR_TAB (new int[] {644, 684, 32, 32}); + IMG_CUR_L (new int[] {564, 724, 32, 32}), /** */ + IMG_CUR_R (new int[] {564, 764, 32, 32}), /** */ + IMG_CUR_T (new int[] {604, 724, 32, 32}), /** */ + IMG_CUR_B (new int[] {604, 764, 32, 32}), /** */ + IMG_CUR_TAB (new int[] {644, 764, 32, 32}); private int[] coords; /** @param xy   int[] coordinates */ @@ -290,6 +296,24 @@ public enum FSkin { public int[] getCoords() { return coords; } } + /** */ + public enum EditorImages implements SkinProp { /** */ + IMG_ARTIFACT (new int[] {280, 720, 40, 40}), /** */ + IMG_CREATURE (new int[] {240, 720, 40, 40}), /** */ + IMG_ENCHANTMENT (new int[] {320, 720, 40, 40}), /** */ + IMG_INSTANT (new int[] {360, 720, 40, 40}), /** */ + IMG_LAND (new int[] {120, 720, 40, 40}), /** */ + IMG_MULTI (new int[] {80, 720, 40, 40}), /** */ + IMG_PLANESWALKER (new int[] {200, 720, 40, 40}), /** */ + IMG_SORCERY (new int[] {160, 720, 40, 40}); + + private int[] coords; + /** @param xy   int[] coordinates */ + EditorImages(final int[] xy) { this.coords = xy; } + /** @return int[] */ + public int[] getCoords() { return coords; } + } + /** */ public enum ButtonImages implements SkinProp { /** */ IMG_BTN_START_UP (new int[] {480, 200, 160, 80}), /** */ @@ -504,6 +528,7 @@ public enum FSkin { for (final ButtonImages e : ButtonImages.values()) { FSkin.setIcon(e); } for (final QuestIcons e : QuestIcons.values()) { FSkin.setIcon(e); } + for (final EditorImages e : EditorImages.values()) { FSkin.setImage(e); } for (final ManaImages e : ManaImages.values()) { FSkin.setImage(e); } for (final ColorlessManaImages e : ColorlessManaImages.values()) { FSkin.setImage(e); } for (final GameplayImages e : GameplayImages.values()) { FSkin.setImage(e); } @@ -515,6 +540,9 @@ public enum FSkin { // Assemble avatar images FSkin.assembleAvatars(); + // Table zebra striping + UIManager.put("Table.alternateRowColor", new Color(240, 240, 240)); + // Images loaded; can start UI init. SwingUtilities.invokeLater(new Runnable() { @Override diff --git a/src/main/java/forge/gui/toolbox/FTextArea.java b/src/main/java/forge/gui/toolbox/FTextArea.java index aca88632543..64f230bbb00 100644 --- a/src/main/java/forge/gui/toolbox/FTextArea.java +++ b/src/main/java/forge/gui/toolbox/FTextArea.java @@ -12,6 +12,7 @@ public class FTextArea extends JTextArea { public FTextArea() { super(); this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + this.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); this.setOpaque(false); this.setWrapStyleWord(true); this.setLineWrap(true); diff --git a/src/main/java/forge/gui/toolbox/FTextField.java b/src/main/java/forge/gui/toolbox/FTextField.java new file mode 100644 index 00000000000..1228bd0d554 --- /dev/null +++ b/src/main/java/forge/gui/toolbox/FTextField.java @@ -0,0 +1,20 @@ +package forge.gui.toolbox; + +import javax.swing.JTextField; + +/** + * A custom instance of JTextArea using Forge skin properties. + * + */ +@SuppressWarnings("serial") +public class FTextField extends JTextField { + /** */ + public FTextField() { + super(); + this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + this.setCaretColor(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + this.setOpaque(false); + this.setFocusable(false); + this.setEditable(false); + } +} diff --git a/src/main/java/forge/item/CardPrinted.java b/src/main/java/forge/item/CardPrinted.java index e7e03cf2502..425e0f05671 100644 --- a/src/main/java/forge/item/CardPrinted.java +++ b/src/main/java/forge/item/CardPrinted.java @@ -36,9 +36,10 @@ import forge.util.closures.Predicate; import forge.util.closures.PredicateString; /** - *

- * CardReference class. - *

+ * A viciously lightweight version of a card, for instances + * where a full set of meta and rules is not needed. + *

+ * The full set of rules is in the CardRules class. * * @author Forge * @version $Id: CardReference.java 9708 2011-08-09 19:34:12Z jendave $ @@ -164,8 +165,10 @@ public final class CardPrinted implements Comparable, InventoryItem return this.card.getType().toString(); } - // Lambda to get rules for selects from list of printed cards - /** The Constant fnGetRules. */ + /** + * Lambda to get rules for selects from list of printed cards. + * + */ public static final Lambda1 FN_GET_RULES = new Lambda1() { @Override public CardRules apply(final CardPrinted from) { diff --git a/src/main/java/forge/item/ItemPool.java b/src/main/java/forge/item/ItemPool.java index f7ba8d3271e..3a90bf2e643 100644 --- a/src/main/java/forge/item/ItemPool.java +++ b/src/main/java/forge/item/ItemPool.java @@ -227,6 +227,11 @@ public class ItemPool extends ItemPoolView { // need not set out-of-sync: either remove did set, or nothing was removed } + /** + * + * TODO: Write javadoc for this method. + * @param flat Iterable + */ public void removeAllFlat(final Iterable flat) { for (final T e : flat) { this.remove(e); diff --git a/src/main/java/forge/model/FModel.java b/src/main/java/forge/model/FModel.java index 1d7e6b15a4b..b660f262695 100644 --- a/src/main/java/forge/model/FModel.java +++ b/src/main/java/forge/model/FModel.java @@ -419,7 +419,7 @@ public enum FModel { fp.setPref(FPref.PHASE_HUMAN_EOT, String.valueOf(fieldViews.get(1).getLblEndTurn().getEnabled())); fp.setPref(FPref.PHASE_HUMAN_CLEANUP, String.valueOf(fieldViews.get(1).getLblCleanup().getEnabled())); - final VDev v = VMatchUI.SINGLETON_INSTANCE.getViewDevMode(); + final VDev v = VDev.SINGLETON_INSTANCE; Constant.Runtime.MILL[0] = v.getLblMilling().getEnabled(); fp.setPref(FPref.DEV_MILLING_LOSS, String.valueOf(Constant.Runtime.MILL[0])); diff --git a/src/main/java/forge/properties/NewConstants.java b/src/main/java/forge/properties/NewConstants.java index 5d6954cfc08..b0f09dfa2b4 100644 --- a/src/main/java/forge/properties/NewConstants.java +++ b/src/main/java/forge/properties/NewConstants.java @@ -43,8 +43,13 @@ public final class NewConstants { /** Constant CARDFORGE_URL = "program/cardforgeURL". */ public static final String CARDFORGE_URL = "program/cardforgeURL"; - /** Constant CARDFORGE_URL = "program/cardforgeURL". */ + /** Constant PREFERENCE_FILE = "forge.preferences". */ public static final String PREFERENCE_FILE = "forge.preferences"; + /** Constant PREFERENCE_FILE = "forge.preferences". */ + public static final String PREFERENCES_FILE_EDITOR = "editor.preferences"; + + /** Constant LAYOUT_DIR = "res/layouts/". */ + public static final String LAYOUT_DIR = "res/layouts/"; /** Constant DECKS="decks". */ public static final String DECKS = "decks"; @@ -60,6 +65,7 @@ public final class NewConstants { /** Constant CARD_PICTURES_A="card-pictures_a". */ public static final class CardPicturesByLetter { + /** */ public static final String CARD_PICTURES_A = "card-pictures_a"; /** Constant CARD_PICTURES_B="card-pictures_b". */ public static final String CARD_PICTURES_B = "card-pictures_b"; @@ -112,22 +118,15 @@ public final class NewConstants { /** Constant CARD_PICTURES_Z="card-pictures_z". */ public static final String CARD_PICTURES_Z = "card-pictures_z"; } - /** Constant CARD_PICTURES_OTHER="card-pictures_other". */ - public static final String CARD_PICTURES_OTHER = "card-pictures_other"; - /** Constant CARD_PICTURES_TOKEN_HQ="card-pictures_token_hq". */ - public static final String CARD_PICTURES_TOKEN_HQ = "card-pictures_token_hq"; + /** Constant TOKEN_IMAGES="token-images". */ public static final String TOKEN_IMAGES = "token-images"; - /** Constant CARDS="cards". */ - public static final String CARDS = "cards"; /** Constant CARDSFOLDER="cardsfolder". */ public static final String CARDSFOLDER = "cardsfolder"; /** Constant REMOVED="removed-cards". */ public static final String REMOVED = "removed-cards"; /** Constant NAME_MUTATOR="name-mutator". */ public static final String NAME_MUTATOR = "name-mutator"; - /** Constant BOOSTERDATA="boosterdata". */ - public static final String BOOSTERDATA = "boosterdata"; /** The file name of the image for face down cards on the battlefield. */ public static final String MORPH_IMAGE_FILE_NAME = "morph"; @@ -143,12 +142,10 @@ public final class NewConstants { public static final String IMAGE_TOKEN = "image/token"; /** Constant IMAGE_ICON="image/icon". */ public static final String IMAGE_ICON = "image/icon"; + /** Constant IMAGE_SEALED_PRODUCT="image/product". */ public static final String IMAGE_SEALED_PRODUCT = "image/product"; /** Constant PICS_BOOSTER_IMAGES="pics/booster/images". */ public static final String PICS_BOOSTER_IMAGES = "pics/booster/images"; - /** Constant SOUND_BASE="sound/base". */ - public static final String SOUND_BASE = "sound/base"; - /** * These properties are for a regular game. @@ -199,6 +196,7 @@ public final class NewConstants { /** The DECKS. */ public static final String DUELS = "quest/duels-dir"; + /** */ public static final String CHALLENGES = "quest/challenges-dir"; /** The XMLDATA. */ @@ -222,38 +220,12 @@ public final class NewConstants { /** */ public static final String PRECONS = "quest/precons-dir"; + /** */ public static final String BAZAAR = "quest/bazaar"; + /** */ public static final String BAZAAR_DIR = "quest/bazaar-dir"; } - /** - * These are GUI-related properties. - */ - public static class Gui { - - /** - * The Interface GuiDisplay. - */ - public static class GuiDisplay { - - /** The LAYOUT. */ - public static final String LAYOUT = "gui/Display"; - - /** The LAYOUT_NEW. */ - public static final String LAYOUT_NEW = "gui/Display/new"; - } - - /** - * The Interface GuiDeckEditor. - */ - public static class GuiDeckEditor { - - /** The LAYOUT. */ - public static final String LAYOUT = "gui/DeckEditor"; - - } - } - /** * These are localization properties. */ diff --git a/src/main/java/forge/quest/QuestUtilCards.java b/src/main/java/forge/quest/QuestUtilCards.java index ccf9a600297..e53ae18e44e 100644 --- a/src/main/java/forge/quest/QuestUtilCards.java +++ b/src/main/java/forge/quest/QuestUtilCards.java @@ -279,7 +279,7 @@ public final class QuestUtilCards { * * @return the sell mutliplier */ - public double getSellMutliplier() { + public double getSellMultiplier() { double multi = 0.20 + (0.001 * this.qc.getAchievements().getWin()); if (multi > 0.6) { multi = 0.6; diff --git a/src/main/java/forge/util/closures/Predicate.java b/src/main/java/forge/util/closures/Predicate.java index 9126cf68c3b..caf4971be01 100644 --- a/src/main/java/forge/util/closures/Predicate.java +++ b/src/main/java/forge/util/closures/Predicate.java @@ -26,7 +26,7 @@ import java.util.Map; /** * Predicate class allows to select items or type , which are or contain an * object of type , matching to some criteria set by predicate. No need to - * write that simple operations by hand. + * write that simple operation by hand. * * PS: com.google.common.base.Predicates contains almost the same functionality, * except for they keep filtering, transformations aside from the predicate in @@ -58,7 +58,9 @@ public abstract class Predicate { NOR, /** The NAND. */ NAND, + /** */ GT, + /** */ LT } @@ -84,9 +86,8 @@ public abstract class Predicate { LT_OR_EQUAL } - // This is the main method, predicates were made for. /** - * Checks if is true. + * This is the main method, predicates were made for. * * @param subject * the subject @@ -94,11 +95,10 @@ public abstract class Predicate { */ public abstract boolean isTrue(T subject); - // These are checks against constants, they will let build simpler - // expressions // Overloaded only in LeafConstant /** - * Checks if is 1. + * These are checks against constants, they will let simpler + * expressions be built. * * @return true, if is 1 */ @@ -675,7 +675,8 @@ public abstract class Predicate { // Static builder methods - they choose concrete implementation by // themselves /** - * Brigde. + * Brigde (transforms a predicate of type T into a predicate + * of type U, using a bridge function passed as an argument). * * @param * the generic type @@ -708,19 +709,6 @@ public abstract class Predicate { return new BridgeToInstance(predicate, clsTarget); } - /** - * Not. - * - * @param - * the generic type - * @param operand1 - * the operand1 - * @return the predicate - */ - public static Predicate not(final Predicate operand1) { - return new Not(operand1); - } - /** * Compose. * @@ -842,6 +830,32 @@ public abstract class Predicate { return new NodeOrBridged(operand1, operand2, bridge); } + /** + * Not. + * + * @param + * the generic type + * @param operand1 + * the operand1 + * @return the predicate + */ + public static Predicate not(final Predicate operand1) { + return new Not(operand1); + } + + /** + * Not. + * + * @param + * the generic type + * @param operand + * the operand + * @return the predicate + */ + public static Predicate not(final Iterable> operand) { + return new MultiNodeNot(operand); + } + /** * Gets the true. * @@ -1252,6 +1266,35 @@ final class MultiNodeOr extends MultiNode { } } + +/** + * + * TODO: Write javadoc for this type. + * + * @param + */ +final class MultiNodeNot extends MultiNode { + /** + * + * TODO: Write javadoc for Constructor. + * @param filters Iterable> + */ + public MultiNodeNot(final Iterable> filters) { + super(filters); + } + + @Override + public boolean isTrue(final T subject) { + for (final Predicate p : this.getOperands()) { + if (!p.isTrue(subject)) { + return true; + } + } + return false; + } +} + + /** * * TODO: Write javadoc for this type. diff --git a/src/main/java/forge/util/closures/PredicateInteger.java b/src/main/java/forge/util/closures/PredicateInteger.java new file mode 100644 index 00000000000..09278cb7896 --- /dev/null +++ b/src/main/java/forge/util/closures/PredicateInteger.java @@ -0,0 +1,75 @@ +/* + * Forge: Play Magic: the Gathering. + * Copyright (C) 2011 MaxMtg + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package forge.util.closures; + +/** + * Special predicate class to perform integer operations. + * + * @param + * the generic type + */ +public abstract class PredicateInteger extends Predicate { + + /** The operator. */ + private final ComparableOp operator; + + /** + * Op. + * + * @param op1 + * the op1 + * @param op2 + * the op2 + * @return true, if successful + */ + protected final boolean op(final int op1, final int op2) { + switch (this.getOperator()) { + case GREATER_THAN: + return op1 > op2; + case LESS_THAN: + return op1 < op2; + case GT_OR_EQUAL: + return op1 >= op2; + case LT_OR_EQUAL: + return op1 <= op2; + case EQUALS: + return op1 == op2; + case NOT_EQUALS: + return op1 != op2; + default: + return false; + } + } + + /** + * Instantiates a new integer predicate. + * + * @param operator + * the operator + */ + public PredicateInteger(final ComparableOp operator) { + this.operator = operator; + } + + /** + * @return the operator + */ + public ComparableOp getOperator() { + return operator; + } +} diff --git a/src/main/java/forge/view/FView.java b/src/main/java/forge/view/FView.java index 0b11d767f21..b667c98ebb8 100644 --- a/src/main/java/forge/view/FView.java +++ b/src/main/java/forge/view/FView.java @@ -19,11 +19,10 @@ import net.miginfocom.swing.MigLayout; import forge.AllZone; import forge.Singletons; import forge.control.FControl; +import forge.gui.deckeditor.VDeckEditorUI; import forge.gui.framework.DragCell; import forge.gui.framework.EDocID; import forge.gui.framework.SLayoutConstants; -import forge.gui.framework.SOverflowUtil; -import forge.gui.framework.SResizingUtil; import forge.gui.home.VHomeUI; import forge.gui.match.VMatchUI; import forge.gui.toolbox.FOverlay; @@ -38,7 +37,6 @@ public enum FView { private SplashFrame splash; // Non-singleton instances (deprecated, but not updated yet) - private ViewEditorUI editor = null; private ViewBazaarUI bazaar = null; // Top-level UI components; all have getters. @@ -63,7 +61,6 @@ public enum FView { /** */ public void initialize() { SplashFrame.PROGRESS_BAR.setDescription("Creating display components."); - Singletons.getView().cacheUIStates(); // Frame styling frmDocument.setMinimumSize(new Dimension(800, 600)); @@ -91,10 +88,12 @@ public enum FView { FOverlay.SINGLETON_INSTANCE.getPanel().setBackground(FSkin.getColor(FSkin.Colors.CLR_OVERLAY)); - // Populate all drag tabs. After they are realized, - // their controller can initialize actions on their components. + // Populate all drag tab components. + this.cacheUIStates(); + + // Initialize actions on all drag tab components (which should + // be realized / populated already). for (EDocID doc : EDocID.values()) { - if (doc.getDoc().getControl() == null) { continue; } doc.getDoc().getControl().initialize(); } @@ -105,11 +104,6 @@ public enum FView { FView.this.splash = null; frmDocument.setVisible(true); - - // TODO MOVE TO CONTROL! - // TODO delete FViewOld - lpnDocument.addMouseListener(SOverflowUtil.getHideOverflowListener()); - lpnDocument.addComponentListener(SResizingUtil.getWindowResizeListener()); } /** @return {@link javax.swing.JFrame} */ @@ -190,15 +184,6 @@ public enum FView { } } - /** @return {@link forge.view.ViewEditorUI} */ - public ViewEditorUI getViewEditor() { - if (Singletons.getControl().getState() != FControl.DEFAULT_EDITOR) { - throw new IllegalArgumentException("FView$getViewEditor\n" - + "may only be called while the editor UI is showing."); - } - return FView.this.editor; - } - /** @return {@link forge.view.ViewBazaarUI} */ public ViewBazaarUI getViewBazaar() { if (Singletons.getControl().getState() != FControl.QUEST_BAZAAR) { @@ -210,9 +195,9 @@ public enum FView { /** */ private void cacheUIStates() { - FView.this.editor = new ViewEditorUI(); FView.this.bazaar = new ViewBazaarUI(AllZone.getQuest().getBazaar()); VMatchUI.SINGLETON_INSTANCE.instantiate(); VHomeUI.SINGLETON_INSTANCE.instantiate(); + VDeckEditorUI.SINGLETON_INSTANCE.instantiate(); } }