() {
@Override
public int compare(KeyValueItem o1, KeyValueItem o2) {
- Integer n1 = choice.getSortData().get(o1.getKey());
- Integer n2 = choice.getSortData().get(o2.getKey());
+ Integer n1 = choice.getSortData().get(o1.Key);
+ Integer n2 = choice.getSortData().get(o2.Key);
return n1.compareTo(n2);
}
});
@@ -222,24 +184,18 @@ 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)currentlistChoices.getModel().getElementAt(i);
- String elementOfList = currentlistChoices.getModel().getElementAt(i).toString();
- if (elementOfList.equals(startSelectionValue)){
+ KeyValueItem listItem = (KeyValueItem)this.listChoices.getModel().getElementAt(i);
+ if (listItem.Key.equals(startSelectionValue)){
selectIndex = i;
break;
}
}
if(selectIndex >= 0){
- // currentlistChoices=this.get_a_Jlist_from_ScrollListView();
- /*currentlistChoices = this.listChoices;*/
- currentlistChoices.setSelectedIndex(selectIndex);
- currentlistChoices.ensureIndexIsVisible(selectIndex);
+ this.listChoices.setSelectedIndex(selectIndex);
+ this.listChoices.ensureIndexIsVisible(selectIndex);
}
}
@@ -252,16 +208,14 @@ 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(Locale.ENGLISH);
this.dataModel.clear();
- this.m_dataModel.clear();
for(KeyValueItem item: this.allItems){
if(!choice.isSearchEnabled() || item.Value.toLowerCase(Locale.ENGLISH).contains(filter)){
this.dataModel.addElement(item);
- this.m_dataModel.addElement(item.getObjectValue());
}
}
}
@@ -294,9 +248,7 @@ public class PickChoiceDialog extends MageDialog {
}
private void doChoose(){
- if((tList != null)||(setChoice())){
- this.m_dataModel.clear();
- restoreData(this.m_dataModel);
+ if(setChoice()){
this.hideDialog();
}
}
@@ -307,35 +259,13 @@ public class PickChoiceDialog extends MageDialog {
hideDialog();
}
- /**
- * Creates new form PickChoiceDialog
- * @param list
- */
- 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);
+ initComponents();
+ this.listChoices.setModel(dataModel);
+ this.setModal(true);
}
public boolean setChoice() {
@@ -364,31 +294,19 @@ public class PickChoiceDialog extends MageDialog {
{
private final String Key;
private final String Value;
- 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) {
+
+ public KeyValueItem(String value, String label) {
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() {
@@ -416,7 +334,6 @@ 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
");
@@ -431,17 +348,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.PREFERRED_SIZE, 0, Short.MAX_VALUE)
- .addComponent(labelSubMessage, javax.swing.GroupLayout.Alignment.TRAILING))
+ .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, Short.MAX_VALUE)
+ .addGap(0, 0, 0)
.addComponent(labelMessage)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(labelSubMessage, javax.swing.GroupLayout.DEFAULT_SIZE, 30, Short.MAX_VALUE))
+ .addGap(0, 0, 0)
+ .addComponent(labelSubMessage))
);
labelSearch.setText("Search:");
@@ -490,39 +407,30 @@ 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, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+ .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)
- .addComponent(btClear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(btOK))
.addContainerGap())
);
- getRootPane().setDefaultButton(btOK);
getRootPane().setDefaultButton(btOK);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
@@ -546,7 +454,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, 240, Short.MAX_VALUE)
+ .addComponent(scrollList, javax.swing.GroupLayout.DEFAULT_SIZE, 246, 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())
@@ -570,16 +478,8 @@ 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/util/gui/FastSearchUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/FastSearchUtil.java
index 9b35be5133..ed54815434 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,60 +3,54 @@ 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(s) or expansion(s)";
- public static String DEFAULT_EXPANSION_TOOLTIP_MESSAGE = "Fast search set(s) or expansion(s)";
+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 CheckBoxList components
- * @param combo CheckBoxList control with default data model
+ * 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(CheckBoxList combo, String chooseMessage){
- // fast search/choice dialog for string combobox
-
+ */
+ 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)
- DefaultListModel comboModel = (DefaultListModel)combo.getModel();
+ 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.size(); i++){
+ for(int i = 0; i < comboModel.getSize(); 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.firstElement().toString();
+ needSelectValue = comboModel.getSelectedItem().toString();
// ask for new value
- PickChoiceDialog dlg = new PickChoiceDialog(combo);
+ PickChoiceDialog dlg = new PickChoiceDialog();
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)
@@ -66,14 +60,5 @@ 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()));
- }
- */
}
}
-