This commit is contained in:
LevelX2 2013-09-26 21:39:07 +02:00
commit 8841cca120
9 changed files with 278 additions and 174 deletions

View file

@ -74,28 +74,39 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
* Max amount of cards in card grid for which card images will be drawn. * Max amount of cards in card grid for which card images will be drawn.
* Done so to solve issue with memory for big piles of cards. * Done so to solve issue with memory for big piles of cards.
*/ */
private static final int MAX_IMAGES = 250; public static final int MAX_IMAGES = 300;
public CardGrid() { public CardGrid() {
initComponents(); initComponents();
setOpaque(false); setOpaque(false);
} }
@Override @Override
public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) { public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) {
this.loadCards(showCards, sortBy, piles, bigCard, gameId, true);
}
@Override
public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId, boolean merge) {
boolean drawImage = showCards.size() < MAX_IMAGES; boolean drawImage = showCards.size() < MAX_IMAGES;
this.bigCard = bigCard; this.bigCard = bigCard;
this.gameId = gameId; this.gameId = gameId;
for (CardView card: showCards.values()) { if (merge) {
if (!cards.containsKey(card.getId())) { for (CardView card: showCards.values()) {
addCard(card, bigCard, gameId, drawImage); if (!cards.containsKey(card.getId())) {
addCard(card, bigCard, gameId, drawImage);
}
} }
} for (Iterator<Entry<UUID, MageCard>> i = cards.entrySet().iterator(); i.hasNext();) {
for (Iterator<Entry<UUID, MageCard>> i = cards.entrySet().iterator(); i.hasNext();) { Entry<UUID, MageCard> entry = i.next();
Entry<UUID, MageCard> entry = i.next(); if (!showCards.containsKey(entry.getKey())) {
if (!showCards.containsKey(entry.getKey())) { removeCardImg(entry.getKey());
removeCardImg(entry.getKey()); i.remove();
i.remove(); }
}
} else {
this.clear();
for (CardView card: showCards.values()) {
addCard(card, bigCard, gameId, drawImage);
} }
} }
System.gc(); System.gc();
@ -144,8 +155,9 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
MageCard lastCard = null; MageCard lastCard = null;
for (MageCard cardImg: sortedCards) { for (MageCard cardImg: sortedCards) {
if (piles) { if (piles) {
if (lastCard == null) if (lastCard == null) {
lastCard = cardImg; lastCard = cardImg;
}
switch (sortBy) { switch (sortBy) {
case NAME: case NAME:
if (!cardImg.getOriginal().getName().equals(lastCard.getOriginal().getName())) { if (!cardImg.getOriginal().getName().equals(lastCard.getOriginal().getName())) {
@ -203,6 +215,19 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
repaint(); repaint();
} }
private void clear() {
this.cards.clear();
removeAllCardImg();
}
private void removeAllCardImg() {
for (Component comp: getComponents()) {
if (comp instanceof Card || comp instanceof MageCard) {
remove(comp);
}
}
}
private void removeCardImg(UUID cardId) { private void removeCardImg(UUID cardId) {
for (Component comp: getComponents()) { for (Component comp: getComponents()) {
if (comp instanceof Card) { if (comp instanceof Card) {
@ -307,6 +332,11 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
revalidate(); revalidate();
repaint(); repaint();
} }
@Override
public int cardsSize() {
return cards.size();
}
} }
class CardNameComparator implements Comparator<MageCard> { class CardNameComparator implements Comparator<MageCard> {

View file

@ -1,4 +1,4 @@
<?xml version="1.1" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> <Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<Properties> <Properties>
@ -35,7 +35,7 @@
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<Component id="jPanel1" min="-2" max="-2" attributes="0"/> <Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jScrollPane1" pref="305" max="32767" attributes="0"/> <Component id="jScrollPane1" pref="23" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>

View file

@ -163,6 +163,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
return list; return list;
} }
public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) { public void loadCards(CardsView showCards, BigCard bigCard, UUID gameId) {
this.cards = showCards; this.cards = showCards;
this.bigCard = bigCard; this.bigCard = bigCard;
@ -317,6 +318,11 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
@Override @Override
public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) { public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) {
this.loadCards(showCards, sortBy, piles, bigCard, gameId, true);
}
@Override
public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId, boolean merge) {
cards = showCards; cards = showCards;
this.bigCard = bigCard; this.bigCard = bigCard;
this.gameId = gameId; this.gameId = gameId;
@ -534,4 +540,9 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
public void setDisplayNoCopies(boolean value) { public void setDisplayNoCopies(boolean value) {
mainModel.setDisplayNoCopies(value); mainModel.setDisplayNoCopies(value);
} }
@Override
public int cardsSize() {
return cards.size();
}
} }

View file

@ -46,5 +46,7 @@ public interface ICardGrid {
void addCardEventListener(Listener<Event> listener); void addCardEventListener(Listener<Event> listener);
void drawCards(Constants.SortBy sortBy, boolean piles); 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);
void loadCards(CardsView showCards, Constants.SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId, boolean merge);
void refresh(); void refresh();
int cardsSize();
} }

View file

@ -34,7 +34,23 @@
package mage.client.deckeditor; package mage.client.deckeditor;
import mage.constants.CardType; import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableCellRenderer;
import mage.MageObject; import mage.MageObject;
import mage.ObjectColor; import mage.ObjectColor;
import mage.cards.Card; import mage.cards.Card;
@ -49,6 +65,7 @@ import mage.client.cards.ICardGrid;
import mage.client.constants.Constants.SortBy; import mage.client.constants.Constants.SortBy;
import mage.client.deckeditor.table.TableModel; import mage.client.deckeditor.table.TableModel;
import mage.client.util.sets.ConstructedFormats; import mage.client.util.sets.ConstructedFormats;
import mage.constants.CardType;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.Predicate; import mage.filter.predicate.Predicate;
import mage.filter.predicate.Predicates; import mage.filter.predicate.Predicates;
@ -59,12 +76,6 @@ import mage.filter.predicate.other.CardTextPredicate;
import mage.filter.predicate.other.ExpansionSetPredicate; import mage.filter.predicate.other.ExpansionSetPredicate;
import mage.view.CardsView; import mage.view.CardsView;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.*;
import java.util.*;
/** /**
* *
@ -92,7 +103,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
currentView = mainModel; // by default we use List View currentView = mainModel; // by default we use List View
} }
public void makeTransparent() { private void makeTransparent() {
this.addComponentListener(this); this.addComponentListener(this);
setOpaque(false); setOpaque(false);
cardGrid.setOpaque(false); cardGrid.setOpaque(false);
@ -107,7 +118,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
tbTypes.setOpaque(true); // false = transparent tbTypes.setOpaque(true); // false = transparent
} }
public void initListViewComponents() { private void initListViewComponents() {
mainTable = new JTable(); mainTable = new JTable();
mainModel = new TableModel(); mainModel = new TableModel();
@ -135,6 +146,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
chkPiles.setEnabled(false); chkPiles.setEnabled(false);
mainTable.addMouseListener(new MouseAdapter() { mainTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2 && !e.isConsumed()) { if (e.getClickCount() == 2 && !e.isConsumed()) {
e.consume(); e.consume();
@ -178,70 +190,73 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
this.btnClear.setVisible(true); this.btnClear.setVisible(true);
this.cbExpansionSet.setVisible(true); this.cbExpansionSet.setVisible(true);
cbExpansionSet.setModel(new DefaultComboBoxModel(ConstructedFormats.getTypes())); cbExpansionSet.setModel(new DefaultComboBoxModel(ConstructedFormats.getTypes()));
// Action event on Expansion set triggers loadCards method
cbExpansionSet.setSelectedIndex(0); cbExpansionSet.setSelectedIndex(0);
filterCards();
} }
private FilterCard buildFilter() { private FilterCard buildFilter() {
FilterCard filter = new FilterCard(); FilterCard filter = new FilterCard();
ArrayList<Predicate<MageObject>> predicates = new ArrayList<Predicate<MageObject>>();
if (this.rdoGreen.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.GREEN));
}
if (this.rdoRed.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.RED));
}
if (this.rdoBlack.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.BLACK));
}
if (this.rdoBlue.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.BLUE));
}
if (this.rdoWhite.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.WHITE));
}
if (this.rdoColorless.isSelected()) {
predicates.add(new ColorlessPredicate());
}
filter.add(Predicates.or(predicates));
predicates.clear();
if (this.rdoLand.isSelected()) {
predicates.add(new CardTypePredicate(CardType.LAND));
}
if (this.rdoArtifacts.isSelected()) {
predicates.add(new CardTypePredicate(CardType.ARTIFACT));
}
if (this.rdoCreatures.isSelected()) {
predicates.add(new CardTypePredicate(CardType.CREATURE));
}
if (this.rdoEnchantments.isSelected()) {
predicates.add(new CardTypePredicate(CardType.ENCHANTMENT));
}
if (this.rdoInstants.isSelected()) {
predicates.add(new CardTypePredicate(CardType.INSTANT));
}
if (this.rdoSorceries.isSelected()) {
predicates.add(new CardTypePredicate(CardType.SORCERY));
}
if (this.rdoPlaneswalkers.isSelected()) {
predicates.add(new CardTypePredicate(CardType.PLANESWALKER));
}
filter.add(Predicates.or(predicates));
String name = jTextFieldSearch.getText().trim(); String name = jTextFieldSearch.getText().trim();
filter.add(new CardTextPredicate(name)); filter.add(new CardTextPredicate(name));
if (this.cbExpansionSet.isVisible()) { if (limited) {
String expansionSelection = this.cbExpansionSet.getSelectedItem().toString(); ArrayList<Predicate<MageObject>> predicates = new ArrayList<Predicate<MageObject>>();
if (!expansionSelection.equals("- All Sets")) {
ArrayList<Predicate<Card>> expansionPredicates = new ArrayList<Predicate<Card>>(); if (this.rdoGreen.isSelected()) {
for (String setCode : ConstructedFormats.getSetsByFormat(expansionSelection)) { predicates.add(new ColorPredicate(ObjectColor.GREEN));
expansionPredicates.add(new ExpansionSetPredicate(setCode)); }
if (this.rdoRed.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.RED));
}
if (this.rdoBlack.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.BLACK));
}
if (this.rdoBlue.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.BLUE));
}
if (this.rdoWhite.isSelected()) {
predicates.add(new ColorPredicate(ObjectColor.WHITE));
}
if (this.rdoColorless.isSelected()) {
predicates.add(new ColorlessPredicate());
}
filter.add(Predicates.or(predicates));
predicates.clear();
if (this.rdoLand.isSelected()) {
predicates.add(new CardTypePredicate(CardType.LAND));
}
if (this.rdoArtifacts.isSelected()) {
predicates.add(new CardTypePredicate(CardType.ARTIFACT));
}
if (this.rdoCreatures.isSelected()) {
predicates.add(new CardTypePredicate(CardType.CREATURE));
}
if (this.rdoEnchantments.isSelected()) {
predicates.add(new CardTypePredicate(CardType.ENCHANTMENT));
}
if (this.rdoInstants.isSelected()) {
predicates.add(new CardTypePredicate(CardType.INSTANT));
}
if (this.rdoSorceries.isSelected()) {
predicates.add(new CardTypePredicate(CardType.SORCERY));
}
if (this.rdoPlaneswalkers.isSelected()) {
predicates.add(new CardTypePredicate(CardType.PLANESWALKER));
}
filter.add(Predicates.or(predicates));
if (this.cbExpansionSet.isVisible()) {
String expansionSelection = this.cbExpansionSet.getSelectedItem().toString();
if (!expansionSelection.equals("- All Sets")) {
ArrayList<Predicate<Card>> expansionPredicates = new ArrayList<Predicate<Card>>();
for (String setCode : ConstructedFormats.getSetsByFormat(expansionSelection)) {
expansionPredicates.add(new ExpansionSetPredicate(setCode));
}
filter.add(Predicates.or(expansionPredicates));
} }
filter.add(Predicates.or(expansionPredicates));
} }
} }
@ -279,11 +294,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
criteria.types(CardType.PLANESWALKER); criteria.types(CardType.PLANESWALKER);
} }
String text = jTextFieldSearch.getText().trim();
if (!text.isEmpty()) {
// criteria.rules(text);
}
if (this.cbExpansionSet.isVisible()) { if (this.cbExpansionSet.isVisible()) {
String expansionSelection = this.cbExpansionSet.getSelectedItem().toString(); String expansionSelection = this.cbExpansionSet.getSelectedItem().toString();
if (!expansionSelection.equals("- All Sets")) { if (!expansionSelection.equals("- All Sets")) {
@ -314,9 +324,12 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
if (filter.match(card, null)) { if (filter.match(card, null)) {
filteredCards.add(card); filteredCards.add(card);
} }
} }
} }
this.currentView.loadCards(new CardsView(filteredCards), (SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected(), bigCard, null); 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.cardCount.setText(String.valueOf(filteredCards.size())); this.cardCount.setText(String.valueOf(filteredCards.size()));
} }
finally { finally {
@ -328,10 +341,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
this.cardCount.setText(String.valueOf(value)); this.cardCount.setText(String.valueOf(value));
} }
public ICardGrid getCardsList() {
return this.currentView;
}
public List<ICardGrid> getCardGridComponents() { public List<ICardGrid> getCardGridComponents() {
List<ICardGrid> components = new ArrayList<ICardGrid>(); List<ICardGrid> components = new ArrayList<ICardGrid>();
components.add(mainModel); components.add(mainModel);
@ -807,13 +816,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
}//GEN-LAST:event_rdoPlaneswalkersActionPerformed }//GEN-LAST:event_rdoPlaneswalkersActionPerformed
private void cbExpansionSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbExpansionSetActionPerformed private void cbExpansionSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbExpansionSetActionPerformed
if (this.cbExpansionSet.getSelectedItem().equals("-- Standard")) { filterCards();
filterCards();
} else {
// auto switch for ListView for "All sets" (too many cards to load)
jToggleListView.doClick();
jToggleListView.setSelected(true);
}
}//GEN-LAST:event_cbExpansionSetActionPerformed }//GEN-LAST:event_cbExpansionSetActionPerformed
private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed private void btnClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnClearActionPerformed
@ -841,35 +844,39 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
}//GEN-LAST:event_btnBoosterActionPerformed }//GEN-LAST:event_btnBoosterActionPerformed
private void cbSortByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortByActionPerformed private void cbSortByActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSortByActionPerformed
if (cbSortBy.getSelectedItem() instanceof SortBy) if (cbSortBy.getSelectedItem() instanceof SortBy) {
this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
}//GEN-LAST:event_cbSortByActionPerformed }//GEN-LAST:event_cbSortByActionPerformed
private void chkPilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPilesActionPerformed private void chkPilesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkPilesActionPerformed
if (cbSortBy.getSelectedItem() instanceof SortBy) if (cbSortBy.getSelectedItem() instanceof SortBy) {
this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
}//GEN-LAST:event_chkPilesActionPerformed }//GEN-LAST:event_chkPilesActionPerformed
private void jToggleListViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleListViewActionPerformed private void jToggleListViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleListViewActionPerformed
jToggleCardView.setSelected(false); if (!(currentView instanceof TableModel)) {
currentView = mainModel; toggleViewMode();
jScrollPane1.setViewportView(mainTable); } else {
cbSortBy.setEnabled(false); jToggleListView.setSelected(true);
chkPiles.setEnabled(false); }
jButtonAddToMain.setEnabled(true);
jButtonAddToSideboard.setEnabled(true);
filterCards(); filterCards();
}//GEN-LAST:event_jToggleListViewActionPerformed }//GEN-LAST:event_jToggleListViewActionPerformed
private void jToggleCardViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleCardViewActionPerformed private void jToggleCardViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleCardViewActionPerformed
jToggleListView.setSelected(false); if (currentView.cardsSize() > CardGrid.MAX_IMAGES) {
currentView = cardGrid; jToggleCardView.setSelected(false);
jScrollPane1.setViewportView(cardGrid); JOptionPane.showMessageDialog(this, new StringBuilder("The card view can't be used for more than ").append(CardGrid.MAX_IMAGES).append(" cards.").toString());
cbSortBy.setEnabled(true);
chkPiles.setEnabled(true); } else {
jButtonAddToMain.setEnabled(false); if (!(currentView instanceof CardGrid)) {
jButtonAddToSideboard.setEnabled(false); toggleViewMode();
filterCards(); } else {
jToggleCardView.setSelected(true);
}
filterCards();
}
}//GEN-LAST:event_jToggleCardViewActionPerformed }//GEN-LAST:event_jToggleCardViewActionPerformed
private void jButtonAddToMainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddToMainActionPerformed private void jButtonAddToMainActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddToMainActionPerformed
@ -881,8 +888,9 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
mainModel.doubleClick(index); mainModel.doubleClick(index);
} }
//if (!mode.equals(Constants.DeckEditorMode.Constructed)) //if (!mode.equals(Constants.DeckEditorMode.Constructed))
if (limited) if (limited) {
mainModel.fireTableDataChanged(); mainModel.fireTableDataChanged();
}
} }
}//GEN-LAST:event_jButtonAddToMainActionPerformed }//GEN-LAST:event_jButtonAddToMainActionPerformed
@ -895,8 +903,9 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
mainModel.shiftDoubleClick(index); mainModel.shiftDoubleClick(index);
} }
//if (!mode.equals(Constants.DeckEditorMode.Constructed)) //if (!mode.equals(Constants.DeckEditorMode.Constructed))
if (limited) if (limited) {
mainModel.fireTableDataChanged(); mainModel.fireTableDataChanged();
}
} }
}//GEN-LAST:event_jButtonAddToSideboardActionPerformed }//GEN-LAST:event_jButtonAddToSideboardActionPerformed
@ -918,9 +927,33 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
filterCards(); filterCards();
}//GEN-LAST:event_jButtonCleanActionPerformed }//GEN-LAST:event_jButtonCleanActionPerformed
private void toggleViewMode() {
if (currentView instanceof CardGrid) {
jToggleListView.setSelected(true);
jToggleCardView.setSelected(false);
currentView = mainModel;
jScrollPane1.setViewportView(mainTable);
cbSortBy.setEnabled(false);
chkPiles.setEnabled(false);
jButtonAddToMain.setEnabled(true);
jButtonAddToSideboard.setEnabled(true);
} else {
jToggleCardView.setSelected(true);
jToggleListView.setSelected(false);
currentView = cardGrid;
jScrollPane1.setViewportView(cardGrid);
cbSortBy.setEnabled(true);
chkPiles.setEnabled(true);
jButtonAddToMain.setEnabled(false);
jButtonAddToSideboard.setEnabled(false);
}
}
public List<Integer> asList(final int[] is) { public List<Integer> asList(final int[] is) {
List<Integer> list = new ArrayList<Integer>(); List<Integer> list = new ArrayList<Integer>();
for (int i : is) list.add(i); for (int i : is) {
list.add(i);
}
return list; return list;
} }
@ -978,26 +1011,30 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
@Override @Override
public void componentResized(ComponentEvent e) { public void componentResized(ComponentEvent e) {
if (cbSortBy.getSelectedItem() instanceof SortBy) if (cbSortBy.getSelectedItem() instanceof SortBy) {
this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
} }
@Override @Override
public void componentMoved(ComponentEvent e) { public void componentMoved(ComponentEvent e) {
if (cbSortBy.getSelectedItem() instanceof SortBy) if (cbSortBy.getSelectedItem() instanceof SortBy) {
this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
} }
@Override @Override
public void componentShown(ComponentEvent e) { public void componentShown(ComponentEvent e) {
if (cbSortBy.getSelectedItem() instanceof SortBy) if (cbSortBy.getSelectedItem() instanceof SortBy) {
this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
} }
@Override @Override
public void componentHidden(ComponentEvent e) { public void componentHidden(ComponentEvent e) {
if (cbSortBy.getSelectedItem() instanceof SortBy) if (cbSortBy.getSelectedItem() instanceof SortBy) {
this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected()); this.currentView.drawCards((SortBy) cbSortBy.getSelectedItem(), chkPiles.isSelected());
}
} }
} }

View file

@ -84,69 +84,84 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
@Override @Override
public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) { public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId) {
this.loadCards(showCards, sortBy, piles, bigCard, gameId, true);
}
@Override
public void loadCards(CardsView showCards, SortBy sortBy, boolean piles, BigCard bigCard, UUID gameId, boolean merge) {
this.bigCard = bigCard; this.bigCard = bigCard;
this.gameId = gameId; this.gameId = gameId;
int landCount = 0; int landCount = 0;
int creatureCount = 0; int creatureCount = 0;
for (CardView card : showCards.values()) { if (!merge) {
if (!cards.containsKey(card.getId())) { this.clear();
for (CardView card : showCards.values()) {
addCard(card, bigCard, gameId); addCard(card, bigCard, gameId);
} }
if (updateCountsCallback != null) { } else {
if (card.getCardTypes().contains(CardType.LAND)) for (CardView card : showCards.values()) {
landCount++; if (!cards.containsKey(card.getId())) {
if (card.getCardTypes().contains(CardType.CREATURE)) addCard(card, bigCard, gameId);
creatureCount++; }
if (updateCountsCallback != null) {
if (card.getCardTypes().contains(CardType.LAND)) {
landCount++;
}
if (card.getCardTypes().contains(CardType.CREATURE)) {
creatureCount++;
}
}
} }
}
// not easy logic for merge :) // no easy logic for merge :)
for (Iterator<Entry<UUID, CardView>> i = cards.entrySet().iterator(); i.hasNext();) { for (Iterator<Entry<UUID, CardView>> i = cards.entrySet().iterator(); i.hasNext();) {
Entry<UUID, CardView> entry = i.next(); Entry<UUID, CardView> entry = i.next();
if (!showCards.containsKey(entry.getKey())) { if (!showCards.containsKey(entry.getKey())) {
i.remove(); i.remove();
if (displayNoCopies) { if (displayNoCopies) {
String key = entry.getValue().getName() + entry.getValue().getExpansionSetCode() + entry.getValue().getCardNumber(); String key = entry.getValue().getName() + entry.getValue().getExpansionSetCode() + entry.getValue().getCardNumber();
if (cardsNoCopies.containsKey(key)) { if (cardsNoCopies.containsKey(key)) {
Integer count = cardsNoCopies.get(key); Integer count = cardsNoCopies.get(key);
count--; count--;
if (count > 0) { if (count > 0) {
cardsNoCopies.put(key, count); cardsNoCopies.put(key, count);
} else { } else {
cardsNoCopies.remove(key); cardsNoCopies.remove(key);
} }
for (int j = 0; j < view.size(); j++) { for (int j = 0; j < view.size(); j++) {
CardView cv = view.get(j); CardView cv = view.get(j);
if (cv.getId().equals(entry.getValue().getId())) { if (cv.getId().equals(entry.getValue().getId())) {
if (count > 0) { if (count > 0) {
// replace by another card with the same name+setCode // replace by another card with the same name+setCode
String key1 = cv.getName()+cv.getExpansionSetCode()+cv.getCardNumber(); String key1 = cv.getName()+cv.getExpansionSetCode()+cv.getCardNumber();
for (CardView cardView : cards.values()) { for (CardView cardView : cards.values()) {
String key2 = cardView.getName()+cardView.getExpansionSetCode()+cardView.getCardNumber(); String key2 = cardView.getName()+cardView.getExpansionSetCode()+cardView.getCardNumber();
if ((key1).equals(key2)) { if ((key1).equals(key2)) {
view.set(j, cardView); view.set(j, cardView);
break; break;
}
} }
} else {
view.remove(j);
} }
} else { break;
view.remove(j);
} }
}
}
} else {
for (CardView cv : view) {
if (cv.getId().equals(entry.getKey())) {
view.remove(cv);
break; break;
} }
} }
} }
} else {
for (CardView cv : view) {
if (cv.getId().equals(entry.getKey())) {
view.remove(cv);
break;
}
}
} }
} }
}
if (updateCountsCallback != null) { if (updateCountsCallback != null) {
updateCountsCallback.update(cards.size(), creatureCount, landCount); updateCountsCallback.update(cards.size(), creatureCount, landCount);
}
} }
sort(1, true); sort(1, true);
@ -384,4 +399,9 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
public void setUpdateCountsCallback(UpdateCountsCallback callback) { public void setUpdateCountsCallback(UpdateCountsCallback callback) {
this.updateCountsCallback = callback; this.updateCountsCallback = callback;
} }
@Override
public int cardsSize() {
return cards.size();
}
} }

View file

@ -54,7 +54,7 @@ import mage.watchers.common.DamagedByWatcher;
public class KumanosPupils extends CardImpl<KumanosPupils> { public class KumanosPupils extends CardImpl<KumanosPupils> {
public KumanosPupils(UUID ownerId) { public KumanosPupils(UUID ownerId) {
super(ownerId, 177, "Kumano's Pupils", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{4}{R}"); super(ownerId, 177, "Kumano's Pupils", Rarity.UNCOMMON, new CardType[]{CardType.CREATURE}, "{4}{R}");
this.expansionSetCode = "CHK"; this.expansionSetCode = "CHK";
this.subtype.add("Human"); this.subtype.add("Human");
this.subtype.add("Shaman"); this.subtype.add("Shaman");

View file

@ -204,12 +204,15 @@ public class CardCriteria {
clausesCount++; clausesCount++;
} }
for (CardType type : types) {
where.like("types", new SelectArg('%' + type.name() + '%')); if (types.size() != 7) { //if all types selected - no selection needed
} for (CardType type : types) {
if (!types.isEmpty()) { where.like("types", new SelectArg('%' + type.name() + '%'));
where.or(types.size()); }
clausesCount++; if (!types.isEmpty()) {
where.or(types.size());
clausesCount++;
}
} }
for (CardType type : notTypes) { for (CardType type : notTypes) {
@ -277,6 +280,6 @@ public class CardCriteria {
qb.limit(count); qb.limit(count);
} }
qb.orderBy("cardNumber", true); // qb.orderBy("cardNumber", true);
} }
} }

View file

@ -44,6 +44,7 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import mage.constants.CardType; import mage.constants.CardType;
import org.apache.log4j.Logger;
/** /**
* *
@ -265,7 +266,7 @@ public enum CardRepository {
try { try {
QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder(); QueryBuilder<CardInfo, Object> queryBuilder = cardDao.queryBuilder();
criteria.buildQuery(queryBuilder); criteria.buildQuery(queryBuilder);
return cardDao.query(queryBuilder.prepare()); return cardDao.query(queryBuilder.prepare());
} catch (SQLException ex) { } catch (SQLException ex) {
} }