diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form index 40acdd8c3d8..a4a3a90526e 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form +++ b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.form @@ -38,7 +38,9 @@ + + @@ -263,17 +265,6 @@ - - - - - - - - - - - diff --git a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java index 3c9976a3d59..102a831e81f 100644 --- a/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java +++ b/Mage.Client/src/main/java/mage/client/deckeditor/CardSelector.java @@ -58,7 +58,6 @@ import static mage.client.dialog.PreferencesDialog.KEY_DECK_EDITOR_SEARCH_UNIQUE import mage.client.util.GUISizeHelper; import mage.client.util.gui.FastSearchUtil; import mage.client.dialog.CheckBoxList; -import mage.client.util.gui.FastSearchUtil_1; import mage.client.util.sets.ConstructedFormats; import mage.constants.CardType; @@ -73,7 +72,6 @@ import mage.filter.predicate.other.CardTextPredicate; import mage.filter.predicate.other.ExpansionSetPredicate; import mage.view.CardView; import mage.view.CardsView; -//import org.apache.log4j.helpers.LogLog; import org.mage.card.arcane.ManaSymbolsCellRenderer; /** @@ -88,12 +86,16 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene private final SortSetting sortSetting; private static final Map pdAllowed = new HashMap<>(); + private final String TEST_MULTI_SET="Multiple Sets selected"; + private final ActionListener searchAction = evt -> jButtonSearchActionPerformed(evt); /** * Creates new form CardSelector */ public CardSelector() { + + sortSetting = SortSettingBase.getInstance(); initComponents(); cardGrid = new CardGrid(); @@ -101,7 +103,25 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene initListViewComponents(); setGUISize(); currentView = mainModel; // by default we use List View - } + + listCodeSelected = new CheckBoxList(); + // remove the all option + boolean is_removeFinish=false; + + String[] setCodes = ConstructedFormats.getTypes(); + java.util.List result = new ArrayList<>(); + + for(int i=0; (i setCodes; + private CardCriteria buildCriteria() { CardCriteria criteria = new CardCriteria(); criteria.black(this.tbBlack.isSelected()); criteria.blue(this.tbBlue.isSelected()); @@ -363,13 +381,33 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene } if (this.cbExpansionSet.isVisible()) { - String expansionSelection = this.cbExpansionSet.getSelectedItem().toString(); - if (!expansionSelection.equals("- All Sets")) { - java.util.List setCodes = ConstructedFormats.getSetsByFormat(expansionSelection); + if(listCodeSelected.getCheckedIndices().length <= 1) + { + String expansionSelection = this.cbExpansionSet.getSelectedItem().toString(); + if (!expansionSelection.equals("- All Sets")) { + java.util.List setCodes = ConstructedFormats.getSetsByFormat(expansionSelection); + criteria.setCodes(setCodes.toArray(new String[0])); + } + } + else + { + java.util.List setCodes = new ArrayList<>() ; + //java.util.List listReceived=new ArrayList<>() ; + + int[] choiseValue=listCodeSelected.getCheckedIndices(); + ListModel x= listCodeSelected.getModel(); + + for(int itemIndex: choiseValue){ + + java.util.List listReceived=ConstructedFormats.getSetsByFormat(x.getElementAt(itemIndex).toString()); + listReceived.stream().filter((item) -> (setCodes.contains(item)==false)).forEachOrdered((item) -> { + setCodes.add(item); + }); + } criteria.setCodes(setCodes.toArray(new String[0])); } } - if(cbSetTag!=null) + /*if(cbSetTag!=null) { if(listCodeSelected != null) { @@ -389,7 +427,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene criteria.setCodes(setCodes.toArray(new String[0])); } } - } + }*/ return criteria; } @@ -472,16 +510,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene continue; } } - filteredCards.add(card); - if(cbSetTag==null) - { - cbSetTag = new javax.swing.JComboBox<>(); - fist_time = true; - } - if(fist_time == true) - { - cbSetTag.addItem(cardInfo.getSetCode()); - } + filteredCards.add(card); } } } @@ -558,7 +587,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene chkPennyDreadful = new javax.swing.JCheckBox(); btnBooster = new javax.swing.JButton(); btnClear = new javax.swing.JButton(); - jButton1 = new javax.swing.JButton(); tbTypes = new javax.swing.JToolBar(); tbLand = new javax.swing.JToggleButton(); tbCreatures = new javax.swing.JToggleButton(); @@ -761,17 +789,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene }); tbColor.add(btnClear); - jButton1.setText("Filter Set"); - jButton1.setFocusable(false); - jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - jButton1.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); - } - }); - tbColor.add(jButton1); - tbTypes.setFloatable(false); tbTypes.setRollover(true); tbTypes.setToolTipText("Hold the ALT-key while clicking to deselect all other card types or hold the CTRL-key to only select all other card types."); // NOI18N @@ -1193,7 +1210,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene .addComponent(cardCountLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cardCount, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap(139, Short.MAX_VALUE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); cardSelectorBottomPanelLayout.setVerticalGroup( cardSelectorBottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -1238,12 +1255,32 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene .addComponent(tbColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, 0) .addComponent(tbTypes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, 0) .addComponent(cardSelectorScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE) + .addGap(0, 0, 0) .addComponent(cardSelectorBottomPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) ); }// //GEN-END:initComponents private void cbExpansionSetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbExpansionSetActionPerformed + + + if(!cbExpansionSet.getSelectedItem().toString().contains(TEST_MULTI_SET)) + { + int index=cbExpansionSet.getSelectedIndex(); + if(cbExpansionSet.getItemAt(0).contains(TEST_MULTI_SET)) + { + cbExpansionSet.removeItemAt(0); + index--; + } + listCodeSelected.uncheckAll(); + if(index > 0) + { + //ofset because all sets is removed from the list + listCodeSelected.setChecked(index-1, true); + } + } + filterCards(); }//GEN-LAST:event_cbExpansionSetActionPerformed @@ -1425,7 +1462,46 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene }//GEN-LAST:event_chkRulesActionPerformed private void btnExpansionSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExpansionSearchActionPerformed - FastSearchUtil.showFastSearchForStringComboBox(cbExpansionSet, "Select set or expansion"); + + FastSearchUtil.showFastSearchForStringComboBox(listCodeSelected, FastSearchUtil.DEFAULT_EXPANSION_SEARCH_MESSAGE); +// + int[] choiseValue=listCodeSelected.getCheckedIndices(); + ListModel x= listCodeSelected.getModel(); + + if(choiseValue.length==0)//none + { + cbExpansionSet.setSelectedIndex(0); + } + else if(choiseValue.length==1)//one + { + String itemSelected=listCodeSelected.getModel().getElementAt(choiseValue[0]).toString(); + for(int index=0;index < cbExpansionSet.getItemCount();index++) + { + if(cbExpansionSet.getItemAt(index).equals(itemSelected)) + { + cbExpansionSet.setSelectedIndex(index); + } + } + + } + else//many + { + String message=String.format("%s:%d",TEST_MULTI_SET,choiseValue.length); + + cbExpansionSet.insertItemAt(message, 0); + cbExpansionSet.setSelectedIndex(0); + + //listCodeSelected.setChecked(index-1, true); + //cbExpansionSet. + } + + /*for(int itemIndex: choiseValue){ + // LogLog.warn(String.format("%d:%s",itemIndex,x.getElementAt(itemIndex).toString())); + } + */ +// + + filterCards(); }//GEN-LAST:event_btnExpansionSearchActionPerformed private void tbCommonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tbCommonActionPerformed @@ -1448,14 +1524,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene filterCardsRarity(evt.getModifiers(), evt.getActionCommand()); }//GEN-LAST:event_tbSpecialActionPerformed - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed - - CheckBoxList testList; - listCodeSelected = FastSearchUtil_1.showFastSearchForStringComboBox(cbSetTag, FastSearchUtil_1.DEFAULT_EXPANSION_SEARCH_MESSAGE); - filterCards(); - - }//GEN-LAST:event_jButton1ActionPerformed - private void toggleViewMode() { if (currentView instanceof CardGrid) { jToggleListView.setSelected(true); @@ -1494,6 +1562,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene private JTable mainTable; private ICardGrid currentView; + static boolean isFirstTimeHere=true; private CheckBoxList listCodeSelected; private javax.swing.JComboBox cbSetTag; // Variables declaration - do not modify//GEN-BEGIN:variables @@ -1513,7 +1582,6 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene private javax.swing.JCheckBox chkRules; private javax.swing.JCheckBox chkTypes; private javax.swing.JCheckBox chkUnique; - private javax.swing.JButton jButton1; private javax.swing.JButton jButtonAddToMain; private javax.swing.JButton jButtonAddToSideboard; private javax.swing.JButton jButtonClean; diff --git a/Mage.Client/src/main/java/mage/client/dialog/CheckBoxList.java b/Mage.Client/src/main/java/mage/client/dialog/CheckBoxList.java index 5a07653be85..49c007c1f0d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/CheckBoxList.java +++ b/Mage.Client/src/main/java/mage/client/dialog/CheckBoxList.java @@ -552,7 +552,7 @@ public class CheckBoxList extends JList { int index = locationToIndex(e.getPoint()); if (index != -1) { - setChecked(index, !getChecked(index)); + setChecked(index, !getChecked(index)); repaint(); } } @@ -665,4 +665,16 @@ public class CheckBoxList extends JList { return result; } + + public void checkAll() { + for (int i = 0; i < getModel().getSize(); i++) { + this.setChecked(i,true); + } + } + public void uncheckAll() { + int[] choiceToUncheck = this.getCheckedIndices(); + for(int itemIndex: choiceToUncheck){ + this.setChecked(itemIndex,false); + } + } } diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form index 4b4f2fa9812..de1e7b96128 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.form @@ -39,7 +39,7 @@ - + @@ -55,8 +55,8 @@ - - + + @@ -65,10 +65,10 @@ - + - - + + @@ -158,12 +158,14 @@ - + + + + + + + - - - - @@ -174,6 +176,7 @@ + @@ -200,6 +203,20 @@ + + + + + + + + + + + + + + diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java index 80a28468f9e..add88fddba3 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog.java @@ -5,6 +5,7 @@ */ package mage.client.dialog; +import java.awt.Color; import java.awt.Dimension; import java.awt.Point; import java.awt.event.ActionEvent; @@ -32,6 +33,7 @@ import mage.client.util.gui.MageDialogState; /** * * @author JayDi85 + * @author Salco */ public class PickChoiceDialog extends MageDialog { @@ -39,9 +41,29 @@ public class PickChoiceDialog extends MageDialog { Choice choice; ArrayList allItems = new ArrayList<>(); DefaultListModel dataModel = new DefaultListModel(); + CheckBoxList.CheckBoxListModel m_dataModel; + + CheckBoxList tList; final private static String HTML_TEMPLATE = "
%s
"; + private void setFocus(CheckBoxList obj){ + + if (!(obj instanceof java.awt.Component)) { + throw new IllegalArgumentException("Must be a java.awt.Component!"); + } + this.scrollList.setViewportView((java.awt.Component)obj); + } + private javax.swing.JList get_a_Jlist_from_ScrollListView(){ + return ((javax.swing.JList)this.scrollList.getViewport().getView()); + } + + private void restoreData(Object dataFrom){ + this.allItems.forEach((item) -> { + ((CheckBoxList.CheckBoxListModel)dataFrom).addElement(item.getObjectValue()); + }); + } + public void showDialog(Choice choice) { showDialog(choice, null, null, null); } @@ -56,7 +78,9 @@ public class PickChoiceDialog extends MageDialog { public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState, String startSelectionValue) { this.choice = choice; - + KeyValueItem tempKeyValue; + int indexInTList; + setLabelText(this.labelMessage, choice.getMessage()); setLabelText(this.labelSubMessage, choice.getSubMessage()); @@ -68,11 +92,25 @@ public class PickChoiceDialog extends MageDialog { this.allItems.clear(); if (choice.isKeyChoice()){ for (Map.Entry entry: choice.getKeyChoices().entrySet()) { - this.allItems.add(new KeyValueItem(entry.getKey(), entry.getValue())); + if(tList != null){ + indexInTList = m_dataModel.indexOf(entry.getKey()); + tempKeyValue=new KeyValueItem(entry.getKey(), entry.getValue(),(CheckBoxList.CheckBoxListItem) this.tList.getModel().getElementAt(indexInTList)); + } + else{ + tempKeyValue=new KeyValueItem(entry.getKey(), entry.getValue()); + } + this.allItems.add(tempKeyValue); } } else { for (String value: choice.getChoices()){ - this.allItems.add(new KeyValueItem(value, value)); + if(tList != null){ + indexInTList = m_dataModel.indexOf(value); + tempKeyValue=new KeyValueItem(value, value,(CheckBoxList.CheckBoxListItem) tList.getModel().getElementAt(indexInTList)); + } + else{ + tempKeyValue=new KeyValueItem(value, value); + } + this.allItems.add(tempKeyValue); } } @@ -81,8 +119,8 @@ public class PickChoiceDialog extends MageDialog { Collections.sort(this.allItems, new Comparator() { @Override public int compare(KeyValueItem o1, KeyValueItem o2) { - Integer n1 = choice.getSortData().get(o1.Key); - Integer n2 = choice.getSortData().get(o2.Key); + Integer n1 = choice.getSortData().get(o1.getKey()); + Integer n2 = choice.getSortData().get(o2.getKey()); return n1.compareTo(n2); } }); @@ -184,18 +222,24 @@ public class PickChoiceDialog extends MageDialog { // start selection if((startSelectionValue != null)){ + javax.swing.JList currentlistChoices;// = new javax.swing.JList(); + currentlistChoices=this.get_a_Jlist_from_ScrollListView(); + /*currentlistChoices = this.listChoices;*/ int selectIndex = -1; for(int i = 0; i < this.listChoices.getModel().getSize(); i++){ - KeyValueItem listItem = (KeyValueItem)this.listChoices.getModel().getElementAt(i); - if (listItem.Key.equals(startSelectionValue)){ + //KeyValueItem listItem = (KeyValueItem)currentlistChoices.getModel().getElementAt(i); + String elementOfList = currentlistChoices.getModel().getElementAt(i).toString(); + if (elementOfList.equals(startSelectionValue)){ selectIndex = i; break; } } if(selectIndex >= 0){ - this.listChoices.setSelectedIndex(selectIndex); - this.listChoices.ensureIndexIsVisible(selectIndex); + // currentlistChoices=this.get_a_Jlist_from_ScrollListView(); + /*currentlistChoices = this.listChoices;*/ + currentlistChoices.setSelectedIndex(selectIndex); + currentlistChoices.ensureIndexIsVisible(selectIndex); } } @@ -208,14 +252,16 @@ public class PickChoiceDialog extends MageDialog { private void loadData(){ // load data to datamodel after filter or on startup - String filter = choice.getSearchText(); + String filter = choice.getSearchText(); if (filter == null){ filter = ""; } filter = filter.toLowerCase(); this.dataModel.clear(); + this.m_dataModel.clear(); for(KeyValueItem item: this.allItems){ if(!choice.isSearchEnabled() || item.Value.toLowerCase().contains(filter)){ this.dataModel.addElement(item); + this.m_dataModel.addElement(item.getObjectValue()); } } } @@ -248,7 +294,9 @@ public class PickChoiceDialog extends MageDialog { } private void doChoose(){ - if(setChoice()){ + if((tList != null)||(setChoice())){ + this.m_dataModel.clear(); + restoreData(this.m_dataModel); this.hideDialog(); } } @@ -261,11 +309,33 @@ public class PickChoiceDialog extends MageDialog { /** * Creates new form PickChoiceDialog + * @param list */ - public PickChoiceDialog() { + public PickChoiceDialog(CheckBoxList list) { initComponents(); + tList=list; + this.listChoices.setModel(dataModel); this.setModal(true); + + if(tList != null) + { + this.listChoices.setVisible(false); + + m_dataModel= ( CheckBoxList.CheckBoxListModel )tList.getModel(); + tList.setSelectionForeground(Color.BLUE); + + if(this.tList instanceof javax.swing.JList){ + setFocus(tList); + } + + } + } + /** + * Creates new form PickChoiceDialog + */ + public PickChoiceDialog() { + this(null); } public boolean setChoice() { @@ -294,19 +364,31 @@ public class PickChoiceDialog extends MageDialog { { private final String Key; private final String Value; - - public KeyValueItem(String value, String label) { + private final CheckBoxList.CheckBoxListItem objectValue; + + public KeyValueItem(String value) { + this(value,null,null); + } + public KeyValueItem(String value, String label) { + this(value,label,null); + } + public KeyValueItem(String value, String label,CheckBoxList.CheckBoxListItem object) { this.Key = value; this.Value = label; + this.objectValue = object; } public String getKey() { return this.Key; - } + } public String getValue() { return this.Value; } + + public Object getObjectValue(){ + return (CheckBoxList.CheckBoxListItem)this.objectValue; + } @Override public String toString() { @@ -334,6 +416,7 @@ public class PickChoiceDialog extends MageDialog { panelCommands = new javax.swing.JPanel(); btOK = new javax.swing.JButton(); btCancel = new javax.swing.JButton(); + btClear = new javax.swing.JButton(); labelMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); labelMessage.setText("
example long message example long message example long message example long message example long message
"); @@ -348,17 +431,17 @@ public class PickChoiceDialog extends MageDialog { panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelHeaderLayout.createSequentialGroup() .addGroup(panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(labelMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE) - .addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)) + .addComponent(labelMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) + .addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING)) .addGap(0, 0, 0)) ); panelHeaderLayout.setVerticalGroup( panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelHeaderLayout.createSequentialGroup() - .addGap(0, 0, 0) + .addGap(0, 0, Short.MAX_VALUE) .addComponent(labelMessage) - .addGap(0, 0, 0) - .addComponent(labelSubMessage)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(labelSubMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE)) ); labelSearch.setText("Search:"); @@ -407,30 +490,39 @@ public class PickChoiceDialog extends MageDialog { } }); + btClear.setText("Clear"); + btClear.setMinimumSize(new java.awt.Dimension(30, 25)); + btClear.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btClearActionPerformed(evt); + } + }); + javax.swing.GroupLayout panelCommandsLayout = new javax.swing.GroupLayout(panelCommands); panelCommands.setLayout(panelCommandsLayout); panelCommandsLayout.setHorizontalGroup( panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelCommandsLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(btClear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btOK) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) + .addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); - - panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOK}); - panelCommandsLayout.setVerticalGroup( panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(panelCommandsLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btCancel) - .addComponent(btOK)) + .addComponent(btOK) + .addComponent(btClear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap()) ); + getRootPane().setDefaultButton(btOK); getRootPane().setDefaultButton(btOK); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); @@ -454,7 +546,7 @@ public class PickChoiceDialog extends MageDialog { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(panelSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollList, javax.swing.GroupLayout.DEFAULT_SIZE, 246, Short.MAX_VALUE) + .addComponent(scrollList, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) @@ -478,8 +570,16 @@ public class PickChoiceDialog extends MageDialog { doCancel(); }//GEN-LAST:event_closeDialog + private void btClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btClearActionPerformed + // TODO add your handling code here: + this.tList.uncheckAll(); + //this.tList.repaint(); + scrollList.repaint(); + }//GEN-LAST:event_btClearActionPerformed + // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btCancel; + private javax.swing.JButton btClear; private javax.swing.JButton btOK; private javax.swing.JTextField editSearch; private javax.swing.JLabel labelMessage; diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog_1.form b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog_1.form deleted file mode 100644 index 704d52d82d2..00000000000 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog_1.form +++ /dev/null @@ -1,206 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog_1.java b/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog_1.java deleted file mode 100644 index 186647d0d96..00000000000 --- a/Mage.Client/src/main/java/mage/client/dialog/PickChoiceDialog_1.java +++ /dev/null @@ -1,654 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package mage.client.dialog; - -import java.awt.Dimension; -import java.awt.Point; -import java.awt.event.ActionEvent; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import java.awt.event.MouseAdapter; -import java.awt.event.MouseEvent; -import java.util.*; -import javax.swing.AbstractAction; -import javax.swing.ActionMap; -import javax.swing.DefaultListModel; -import javax.swing.InputMap; -import javax.swing.JComponent; -import javax.swing.JLabel; -import javax.swing.JLayeredPane; -//import javax.swing.JList; -import javax.swing.KeyStroke; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import mage.choices.Choice; -import mage.client.MageFrame; -import mage.client.util.SettingsManager; -import mage.client.util.gui.GuiDisplayUtil; -import mage.client.util.gui.MageDialogState; -import org.apache.log4j.helpers.LogLog; -import mage.client.dialog.CheckBoxList; -/** - * - * @author JayDi85 - */ - -public class PickChoiceDialog_1 extends MageDialog { - - Choice choice; - ArrayList allItems = new ArrayList<>(); - //ArrayList allItems = new ArrayList<>(); - DefaultListModel dataModel =new DefaultListModel(); - CheckBoxList.CheckBoxListModel m_dataModel; - - CheckBoxList tList; - T tListChoices; - - final private static String HTML_TEMPLATE = "
%s
"; - - public void setList(T t) { this.tList = (CheckBoxList)t; } - public T getList() { return (T)tList; } - - private void setFocus(T obj){ - //((JList)obj).setModel(dataModel); - if (!(obj instanceof java.awt.Component)) { - throw new IllegalArgumentException("Must be a java.awt.Component!"); - } - this.scrollList.setViewportView((java.awt.Component)obj); - } - private javax.swing.JList castAsJList(Object anObject){ - return ((javax.swing.JList)anObject); - } - private javax.swing.JList get_a_Jlist_from_ScrollListView(){ - return ((javax.swing.JList)this.scrollList.getViewport().getView()); - } - private void backupData(Object model){ - KeyValueItem item; - int indexInTList; - String name; - - int maxLenght = this.allItems.size();//(((CheckBoxList.CheckBoxListModel)model).size()); - for(int index=0;index < maxLenght;index++){ - item= this.allItems.get(index); - name=item.getKey();//((CheckBoxList.CheckBoxListModel)model).getElementAt(index).toString(); - indexInTList = ((CheckBoxList.CheckBoxListModel)model).indexOf(item.getKey()); - - if(indexInTList>=0){ - - - //if(item.getKey().equals(((CheckBoxList.CheckBoxListModel)model).get(index).toString())){ - if( !(item.getObjectValue().equals(((CheckBoxList.CheckBoxListModel)model).getElementAt(indexInTList)))){ - LogLog.warn(String.format("%s change",((CheckBoxList.CheckBoxListModel)model).getElementAt(indexInTList).toString())); - //this.allItems.get(indexInTList) - } - //} - } - } - } - private void restoreData(Object dataFrom){ - /* KeyValueItem item; - int maxLenght = this.allItems.size();//((CheckBoxList.CheckBoxListModel)dataFrom).size()); - for(int index=0;index < maxLenght;index++){ - item= this.allItems.get(index); - if(item.getKey().equals(((CheckBoxList.CheckBoxListModel)dataFrom).get(index).toString())){ - if( !(item.getObjectValue().equals(((CheckBoxList.CheckBoxListModel)dataFrom).getElementAt(index)))){ - LogLog.warn(String.format("%s change",((CheckBoxList.CheckBoxListModel)dataFrom).getElementAt(index).toString())); - } - } - } - */ - for(KeyValueItem item: this.allItems){ - ((CheckBoxList.CheckBoxListModel)dataFrom).addElement(item.getObjectValue()); - } - } - - public void showDialog(Choice choice) { - showDialog(choice, null, null, null); - } - - public void showDialog(Choice choice, String startSelectionValue) { - showDialog(choice, null, null, startSelectionValue); - } - - public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState) { - showDialog(choice, objectId, mageDialogState, null); - } - - public void showDialog(Choice choice, UUID objectId, MageDialogState mageDialogState, String startSelectionValue) { - this.choice = choice; - - setLabelText(this.labelMessage, choice.getMessage()); - setLabelText(this.labelSubMessage, choice.getSubMessage()); - - btCancel.setEnabled(!choice.isRequired()); - - // 2 modes: string or key-values - // sore data in allItems for inremental filtering - // http://logicbig.com/tutorials/core-java-tutorial/swing/list-filter/ - this.allItems.clear(); - KeyValueItem tempKeyValue; - int indexInTList; - - if (choice.isKeyChoice()){ - for (Map.Entry entry: choice.getKeyChoices().entrySet()) { - - if(tList != null){ - /*for(int index=0;index() { - @Override - public int compare(KeyValueItem o1, KeyValueItem o2) { - Integer n1 = choice.getSortData().get(o1.Key); - Integer n2 = choice.getSortData().get(o2.Key); - return n1.compareTo(n2); - } - }); - } - - // search - if(choice.isSearchEnabled()) - { - panelSearch.setVisible(true); - this.editSearch.setText(choice.getSearchText()); - }else{ - panelSearch.setVisible(false); - this.editSearch.setText(""); - } - - // listeners for inremental filtering - editSearch.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { - choice.setSearchText(editSearch.getText()); - loadData(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - choice.setSearchText(editSearch.getText()); - loadData(); - } - - @Override - public void changedUpdate(DocumentEvent e) { - choice.setSearchText(editSearch.getText()); - loadData(); - } - }); - - // listeners for select up and down without edit focus lost - editSearch.addKeyListener(new KeyListener() { - @Override - public void keyTyped(KeyEvent e) { - //System.out.println("types"); - } - - @Override - public void keyPressed(KeyEvent e) { - if(e.getKeyCode() == KeyEvent.VK_UP){ - doPrevSelect(); - }else if(e.getKeyCode() == KeyEvent.VK_DOWN){ - doNextSelect(); - } - } - - @Override - public void keyReleased(KeyEvent e) { - //System.out.println("released"); - } - }); - - // listeners double click choose - listChoices.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - if(e.getClickCount() == 2){ - doChoose(); - } - } - }); - - // listeners for ESC close - if(!choice.isRequired()){ - String cancelName = "cancel"; - InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); - ActionMap actionMap = getRootPane().getActionMap(); - actionMap.put(cancelName, new AbstractAction() { - public void actionPerformed(ActionEvent e) { - doCancel(); - } - }); - } - - // window settings - if (this.isModal()){ - MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER); - }else{ - MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER); - } - if (mageDialogState != null) { - mageDialogState.setStateToDialog(this); - - } else { - Point centered = SettingsManager.instance.getComponentPosition(getWidth(), getHeight()); - this.setLocation(centered.x, centered.y); - GuiDisplayUtil.keepComponentInsideScreen(centered.x, centered.y, this); - } - - // final load - loadData(); - - // start selection - if((startSelectionValue != null)){ - int selectIndex = -1; - - for(int i = 0; i < this.get_a_Jlist_from_ScrollListView().getModel().getSize(); i++){ - String elementOfList = this.get_a_Jlist_from_ScrollListView().getModel().getElementAt(i).toString(); - - if (elementOfList.equals(startSelectionValue)){ - selectIndex = i; - break; - } - } - - if(selectIndex >= 0){ - this.get_a_Jlist_from_ScrollListView().setSelectedIndex(selectIndex); - this.get_a_Jlist_from_ScrollListView().ensureIndexIsVisible(selectIndex); - } - } - - this.setVisible(true); - } - - public void setWindowSize(int width, int heigth){ - this.setSize(new Dimension(width, heigth)); - } - - private void loadData(){ - // load data to datamodel after filter or on startup - String filter = choice.getSearchText(); - if (filter == null){ filter = ""; } - filter = filter.toLowerCase(); - - backupData(this.m_dataModel); - - this.dataModel.clear();this.m_dataModel.clear(); - - for(KeyValueItem item: this.allItems){ - if(!choice.isSearchEnabled() || item.Value.toLowerCase().contains(filter)){ - this.dataModel.addElement(item);this.m_dataModel.addElement(item.getObjectValue()); - } - } - if(this.tList!=null){ - //((javax.swing.JList)this.tList).setModel(dataModel); - //new CheckBoxListModel(); - //((javax.swing.JList)this.scrollList.getViewport().getView()).setModel(dataModel);setListData(dataModel.toArray()); - } - - } - - private void setLabelText(JLabel label, String text){ - if ((text != null) && !text.equals("")){ - label.setText(String.format(HTML_TEMPLATE, text)); - label.setVisible(true); - }else{ - label.setText(""); - label.setVisible(false); - } - } - - private void doNextSelect(){ - int newSel = this.listChoices.getSelectedIndex() + 1; - int maxSel = this.listChoices.getModel().getSize() - 1; - if(newSel <= maxSel){ - this.listChoices.setSelectedIndex(newSel); - this.listChoices.ensureIndexIsVisible(newSel); - } - } - - private void doPrevSelect(){ - int newSel = this.listChoices.getSelectedIndex() - 1; - if(newSel >= 0){ - this.listChoices.setSelectedIndex(newSel); - this.listChoices.ensureIndexIsVisible(newSel); - } - } - - private void doChoose(){ - - if((tList != null)||(setChoice())){ - this.m_dataModel.clear(); - restoreData(this.m_dataModel); - this.hideDialog(); - } - - - } - - private void doCancel(){ - this.listChoices.clearSelection(); - this.choice.clearChoice(); - hideDialog(); - } - - /** - * Creates new form PickChoiceDialog_1 - * @param list - */ - public PickChoiceDialog_1(CheckBoxList list) { - this(); - setList((T)list); - //dataModel = ((javax.swing.JList)tList).getModel(); - - this.listChoices.setVisible(false); - //tList.getModel() - //this.tListChoices = new list.getClass(); - m_dataModel= ( CheckBoxList.CheckBoxListModel )tList.getModel(); - if(this.tList instanceof javax.swing.JList){ - setFocus((T)tList); - //((javax.swing.JList)tList).setModel(dataModel); - } - - /* else if(tList instanceof javax.swing.JComboBox){ - ((javax.swing.JComboBox)tList).setModel(dataModel); - }*/ - - /*if((this.panelListChoices.getViewport().getView())!=null){ - //((T)tList.setListData(dataModel.toArray()); - }*/ - /* if ((tList instanceof javax.swing.JList)) { - //throw new IllegalArgumentException("Must be a java.awt.Component!"); - - ((javax.swing.JList)tList).setModel(((javax.swing.ListModel)dataModel)); - } */ - } - public PickChoiceDialog_1() { - initComponents(); - tList=null; - - - this.listChoices.setModel(dataModel); - /*if((this.scrollList.getViewport().getView())!=null){ - //((CheckBoxList)this.panelListChoices.getViewport().getView()).setListData(dataModel.toArray()); - ((javax.swing.JList)this.scrollList.getViewport().getView()).setListData(dataModel.toArray()); - - }*/ - //test.setModel(dataModel); - //item.setModel(dataModel); - - this.setModal(true); - } - - public boolean setChoice() { - KeyValueItem item = (KeyValueItem)this.listChoices.getSelectedValue(); - - // auto select one item (after incemental filtering) - if((item == null) && (this.listChoices.getModel().getSize() == 1)){ - this.listChoices.setSelectedIndex(0); - item = (KeyValueItem)this.listChoices.getSelectedValue(); - } - - if(item != null){ - if(choice.isKeyChoice()){ - choice.setChoiceByKey(item.getKey()); - }else{ - choice.setChoice(item.getKey()); - } - return true; - }else{ - choice.clearChoice(); - return false; - } - } - - class KeyValueItem - { - private /*final*/ String Key; - private final String Value; - private final CheckBoxList.CheckBoxListItem objectValue; - - public KeyValueItem(String value) { - this.Key = value; - this.Value = null; - this.objectValue = null; - } - public KeyValueItem(String value, String label) { - this.Key = value; - this.Value = label; - this.objectValue = null; - } - public KeyValueItem(String value, String label,CheckBoxList.CheckBoxListItem object) { - this.Key = value; - this.Value = label; - this.objectValue = object; - } - - public String getKey() { - return this.Key; - } - public void setKey(String value) { - this.Key= value; - } - - public String getValue() { - return this.Value; - } - - public Object getObjectValue(){ - return (CheckBoxList.CheckBoxListItem)this.objectValue; - } - - @Override - public String toString() { - return this.Value; - } - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { - - panelHeader = new javax.swing.JPanel(); - labelMessage = new javax.swing.JLabel(); - labelSubMessage = new javax.swing.JLabel(); - panelSearch = new javax.swing.JPanel(); - labelSearch = new javax.swing.JLabel(); - editSearch = new javax.swing.JTextField(); - scrollList = new javax.swing.JScrollPane(); - listChoices = new javax.swing.JList(); - panelCommands = new javax.swing.JPanel(); - btOK = new javax.swing.JButton(); - btCancel = new javax.swing.JButton(); - - labelMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - labelMessage.setText("
example long message example long message example long message example long message example long message
"); - - labelSubMessage.setFont(labelSubMessage.getFont().deriveFont((labelSubMessage.getFont().getStyle() | java.awt.Font.ITALIC) | java.awt.Font.BOLD)); - labelSubMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); - labelSubMessage.setText("
example long message example long
"); - - javax.swing.GroupLayout panelHeaderLayout = new javax.swing.GroupLayout(panelHeader); - panelHeader.setLayout(panelHeaderLayout); - panelHeaderLayout.setHorizontalGroup( - panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelHeaderLayout.createSequentialGroup() - .addGroup(panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(labelMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE) - .addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 210, Short.MAX_VALUE)) - .addGap(0, 0, 0)) - ); - panelHeaderLayout.setVerticalGroup( - panelHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelHeaderLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(labelMessage) - .addGap(0, 0, 0) - .addComponent(labelSubMessage)) - ); - - labelSearch.setText("Search:"); - - editSearch.setText("sample search text"); - - javax.swing.GroupLayout panelSearchLayout = new javax.swing.GroupLayout(panelSearch); - panelSearch.setLayout(panelSearchLayout); - panelSearchLayout.setHorizontalGroup( - panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSearchLayout.createSequentialGroup() - .addGap(0, 0, 0) - .addComponent(labelSearch) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(editSearch) - .addGap(0, 0, 0)) - ); - panelSearchLayout.setVerticalGroup( - panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelSearchLayout.createSequentialGroup() - .addGap(3, 3, 3) - .addGroup(panelSearchLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(labelSearch) - .addComponent(editSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addGap(3, 3, 3)) - ); - - listChoices.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "item1", "item2", "item3" }; - public int getSize() { return strings.length; } - public Object getElementAt(int i) { return strings[i]; } - }); - scrollList.setViewportView(listChoices); - - btOK.setText("Choose"); - btOK.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btOKActionPerformed(evt); - } - }); - - btCancel.setText("Cancel"); - btCancel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btCancelActionPerformed(evt); - } - }); - - javax.swing.GroupLayout panelCommandsLayout = new javax.swing.GroupLayout(panelCommands); - panelCommands.setLayout(panelCommandsLayout); - panelCommandsLayout.setHorizontalGroup( - panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCommandsLayout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(btOK) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOK}); - - panelCommandsLayout.setVerticalGroup( - panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(panelCommandsLayout.createSequentialGroup() - .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) - .addComponent(btCancel) - .addComponent(btOK)) - .addContainerGap()) - ); - - getRootPane().setDefaultButton(btOK); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) - .addComponent(scrollList) - .addComponent(panelCommands, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelHeader, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(panelSearch, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addContainerGap()) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .addComponent(panelHeader, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(scrollList, javax.swing.GroupLayout.PREFERRED_SIZE, 246, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(panelCommands, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - ); - - pack(); - }//
//GEN-END:initComponents - - private void btOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btOKActionPerformed - doChoose(); - }//GEN-LAST:event_btOKActionPerformed - - private void btCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCancelActionPerformed - doCancel(); - }//GEN-LAST:event_btCancelActionPerformed - - /** - * Closes the dialog - */ - private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog - doCancel(); - }//GEN-LAST:event_closeDialog - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btCancel; - private javax.swing.JButton btOK; - private javax.swing.JTextField editSearch; - private javax.swing.JLabel labelMessage; - private javax.swing.JLabel labelSearch; - private javax.swing.JLabel labelSubMessage; - private javax.swing.JList listChoices; - private javax.swing.JPanel panelCommands; - private javax.swing.JPanel panelHeader; - private javax.swing.JPanel panelSearch; - private javax.swing.JScrollPane scrollList; - // End of variables declaration//GEN-END:variables -} diff --git a/Mage.Client/src/main/java/mage/client/util/gui/FastSearchUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/FastSearchUtil.java index ed54815434b..9b35be5133c 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/FastSearchUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/FastSearchUtil.java @@ -3,54 +3,60 @@ package mage.client.util.gui; import mage.choices.ChoiceImpl; import mage.client.dialog.PickChoiceDialog; +//import java.util.ArrayList; +import mage.client.dialog.CheckBoxList; + import javax.swing.*; import java.util.HashMap; import java.util.Map; +//import javax.swing.text.Position; + +//import org.apache.log4j.helpers.LogLog; /** * * @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"; +public class FastSearchUtil { + public static String DEFAULT_EXPANSION_SEARCH_MESSAGE = "Select set(s) or expansion(s)"; + public static String DEFAULT_EXPANSION_TOOLTIP_MESSAGE = "Fast search set(s) or expansion(s)"; /** - * Show fast choice modal dialog with incremental searching for any string combobox components - * @param combo combobox control with default data model + * Show fast choice modal dialog with incremental searching for any string CheckBoxList components + * @param combo CheckBoxList 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 - + */ + public static void showFastSearchForStringComboBox(CheckBoxList 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(); + DefaultListModel comboModel = (DefaultListModel)combo.getModel(); Map choiceItems = new HashMap<>(comboModel.getSize()); Map choiceSorting = new HashMap<>(comboModel.getSize()); String item; - for(int i = 0; i < comboModel.getSize(); i++){ + for(int i = 0; i < comboModel.size(); i++){ item = comboModel.getElementAt(i).toString(); + 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 = comboModel.getSelectedItem().toString(); + needSelectValue = comboModel.firstElement().toString(); // ask for new value - PickChoiceDialog dlg = new PickChoiceDialog(); + PickChoiceDialog dlg = new PickChoiceDialog(combo); dlg.setWindowSize(300, 500); dlg.showDialog(choice, needSelectValue); - if(choice.isChosen()){ + if(choice.isChosen()){ item = choice.getChoiceKey(); // compatible select for object's models (use setSelectedIndex instead setSelectedObject) @@ -60,5 +66,14 @@ public class FastSearchUtil { } } } + + /* + int[] choiseValue=combo.getCheckedIndices(); + ListModel x= combo.getModel(); + for(int itemIndex: choiseValue){ + LogLog.warn(String.format("%d:%s",itemIndex,x.getElementAt(itemIndex).toString())); + } + */ } } + diff --git a/Mage.Client/src/main/java/mage/client/util/gui/FastSearchUtil_1.java b/Mage.Client/src/main/java/mage/client/util/gui/FastSearchUtil_1.java deleted file mode 100644 index 9013a12cc3f..00000000000 --- a/Mage.Client/src/main/java/mage/client/util/gui/FastSearchUtil_1.java +++ /dev/null @@ -1,86 +0,0 @@ -package mage.client.util.gui; - -import java.util.ArrayList; -import mage.choices.ChoiceImpl; -import mage.client.dialog.PickChoiceDialog_1; - -import javax.swing.*; -import java.util.HashMap; -import java.util.Map; -import mage.client.dialog.CheckBoxList; -//import org.apache.log4j.helpers.LogLog; - -/** - * - * @author JayDi85 - */ -public class FastSearchUtil_1 { - - 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 - * @return The list of all item - */ - public static CheckBoxList showFastSearchForStringComboBox(JComboBox combo, String chooseMessage){ - // fast search/choice dialog for string combobox - - CheckBoxList langList= new CheckBoxList(); - java.util.List myList = new ArrayList<>(); - - - - - mage.choices.Choice choice = new ChoiceImpl(false); - - // collect data from expansion combobox (String) - DefaultComboBoxModel comboModel = (DefaultComboBoxModel)combo.getModel(); - Map choiceItems = new HashMap<>(comboModel.getSize()); - Map choiceSorting = new HashMap<>(comboModel.getSize()); - String item; - - for(int i = 0; i < comboModel.getSize(); i++){ - item = comboModel.getElementAt(i).toString(); - myList.add(item); - choiceItems.put(item, item); - choiceSorting.put(item, i); // need so sorting - } - - langList.setListData(myList.toArray()); - langList.setChecked(0, true); - langList.setChecked(3, true); - choice.setKeyChoices(choiceItems); - choice.setSortData(choiceSorting); - choice.setMessage(chooseMessage); - - // current selection value restore - String needSelectValue; - needSelectValue = comboModel.getSelectedItem().toString(); - - // ask for new value - PickChoiceDialog_1 dlg = new PickChoiceDialog_1(langList); - dlg.setWindowSize(300, 500); - //dlg.set(langList.); - dlg.showDialog(choice, needSelectValue); - /*int[] choiseValue=langList.getCheckedIndices(); - LogLog.warn("selected:"); - for(int itemIndex: choiseValue){ - - LogLog.warn(String.format("%d",itemIndex)); - }*/ - if(choice.isChosen()){ - item = choice.getChoiceKey(); - - // compatible select for object's models (use setSelectedIndex instead setSelectedObject) - for(int i = 0; i < comboModel.getSize(); i++){ - if(comboModel.getElementAt(i).toString().equals(item)){ - combo.setSelectedIndex(i); - } - } - } - return langList; - } -}