sort cards in deck editor by name

This commit is contained in:
BetaSteward 2011-01-06 23:20:00 -05:00
parent 499a6fb0df
commit 41bf33d107
3 changed files with 25 additions and 5 deletions

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties>

View file

@ -39,6 +39,10 @@ import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.beans.Beans;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import mage.cards.MageCard;
@ -66,12 +70,19 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
}
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) {
loadCards(showCards, bigCard, gameId, false);
}
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId, boolean sorted) {
//FIXME: why we remove all cards? for performance it's better to merge changes
cardArea.removeAll();
if (showCards != null && showCards.size() > 0) {
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
int count = 0;
for (CardView card: showCards.values()) {
List<CardView> sortedCards = new ArrayList<CardView>(showCards.values());
if (sorted)
Collections.sort(sortedCards, new CardViewComparator());
for (CardView card: sortedCards) {
addCard(card, bigCard, gameId, rectangle);
if (count >= 10) {
rectangle.translate(Config.dimensions.frameWidth, -200);
@ -164,3 +175,12 @@ public class CardsList extends javax.swing.JPanel implements MouseListener {
}
}
class CardViewComparator implements Comparator<CardView> {
@Override
public int compare(CardView o1, CardView o2) {
return o1.getName().compareTo(o2.getName());
}
}

View file

@ -37,7 +37,7 @@ package mage.client.deckeditor;
import mage.cards.Card;
import mage.cards.decks.Deck;
import mage.client.MageFrame;
import mage.client.deckeditor.collection.viewer.Huerotator2;
//import mage.client.deckeditor.collection.viewer.Huerotator2;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Event;
import mage.client.util.Listener;
@ -149,8 +149,8 @@ public class DeckEditorPanel extends javax.swing.JPanel {
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
this.txtDeckName.setText(deck.getName());
deckArea.getDeckList().loadCards(new CardsView(deck.getCards()), bigCard, null);
deckArea.getSideboardList().loadCards(new CardsView(deck.getSideboard()), bigCard, null);
deckArea.getDeckList().loadCards(new CardsView(deck.getCards()), bigCard, null, true);
deckArea.getSideboardList().loadCards(new CardsView(deck.getSideboard()), bigCard, null, true);
}
finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));