Deck editor UI integration.
97
.gitattributes
vendored
@@ -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
|
||||
|
||||
2
.gitignore
vendored
@@ -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
|
||||
|
||||
32
editor.preferences
Normal file
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0"?>
|
||||
<preferences type="editor">
|
||||
<pref name="stats_deck" value="true"></pref>
|
||||
<pref name="stats_catalog" value="true"></pref>
|
||||
<col enumval="CAT_QUANTITY" identifier="Quantity" index="0" show="true" sortpriority="0" sortstate="NONE" width="56"></col>
|
||||
<col enumval="CAT_NAME" identifier="Name" index="1" show="true" sortpriority="1" sortstate="ASC" width="62"></col>
|
||||
<col enumval="CAT_COST" identifier="Cost" index="3" show="true" sortpriority="0" sortstate="NONE" width="54"></col>
|
||||
<col enumval="CAT_COLOR" identifier="Color" index="2" show="true" sortpriority="0" sortstate="NONE" width="65"></col>
|
||||
<col enumval="CAT_TYPE" identifier="Type" index="4" show="true" sortpriority="0" sortstate="ASC" width="72"></col>
|
||||
<col enumval="CAT_POWER" identifier="Power" index="5" show="true" sortpriority="0" sortstate="NONE" width="40"></col>
|
||||
<col enumval="CAT_TOUGHNESS" identifier="Toughness" index="6" show="true" sortpriority="0" sortstate="NONE" width="41"></col>
|
||||
<col enumval="CAT_CMC" identifier="CMC" index="7" show="true" sortpriority="0" sortstate="NONE" width="40"></col>
|
||||
<col enumval="CAT_RARITY" identifier="Rarity" index="7" show="false" sortpriority="0" sortstate="ASC" width="75"></col>
|
||||
<col enumval="CAT_SET" identifier="Set" index="9" show="false" sortpriority="0" sortstate="NONE" width="75"></col>
|
||||
<col enumval="CAT_AI" identifier="AI" index="10" show="false" sortpriority="0" sortstate="NONE" width="75"></col>
|
||||
<col enumval="CAT_NEW" identifier="New" index="8" show="true" sortpriority="0" sortstate="NONE" width="64"></col>
|
||||
<col enumval="CAT_PURCHASE_PRICE" identifier="Purchase Price" index="10" show="true" sortpriority="0" sortstate="NONE" width="75"></col>
|
||||
<col enumval="CAT_DECKS" identifier="Decks" index="9" show="true" sortpriority="0" sortstate="NONE" width="75"></col>
|
||||
<col enumval="DECK_QUANTITY" identifier="Quantity" index="0" show="true" sortpriority="0" sortstate="NONE" width="41"></col>
|
||||
<col enumval="DECK_NAME" identifier="Name" index="1" show="true" sortpriority="1" sortstate="ASC" width="102"></col>
|
||||
<col enumval="DECK_COST" identifier="Cost" index="2" show="true" sortpriority="0" sortstate="NONE" width="36"></col>
|
||||
<col enumval="DECK_COLOR" identifier="Color" index="5" show="true" sortpriority="0" sortstate="NONE" width="35"></col>
|
||||
<col enumval="DECK_TYPE" identifier="Type" index="4" show="true" sortpriority="0" sortstate="NONE" width="35"></col>
|
||||
<col enumval="DECK_POWER" identifier="Power" index="6" show="true" sortpriority="0" sortstate="NONE" width="34"></col>
|
||||
<col enumval="DECK_TOUGHNESS" identifier="Toughness" index="7" show="true" sortpriority="0" sortstate="NONE" width="31"></col>
|
||||
<col enumval="DECK_CMC" identifier="CMC" index="8" show="true" sortpriority="0" sortstate="NONE" width="34"></col>
|
||||
<col enumval="DECK_RARITY" identifier="Rarity" index="9" show="true" sortpriority="0" sortstate="NONE" width="30"></col>
|
||||
<col enumval="DECK_SET" identifier="Set" index="10" show="true" sortpriority="0" sortstate="NONE" width="30"></col>
|
||||
<col enumval="DECK_AI" identifier="AI" index="3" show="true" sortpriority="0" sortstate="NONE" width="37"></col>
|
||||
<col enumval="DECK_NEW" identifier="New" index="11" show="true" sortpriority="0" sortstate="NONE" width="64"></col>
|
||||
<col enumval="DECK_SALE_PRICE" identifier="Sale Price" index="12" show="true" sortpriority="1" sortstate="ASC" width="75"></col>
|
||||
</preferences>
|
||||
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.3 KiB |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 3.4 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 559 KiB After Width: | Height: | Size: 585 KiB |
@@ -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;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* CardOracle class.
|
||||
* </p>
|
||||
* 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<CardRules> 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<CardRules> 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<CardRules> wasPrintedInSets(final List<String> setCodes) {
|
||||
return new PredicateExitsInSets(setCodes);
|
||||
return new PredicateExistsInSets(setCodes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -568,7 +590,7 @@ public final class CardRules {
|
||||
* @return the predicate
|
||||
*/
|
||||
public static Predicate<CardRules> 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<CardRules> {
|
||||
private static class PredicateExistsInSets extends Predicate<CardRules> {
|
||||
private final List<String> sets;
|
||||
|
||||
public PredicateExitsInSets(final List<String> wantSets) {
|
||||
public PredicateExistsInSets(final List<String> wantSets) {
|
||||
this.sets = wantSets; // maybe should make a copy here?
|
||||
}
|
||||
|
||||
@@ -808,6 +830,9 @@ public final class CardRules {
|
||||
public static final Predicate<CardRules> IS_NON_CREATURE_SPELL = Predicate.compose(Presets.IS_CREATURE,
|
||||
PredicatesOp.NOR, Presets.IS_LAND);
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final Predicate<CardRules> IS_NONCREATURE_SPELL_FOR_GENERATOR = Predicate.or(Arrays.asList(
|
||||
Presets.IS_SORCERY, Presets.IS_INSTANT, Presets.IS_PLANESWALKER, Presets.IS_ENCHANTMENT,
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
113
src/main/java/forge/gui/deckeditor/CDeckEditorUI.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 <T> the generic type
|
||||
* @param <TModel> the generic type
|
||||
*/
|
||||
public abstract class DeckEditorBase<T extends InventoryItem, TModel extends DeckBase> 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<T> topTableWithCards;
|
||||
|
||||
/** The bottom. */
|
||||
private TableView<T> 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<T> getTopTableModel() {
|
||||
return this.getTopTableWithCards();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getTop()
|
||||
*/
|
||||
/**
|
||||
* Gets the top.
|
||||
*
|
||||
* @return the top
|
||||
*/
|
||||
public final ItemPoolView<T> 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<T> getBottom() {
|
||||
return this.getBottomTableWithCards().getCards();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the controller.
|
||||
*
|
||||
* @return the controller
|
||||
*/
|
||||
public abstract DeckController<TModel> 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<T> 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<CardPrinted> 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<T, TModel> 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<T> getBottomTableWithCards() {
|
||||
return this.bottomTableWithCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bottom table with cards.
|
||||
*
|
||||
* @param bottomTableWithCards0
|
||||
* the bottomTableWithCards to set
|
||||
*/
|
||||
public void setBottomTableWithCards(final TableView<T> bottomTableWithCards0) {
|
||||
this.bottomTableWithCards = bottomTableWithCards0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top table with cards.
|
||||
*
|
||||
* @return the topTableWithCards
|
||||
*/
|
||||
public TableView<T> getTopTableWithCards() {
|
||||
return this.topTableWithCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the top table with cards.
|
||||
*
|
||||
* @param topTableWithCards0
|
||||
* the topTableWithCards to set
|
||||
*/
|
||||
public void setTopTableWithCards(final TableView<T> topTableWithCards0) {
|
||||
this.topTableWithCards = topTableWithCards0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class DeckEditorConstructed extends DeckEditorBase<CardPrinted, Deck> {
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code>. */
|
||||
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<Deck> 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<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
|
||||
PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE,
|
||||
PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE,
|
||||
PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
|
||||
PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 60, PresetColumns.FN_STATS_COMPARE,
|
||||
PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("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<CardPrinted>("Available Cards", true, true, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Deck", true, CardPrinted.class));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
final Lambda0<Deck> newCreator = new Lambda0<Deck>() {
|
||||
@Override
|
||||
public Deck apply() {
|
||||
return new Deck();
|
||||
}
|
||||
};
|
||||
this.controller = new DeckController<Deck>(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<CardPrinted> buildFilter() {
|
||||
final Predicate<CardPrinted> 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<Deck> getController() {
|
||||
return this.controller;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $
|
||||
*/
|
||||
public final class DeckEditorLimited extends DeckEditorBase<CardPrinted, DeckGroup> {
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code>. */
|
||||
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<DeckGroup> 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<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
|
||||
PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE,
|
||||
PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE,
|
||||
PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
|
||||
PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 60, PresetColumns.FN_STATS_COMPARE,
|
||||
PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("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<DeckGroup> deckMap) {
|
||||
super(mainFrame);
|
||||
try {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(true));
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("Avaliable Cards", true, true, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Deck", true, CardPrinted.class));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
final Lambda0<DeckGroup> newCreator = new Lambda0<DeckGroup>() {
|
||||
@Override
|
||||
public DeckGroup apply() {
|
||||
return new DeckGroup("");
|
||||
}
|
||||
};
|
||||
this.controller = new DeckController<DeckGroup>(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<CardPrinted> buildFilter() {
|
||||
final Predicate<CardPrinted> 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<DeckGroup> 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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_Quest_DeckEditor class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class DeckEditorQuest extends DeckEditorBase<CardPrinted, Deck> {
|
||||
/** Constant <code>serialVersionUID=152061168634545L</code>. */
|
||||
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<Deck> 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)
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setup.
|
||||
* </p>
|
||||
*/
|
||||
public void setup() {
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
|
||||
PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.FN_NAME_COMPARE,
|
||||
PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE,
|
||||
PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
|
||||
PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.FN_STATS_COMPARE,
|
||||
PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("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<CardPrinted>("All Cards", true, true, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Your deck", true, CardPrinted.class));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
final Lambda0<Deck> newCreator = new Lambda0<Deck>() {
|
||||
@Override
|
||||
public Deck apply() {
|
||||
return new Deck();
|
||||
}
|
||||
};
|
||||
this.controller = new DeckController<Deck>(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<CardPrinted> buildFilter() {
|
||||
final Predicate<CardPrinted> 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<Deck> getController() {
|
||||
return this.controller;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
@Override
|
||||
public void updateView() {
|
||||
final Deck deck = this.controller.getModel();
|
||||
|
||||
final ItemPool<CardPrinted> cardpool = new ItemPool<CardPrinted>(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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <TItem>
|
||||
* @param <TModel>
|
||||
*/
|
||||
public class DeckImport extends JDialog {
|
||||
public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> 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<DeckRecognizer.Token> tokens = new ArrayList<DeckRecognizer.Token>();
|
||||
|
||||
private final DeckEditorConstructed host;
|
||||
private final ACEditorBase<TItem, TModel> 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<TItem, TModel> 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));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* DeckEditorDraft class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DraftingProcess extends DeckEditorBase<CardPrinted, DeckGroup> {
|
||||
/**
|
||||
* Constant <code>serialVersionUID=-6055633915602448260L</code>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addListeners.
|
||||
* </p>
|
||||
*/
|
||||
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()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setup.
|
||||
* </p>
|
||||
*/
|
||||
private void setup() {
|
||||
this.addListeners();
|
||||
// setupMenu();
|
||||
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
|
||||
PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 180, PresetColumns.FN_NAME_COMPARE,
|
||||
PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE,
|
||||
PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
|
||||
PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.FN_STATS_COMPARE,
|
||||
PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 35, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("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<CardPrinted>("Choose one card", false, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Previously picked cards", true, CardPrinted.class));
|
||||
this.setFilterBoxes(null);
|
||||
this.cardView = new CardPanelLite();
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* jbInit.
|
||||
* </p>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* jButton1_actionPerformed.
|
||||
* </p>
|
||||
*
|
||||
* @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 */
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* showChoices.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
private void showChoices(final ItemPoolView<CardPrinted> list) {
|
||||
this.getTopTableWithCards().setDeck(list);
|
||||
this.cardView.showCard(null);
|
||||
this.getTopTableWithCards().fixSelection(0);
|
||||
} // showChoices()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getPlayersDeck.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* saveDraft.
|
||||
* </p>
|
||||
*/
|
||||
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<CardPrinted> buildFilter() {
|
||||
return Predicate.getTrue(CardPrinted.class);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#getController()
|
||||
*/
|
||||
@Override
|
||||
public DeckController<DeckGroup> 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<InventoryItem>) null);
|
||||
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
|
||||
this.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @param <T> the generic type
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommonMenu.java 13590 2012-01-27 20:46:27Z Max mtg $
|
||||
*/
|
||||
public class MenuBase<T extends DeckBase> extends JMenuBar {
|
||||
|
||||
private static final long serialVersionUID = -4037993759604768755L;
|
||||
private final Command exitCommand;
|
||||
private final DeckController<T> controller;
|
||||
|
||||
/**
|
||||
* Menu for Deck Editor.
|
||||
*
|
||||
* @param ctrl the ctrl
|
||||
* @param exit a Command
|
||||
*/
|
||||
public MenuBase(final DeckController<T> ctrl, final Command exit) {
|
||||
this.controller = ctrl;
|
||||
this.exitCommand = exit;
|
||||
|
||||
this.setupMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the controller.
|
||||
*
|
||||
* @return the controller
|
||||
*/
|
||||
protected final DeckController<T> 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<String> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getUserInput_GetDeckName.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setupSortMenu.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -44,11 +26,11 @@ import forge.util.closures.Predicate;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class MenuCommon extends MenuBase<Deck> {
|
||||
public final class MenuCommon {
|
||||
|
||||
/** Constant <code>serialVersionUID=-4037993759604768755L</code>. */
|
||||
/** Constant <code>serialVersionUID=-4037993759604768755L</code>. *
|
||||
private static final long serialVersionUID = -4037993759604768755L;
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
/** Constant <code>previousDirectory</code>. *
|
||||
private static File previousDirectory = null;
|
||||
|
||||
/**
|
||||
@@ -58,7 +40,7 @@ public final class MenuCommon extends MenuBase<Deck> {
|
||||
* the ctrl
|
||||
* @param exit
|
||||
* a Command
|
||||
*/
|
||||
*
|
||||
public MenuCommon(final DeckController<Deck> ctrl, final Command exit) {
|
||||
super(ctrl, exit);
|
||||
|
||||
@@ -132,7 +114,7 @@ public final class MenuCommon extends MenuBase<Deck> {
|
||||
* <p>
|
||||
* exportDeck.
|
||||
* </p>
|
||||
*/
|
||||
*
|
||||
private void exportDeck() {
|
||||
final File filename = this.getExportFilename();
|
||||
if (filename == null) {
|
||||
@@ -168,7 +150,7 @@ public final class MenuCommon extends MenuBase<Deck> {
|
||||
* <p>
|
||||
* Generate Proxy for a Deck.
|
||||
* </p>
|
||||
*/
|
||||
*
|
||||
private void generateProxies() {
|
||||
final File filename = this.getProxiesFilename();
|
||||
if (filename == null) {
|
||||
@@ -206,7 +188,7 @@ public final class MenuCommon extends MenuBase<Deck> {
|
||||
* (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<Deck> {
|
||||
|
||||
return fileMenu;
|
||||
} // setupMenu()
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.DeckGroup;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommonMenu.java 13590 2012-01-27 20:46:27Z Max mtg $
|
||||
*/
|
||||
public final class MenuLimited extends MenuBase<DeckGroup> {
|
||||
|
||||
/** Constant <code>serialVersionUID=-4037993759604768755L</code>. */
|
||||
private static final long serialVersionUID = -4037993759604768755L;
|
||||
|
||||
/**
|
||||
* Menu for Deck Editor.
|
||||
*
|
||||
* @param ctrl the ctrl
|
||||
* @param exit a Command
|
||||
*/
|
||||
public MenuLimited(final DeckController<DeckGroup> ctrl, final Command exit) {
|
||||
super(ctrl, exit);
|
||||
}
|
||||
|
||||
// deck.setName(currentDeckName);
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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
|
||||
/**
|
||||
* <p>
|
||||
* Gui_Quest_DeckEditor_Menu class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MenuQuest extends MenuBase<Deck> {
|
||||
/** Constant <code>serialVersionUID=-4052319220021158574L</code>. */
|
||||
private static final long serialVersionUID = -4052319220021158574L;
|
||||
|
||||
// used for import and export, try to made the gui user friendly
|
||||
/** Constant <code>previousDirectory</code>. */
|
||||
private static File previousDirectory = null;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Gui_Quest_DeckEditor_Menu.
|
||||
* </p>
|
||||
*
|
||||
* @param d
|
||||
* a {@link forge.gui.deckeditor.IDeckDisplay} object.
|
||||
* @param exit
|
||||
* a {@link forge.Command} object.
|
||||
*/
|
||||
public MenuQuest(final DeckController<Deck> d, final Command exit) {
|
||||
super(d, exit);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* importDeck.
|
||||
* </p>
|
||||
*/
|
||||
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()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getImportFilename.
|
||||
* </p>
|
||||
*
|
||||
* @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<CardPrinted> uniqueCards = CardDb.instance().getAllUniqueCards();
|
||||
final List<String> cards = new ArrayList<String>();
|
||||
for (final CardPrinted c : uniqueCards) {
|
||||
cards.add(c.getName());
|
||||
}
|
||||
Collections.sort(cards);
|
||||
|
||||
// use standard forge's list selection dialog
|
||||
final ListChooser<String> c = new ListChooser<String>("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;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addImportExport.
|
||||
* </p>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<Comparable, Entry<InventoryItem, Integer>> FN_QTY_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getValue();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnQtyGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_QTY_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getValue();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnNameCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_NAME_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getName();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnNameGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_NAME_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> 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<Comparable, Entry<InventoryItem, Integer>> FN_COST_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toManaCost(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnCostGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_COST_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toManaCost(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnColorCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_COLOR_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toColor(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnColorGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_COLOR_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toColor(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnTypeCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_TYPE_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getType();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnTypeGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_TYPE_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getType();
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnStatsCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_STATS_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toPTL(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnStatsGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_STATS_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toPTL(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnRarityCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_RARITY_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toRarity(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnRarityGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_RARITY_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toRarity(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnSetCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_SET_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toSetCmp(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnSetGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_SET_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toSetStr(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnAiStatusCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_AI_STATUS_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toAiCmp(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** The Constant fnAiStatusGet. */
|
||||
public static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_AI_STATUS_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return PresetColumns.toAiStr(from.getKey());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_CardShop class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class QuestCardShop extends DeckEditorBase<InventoryItem, DeckBase> {
|
||||
/** Constant <code>serialVersionUID=3988857075791576483L</code>. */
|
||||
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<String, Integer> mapPrices = this.r.getPriceList();
|
||||
private Map<CardPrinted, Integer> 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<InventoryItem> forSale = this.questData.getCards().getShopList();
|
||||
if (forSale.isEmpty()) {
|
||||
this.questData.getCards().generateCardsInShop();
|
||||
forSale = this.questData.getCards().getShopList();
|
||||
}
|
||||
// newCardsList = questData.getCards().getNewCards();
|
||||
final ItemPool<InventoryItem> ownedItems = new ItemPool<InventoryItem>(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("<html>Selling cards at " + formatter.format(multiPercent)
|
||||
+ "% of their value.<br>" + maxSellingPrice + "</html>");
|
||||
|
||||
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<CardPrinted, Integer> countDecksForEachCard() {
|
||||
final Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>();
|
||||
for (final Deck deck : this.questData.getMyDecks()) {
|
||||
for (final Entry<CardPrinted, Integer> 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setup.
|
||||
* </p>
|
||||
*/
|
||||
private void setup() {
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
|
||||
PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 176, PresetColumns.FN_NAME_COMPARE,
|
||||
PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 70, PresetColumns.FN_COST_COMPARE,
|
||||
PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 50, PresetColumns.FN_COLOR_COMPARE,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
|
||||
PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 40, PresetColumns.FN_STATS_COMPARE,
|
||||
PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 35, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.get(2).setCellRenderer(new ManaCostRenderer());
|
||||
|
||||
final List<TableColumnInfo<InventoryItem>> columnsBelow = new ArrayList<TableColumnInfo<InventoryItem>>(columns);
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Price", 45, this.fnPriceCompare, this.fnPriceGet));
|
||||
this.getTopTableWithCards().setup(columns, this.getCardView());
|
||||
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("Dks", 30, this.fnDeckCompare, this.fnDeckGet));
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("New", 35, this.questData.getCards().getFnNewCompare(),
|
||||
this.questData.getCards().getFnNewGet()));
|
||||
columnsBelow.add(new TableColumnInfo<InventoryItem>("Price", 45, this.fnPriceCompare, this.fnPriceSellGet));
|
||||
this.getBottomTableWithCards().setup(columnsBelow, this.getCardView());
|
||||
|
||||
this.setSize(1024, 740);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Constructor for Gui_CardShop.
|
||||
* </p>
|
||||
*
|
||||
* @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<InventoryItem>("Cards for sale", false, false, InventoryItem.class));
|
||||
this.setBottomTableWithCards(new TableView<InventoryItem>("Owned Cards", false, InventoryItem.class));
|
||||
this.setCardView(new CardPanelLite());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* jbInit.
|
||||
* </p>
|
||||
*
|
||||
* @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<InventoryItem> buildFilter() {
|
||||
final Predicate<CardPrinted> cardFilter = Predicate.and(
|
||||
this.getFilterBoxes().buildFilter(),
|
||||
this.filterNameTypeSet.buildFilter());
|
||||
|
||||
// Until this is filterable, always show packs and decks in the card shop
|
||||
Predicate<InventoryItem> 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<CardPrinted> 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<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return QuestCardShop.this.getCardValue(from.getKey());
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return QuestCardShop.this.getCardValue(from.getKey());
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceSellGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return (int) (QuestCardShop.this.multiplier * QuestCardShop.this.getCardValue(from.getKey()));
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnDeckCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
final Integer iValue = QuestCardShop.this.decksUsingMyCards.get(from.getKey());
|
||||
return iValue == null ? Integer.valueOf(0) : iValue;
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnDeckGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> 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<DeckBase> getController() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
@Override
|
||||
public void updateView() {
|
||||
}
|
||||
|
||||
}
|
||||
303
src/main/java/forge/gui/deckeditor/SEditorIO.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(S at beginning of class name denotes a static factory.)</i>
|
||||
*/
|
||||
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<EditorPreference, Boolean> PREFS
|
||||
= new HashMap<EditorPreference, Boolean>();
|
||||
|
||||
private static final Map<ColumnName, TableColumnInfo<InventoryItem>> COLS
|
||||
= new TreeMap<ColumnName, TableColumnInfo<InventoryItem>>();
|
||||
|
||||
/**
|
||||
* Retrieve a preference from the editor preference map.
|
||||
*
|
||||
* @param name0   {@link forge.gui.deckeditor.SEditorUtil.EditorPreference}
|
||||
* @return TableColumnInfo<InventoryItem>
|
||||
*/
|
||||
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<InventoryItem>
|
||||
*/
|
||||
public static TableColumnInfo<InventoryItem> 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<DeckBase> controller = (DeckController<DeckBase>) 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<DeckBase>) 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 <TItem> extends InventoryItem
|
||||
* @param <TModel> 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<InventoryItem> 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<InventoryItem>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
149
src/main/java/forge/gui/deckeditor/SEditorUtil.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br>
|
||||
* <i>(S at beginning of class name denotes a static factory.)</i>
|
||||
*
|
||||
*/
|
||||
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 <T>   the generic type
|
||||
* @param deck   ItemPoolView<InventoryITem>
|
||||
* @param view   {@link forge.gui.deckeditor.views.ITableContainer}
|
||||
*/
|
||||
public static <T extends InventoryItem> void setStats(final ItemPoolView<T> 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);
|
||||
}
|
||||
}
|
||||
515
src/main/java/forge/gui/deckeditor/SFilterUtil.java
Normal file
@@ -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.
|
||||
* <br><br>
|
||||
* <i>(S at beginning of class name denotes a static factory.)</i>
|
||||
*/
|
||||
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<FilterProperty, ChbPnl> MAP_COLOR_CHECKBOXES =
|
||||
new HashMap<FilterProperty, ChbPnl>();
|
||||
|
||||
private static final Map<FilterProperty, ChbPnl> MAP_TYPE_CHECKBOXES =
|
||||
new HashMap<FilterProperty, ChbPnl>();
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
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.
|
||||
* <br><br>
|
||||
* Handles "multicolor" label, which is quite tricky.
|
||||
*
|
||||
* @return Predicate<CardPrinted>
|
||||
*/
|
||||
public static Predicate<CardPrinted> buildColorFilter() {
|
||||
if (MAP_COLOR_CHECKBOXES.isEmpty()) { return Predicate.getTrue(CardPrinted.class); }
|
||||
|
||||
final List<Predicate<CardRules>> ors = new ArrayList<Predicate<CardRules>>();
|
||||
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<CardPrinted> 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<CardPrinted> 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<CardPrinted>
|
||||
*/
|
||||
public static Predicate<CardPrinted> 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<CardPrinted> 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<CardPrinted>
|
||||
*/
|
||||
public static Predicate<CardPrinted> buildTypeFilter() {
|
||||
if (MAP_TYPE_CHECKBOXES.isEmpty()) { return Predicate.getTrue(CardPrinted.class); }
|
||||
|
||||
final List<Predicate<CardRules>> ors = new ArrayList<Predicate<CardRules>>();
|
||||
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<CardPrinted>
|
||||
*/
|
||||
public static Predicate<CardPrinted> buildTextFilter() {
|
||||
Predicate<CardPrinted> filterAnd = Predicate.getTrue(CardPrinted.class);
|
||||
Predicate<CardPrinted> 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<Predicate<CardPrinted>> ands = new ArrayList<Predicate<CardPrinted>>();
|
||||
|
||||
for (final String s : splitContains) {
|
||||
final List<Predicate<CardPrinted>> subands = new ArrayList<Predicate<CardPrinted>>();
|
||||
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<Predicate<CardPrinted>> nots = new ArrayList<Predicate<CardPrinted>>();
|
||||
|
||||
for (final String s : splitWithout) {
|
||||
final List<Predicate<CardPrinted>> subnots = new ArrayList<Predicate<CardPrinted>>();
|
||||
|
||||
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<CardPrinted>
|
||||
*/
|
||||
public static Predicate<CardPrinted> buildIntervalFilter() {
|
||||
final VFilters view = VFilters.SINGLETON_INSTANCE;
|
||||
Predicate<CardPrinted> 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<CardPrinted> prePower;
|
||||
final Predicate<CardPrinted> preToughness;
|
||||
final Predicate<CardPrinted> 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<CardPrinted> 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<CardPrinted> 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<CardPrinted> 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<CardPrinted> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
61
src/main/java/forge/gui/deckeditor/VDeckEditorUI.java
Normal file
@@ -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.<br>
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*
|
||||
*/
|
||||
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<Void, Void> w = new SwingWorker<Void, Void>() {
|
||||
@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();
|
||||
}
|
||||
}
|
||||
115
src/main/java/forge/gui/deckeditor/controllers/ACEditorBase.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* <br><br>
|
||||
* 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.
|
||||
*
|
||||
* <br><br><i>(A at beginning of class name denotes an abstract class.)</i>
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
* @param <TItem> extends {@link forge.item.InventoryItem}
|
||||
* @param <TModel> extends {@link forge.deck.DeckBase}
|
||||
*/
|
||||
public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends DeckBase> {
|
||||
|
||||
private TableView<TItem> tblCatalog;
|
||||
private TableView<TItem> 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<TModel> 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<TItem> 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<TItem> table0) {
|
||||
this.tblDeck = table0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the TableView holding the cards in the current catalog.
|
||||
*
|
||||
* @return {@link forge.gui.deckeditor.tables.TableView}
|
||||
*/
|
||||
public TableView<TItem> 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<TItem> table0) {
|
||||
this.tblCatalog = table0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
*/
|
||||
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 <TItem extends InventoryItem, TModel extends DeckBase> void importDeck() {
|
||||
final ACEditorBase<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
final DeckImport dImport = new DeckImport(ed);
|
||||
dImport.setModalityType(ModalityType.APPLICATION_MODAL);
|
||||
dImport.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
*/
|
||||
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() {
|
||||
}
|
||||
}
|
||||
202
src/main/java/forge/gui/deckeditor/controllers/CCurrentDeck.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
*/
|
||||
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<DeckBase>) 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<DeckBase>) 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<Deck>) 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;
|
||||
}
|
||||
}
|
||||
120
src/main/java/forge/gui/deckeditor/controllers/CDeckgen.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
*/
|
||||
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 <TItem extends InventoryItem, TModel extends DeckBase> 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<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
ed.getDeckController().setModel((TModel) randomDeck);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <TItem extends InventoryItem, TModel extends DeckBase> 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<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
ed.getDeckController().setModel((TModel) genConstructed);
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class CEditorConstructed extends ACEditorBase<CardPrinted, Deck> {
|
||||
private final DeckController<Deck> controller;
|
||||
|
||||
//=========== Constructor
|
||||
/**
|
||||
* Child controller for constructed deck editor UI.
|
||||
* This is the least restrictive mode;
|
||||
* all cards are available.
|
||||
*/
|
||||
public CEditorConstructed() {
|
||||
super();
|
||||
|
||||
final TableView<CardPrinted> tblCatalog = new TableView<CardPrinted>(true, CardPrinted.class);
|
||||
final TableView<CardPrinted> tblDeck = new TableView<CardPrinted>(true, CardPrinted.class);
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable());
|
||||
VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable());
|
||||
|
||||
this.setTableCatalog(tblCatalog);
|
||||
this.setTableDeck(tblDeck);
|
||||
|
||||
final Lambda0<Deck> newCreator = new Lambda0<Deck>() {
|
||||
@Override
|
||||
public Deck apply() {
|
||||
return new Deck();
|
||||
}
|
||||
};
|
||||
this.controller = new DeckController<Deck>(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<Deck> getDeckController() {
|
||||
return this.controller;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.ACEditorBase#show(forge.Command)
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
final List<TableColumnInfo<InventoryItem>> 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();
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class CEditorDraftingProcess extends ACEditorBase<CardPrinted, DeckGroup> {
|
||||
private IBoosterDraft boosterDraft;
|
||||
|
||||
//========== Constructor
|
||||
|
||||
/**
|
||||
* Updates the deck editor UI as necessary draft selection mode.
|
||||
*/
|
||||
public CEditorDraftingProcess() {
|
||||
final TableView<CardPrinted> tblCatalog = new TableView<CardPrinted>(true, CardPrinted.class);
|
||||
final TableView<CardPrinted> tblDeck = new TableView<CardPrinted>(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();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setup.
|
||||
* </p>
|
||||
*/
|
||||
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() {
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* showChoices.
|
||||
* </p>
|
||||
*
|
||||
* @param list
|
||||
* a {@link forge.CardList} object.
|
||||
*/
|
||||
private void showChoices(final ItemPoolView<CardPrinted> 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()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getPlayersDeck.
|
||||
* </p>
|
||||
*
|
||||
* @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()
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* saveDraft.
|
||||
* </p>
|
||||
*/
|
||||
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<DeckGroup> 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<InventoryItem>) null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.controllers.ACEditorBase#exit()
|
||||
*/
|
||||
@Override
|
||||
public boolean exit() {
|
||||
CSubmenuDraft.SINGLETON_INSTANCE.update();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $
|
||||
*/
|
||||
public final class CEditorLimited extends ACEditorBase<CardPrinted, DeckGroup> {
|
||||
|
||||
private final DeckController<DeckGroup> controller;
|
||||
|
||||
//========== Constructor
|
||||
|
||||
/**
|
||||
* Child controller for limited deck editor UI.
|
||||
*
|
||||
* @param deckMap0   {@link forge.deck.DeckGroup}<{@link forge.util.IStorage}>
|
||||
*/
|
||||
public CEditorLimited(final IStorage<DeckGroup> deckMap0) {
|
||||
final TableView<CardPrinted> tblCatalog = new TableView<CardPrinted>(true, CardPrinted.class);
|
||||
final TableView<CardPrinted> tblDeck = new TableView<CardPrinted>(true, CardPrinted.class);
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable());
|
||||
VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable());
|
||||
|
||||
this.setTableCatalog(tblCatalog);
|
||||
this.setTableDeck(tblDeck);
|
||||
|
||||
final Lambda0<DeckGroup> newCreator = new Lambda0<DeckGroup>() {
|
||||
@Override
|
||||
public DeckGroup apply() {
|
||||
return new DeckGroup("");
|
||||
}
|
||||
};
|
||||
this.controller = new DeckController<DeckGroup>(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<DeckGroup> 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;
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
*/
|
||||
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
|
||||
}
|
||||
204
src/main/java/forge/gui/deckeditor/controllers/CEditorQuest.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* <br><br>
|
||||
* Card catalog and decks are drawn from a QuestController object.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class CEditorQuest extends ACEditorBase<CardPrinted, Deck> {
|
||||
private final QuestController questData;
|
||||
private final DeckController<Deck> controller;
|
||||
|
||||
/**
|
||||
* Child controller for quest deck editor UI.
|
||||
* <br><br>
|
||||
* 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<CardPrinted> tblCatalog = new TableView<CardPrinted>(false, CardPrinted.class);
|
||||
final TableView<CardPrinted> tblDeck = new TableView<CardPrinted>(false, CardPrinted.class);
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable());
|
||||
VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable());
|
||||
|
||||
this.setTableCatalog(tblCatalog);
|
||||
this.setTableDeck(tblDeck);
|
||||
|
||||
final Lambda0<Deck> newCreator = new Lambda0<Deck>() {
|
||||
@Override
|
||||
public Deck apply() {
|
||||
return new Deck();
|
||||
}
|
||||
};
|
||||
this.controller = new DeckController<Deck>(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<CardPrinted> cardpool = new ItemPool<CardPrinted>(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<Deck> getDeckController() {
|
||||
return this.controller;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.gui.deckeditor.ACEditorBase#show(forge.Command)
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
final List<TableColumnInfo<InventoryItem>> columnsCatalog = SColumnUtil.getCatalogDefaultColumns();
|
||||
final List<TableColumnInfo<InventoryItem>> 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;
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: CEditorQuestCardShop.java 15088 2012-04-07 11:34:05Z Max mtg $
|
||||
*/
|
||||
public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, DeckBase> {
|
||||
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<String, Integer> mapPrices = this.r.getPriceList();
|
||||
private Map<CardPrinted, Integer> 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<InventoryItem> tblCatalog = new TableView<InventoryItem>(false, InventoryItem.class);
|
||||
final TableView<InventoryItem> tblDeck = new TableView<InventoryItem>(false, InventoryItem.class);
|
||||
|
||||
VCardCatalog.SINGLETON_INSTANCE.setTableView(tblCatalog.getTable());
|
||||
VCurrentDeck.SINGLETON_INSTANCE.setTableView(tblDeck.getTable());
|
||||
|
||||
this.setTableCatalog(tblCatalog);
|
||||
this.setTableDeck(tblDeck);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setup.
|
||||
* </p>
|
||||
*/
|
||||
private void setup() {
|
||||
final List<TableColumnInfo<InventoryItem>> columnsCatalog = SColumnUtil.getCatalogDefaultColumns();
|
||||
final List<TableColumnInfo<InventoryItem>> 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<CardPrinted, Integer> countDecksForEachCard() {
|
||||
final Map<CardPrinted, Integer> result = new HashMap<CardPrinted, Integer>();
|
||||
for (final Deck deck : this.questData.getMyDecks()) {
|
||||
for (final Entry<CardPrinted, Integer> 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<Comparable, Entry<InventoryItem, Integer>> fnPriceCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return CEditorQuestCardShop.this.getCardValue(from.getKey());
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return CEditorQuestCardShop.this.getCardValue(from.getKey());
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnPriceSellGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return (int) (CEditorQuestCardShop.this.multiplier * CEditorQuestCardShop.this.getCardValue(from.getKey()));
|
||||
}
|
||||
};
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private final Lambda1<Comparable, Entry<InventoryItem, Integer>> fnDeckCompare = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
final Integer iValue = CEditorQuestCardShop.this.decksUsingMyCards.get(from.getKey());
|
||||
return iValue == null ? Integer.valueOf(0) : iValue;
|
||||
}
|
||||
};
|
||||
private final Lambda1<Object, Entry<InventoryItem, Integer>> fnDeckGet = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> 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<CardPrinted> 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<DeckBase> 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<InventoryItem> forSale = this.questData.getCards().getShopList();
|
||||
if (forSale.isEmpty()) {
|
||||
this.questData.getCards().generateCardsInShop();
|
||||
forSale = this.questData.getCards().getShopList();
|
||||
}
|
||||
|
||||
// newCardsList = questData.getCards().getNewCards();
|
||||
final ItemPool<InventoryItem> ownedItems = new ItemPool<InventoryItem>(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("<html>Selling cards at " + formatter.format(multiPercent)
|
||||
+ "% of their value.<br>" + maxSellingPrice + "</html>");
|
||||
}
|
||||
|
||||
/* (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;
|
||||
}
|
||||
}
|
||||
176
src/main/java/forge/gui/deckeditor/controllers/CFilters.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
*/
|
||||
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 <TItem extends InventoryItem, TModel extends DeckBase> 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 <TItem>   extends InventoryItem
|
||||
* @param <TModel>   extends DeckBase
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <TItem extends InventoryItem, TModel extends DeckBase> void buildFilter() {
|
||||
// The main trick here is to apply a CardPrinted predicate
|
||||
// to the table. CardRules will lead to difficulties.
|
||||
final List<Predicate<CardPrinted>> lstFilters = new ArrayList<Predicate<CardPrinted>>();
|
||||
|
||||
final ACEditorBase<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
|
||||
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<TItem>) Predicate.and(lstFilters));
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
*/
|
||||
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 <T extends InventoryItem, TModel extends DeckBase> List<String> analyze() {
|
||||
final ACEditorBase<T, TModel> ed = (ACEditorBase<T, TModel>)
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(
|
||||
ed.getTableDeck().getCards(), CardPrinted.class);
|
||||
|
||||
final List<String> cardProbabilities = new ArrayList<String>();
|
||||
|
||||
final List<CardPrinted> shuffled = deck.toFlatList();
|
||||
Collections.shuffle(shuffled, MyRandom.getRandom());
|
||||
|
||||
// Log totals of each card for decrementing
|
||||
final Map<CardPrinted, Integer> cardTotals = new HashMap<CardPrinted, Integer>();
|
||||
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<CardPrinted> 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;
|
||||
}
|
||||
}
|
||||
191
src/main/java/forge/gui/deckeditor/controllers/CStatistics.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*
|
||||
*/
|
||||
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 <T extends InventoryItem, TModel extends DeckBase> void analyze() {
|
||||
final ACEditorBase<T, TModel> ed = (ACEditorBase<T, TModel>)
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
if (ed == null) { return; }
|
||||
|
||||
final ItemPoolView<CardPrinted> 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<CardPrinted, Integer> 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);
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 <code>previousDirectory</code>. */
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* changeStateButton_actionPerformed.
|
||||
* </p>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getImportFilename.
|
||||
* </p>
|
||||
*
|
||||
* @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"; }
|
||||
*
|
||||
* };
|
||||
*/
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* removePictureButton_actionPerformed
|
||||
* </p>
|
||||
* . 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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<JCheckBox> allColors;
|
||||
|
||||
/** The all types. */
|
||||
private final List<JCheckBox> 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<CardPrinted> buildFilter() {
|
||||
final List<Predicate<CardRules>> colors = new ArrayList<Predicate<CardRules>>();
|
||||
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<CardRules> filterByColor = colors.size() == 6 ? CardRules.Predicates.Presets.CONSTANT_TRUE
|
||||
: Predicate.or(colors);
|
||||
|
||||
final List<Predicate<CardRules>> types = new ArrayList<Predicate<CardRules>>();
|
||||
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<CardRules> 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<JCheckBox> 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<JCheckBox> 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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<CardPrinted> buildFilter() {
|
||||
final List<Predicate<CardPrinted>> rules = new ArrayList<Predicate<CardPrinted>>(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);
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 <T>
|
||||
* the generic type
|
||||
*/
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class TableColumnInfo<T> {
|
||||
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<Comparable, Entry<T, Integer>> fnSort; // this will be
|
||||
// used for
|
||||
// sorting
|
||||
|
||||
/** The fn display. */
|
||||
private final Lambda1<Object, Entry<T, Integer>> 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<Comparable, Entry<T, Integer>> fieldSort,
|
||||
final Lambda1<Object, Entry<T, Integer>> 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<Comparable, Entry<T, Integer>> fieldSort,
|
||||
final Lambda1<Object, Entry<T, Integer>> 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<Comparable, Entry<T, Integer>> fieldSort,
|
||||
final Lambda1<Object, Entry<T, Integer>> 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<Comparable, Entry<T, Integer>> getFnSort() {
|
||||
return this.fnSort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fn display.
|
||||
*
|
||||
* @return the fnDisplay
|
||||
*/
|
||||
public Lambda1<Object, Entry<T, Integer>> getFnDisplay() {
|
||||
return this.fnDisplay;
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TableModel class.
|
||||
* </p>
|
||||
*
|
||||
* @param <T>
|
||||
* the generic type
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public final class TableModel<T extends InventoryItem> 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<Order> orders = new ArrayList<Order>(3);
|
||||
private TableSorterCascade<InventoryItem> 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<InventoryItem> getSorter() {
|
||||
if (!this.isSorterReady) {
|
||||
final List<TableSorter<InventoryItem>> oneColSorters = new ArrayList<TableSorter<InventoryItem>>(this.maxDepth);
|
||||
for (final Order order : this.orders) {
|
||||
oneColSorters.add(new TableSorter<InventoryItem>(TableModel.this.columns.get(order.sortColumn).getFnSort(),
|
||||
order.isSortAsc));
|
||||
}
|
||||
this.sorter = new TableSorterCascade<InventoryItem>(oneColSorters);
|
||||
}
|
||||
return this.sorter;
|
||||
}
|
||||
}
|
||||
|
||||
private final ItemPool<T> data;
|
||||
private final CardPanelBase cardDisplay;
|
||||
private final List<TableColumnInfo<InventoryItem>> 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<TableColumnInfo<InventoryItem>> columnsToShow, final Class<T> cls) {
|
||||
this.data = new ItemPool<T>(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<InventoryItem> 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<T> getCards() {
|
||||
return this.data.getView();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* removeCard.
|
||||
* </p>
|
||||
*
|
||||
* @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<T, Integer> e) {
|
||||
this.data.add(e.getKey(), e.getValue());
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the cards.
|
||||
*
|
||||
* @param c
|
||||
* the c
|
||||
*/
|
||||
public void addCards(final Iterable<Entry<T, Integer>> c) {
|
||||
this.data.addAll(c);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the all cards.
|
||||
*
|
||||
* @param c
|
||||
* the c
|
||||
*/
|
||||
public void addAllCards(final Iterable<T> c) {
|
||||
this.data.addAllFlat(c);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Row to card.
|
||||
*
|
||||
* @param row
|
||||
* the row
|
||||
* @return the entry
|
||||
*/
|
||||
public Entry<T, Integer> rowToCard(final int row) {
|
||||
final List<Entry<T, Integer>> 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<InventoryItem, Integer>) 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addListeners.
|
||||
* </p>
|
||||
*
|
||||
* @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<Entry<T, Integer>> {
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
private TableSorterCascade<InventoryItem> sorter = TableModel.this.sortOrders.getSorter();
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int compare(Entry<T, Integer> o1, Entry<T, Integer> o2) {
|
||||
return sorter.compare((Entry<InventoryItem, Integer>) o1, (Entry<InventoryItem, Integer>) 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
|
||||
@@ -1,3 +0,0 @@
|
||||
/** Forge Card Game. */
|
||||
package forge.gui.deckeditor.elements;
|
||||
|
||||
@@ -15,15 +15,17 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<T extends DeckBase> {
|
||||
private boolean saved;
|
||||
private boolean modelInStore;
|
||||
private final IStorage<T> folder;
|
||||
private final DeckEditorBase<?, T> view;
|
||||
private final ACEditorBase<?, T> view;
|
||||
private final Lambda0<T> newModelCreator;
|
||||
|
||||
/**
|
||||
@@ -48,7 +50,7 @@ public class DeckController<T extends DeckBase> {
|
||||
* @param view0 the view0
|
||||
* @param newModelCreator0 the new model creator0
|
||||
*/
|
||||
public DeckController(final IStorage<T> folder0, final DeckEditorBase<?, T> view0,
|
||||
public DeckController(final IStorage<T> folder0, final ACEditorBase<?, T> view0,
|
||||
final Lambda0<T> newModelCreator0) {
|
||||
this.folder = folder0;
|
||||
this.view = view0;
|
||||
@@ -85,7 +87,12 @@ public class DeckController<T extends DeckBase> {
|
||||
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<T extends DeckBase> {
|
||||
*
|
||||
* @return the view
|
||||
*/
|
||||
public DeckEditorBase<?, T> getView() {
|
||||
public ACEditorBase<?, T> getView() {
|
||||
return this.view;
|
||||
}
|
||||
|
||||
@@ -127,20 +134,6 @@ public class DeckController<T extends DeckBase> {
|
||||
// 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<T extends DeckBase> {
|
||||
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<T extends DeckBase> {
|
||||
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<T extends DeckBase> {
|
||||
public void newModel() {
|
||||
this.model = this.newModelCreator.apply();
|
||||
this.saved = true;
|
||||
this.view.updateView();
|
||||
this.view.resetTables();
|
||||
}
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor.elements;
|
||||
package forge.gui.deckeditor.tables;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
530
src/main/java/forge/gui/deckeditor/tables/SColumnUtil.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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.
|
||||
* <br><br>
|
||||
* <i>(S at beginning of class name denotes a static factory.)</i>
|
||||
*
|
||||
*/
|
||||
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.
|
||||
* <br><br>
|
||||
* 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<TableColumnInfo<InventoryItem>> */
|
||||
public static List<TableColumnInfo<InventoryItem>> getCatalogDefaultColumns() {
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
|
||||
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<TableColumnInfo<InventoryItem>> */
|
||||
public static List<TableColumnInfo<InventoryItem>> getDeckDefaultColumns() {
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
|
||||
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<InventoryItem>
|
||||
* @param <TItem> extends InventoryItem
|
||||
* @param <TModel> extends DeckBase
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <TItem extends InventoryItem, TModel extends DeckBase>
|
||||
void toggleColumn(final TableColumnInfo<InventoryItem> col0) {
|
||||
|
||||
final ACEditorBase<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
|
||||
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<InventoryItem>
|
||||
*/
|
||||
public static TableColumnInfo<InventoryItem> 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 <TItem> extends InventoryItem
|
||||
* @param <TModel> extends InventoryItem
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <TItem extends InventoryItem, TModel extends DeckBase>
|
||||
int getColumnViewIndex(final ColumnName id0) {
|
||||
|
||||
final ACEditorBase<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
|
||||
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 <TItem> extends InventoryItem
|
||||
* @param <TModel> extends InventoryItem
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <TItem extends InventoryItem, TModel extends DeckBase>
|
||||
int getColumnModelIndex(final ColumnName id0) {
|
||||
|
||||
final ACEditorBase<TItem, TModel> ed = (ACEditorBase<TItem, TModel>)
|
||||
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<Comparable, Entry<InventoryItem, Integer>> FN_QTY_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getValue();
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnQtyGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_QTY_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getValue();
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnNameCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_NAME_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getName();
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnNameGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_NAME_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> 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<Comparable, Entry<InventoryItem, Integer>> FN_COST_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toManaCost(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnCostGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_COST_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toManaCost(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnColorCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_COLOR_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toColor(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnColorGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_COLOR_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toColor(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnTypeCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_TYPE_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getType();
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnTypeGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_TYPE_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return from.getKey().getType();
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnPowerCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_POWER_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toPower(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnPowerGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_POWER_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toPower(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnToughnessCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_TOUGHNESS_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toToughness(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnToughnessGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_TOUGHNESS_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toToughness(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnCMCCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_CMC_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toCMC(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnCMCGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_CMC_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toCMC(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnRarityCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_RARITY_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toRarity(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnRarityGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_RARITY_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toRarity(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnSetCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_SET_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toSetCmp(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnSetGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_SET_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toSetStr(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnAiStatusCompare. */
|
||||
@SuppressWarnings("rawtypes")
|
||||
private static final Lambda1<Comparable, Entry<InventoryItem, Integer>> FN_AI_STATUS_COMPARE = new Lambda1<Comparable, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Comparable apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toAiCmp(from.getKey());
|
||||
}
|
||||
};
|
||||
|
||||
/** Lamda sort fnAiStatusGet. */
|
||||
private static final Lambda1<Object, Entry<InventoryItem, Integer>> FN_AI_STATUS_GET = new Lambda1<Object, Entry<InventoryItem, Integer>>() {
|
||||
@Override
|
||||
public Object apply(final Entry<InventoryItem, Integer> from) {
|
||||
return SColumnUtil.toAiStr(from.getKey());
|
||||
}
|
||||
};
|
||||
}
|
||||
142
src/main/java/forge/gui/deckeditor/tables/TableColumnInfo.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 <T> a generic type
|
||||
*/
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "serial" })
|
||||
public class TableColumnInfo<T> extends TableColumn {
|
||||
private SortState sortstate = SortState.NONE;
|
||||
private int sortPriority = 0;
|
||||
private boolean show = true;
|
||||
private String enumval;
|
||||
|
||||
private Lambda1<Comparable, Entry<T, Integer>> fnSort;
|
||||
private Lambda1<Object, Entry<T, Integer>> 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<Comparable, Entry<T, Integer>> 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<Object, Entry<T, Integer>> 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<Comparable, Entry<T, Integer>> lambda0, final Lambda1<Object, Entry<T, Integer>> lambda1) {
|
||||
this.fnSort = lambda0;
|
||||
this.fnDisplay = lambda1;
|
||||
}
|
||||
}
|
||||
373
src/main/java/forge/gui/deckeditor/tables/TableModel.java
Normal file
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* TableModel class.
|
||||
* </p>
|
||||
*
|
||||
* @param <T>
|
||||
* the generic type
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public final class TableModel<T extends InventoryItem> extends AbstractTableModel {
|
||||
private final ItemPool<T> 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 <T>.
|
||||
*
|
||||
* @param table0   {@link javax.swing.JTable}
|
||||
* @param class0   Generic type <T>
|
||||
*/
|
||||
public TableModel(final JTable table0, final Class<T> class0) {
|
||||
this.table = table0;
|
||||
this.data = new ItemPool<T>(class0);
|
||||
}
|
||||
|
||||
/** */
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setup() {
|
||||
final Enumeration<TableColumn> e = table.getColumnModel().getColumns();
|
||||
final TableColumn[] sortcols = new TableColumn[table.getColumnCount()];
|
||||
|
||||
// Assemble priority sort.
|
||||
while (e.hasMoreElements()) {
|
||||
final TableColumnInfo<InventoryItem> col = (TableColumnInfo<InventoryItem>) e.nextElement();
|
||||
|
||||
if (col.getSortPriority() > 0) {
|
||||
sortcols[col.getSortPriority()] = col;
|
||||
}
|
||||
}
|
||||
|
||||
final boolean isDeckTable = ((TableColumnInfo<InventoryItem>) table.getColumnModel()
|
||||
.getColumn(0)).getEnumValue().substring(0, 4).equals("DECK")
|
||||
? true : false;
|
||||
|
||||
if (sortcols[1] == null) {
|
||||
if (isDeckTable) {
|
||||
cascadeManager.add((TableColumnInfo<T>) SColumnUtil.getColumn(ColumnName.DECK_NAME));
|
||||
}
|
||||
else {
|
||||
cascadeManager.add((TableColumnInfo<T>) SColumnUtil.getColumn(ColumnName.CAT_NAME));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ArrayUtils.reverse(sortcols);
|
||||
for (int i = 1; i < sortcols.length; i++) {
|
||||
if (sortcols[i] != null) {
|
||||
cascadeManager.add((TableColumnInfo<T>) 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<T> 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}<Entry<T, Integer>>
|
||||
*/
|
||||
public void addCards(final Iterable<Entry<T, Integer>> cards0) {
|
||||
this.data.addAll(cards0);
|
||||
this.fireTableDataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Row to card.
|
||||
*
|
||||
* @param row
|
||||
* the row
|
||||
* @return the entry
|
||||
*/
|
||||
public Entry<T, Integer> rowToCard(final int row) {
|
||||
final List<Entry<T, Integer>> 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addListeners.
|
||||
* </p>
|
||||
*/
|
||||
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<T>) 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<InventoryItem>) table.getColumnModel().getColumn(table.convertColumnIndexToView(iCol))).getFnDisplay().apply((Entry<InventoryItem, Integer>) this.rowToCard(iRow));
|
||||
}
|
||||
|
||||
//========= Custom class handling
|
||||
|
||||
/**
|
||||
* Manages sorting orders for multiple depths of sorting.
|
||||
*/
|
||||
private final class CascadeManager {
|
||||
private final List<TableColumnInfo<InventoryItem>> colsToSort = new ArrayList<TableColumnInfo<InventoryItem>>(3);
|
||||
private TableSorterCascade<InventoryItem> 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<T> 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<InventoryItem>) col0);
|
||||
}
|
||||
// No column in list; add directly.
|
||||
else {
|
||||
col0.setSortState(SortState.ASC);
|
||||
this.colsToSort.add(0, (TableColumnInfo<InventoryItem>) 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<InventoryItem> getSorter() {
|
||||
final List<TableSorter<InventoryItem>> oneColSorters
|
||||
= new ArrayList<TableSorter<InventoryItem>>(maxSortDepth);
|
||||
|
||||
for (final TableColumnInfo<InventoryItem> col : this.colsToSort) {
|
||||
oneColSorters.add(new TableSorter<InventoryItem>(
|
||||
col.getFnSort(),
|
||||
col.getSortState().equals(SortState.ASC) ? true : false));
|
||||
}
|
||||
|
||||
this.sorter = new TableSorterCascade<InventoryItem>(oneColSorters);
|
||||
return this.sorter;
|
||||
}
|
||||
}
|
||||
|
||||
private class MyComparator implements Comparator<Entry<T, Integer>> {
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public int compare(Entry<T, Integer> o1, Entry<T, Integer> o2) {
|
||||
return TableModel.this.cascadeManager.getSorter().compare(
|
||||
(Entry<InventoryItem, Integer>) o1, (Entry<InventoryItem, Integer>) o2);
|
||||
}
|
||||
}
|
||||
} // CardTableModel
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor.elements;
|
||||
package forge.gui.deckeditor.tables;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map.Entry;
|
||||
@@ -15,7 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package forge.gui.deckeditor.elements;
|
||||
package forge.gui.deckeditor.tables;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -15,24 +15,23 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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<T extends InventoryItem> {
|
||||
|
||||
/** The pool. */
|
||||
private ItemPool<T> pool;
|
||||
|
||||
/** The model. */
|
||||
private TableModel<T> 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<T> filter = null;
|
||||
|
||||
/** The is tracking stats. */
|
||||
private boolean isTrackingStats = false;
|
||||
|
||||
/** The want unique. */
|
||||
private boolean wantUnique = false;
|
||||
|
||||
private final Class<T> 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<T extends InventoryItem> {
|
||||
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<T> cls) {
|
||||
this(title, showStats, false, cls);
|
||||
public TableView(final Class<T> 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<T> 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<T> 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<TableColumnInfo<InventoryItem>>
|
||||
* @param cardView
|
||||
* a CardPanelBase
|
||||
* @param view0   the {@link javax.gui.deckeditor.views.ITableCOntainer}
|
||||
* @param cols0   List<TableColumnInfo<InventoryItem>> of additional columns for this
|
||||
*/
|
||||
public void setup(final List<TableColumnInfo<InventoryItem>> columns, final CardPanelBase cardView) {
|
||||
this.model = new TableModel<T>(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<TableColumnInfo<InventoryItem>> 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<TableColumn> unknownCols = new ArrayList<TableColumn>();
|
||||
|
||||
for (final TableColumn c : cols0) {
|
||||
if (!((TableColumnInfo<InventoryItem>) 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<T> 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 <T>
|
||||
* the generic type
|
||||
* @param deck
|
||||
* an ItemPoolView<InventoryITem>
|
||||
* @return String
|
||||
*/
|
||||
public static <T extends InventoryItem> String getStats(final ItemPoolView<T> 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<Predicate<CardRules>> 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<T> sort(final int iCol) {
|
||||
return this.sort(iCol, true);
|
||||
}
|
||||
this.model = new TableModel<T>(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<T> 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<T> deck = TableView.this.model.getCards().toFlatList();
|
||||
final ItemPool<T> filteredDeck = new ItemPool<T>((Class<T>) 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<T extends InventoryItem> {
|
||||
this.model.addCards(this.pool);
|
||||
}
|
||||
|
||||
this.model.resort();
|
||||
this.model.refreshSort();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,3 @@
|
||||
/** Forge Card Game. */
|
||||
package forge.gui.deckeditor.tables;
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
* <br><br><i>(I at beginning of class name denotes an interface.)</i>
|
||||
*
|
||||
*/
|
||||
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();
|
||||
}
|
||||
110
src/main/java/forge/gui/deckeditor/views/VAllDecks.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
315
src/main/java/forge/gui/deckeditor/views/VCardCatalog.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
406
src/main/java/forge/gui/deckeditor/views/VCurrentDeck.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
128
src/main/java/forge/gui/deckeditor/views/VDeckgen.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
225
src/main/java/forge/gui/deckeditor/views/VEditorPreferences.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*/
|
||||
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
|
||||
|
||||
}
|
||||
306
src/main/java/forge/gui/deckeditor/views/VFilters.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*/
|
||||
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
|
||||
|
||||
}
|
||||
198
src/main/java/forge/gui/deckeditor/views/VProbabilities.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*/
|
||||
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<String> 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 <T extends InventoryItem, TModel extends DeckBase> 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<T, TModel> ed = (ACEditorBase<T, TModel>)
|
||||
CDeckEditorUI.SINGLETON_INSTANCE.getCurrentEditorController();
|
||||
|
||||
final List<CardPrinted> cards = (List<CardPrinted>) 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;
|
||||
}
|
||||
}
|
||||
271
src/main/java/forge/gui/deckeditor/views/VStatistics.java
Normal file
@@ -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.
|
||||
*
|
||||
* <br><br><i>(V at beginning of class name denotes a view class.)</i>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
* <br><br><i>(E at beginning of class name denotes an enum.)</i>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.<br><br>
|
||||
*
|
||||
* be done once, but require non-null view components.
|
||||
* <br><br>
|
||||
* This method should only be called once, in FView, after singletons are populated.
|
||||
*/
|
||||
void initialize();
|
||||
|
||||