UI: added set search button in deck generator (but it bugged and disabled);

This commit is contained in:
Oleg Agafonov 2017-12-30 16:03:49 +04:00
parent b05754bd61
commit a32b4b75af
3 changed files with 84 additions and 42 deletions

View file

@ -42,6 +42,7 @@ import mage.cards.decks.Deck;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import mage.client.util.gui.ColorsChooser; import mage.client.util.gui.ColorsChooser;
import mage.client.util.gui.FastSearchUtil;
import mage.client.util.sets.ConstructedFormats; import mage.client.util.sets.ConstructedFormats;
/** /**
@ -106,22 +107,39 @@ public class DeckGeneratorDialog {
c.weightx = 0.10; c.weightx = 0.10;
mainPanel.add(formatSetText, c); mainPanel.add(formatSetText, c);
// Format/set dropdown // Format/set dropdown with search button
JPanel setPanel = new JPanel();
setPanel.setLayout(new javax.swing.BoxLayout(setPanel, javax.swing.BoxLayout.LINE_AXIS));
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
c.gridx = 1; c.gridx = 1;
c.gridy = 1; c.gridy = 1;
c.ipadx = 30; c.ipadx = 30;
c.insets = new Insets(5, 10, 0, 10); c.insets = new Insets(5, 10, 0, 10);
c.weightx = 0.90; c.weightx = 0.80;
mainPanel.add(setPanel, c);
cbSets = new JComboBox<>(ConstructedFormats.getTypes()); cbSets = new JComboBox<>(ConstructedFormats.getTypes());
cbSets.setSelectedIndex(0); cbSets.setSelectedIndex(0);
mainPanel.add(cbSets, c); cbSets.setAlignmentX(0.0F);
setPanel.add(cbSets);
String prefSet = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_DECK_GENERATOR_SET, null); String prefSet = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_DECK_GENERATOR_SET, null);
if (prefSet != null) { if (prefSet != null) {
cbSets.setSelectedItem(prefSet); cbSets.setSelectedItem(prefSet);
} }
JButton btn = new JButton();
btn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/search_32.png")));
btn.setToolTipText(FastSearchUtil.DEFAULT_EXPANSION_TOOLTIP_MESSAGE);
btn.setAlignmentX(1.0F);
btn.setPreferredSize(new java.awt.Dimension(32, 32));
btn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
FastSearchUtil.showFastSearchForStringComboBox(cbSets, FastSearchUtil.DEFAULT_EXPANSION_SEARCH_MESSAGE);
}
});
//setPanel.add(btn, c); // TODO: can't show pickdialog here... need to replace standard modal dialog (JOptionPane) to internal mage dialog
// Deck size label // Deck size label
c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(0, 15, 0, 0); c.insets = new Insets(0, 15, 0, 0);

View file

@ -47,13 +47,12 @@ import mage.cards.Sets;
import mage.cards.repository.CardCriteria; import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.choices.ChoiceImpl;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.cards.*; import mage.client.cards.*;
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.dialog.PickChoiceDialog;
import mage.client.util.GUISizeHelper; import mage.client.util.GUISizeHelper;
import mage.client.util.gui.FastSearchUtil;
import mage.client.util.sets.ConstructedFormats; import mage.client.util.sets.ConstructedFormats;
import mage.constants.CardType; import mage.constants.CardType;
import mage.filter.FilterCard; import mage.filter.FilterCard;
@ -228,39 +227,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
cbExpansionSet.setSelectedIndex(0); cbExpansionSet.setSelectedIndex(0);
} }
public void doFastExpansionSearch(){
mage.choices.Choice choice = new ChoiceImpl(false);
// collect data from expansion combobox (String)
DefaultComboBoxModel comboModel = (DefaultComboBoxModel)cbExpansionSet.getModel();
Map<String, String> choiceItems = new HashMap<>(comboModel.getSize());
Map<String, Integer> choiceSorting = new HashMap<>(comboModel.getSize());
String item;
for(int i = 0; i < comboModel.getSize() - 1; i++){
item = (String)comboModel.getElementAt(i);
choiceItems.put(item, item);
choiceSorting.put(item, i); // need so sorting
}
choice.setKeyChoices(choiceItems);
choice.setSortData(choiceSorting);
choice.setMessage("Select set or expansion");
// current selection value restore
String needSelectValue;
needSelectValue = (String)comboModel.getSelectedItem();
// ask for new value
PickChoiceDialog dlg = new PickChoiceDialog();
dlg.setWindowSize(300, 500);
dlg.showDialog(choice, needSelectValue);
if(choice.isChosen()){
item = choice.getChoiceKey();
comboModel.setSelectedItem(item);
}
}
private FilterCard buildFilter() { private FilterCard buildFilter() {
FilterCard filter = new FilterCard(); FilterCard filter = new FilterCard();
@ -1255,7 +1221,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
}//GEN-LAST:event_chkRulesActionPerformed }//GEN-LAST:event_chkRulesActionPerformed
private void btnExpansionSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExpansionSearchActionPerformed private void btnExpansionSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExpansionSearchActionPerformed
doFastExpansionSearch(); FastSearchUtil.showFastSearchForStringComboBox(cbExpansionSet, "Select set or expansion");
}//GEN-LAST:event_btnExpansionSearchActionPerformed }//GEN-LAST:event_btnExpansionSearchActionPerformed
private void toggleViewMode() { private void toggleViewMode() {

View file

@ -0,0 +1,58 @@
package mage.client.util.gui;
import mage.choices.ChoiceImpl;
import mage.client.dialog.PickChoiceDialog;
import javax.swing.*;
import java.util.HashMap;
import java.util.Map;
/**
*
* @author JayDi85
*/
public class FastSearchUtil {
public static String DEFAULT_EXPANSION_SEARCH_MESSAGE = "Select set or expansion";
public static String DEFAULT_EXPANSION_TOOLTIP_MESSAGE = "Fast search set or expansion";
/**
* Show fast choice modal dialog with incremental searching for any string combobox components
* @param combo combobox control with default data model
* @param chooseMessage caption message for dialog
*/
public static void showFastSearchForStringComboBox(JComboBox combo, String chooseMessage){
// fast search/choice dialog for string combobox
mage.choices.Choice choice = new ChoiceImpl(false);
// collect data from expansion combobox (String)
DefaultComboBoxModel comboModel = (DefaultComboBoxModel)combo.getModel();
Map<String, String> choiceItems = new HashMap<>(comboModel.getSize());
Map<String, Integer> choiceSorting = new HashMap<>(comboModel.getSize());
String item;
for(int i = 0; i < comboModel.getSize() - 1; i++){
item = (String)comboModel.getElementAt(i);
choiceItems.put(item, item);
choiceSorting.put(item, i); // need so sorting
}
choice.setKeyChoices(choiceItems);
choice.setSortData(choiceSorting);
choice.setMessage(chooseMessage);
// current selection value restore
String needSelectValue;
needSelectValue = (String)comboModel.getSelectedItem();
// ask for new value
PickChoiceDialog dlg = new PickChoiceDialog();
dlg.setWindowSize(300, 500);
dlg.showDialog(choice, needSelectValue);
if(choice.isChosen()){
item = choice.getChoiceKey();
comboModel.setSelectedItem(item);
}
}
}