diff --git a/Mage.Client/src/main/java/mage/client/cards/CardGrid.java b/Mage.Client/src/main/java/mage/client/cards/CardGrid.java index cba0457e0a1..613a5bd0d0a 100644 --- a/Mage.Client/src/main/java/mage/client/cards/CardGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/CardGrid.java @@ -51,6 +51,7 @@ import java.util.Map.Entry; import mage.cards.MageCard; import mage.client.constants.Constants.SortBy; +import mage.client.deckeditor.SortSetting; import mage.client.plugins.impl.Plugins; import mage.client.util.Config; import mage.client.util.Event; @@ -81,12 +82,12 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener, setOpaque(false); } @Override - public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) { - this.loadCards(showCards, sortBy, piles, bigCard, gameId, true); + public void loadCards(CardsView showCards, SortSetting sortSetting, boolean piles, BigCard bigCard, UUID gameId) { + this.loadCards(showCards, sortSetting, piles, bigCard, gameId, true); } @Override - public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId, boolean merge) { + public void loadCards(CardsView showCards, SortSetting sortSetting, boolean piles, BigCard bigCard, UUID gameId, boolean merge) { boolean drawImage = showCards.size() < MAX_IMAGES; this.bigCard = bigCard; this.gameId = gameId; @@ -110,7 +111,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener, } } System.gc(); - drawCards(sortBy, piles); + drawCards(sortSetting, piles); this.setVisible(true); } @@ -127,7 +128,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener, } @Override - public void drawCards(SortBy sortBy, boolean piles) { + public void drawCards(SortSetting sortSetting, boolean piles) { int maxWidth = this.getParent().getWidth(); int numColumns = maxWidth / Config.dimensions.frameWidth; int curColumn = 0; @@ -135,7 +136,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener, if (cards.size() > 0) { Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight); List sortedCards = new ArrayList(cards.values()); - switch (sortBy) { + switch (sortSetting.getSortBy()) { case NAME: Collections.sort(sortedCards, new CardNameComparator()); break; @@ -158,7 +159,7 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener, if (lastCard == null) { lastCard = cardImg; } - switch (sortBy) { + switch (sortSetting.getSortBy()) { case NAME: if (!cardImg.getOriginal().getName().equals(lastCard.getOriginal().getName())) { curColumn++; diff --git a/Mage.Client/src/main/java/mage/client/cards/CardsList.java b/Mage.Client/src/main/java/mage/client/cards/CardsList.java index 823ba16706b..dd815b0e43a 100644 --- a/Mage.Client/src/main/java/mage/client/cards/CardsList.java +++ b/Mage.Client/src/main/java/mage/client/cards/CardsList.java @@ -49,7 +49,9 @@ import javax.swing.*; import javax.swing.table.DefaultTableCellRenderer; import mage.constants.CardType; import mage.cards.MageCard; +import mage.client.constants.Constants; import mage.client.constants.Constants.SortBy; +import mage.client.deckeditor.SortSetting; import mage.client.deckeditor.table.TableModel; import mage.client.deckeditor.table.UpdateCountsCallback; import mage.client.dialog.PreferencesDialog; @@ -70,6 +72,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar private CardsView cards; protected BigCard bigCard; protected UUID gameId; + private SortSetting sortSetting; private TableModel mainModel; private JTable mainTable; @@ -171,22 +174,18 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar boolean piles = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_PILES_TOGGLE, "True").equals("True"); chkPiles.setSelected(piles); - - SortBy sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_SORT_BY, "Color")); - cbSortBy.setSelectedIndex(sortBy.ordinal()); - - currentView.loadCards(showCards, sortBy, piles, bigCard, gameId); + currentView.loadCards(showCards, sortSetting, piles, bigCard, gameId); } private void redrawCards() { if (cards == null) { cards = new CardsView(); } - currentView.loadCards(cards, null, false, bigCard, gameId); + currentView.loadCards(cards, sortSetting, false, bigCard, gameId); } @Override - public void drawCards(SortBy sortBy, boolean piles) { + public void drawCards(SortSetting sortSetting, boolean piles) { int maxWidth = this.getParent().getWidth(); int numColumns = maxWidth / Config.dimensions.frameWidth; int curColumn = 0; @@ -199,7 +198,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar if (cards != null && cards.size() > 0) { Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight); List sortedCards = new ArrayList(cards.values()); - switch (sortBy) { + switch (sortSetting.getSortBy()) { case NAME: Collections.sort(sortedCards, new CardViewNameComparator()); break; @@ -222,7 +221,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar if (lastCard == null) { lastCard = card; } - switch (sortBy) { + switch (sortSetting.getSortBy()) { case NAME: if (!card.getName().equals(lastCard.getName())) { curColumn++; @@ -312,21 +311,21 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar mainModel.addCardEventListener(listener); } - public void drawCards(SortBy sortBy) { - drawCards(sortBy, false); + public void drawCards(SortSetting sortSetting) { + drawCards(sortSetting, false); } @Override - public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) { - this.loadCards(showCards, sortBy, piles, bigCard, gameId, true); + public void loadCards(CardsView showCards, SortSetting sortSetting, boolean piles, BigCard bigCard, UUID gameId) { + this.loadCards(showCards, sortSetting, piles, bigCard, gameId, true); } @Override - public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId, boolean merge) { + public void loadCards(CardsView showCards, SortSetting sortSetting, boolean piles, BigCard bigCard, UUID gameId, boolean merge) { cards = showCards; this.bigCard = bigCard; this.gameId = gameId; - drawCards((SortBy) cbSortBy.getSelectedItem()); + drawCards(sortSetting); } @Override @@ -456,12 +455,12 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar }// //GEN-END:initComponents private void cbSortByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortByActionPerformed - drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); - PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_SORT_BY, cbSortBy.getSelectedItem().toString()); + sortSetting.setSortBy((SortBy) cbSortBy.getSelectedItem()); + drawCards(sortSetting, chkPiles.isSelected()); }//GEN-LAST:event_cbSortByActionPerformed private void chkPilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPilesActionPerformed - drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); + drawCards(sortSetting, chkPiles.isSelected()); PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_PILES_TOGGLE, (chkPiles.isSelected()?"True":"False")); }//GEN-LAST:event_chkPilesActionPerformed @@ -545,4 +544,15 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar public int cardsSize() { return cards.size(); } + + public void setSortBy(SortBy sortBy) { + if (sortBy != null) { + cbSortBy.setSelectedIndex(sortBy.ordinal()); + } + } + + public void setSortSetting(SortSetting sortSetting) { + this.sortSetting = sortSetting; + } + } diff --git a/Mage.Client/src/main/java/mage/client/cards/ICardGrid.java b/Mage.Client/src/main/java/mage/client/cards/ICardGrid.java index 03740b749e7..244449dc57d 100644 --- a/Mage.Client/src/main/java/mage/client/cards/ICardGrid.java +++ b/Mage.Client/src/main/java/mage/client/cards/ICardGrid.java @@ -28,13 +28,12 @@ package mage.client.cards; -import mage.client.constants.Constants; +import java.util.UUID; +import mage.client.deckeditor.SortSetting; import mage.client.util.Event; import mage.client.util.Listener; import mage.view.CardsView; -import java.util.UUID; - /** * Interface for card container. * @@ -44,9 +43,9 @@ import java.util.UUID; public interface ICardGrid { void clearCardEventListeners(); void addCardEventListener(Listener listener); - void drawCards(Constants.SortBy sortBy, boolean piles); - void loadCards(CardsView showCards, Constants.SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId); - void loadCards(CardsView showCards, Constants.SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId, boolean merge); + void drawCards(SortSetting sortSetting, boolean piles); + void loadCards(CardsView showCards, SortSetting sortSetting, boolean piles, BigCard bigCard, UUID gameId); + void loadCards(CardsView showCards, SortSetting sortSetting, boolean piles, BigCard bigCard, UUID gameId, boolean merge); void refresh(); int cardsSize(); } diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form index 508d28bc2fe..f4360c3002b 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form +++ b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form @@ -338,7 +338,7 @@ - + diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java index e4191a4b843..a6ae1ffe669 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java @@ -167,7 +167,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene jButtonAddToSideboard.setEnabled(false); filterCards(); chkPiles.setSelected(true); - this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); + this.currentView.drawCards(SortSettingBase.getInstance(), chkPiles.isSelected()); } public void loadSideboard(List sideboard, BigCard bigCard) { @@ -180,7 +180,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene for (Card card: sideboard) { this.cards.add(card); } - switchToGrid(); filterCards(); } @@ -329,7 +328,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene if (currentView instanceof CardGrid && filteredCards.size() > CardGrid.MAX_IMAGES) { this.toggleViewMode(); } - this.currentView.loadCards(new CardsView(filteredCards), (SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected(), bigCard, null, false); + this.currentView.loadCards(new CardsView(filteredCards), SortSettingBase.getInstance(), chkPiles.isSelected(), bigCard, null, false); this.cardCount.setText(String.valueOf(filteredCards.size())); } finally { @@ -845,13 +844,14 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene private void cbSortByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortByActionPerformed if (cbSortBy.getSelectedItem() instanceof SortBy) { - this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); + SortSettingBase.getInstance().setSortBy((SortBy) cbSortBy.getSelectedItem()); + this.currentView.drawCards(SortSettingBase.getInstance(), chkPiles.isSelected()); } }//GEN-LAST:event_cbSortByActionPerformed private void chkPilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPilesActionPerformed if (cbSortBy.getSelectedItem() instanceof SortBy) { - this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); + this.currentView.drawCards(SortSettingBase.getInstance(), chkPiles.isSelected()); } }//GEN-LAST:event_chkPilesActionPerformed @@ -1012,28 +1012,28 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene @Override public void componentResized(ComponentEvent e) { if (cbSortBy.getSelectedItem() instanceof SortBy) { - this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); + this.currentView.drawCards(SortSettingBase.getInstance(), chkPiles.isSelected()); } } @Override public void componentMoved(ComponentEvent e) { if (cbSortBy.getSelectedItem() instanceof SortBy) { - this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); + this.currentView.drawCards(SortSettingBase.getInstance(), chkPiles.isSelected()); } } @Override public void componentShown(ComponentEvent e) { if (cbSortBy.getSelectedItem() instanceof SortBy) { - this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); + this.currentView.drawCards(SortSettingBase.getInstance(), chkPiles.isSelected()); } } @Override public void componentHidden(ComponentEvent e) { if (cbSortBy.getSelectedItem() instanceof SortBy) { - this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); + this.currentView.drawCards(SortSettingBase.getInstance(), chkPiles.isSelected()); } } diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckArea.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckArea.java index 6ad317716b4..3d5b42babb2 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckArea.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckArea.java @@ -52,6 +52,8 @@ public class DeckArea extends javax.swing.JPanel { public DeckArea() { initComponents(); jSplitPane1.setOpaque(false); + deckList.setSortSetting(SortSettingDeck.getInstance()); + sideboardList.setSortSetting(SortSettingSideboard.getInstance()); deckList.setOpaque(false); sideboardList.setOpaque(false); deckList.setDisplayNoCopies(true); diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java b/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java index a789791664b..3f5c20e2a28 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/DeckEditorPanel.java @@ -27,30 +27,6 @@ */ package mage.client.deckeditor; -import mage.cards.Card; -import mage.cards.decks.Deck; -import mage.cards.decks.importer.DeckImporter; -import mage.cards.decks.importer.DeckImporterUtil; -import mage.cards.repository.CardInfo; -import mage.cards.repository.CardRepository; -import mage.client.MageFrame; -import mage.client.cards.BigCard; -import mage.client.cards.ICardGrid; -import mage.client.constants.Constants.DeckEditorMode; -import mage.client.dialog.AddLandDialog; -import mage.client.plugins.impl.Plugins; -import mage.client.util.Event; -import mage.client.util.Listener; -import mage.components.CardInfoPane; -import mage.game.GameException; -import mage.remote.Session; -import mage.cards.Sets; -import mage.view.CardView; -import mage.view.SimpleCardView; -import org.apache.log4j.Logger; - -import javax.swing.*; -import javax.swing.filechooser.FileFilter; import java.awt.Component; import java.awt.Cursor; import java.awt.Dimension; @@ -63,6 +39,37 @@ import java.util.Iterator; import java.util.UUID; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; +import javax.swing.JComponent; +import javax.swing.JFileChooser; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; +import javax.swing.SwingWorker; +import javax.swing.Timer; +import javax.swing.filechooser.FileFilter; +import mage.cards.Card; +import mage.cards.Sets; +import mage.cards.decks.Deck; +import mage.cards.decks.importer.DeckImporter; +import mage.cards.decks.importer.DeckImporterUtil; +import mage.cards.repository.CardInfo; +import mage.cards.repository.CardRepository; +import mage.client.MageFrame; +import mage.client.cards.BigCard; +import mage.client.cards.ICardGrid; +import mage.client.constants.Constants.DeckEditorMode; +import mage.client.constants.Constants.SortBy; +import mage.client.dialog.AddLandDialog; +import mage.client.dialog.PreferencesDialog; +import mage.client.plugins.impl.Plugins; +import mage.client.util.Event; +import mage.client.util.Listener; +import mage.components.CardInfoPane; +import mage.game.GameException; +import mage.remote.Session; +import mage.view.CardView; +import mage.view.SimpleCardView; +import org.apache.log4j.Logger; /** * @@ -130,6 +137,9 @@ public class DeckEditorPanel extends javax.swing.JPanel { case Sideboard: this.btnSubmit.setVisible(true); this.cardSelector.loadSideboard(new ArrayList(deck.getSideboard()), this.bigCard); + // TODO: take from preferences + this.cardSelector.switchToGrid(); + this.btnExit.setVisible(false); this.btnImport.setVisible(false); if (!MageFrame.getSession().isTestMode()) { @@ -276,7 +286,11 @@ public class DeckEditorPanel extends javax.swing.JPanel { } } ); + // Set Sort from Preferences + SortBy sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_SORT_BY, "Color")); + deckArea.getDeckList().setSortBy(sortBy); refreshDeck(); + this.setVisible(true); this.repaint(); } diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/SortSetting.java b/Mage.Client/src/main/java/mage/client/deckeditor/SortSetting.java new file mode 100644 index 00000000000..a438b73a68c --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/deckeditor/SortSetting.java @@ -0,0 +1,105 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.client.deckeditor; + +import mage.client.constants.Constants.SortBy; +import static mage.client.constants.Constants.SortBy.CASTING_COST; +import static mage.client.constants.Constants.SortBy.COLOR; +import static mage.client.constants.Constants.SortBy.COLOR_DETAILED; +import static mage.client.constants.Constants.SortBy.NAME; +import static mage.client.constants.Constants.SortBy.RARITY; +import mage.client.dialog.PreferencesDialog; + +/** + * + * @author LevelX2 + */ +public abstract class SortSetting { + + SortBy sortBy; + int sortIndex; + boolean ascending; + + public void setSortBy(SortBy sortBy) { + this.sortBy = sortBy; + PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_SORT_BY, sortBy.toString()); + } + + public void setSortIndex(int sortIndex) { + this.sortIndex = sortIndex; + PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_SORT_INDEX, Integer.toString(sortIndex)); + } + + public void setAscending(boolean ascending) { + this.ascending = ascending; + PreferencesDialog.saveValue(PreferencesDialog.KEY_DRAFT_SORT_ASCENDING, this.ascending ? "1":"0"); + } + + public SortBy getSortBy() { + return sortBy; + } + + public int getSortIndex() { + return sortIndex; + } + + public boolean isAscending() { + return ascending; + } + + public int convertSortByToIndex(SortBy sortBy) { + switch(sortBy) { + case NAME: + return 1; + case CASTING_COST: + return 2; + case COLOR: + case COLOR_DETAILED: + return 3; + case RARITY: + return 5; + default: + return 0; + } + } + + public SortBy convertIndexToSortBy(int index) { + switch (index) { + case 1: + return SortBy.NAME; + case 2: + return SortBy.CASTING_COST; + case 3: + return SortBy.COLOR; + case 5: + return SortBy.RARITY; + default: + return SortBy.UNSORTED; + } + } +} diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingBase.java b/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingBase.java new file mode 100644 index 00000000000..517272d4ea5 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingBase.java @@ -0,0 +1,51 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.client.deckeditor; + +import mage.client.constants.Constants.SortBy; +import mage.client.dialog.PreferencesDialog; + +/** + * + * @author LevelX2 + */ + +public class SortSettingBase extends SortSetting { + + private static SortSettingBase fInstance = new SortSettingBase(); + + public static SortSettingBase getInstance() { + return fInstance; + } + + private SortSettingBase() { + this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BASE_SORT_BY, "Color")); + this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BASE_SORT_INDEX, "1")); + this.ascending = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_BASE_SORT_INDEX, "1").equals("1"); + } +} \ No newline at end of file diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingDeck.java b/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingDeck.java new file mode 100644 index 00000000000..8029105fd55 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingDeck.java @@ -0,0 +1,51 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.client.deckeditor; + +import mage.client.constants.Constants.SortBy; +import mage.client.dialog.PreferencesDialog; + +/** + * + * @author LevelX2 + */ + +public class SortSettingDeck extends SortSetting { + + private static SortSettingDeck fInstance = new SortSettingDeck(); + + public static SortSettingDeck getInstance() { + return fInstance; + } + + private SortSettingDeck() { + this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DECK_SORT_BY, "Color")); + this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DECK_SORT_INDEX, "1")); + this.ascending = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DECK_SORT_INDEX, "1").equals("1"); + } +} \ No newline at end of file diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingDraft.java b/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingDraft.java new file mode 100644 index 00000000000..e9d1e6ecdc6 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingDraft.java @@ -0,0 +1,51 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ + +package mage.client.deckeditor; + +import mage.client.constants.Constants.SortBy; +import mage.client.dialog.PreferencesDialog; + +/** + * + * @author LevelX2 + */ +public class SortSettingDraft extends SortSetting { + + private static SortSettingDraft fInstance = new SortSettingDraft(); + + public static SortSettingDraft getInstance() { + return fInstance; + } + + private SortSettingDraft() { + this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_SORT_BY, "Color")); + this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_SORT_INDEX, "1")); + this.ascending = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_SORT_INDEX, "1").equals("1"); + } +} diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingSideboard.java b/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingSideboard.java new file mode 100644 index 00000000000..c9b5551a548 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/deckeditor/SortSettingSideboard.java @@ -0,0 +1,51 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.client.deckeditor; + +import mage.client.constants.Constants.SortBy; +import mage.client.dialog.PreferencesDialog; + +/** + * + * @author LevelX2 + */ + +public class SortSettingSideboard extends SortSetting { + + private static SortSettingSideboard fInstance = new SortSettingSideboard(); + + public static SortSettingSideboard getInstance() { + return fInstance; + } + + private SortSettingSideboard() { + this.sortBy = SortBy.getByString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SIDEBOARD_SORT_BY, "Color")); + this.sortIndex = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SIDEBOARD_SORT_INDEX, "1")); + this.ascending = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SIDEBOARD_SORT_INDEX, "1").equals("1"); + } +} \ No newline at end of file diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java index 13505076060..13cbf27ad26 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/table/TableModel.java @@ -28,11 +28,30 @@ package mage.client.deckeditor.table; +import java.awt.Dimension; +import java.awt.Image; +import java.awt.event.KeyEvent; +import java.awt.event.KeyListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.UUID; +import javax.swing.JTable; +import javax.swing.table.AbstractTableModel; +import javax.swing.table.TableColumnModel; import mage.client.MageFrame; import mage.client.cards.BigCard; import mage.client.cards.CardEventSource; import mage.client.cards.ICardGrid; -import mage.client.constants.Constants.SortBy; +import mage.client.deckeditor.SortSetting; import mage.client.plugins.impl.Plugins; import mage.client.util.Config; import mage.client.util.Event; @@ -45,16 +64,6 @@ import mage.view.CardsView; import org.apache.log4j.Logger; import org.jdesktop.swingx.JXPanel; -import javax.swing.*; -import javax.swing.table.AbstractTableModel; -import javax.swing.table.TableColumnModel; -import java.awt.*; -import java.awt.event.*; -import java.awt.image.BufferedImage; -import java.util.*; -import java.util.List; -import java.util.Map.Entry; - /** * Table Model for card list. * @@ -79,16 +88,23 @@ public class TableModel extends AbstractTableModel implements ICardGrid { private String column[] = { "", "Name", "Cost", "Color", "Type", "Stats", "Rarity", "Set" }; + private SortSetting sortSetting; private int recentSortedColumn; private boolean recentAscending; + + + @Override - public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) { - this.loadCards(showCards, sortBy, piles, bigCard, gameId, true); + public void loadCards(CardsView showCards, SortSetting sortSetting, boolean piles, BigCard bigCard, UUID gameId) { + this.loadCards(showCards, sortSetting, piles, bigCard, gameId, true); } @Override - public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId, boolean merge) { + public void loadCards(CardsView showCards, SortSetting sortSetting, boolean piles, BigCard bigCard, UUID gameId, boolean merge) { + if (this.sortSetting == null) { + this.sortSetting = sortSetting; + } this.bigCard = bigCard; this.gameId = gameId; int landCount = 0; @@ -164,8 +180,8 @@ public class TableModel extends AbstractTableModel implements ICardGrid { } } - sort(1, true); - drawCards(sortBy, piles); + sort(this.sortSetting.getSortIndex(), this.sortSetting.isAscending()); + drawCards(sortSetting, piles); } @Override @@ -258,7 +274,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid { } @Override - public void drawCards(SortBy sortBy, boolean piles) { + public void drawCards(SortSetting sortSetting, boolean piles) { fireTableDataChanged(); } @@ -342,6 +358,8 @@ public class TableModel extends AbstractTableModel implements ICardGrid { if (recentSortedColumn == column) { asc = !recentAscending; } + sortSetting.setSortIndex(column); + sortSetting.setAscending(asc); sort(column, asc); fireTableDataChanged(); } @@ -392,6 +410,14 @@ public class TableModel extends AbstractTableModel implements ICardGrid { return true; } + public int getRecentSortedColumn() { + return recentSortedColumn; + } + + public boolean isRecentAscending() { + return recentAscending; + } + public void setDisplayNoCopies(boolean value) { this.displayNoCopies = value; } @@ -404,4 +430,4 @@ public class TableModel extends AbstractTableModel implements ICardGrid { public int cardsSize() { return cards.size(); } -} \ No newline at end of file +} diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index bc41467a845..f561a43f837 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -147,7 +147,22 @@ public class PreferencesDialog extends javax.swing.JDialog { // used to save and restore the settings for the cardArea (draft, sideboarding, deck builder) public static final String KEY_DRAFT_VIEW = "draftView"; public static final String KEY_DRAFT_PILES_TOGGLE = "draftPilesToggle"; + public static final String KEY_DRAFT_SORT_BY = "draftSortBy"; + public static final String KEY_DRAFT_SORT_INDEX = "draftSortIndex"; + public static final String KEY_DRAFT_SORT_ASCENDING = "draftSortAscending"; + + public static final String KEY_BASE_SORT_BY = "baseSortBy"; + public static final String KEY_BASE_SORT_INDEX = "baseSortIndex"; + public static final String KEY_BASE_SORT_ASCENDING = "baseSortAscending"; + + public static final String KEY_SIDEBOARD_SORT_BY = "sideboardSortBy"; + public static final String KEY_SIDEBOARD_SORT_INDEX = "sideboardSortIndex"; + public static final String KEY_SIDEBOARD_SORT_ASCENDING = "sideboardSortAscending"; + + public static final String KEY_DECK_SORT_BY = "deckSortBy"; + public static final String KEY_DECK_SORT_INDEX = "deckSortIndex"; + public static final String KEY_DECK_SORT_ASCENDING = "deckSortAscending"; public static final String KEY_PROXY_ADDRESS = "proxyAddress"; public static final String KEY_PROXY_PORT = "proxyPort"; diff --git a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java index 7b02c770fa7..aa74c050d3e 100644 --- a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java +++ b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java @@ -49,6 +49,7 @@ import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.UUID; +import mage.client.deckeditor.SortSettingDraft; import mage.view.SimpleCardView; /** @@ -70,6 +71,7 @@ public class DraftPanel extends javax.swing.JPanel { initComponents(); draftBooster.setOpaque(false); + draftPicks.setSortSetting(SortSettingDraft.getInstance()); draftPicks.setOpaque(false); jPanel1.setOpaque(false);