diff --git a/Mage.Client/src/main/java/mage/client/cards/CardsList.form b/Mage.Client/src/main/java/mage/client/cards/CardsList.form
index 54af84ac6da..eaf7cf9a88d 100644
--- a/Mage.Client/src/main/java/mage/client/cards/CardsList.form
+++ b/Mage.Client/src/main/java/mage/client/cards/CardsList.form
@@ -37,7 +37,7 @@
-
+
@@ -105,7 +105,7 @@
-
+
@@ -127,7 +127,7 @@
-
+
@@ -145,7 +145,7 @@
-
+
@@ -163,7 +163,7 @@
-
+
@@ -181,7 +181,7 @@
-
+
@@ -199,7 +199,7 @@
-
+
@@ -217,7 +217,7 @@
-
+
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 4713e383dbc..f983fd866e5 100644
--- a/Mage.Client/src/main/java/mage/client/cards/CardsList.java
+++ b/Mage.Client/src/main/java/mage/client/cards/CardsList.java
@@ -44,7 +44,10 @@ import java.awt.event.MouseListener;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JTable;
@@ -86,6 +89,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
protected CardEventSource cardEventSource = new CardEventSource();
private Dimension cardDimension;
private CardsView cards;
+ private Map mageCards = new LinkedHashMap<>();
protected BigCard bigCard;
protected UUID gameId;
private SortSetting sortSetting;
@@ -123,6 +127,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
((CardPanel)comp).cleanUp();
}
}
+ mageCards.clear();
cardArea.removeAll();
this.bigCard = null;
@@ -276,102 +281,115 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
int numColumns = maxWidth / Config.dimensions.frameWidth;
int curColumn = 0;
int curRow = 0;
- int landCount = 0;
- int creatureCount = 0;
- int sorceryCount = 0;
- int instantCount = 0;
- int enchantmentCount = 0;
- //FIXME: why we remove all cards? for performance it's better to merge changes
- // as it is already done in ListView
- cardArea.removeAll();
+ int maxRow = 0;
+ int maxColumn = 0;
+ Comparator comparator = null;
+ Map oldMageCards = mageCards;
+ mageCards = new LinkedHashMap<>();
+
+ //Find card view
+ for(UUID uuid : cards.keySet()){
+ if(oldMageCards.containsKey(uuid)){
+ mageCards.put(uuid, oldMageCards.get(uuid));
+ oldMageCards.remove(uuid);
+ }
+ else{
+ mageCards.put(uuid, addCard(cards.get(uuid), bigCard, gameId));
+ }
+ }
+ //Remove unused cards
+ for(MageCard card : oldMageCards.values()){
+ cardArea.remove(card);
+ }
+
if (cards != null && cards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
List sortedCards = new ArrayList<>(cards.values());
switch (sortSetting.getSortBy()) {
case NAME:
- Collections.sort(sortedCards, new CardViewNameComparator());
+ comparator = new CardViewNameComparator();
break;
case RARITY:
- Collections.sort(sortedCards, new CardViewRarityComparator());
+ comparator = new CardViewRarityComparator();
break;
case COLOR:
- Collections.sort(sortedCards, new CardViewColorComparator());
+ comparator = new CardViewColorComparator();
break;
case COLOR_DETAILED:
- Collections.sort(sortedCards, new CardViewColorDetailedComparator());
+ comparator = new CardViewColorDetailedComparator();
break;
case CASTING_COST:
- Collections.sort(sortedCards, new CardViewCostComparator());
+ comparator = new CardViewCostComparator();
break;
}
+ if(comparator != null){
+ Collections.sort(sortedCards, new CardViewNameComparator());
+ Collections.sort(sortedCards, comparator);
+ }
CardView lastCard = null;
for (CardView card: sortedCards) {
if (sortSetting.isPilesToggle()) {
if (lastCard == null) {
lastCard = card;
}
- switch (sortSetting.getSortBy()) {
- case NAME:
- if (!card.getName().equals(lastCard.getName())) {
- curColumn++;
- curRow = 0;
- }
- break;
- case RARITY:
- if (!card.getRarity().equals(lastCard.getRarity())) {
- curColumn++;
- curRow = 0;
- }
- break;
- case COLOR:
- if (card.getColor().compareTo(lastCard.getColor()) != 0) {
- curColumn++;
- curRow = 0;
- }
- break;
- case COLOR_DETAILED:
- if (card.getColor().hashCode() != lastCard.getColor().hashCode()) {
- curColumn++;
- curRow = 0;
- }
- break;
- case CASTING_COST:
- if (card.getConvertedManaCost() != lastCard.getConvertedManaCost()) {
- curColumn++;
- curRow = 0;
- }
- break;
+ if(comparator != null){
+ if(comparator.compare(card, lastCard) > 0){
+ curColumn++;
+ maxRow = Math.max(maxRow, curRow);
+ curRow = 0;
+ }
}
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
- addCard(card, bigCard, gameId, rectangle);
+ setCardBounds(mageCards.get(card.getId()), rectangle);
+
curRow++;
lastCard = card;
} else {
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * 20);
- addCard(card, bigCard, gameId, rectangle);
+ setCardBounds(mageCards.get(card.getId()), rectangle);
curColumn++;
if (curColumn == numColumns) {
+ maxColumn = Math.max(maxColumn, curColumn);
curColumn = 0;
curRow++;
}
}
- if (card.getCardTypes().contains(CardType.LAND)) {
- landCount++;
- }
- if (card.getCardTypes().contains(CardType.CREATURE)) {
- creatureCount++;
- }
- if (card.getCardTypes().contains(CardType.SORCERY)) {
- sorceryCount++;
- }
- if (card.getCardTypes().contains(CardType.INSTANT)) {
- instantCount++;
- }
- if (card.getCardTypes().contains(CardType.ENCHANTMENT)) {
- enchantmentCount++;
- }
}
}
+ maxRow = Math.max(maxRow, curRow);
+ maxColumn = Math.max(maxColumn, curColumn);
+ updateCounts();
+ cardArea.setPreferredSize(new Dimension((maxColumn+1) * Config.dimensions.frameWidth, Config.dimensions.frameHeight + maxRow*20));
+ cardArea.revalidate();
+ this.revalidate();
+ this.repaint();
+ this.setVisible(true);
+ }
+
+ private void updateCounts(){
+ int landCount = 0;
+ int creatureCount = 0;
+ int sorceryCount = 0;
+ int instantCount = 0;
+ int enchantmentCount = 0;
+ for (CardView card: cards.values()) {
+ if (card.getCardTypes().contains(CardType.LAND)) {
+ landCount++;
+ }
+ if (card.getCardTypes().contains(CardType.CREATURE)) {
+ creatureCount++;
+ }
+ if (card.getCardTypes().contains(CardType.SORCERY)) {
+ sorceryCount++;
+ }
+ if (card.getCardTypes().contains(CardType.INSTANT)) {
+ instantCount++;
+ }
+ if (card.getCardTypes().contains(CardType.ENCHANTMENT)) {
+ enchantmentCount++;
+ }
+ }
+
int count = cards != null ? cards.size() : 0;
this.lblCount.setText(Integer.toString(count));
this.lblCreatureCount.setText(Integer.toString(creatureCount));
@@ -379,24 +397,24 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
this.lblSorceryCount.setText(Integer.toString(sorceryCount));
this.lblInstantCount.setText(Integer.toString(instantCount));
this.lblEnchantmentCount.setText(Integer.toString(enchantmentCount));
- cardArea.setPreferredSize(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight + 200));
- cardArea.revalidate();
- this.revalidate();
- this.repaint();
- this.setVisible(true);
}
- private void addCard(CardView card, BigCard bigCard, UUID gameId, Rectangle rectangle) {
+ private MageCard addCard(CardView card, BigCard bigCard, UUID gameId) {
if (cardDimension == null) {
cardDimension = new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
}
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, cardDimension, gameId, true);
- cardImg.setBounds(rectangle);
cardArea.add(cardImg);
- cardArea.moveToFront(cardImg);
cardImg.update(card);
cardImg.addMouseListener(this);
- cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
+ return cardImg;
+ }
+
+
+ private void setCardBounds(MageCard card, Rectangle rectangle) {
+ card.setBounds(rectangle);
+ card.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
+ cardArea.moveToFront(card);
}
@Override
@@ -437,7 +455,6 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
@SuppressWarnings("unchecked")
// //GEN-BEGIN:initComponents
private void initComponents() {
- java.awt.GridBagConstraints gridBagConstraints;
bgView = new javax.swing.ButtonGroup();
panelControl = new javax.swing.JPanel();
@@ -615,7 +632,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
.addComponent(lblLandCount)
.addComponent(lblCreatureCount)
.addComponent(lblSorceryCount)
- .addComponent(lblInstantCount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(lblInstantCount)
.addComponent(lblEnchantmentCount)
.addComponent(chkPiles))
.addComponent(cbSortBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
@@ -636,7 +653,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
.addGroup(layout.createSequentialGroup()
.addGap(1, 1, 1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(panelControl, javax.swing.GroupLayout.DEFAULT_SIZE, 654, Short.MAX_VALUE)
+ .addComponent(panelControl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(panelCardArea)))
);
layout.setVerticalGroup(
diff --git a/Mage.Client/src/main/java/mage/client/util/CardViewColorComparator.java b/Mage.Client/src/main/java/mage/client/util/CardViewColorComparator.java
index 876ec5a4f99..fe41208edcc 100644
--- a/Mage.Client/src/main/java/mage/client/util/CardViewColorComparator.java
+++ b/Mage.Client/src/main/java/mage/client/util/CardViewColorComparator.java
@@ -39,13 +39,7 @@ public class CardViewColorComparator implements Comparator {
@Override
public int compare(CardView o1, CardView o2) {
- int val = o1.getColor().compareTo(o2.getColor());
- if (val == 0) {
- return o1.getName().compareTo(o2.getName());
- }
- else {
- return val;
- }
+ return o1.getColor().compareTo(o2.getColor());
}
}
\ No newline at end of file
diff --git a/Mage.Client/src/main/java/mage/client/util/CardViewColorDetailedComparator.java b/Mage.Client/src/main/java/mage/client/util/CardViewColorDetailedComparator.java
index 6e979f7c81b..179254b961c 100644
--- a/Mage.Client/src/main/java/mage/client/util/CardViewColorDetailedComparator.java
+++ b/Mage.Client/src/main/java/mage/client/util/CardViewColorDetailedComparator.java
@@ -1,51 +1,45 @@
-/*
- * Copyright 2011 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.util;
-
-import java.util.Comparator;
-import mage.view.CardView;
-
-/**
- *
- * @author BetaSteward_at_googlemail.com
- */
-public class CardViewColorDetailedComparator implements Comparator {
-
- @Override
- public int compare(CardView o1, CardView o2) {
- int val = o1.getColor().hashCode() - o2.getColor().hashCode();
- if (val == 0) {
- return o1.getName().compareTo(o2.getName());
- }
- else {
- return val;
- }
- }
-
+/*
+ * Copyright 2011 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.util;
+
+import java.util.Comparator;
+import mage.view.CardView;
+
+/**
+ *
+ * @author BetaSteward_at_googlemail.com
+ */
+public class CardViewColorDetailedComparator implements Comparator {
+
+ @Override
+ public int compare(CardView o1, CardView o2) {
+ return o1.getColor().hashCode() - o2.getColor().hashCode();
+ }
+
}
\ No newline at end of file
diff --git a/Mage.Client/src/main/java/mage/client/util/CardViewCostComparator.java b/Mage.Client/src/main/java/mage/client/util/CardViewCostComparator.java
index fcd3b4c0cec..22eae462b06 100644
--- a/Mage.Client/src/main/java/mage/client/util/CardViewCostComparator.java
+++ b/Mage.Client/src/main/java/mage/client/util/CardViewCostComparator.java
@@ -39,13 +39,7 @@ public class CardViewCostComparator implements Comparator {
@Override
public int compare(CardView o1, CardView o2) {
- int val = Integer.valueOf(o1.getConvertedManaCost()).compareTo(Integer.valueOf(o2.getConvertedManaCost()));
- if (val == 0) {
- return o1.getName().compareTo(o2.getName());
- }
- else {
- return val;
- }
+ return Integer.valueOf(o1.getConvertedManaCost()).compareTo(Integer.valueOf(o2.getConvertedManaCost()));
}
}
diff --git a/Mage.Client/src/main/java/mage/client/util/CardViewRarityComparator.java b/Mage.Client/src/main/java/mage/client/util/CardViewRarityComparator.java
index 5389d89778e..f8cd723f10f 100644
--- a/Mage.Client/src/main/java/mage/client/util/CardViewRarityComparator.java
+++ b/Mage.Client/src/main/java/mage/client/util/CardViewRarityComparator.java
@@ -39,13 +39,7 @@ public class CardViewRarityComparator implements Comparator {
@Override
public int compare(CardView o1, CardView o2) {
- int val = o1.getRarity().compareTo(o2.getRarity());
- if (val == 0) {
- return o1.getName().compareTo(o2.getName());
- }
- else {
- return val;
- }
+ return o1.getRarity().compareTo(o2.getRarity());
}
}
\ No newline at end of file