Enhanced card-by-text searching in deck editor

This commit is contained in:
magenoxx 2012-05-08 14:28:06 +04:00
parent 901eb16a23
commit be7f01b0ba
2 changed files with 33 additions and 22 deletions

View file

@ -50,10 +50,7 @@ import mage.view.CardsView;
import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.util.*;
import java.util.List;
@ -67,6 +64,13 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
private final FilterCard filter = new FilterCard();
private BigCard bigCard;
private boolean limited = false;
private final ActionListener searchAction = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
jButtonSearchActionPerformed(evt);
}
};
/** Creates new form CardSelector */
public CardSelector() {
@ -83,6 +87,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
jScrollPane1.setOpaque(false);
jScrollPane1.getViewport().setOpaque(false);
cbSortBy.setModel(new DefaultComboBoxModel(SortBy.values()));
jTextFieldSearch.addActionListener(searchAction);
}
public void initListViewComponents() {

View file

@ -28,15 +28,12 @@
package mage.filter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.Constants.TargetController;
import mage.cards.Card;
import mage.game.Game;
import java.util.*;
/**
*
* @author BetaSteward_at_googlemail.com
@ -90,24 +87,33 @@ public class FilterCard<T extends FilterCard<T>> extends FilterObject<Card, Filt
boolean filterOut = !card.getName().toLowerCase().contains(text.toLowerCase());
// if couldn't find
if (filterOut) {
// then try to find in rules
for (String rule : card.getRules()) {
if (rule.toLowerCase().contains(text.toLowerCase())) {
filterOut = false;
break;
}
}
//separate by spaces
String[] tokens = text.toLowerCase().split(" ");
int count = 0;
int found = 0;
for (String token : tokens) {
if (!token.isEmpty()) {
count++;
// then try to find in rules
for (String rule : card.getRules()) {
if (rule.toLowerCase().contains(token)) {
found++;
break;
}
}
if (filterOut) {
for (String subType : card.getSubtype()) {
if (subType.equalsIgnoreCase(text)) {
filterOut = false;
break;
if (filterOut) {
for (String subType : card.getSubtype()) {
if (subType.equalsIgnoreCase(token)) {
found++;
break;
}
}
}
}
}
if (filterOut)
if (found < count)
return notFilter;
}