mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 12:02:01 -08:00
new button to filter TAG
This commit is contained in:
parent
87f590f6b8
commit
cd3e58dbab
6 changed files with 1757 additions and 11 deletions
|
|
@ -4,6 +4,12 @@
|
|||
<NonVisualComponents>
|
||||
<Component class="javax.swing.ButtonGroup" name="bgView">
|
||||
</Component>
|
||||
<Component class="javax.swing.JCheckBoxMenuItem" name="jCheckBoxMenuItem1">
|
||||
<Properties>
|
||||
<Property name="selected" type="boolean" value="true"/>
|
||||
<Property name="text" type="java.lang.String" value="jCheckBoxMenuItem1"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</NonVisualComponents>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
|
|
@ -21,9 +27,9 @@
|
|||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="tbColor" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="tbTypes" alignment="0" pref="1057" max="32767" attributes="0"/>
|
||||
<Component id="tbTypes" alignment="0" pref="1061" max="32767" attributes="0"/>
|
||||
<Component id="cardSelectorBottomPanel" alignment="0" pref="1061" max="32767" attributes="0"/>
|
||||
<Component id="cardSelectorScrollPane" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="cardSelectorBottomPanel" alignment="0" pref="1057" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
|
|
@ -32,9 +38,7 @@
|
|||
<Component id="tbColor" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="tbTypes" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="cardSelectorScrollPane" pref="237" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="cardSelectorBottomPanel" min="-2" pref="31" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
|
|
@ -259,6 +263,17 @@
|
|||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnClearActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton1">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Filter Set"/>
|
||||
<Property name="focusable" type="boolean" value="false"/>
|
||||
<Property name="horizontalTextPosition" type="int" value="0"/>
|
||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JToolBar" name="tbTypes">
|
||||
|
|
@ -650,7 +665,7 @@
|
|||
<Component id="cardCountLabel" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="cardCount" min="-2" pref="48" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<EmptySpace pref="139" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
|
|
|||
|
|
@ -57,6 +57,10 @@ import static mage.client.dialog.PreferencesDialog.KEY_DECK_EDITOR_SEARCH_TYPES;
|
|||
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.dialog.PickChoiceDialog_1;
|
||||
import mage.client.util.gui.FastSearchUtil_1;
|
||||
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
|
|
@ -70,6 +74,7 @@ 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;
|
||||
|
||||
/**
|
||||
|
|
@ -302,11 +307,13 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return filter;
|
||||
}
|
||||
|
||||
private CardCriteria buildCriteria() {
|
||||
//java.util.List<String> setCodes;
|
||||
CardCriteria criteria = new CardCriteria();
|
||||
criteria.black(this.tbBlack.isSelected());
|
||||
criteria.blue(this.tbBlue.isSelected());
|
||||
|
|
@ -364,6 +371,44 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
criteria.setCodes(setCodes.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
if(cbSetTag!=null)
|
||||
{
|
||||
/*if(setCodes==null)
|
||||
{
|
||||
setCodes= new String[0];
|
||||
}*/
|
||||
if(listCodeSelected != null)
|
||||
{
|
||||
boolean isAtLeastOneSelected=false;
|
||||
java.util.List<String> setCodes = new ArrayList<>() ;
|
||||
|
||||
int[] choiseValue=listCodeSelected.getCheckedIndices();
|
||||
ListModel x= listCodeSelected.getModel();
|
||||
|
||||
for(int itemIndex: choiseValue){
|
||||
isAtLeastOneSelected=true;
|
||||
setCodes.add(x.getElementAt(itemIndex).toString());
|
||||
LogLog.warn(x.getElementAt(itemIndex).toString());
|
||||
}
|
||||
if(isAtLeastOneSelected)
|
||||
{
|
||||
criteria.setCodes(setCodes.toArray(new String[0]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//cbSetTag.
|
||||
/* for(int itemIndex: choiseValue){
|
||||
|
||||
LogLog.warn(String.format("%d",itemIndex));
|
||||
}
|
||||
String expansionSelection = this.cbSetTag.getSelectedItem().toString();
|
||||
if (!expansionSelection.equals("- All Sets")) {
|
||||
java.util.List<String> setCodes = ConstructedFormats.getSetsByFormat(expansionSelection);
|
||||
criteria.setCodes(setCodes.toArray(new String[0]));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return criteria;
|
||||
}
|
||||
|
|
@ -419,6 +464,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
}
|
||||
|
||||
private void filterCards() {
|
||||
boolean fist_time =false;
|
||||
FilterCard filter = buildFilter();
|
||||
try {
|
||||
java.util.List<Card> filteredCards = new ArrayList<>();
|
||||
|
|
@ -446,6 +492,15 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
}
|
||||
}
|
||||
filteredCards.add(card);
|
||||
if(cbSetTag==null)
|
||||
{
|
||||
cbSetTag = new javax.swing.JComboBox<>();
|
||||
fist_time = true;
|
||||
}
|
||||
if(fist_time == true)
|
||||
{
|
||||
cbSetTag.addItem(cardInfo.getSetCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -507,6 +562,7 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
private void initComponents() {
|
||||
|
||||
bgView = new javax.swing.ButtonGroup();
|
||||
jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
|
||||
tbColor = new javax.swing.JToolBar();
|
||||
tbRed = new javax.swing.JToggleButton();
|
||||
tbGreen = new javax.swing.JToggleButton();
|
||||
|
|
@ -521,6 +577,7 @@ 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();
|
||||
|
|
@ -559,6 +616,9 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
cardCountLabel = new javax.swing.JLabel();
|
||||
cardCount = new javax.swing.JLabel();
|
||||
|
||||
jCheckBoxMenuItem1.setSelected(true);
|
||||
jCheckBoxMenuItem1.setText("jCheckBoxMenuItem1");
|
||||
|
||||
tbColor.setFloatable(false);
|
||||
tbColor.setRollover(true);
|
||||
tbColor.setToolTipText("Hold the ALT-key while clicking to deselect all other colors or hold the CTRL-key to select only all other colors.");
|
||||
|
|
@ -720,6 +780,17 @@ 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
|
||||
|
|
@ -1141,7 +1212,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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap(139, Short.MAX_VALUE))
|
||||
);
|
||||
cardSelectorBottomPanelLayout.setVerticalGroup(
|
||||
cardSelectorBottomPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
|
|
@ -1176,9 +1247,9 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(tbColor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(tbTypes, javax.swing.GroupLayout.DEFAULT_SIZE, 1057, Short.MAX_VALUE)
|
||||
.addComponent(tbTypes, javax.swing.GroupLayout.DEFAULT_SIZE, 1061, Short.MAX_VALUE)
|
||||
.addComponent(cardSelectorBottomPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1061, Short.MAX_VALUE)
|
||||
.addComponent(cardSelectorScrollPane)
|
||||
.addComponent(cardSelectorBottomPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1057, Short.MAX_VALUE)
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
|
|
@ -1186,9 +1257,7 @@ 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))
|
||||
);
|
||||
}// </editor-fold>//GEN-END:initComponents
|
||||
|
|
@ -1398,6 +1467,50 @@ 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
|
||||
//javax.swing.JComboBox<String> cbSetTag;
|
||||
//CheckBoxListEntry itemA_box = new CheckBoxListEntry("test",false);
|
||||
//DefaultListModel<JCheckBox> modeldefault = new DefaultListModel<JCheckBox>();
|
||||
// langList = new CheckBoxList();
|
||||
|
||||
/*String myList[]={"Afghanistan", "af"},
|
||||
/{"Åland Islands", "ax"},
|
||||
{"Albania", "al"},
|
||||
{"Algeria", "dz"},
|
||||
{"American Samoa", "as"},
|
||||
{"Andorra", "ad"},
|
||||
{"Angola", "an"},
|
||||
{"Anguilla", "ai"},
|
||||
{"Antarctica", "ao"},};
|
||||
langList = new CheckBoxList();*/
|
||||
/*DefaultListModel<JCheckBox> model= new DefaultListModel();
|
||||
JCheckBox check1 = new JCheckBox("One");
|
||||
JCheckBox check2 = new JCheckBox("two");
|
||||
model.addElement(check1);
|
||||
model.addElement(check2);
|
||||
JCheckBox[] myList = { check1, check2};
|
||||
JList list = new JList(model);*/
|
||||
|
||||
// langList.setListData(myList);
|
||||
//langList.add(list);
|
||||
/*langList.addElement(new JCheckBox("Checkbox1"));
|
||||
langList.addElement(new JCheckBox("Checkbox2"));
|
||||
langList.addElement(new JCheckBox("Checkbox3"));
|
||||
//checkBoxList1.getCheckedItems();*/
|
||||
CheckBoxList testList;
|
||||
listCodeSelected = FastSearchUtil_1.showFastSearchForStringComboBox(cbSetTag, FastSearchUtil_1.DEFAULT_EXPANSION_SEARCH_MESSAGE);
|
||||
filterCards();
|
||||
/*int[] choiseValue=testList.getCheckedIndices();
|
||||
ListModel x= testList.getModel();
|
||||
LogLog.warn("selected:");
|
||||
for(int itemIndex: choiseValue){
|
||||
|
||||
LogLog.warn(x.getElementAt(itemIndex).toString());
|
||||
LogLog.warn(String.format("%d",itemIndex));
|
||||
}*/
|
||||
//CheckTable.main(null);
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
private void toggleViewMode() {
|
||||
if (currentView instanceof CardGrid) {
|
||||
jToggleListView.setSelected(true);
|
||||
|
|
@ -1435,7 +1548,10 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
|
|||
private TableModel mainModel;
|
||||
private JTable mainTable;
|
||||
private ICardGrid currentView;
|
||||
|
||||
|
||||
//private CheckBoxList langList = null;
|
||||
private CheckBoxList listCodeSelected;
|
||||
private javax.swing.JComboBox<String> cbSetTag;
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.ButtonGroup bgView;
|
||||
private javax.swing.JButton btnBooster;
|
||||
|
|
@ -1453,12 +1569,14 @@ 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;
|
||||
private javax.swing.JButton jButtonRemoveFromMain;
|
||||
private javax.swing.JButton jButtonRemoveFromSideboard;
|
||||
private javax.swing.JButton jButtonSearch;
|
||||
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
|
||||
private javax.swing.JToolBar.Separator jSeparator1;
|
||||
private javax.swing.JToolBar.Separator jSeparator2;
|
||||
private javax.swing.JToolBar.Separator jSeparator3;
|
||||
|
|
|
|||
668
Mage.Client/src/main/java/mage/client/dialog/CheckBoxList.java
Normal file
668
Mage.Client/src/main/java/mage/client/dialog/CheckBoxList.java
Normal file
|
|
@ -0,0 +1,668 @@
|
|||
/*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* CheckBoxList.java
|
||||
* Copyright (C) 2006-2012 University of Waikato, Hamilton, New Zealand
|
||||
*/
|
||||
|
||||
package mage.client.dialog;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.ListCellRenderer;
|
||||
import javax.swing.ListModel;
|
||||
|
||||
/**
|
||||
* An extended JList that contains CheckBoxes. If necessary a CheckBoxListItem
|
||||
* wrapper is added around the displayed object in any of the Model methods,
|
||||
* e.g., addElement. For methods returning objects the opposite takes place, the
|
||||
* wrapper is removed and only the payload object is returned.
|
||||
*
|
||||
* @author fracpete (fracpete at waikato dot ac dot nz)
|
||||
* @version $Revision: 10219 $
|
||||
*/
|
||||
public class CheckBoxList extends JList {
|
||||
|
||||
/** for serialization */
|
||||
private static final long serialVersionUID = -4359573373359270258L;
|
||||
|
||||
/**
|
||||
* represents an item in the CheckBoxListModel
|
||||
*
|
||||
* @author fracpete (fracpete at waikato dot ac dot nz)
|
||||
* @version $Revision: 10219 $
|
||||
*/
|
||||
protected class CheckBoxListItem {
|
||||
|
||||
/** whether item is checked or not */
|
||||
private boolean m_Checked = false;
|
||||
|
||||
/** the actual object */
|
||||
private Object m_Content = null;
|
||||
|
||||
/**
|
||||
* initializes the item with the given object and initially unchecked
|
||||
*
|
||||
* @param o the content object
|
||||
*/
|
||||
public CheckBoxListItem(Object o) {
|
||||
this(o, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* initializes the item with the given object and whether it's checked
|
||||
* initially
|
||||
*
|
||||
* @param o the content object
|
||||
* @param checked whether the item should be checked initially
|
||||
*/
|
||||
public CheckBoxListItem(Object o, boolean checked) {
|
||||
m_Checked = checked;
|
||||
m_Content = o;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the content object
|
||||
*/
|
||||
public Object getContent() {
|
||||
return m_Content;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the checked state of the item
|
||||
*/
|
||||
public void setChecked(boolean value) {
|
||||
m_Checked = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the checked state of the item
|
||||
*/
|
||||
public boolean getChecked() {
|
||||
return m_Checked;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the string representation of the content object
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return m_Content.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns true if the "payload" objects of the current and the given
|
||||
* CheckBoxListItem are the same.
|
||||
*
|
||||
* @param o the CheckBoxListItem to check
|
||||
* @throws IllegalArgumentException if the provided object is not a
|
||||
* CheckBoxListItem
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof CheckBoxListItem)) {
|
||||
throw new IllegalArgumentException("Must be a CheckBoxListItem!");
|
||||
}
|
||||
|
||||
return getContent().equals(((CheckBoxListItem) o).getContent());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A specialized model.
|
||||
*
|
||||
* @author fracpete (fracpete at waikato dot ac dot nz)
|
||||
* @version $Revision: 10219 $
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class CheckBoxListModel extends DefaultListModel {
|
||||
|
||||
/** for serialization */
|
||||
private static final long serialVersionUID = 7772455499540273507L;
|
||||
|
||||
/**
|
||||
* initializes the model with no data.
|
||||
*/
|
||||
public CheckBoxListModel() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a CheckBoxListModel from an array of objects and then applies
|
||||
* setModel to it.
|
||||
*
|
||||
* @param listData the data to use
|
||||
*/
|
||||
public CheckBoxListModel(Object[] listData) {
|
||||
for (Object element : listData) {
|
||||
addElement(element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a CheckBoxListModel from a Vector and then applies setModel to
|
||||
* it.
|
||||
*/
|
||||
public CheckBoxListModel(Vector listData) {
|
||||
for (int i = 0; i < listData.size(); i++) {
|
||||
addElement(listData.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the specified element at the specified position in this list.
|
||||
*
|
||||
* @param index index at which the specified element is to be inserted
|
||||
* @param element element to be inserted
|
||||
*/
|
||||
@Override
|
||||
public void add(int index, Object element) {
|
||||
if (!(element instanceof CheckBoxListItem)) {
|
||||
super.add(index, new CheckBoxListItem(element));
|
||||
} else {
|
||||
super.add(index, element);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified component to the end of this list.
|
||||
*
|
||||
* @param obj the component to be added
|
||||
*/
|
||||
@Override
|
||||
public void addElement(Object obj) {
|
||||
if (!(obj instanceof CheckBoxListItem)) {
|
||||
super.addElement(new CheckBoxListItem(obj));
|
||||
} else {
|
||||
super.addElement(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the specified object is a component in this list.
|
||||
*
|
||||
* @param elem the element to check
|
||||
* @return true if the element is in the list
|
||||
*/
|
||||
@Override
|
||||
public boolean contains(Object elem) {
|
||||
if (!(elem instanceof CheckBoxListItem)) {
|
||||
return super.contains(new CheckBoxListItem(elem));
|
||||
} else {
|
||||
return super.contains(elem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the components of this list into the specified array.
|
||||
*
|
||||
* @param anArray the array into which the components get copied
|
||||
* @throws IndexOutOfBoundsException if the array is not big enough
|
||||
*/
|
||||
@Override
|
||||
public void copyInto(Object[] anArray) {
|
||||
if (anArray.length < getSize()) {
|
||||
throw new IndexOutOfBoundsException("Array not big enough!");
|
||||
}
|
||||
|
||||
for (int i = 0; i < getSize(); i++) {
|
||||
anArray[i] = ((CheckBoxListItem) getElementAt(i)).getContent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the component at the specified index. Throws an
|
||||
* ArrayIndexOutOfBoundsException if the index is negative or not less than
|
||||
* the size of the list.
|
||||
*
|
||||
* @param index an index into this list
|
||||
* @return the component at the specified index
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
@Override
|
||||
public Object elementAt(int index) {
|
||||
return ((CheckBoxListItem) super.elementAt(index)).getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first component of this list. Throws a NoSuchElementException
|
||||
* if this vector has no components.
|
||||
*
|
||||
* @return the first component of this list
|
||||
* @throws NoSuchElementException
|
||||
*/
|
||||
@Override
|
||||
public Object firstElement() {
|
||||
return ((CheckBoxListItem) super.firstElement()).getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element at the specified position in this list.
|
||||
*
|
||||
* @param index of element to return
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
@Override
|
||||
public Object get(int index) {
|
||||
return ((CheckBoxListItem) super.get(index)).getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the component at the specified index.
|
||||
*
|
||||
* @param index an index into this list
|
||||
* @return the component at the specified index
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
@Override
|
||||
public Object getElementAt(int index) {
|
||||
return ((CheckBoxListItem) super.getElementAt(index));//.getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the first occurrence of elem.
|
||||
*
|
||||
* @param elem an object
|
||||
* @return the index of the first occurrence of the argument in this list;
|
||||
* returns -1 if the object is not found
|
||||
*/
|
||||
@Override
|
||||
public int indexOf(Object elem) {
|
||||
if (!(elem instanceof CheckBoxListItem)) {
|
||||
return super.indexOf(new CheckBoxListItem(elem));
|
||||
} else {
|
||||
return super.indexOf(elem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches for the first occurrence of elem, beginning the search at index.
|
||||
*
|
||||
* @param elem the desired component
|
||||
* @param index the index from which to begin searching
|
||||
* @return the index where the first occurrence of elem is found after
|
||||
* index; returns -1 if the elem is not found in the list
|
||||
*/
|
||||
@Override
|
||||
public int indexOf(Object elem, int index) {
|
||||
if (!(elem instanceof CheckBoxListItem)) {
|
||||
return super.indexOf(new CheckBoxListItem(elem), index);
|
||||
} else {
|
||||
return super.indexOf(elem, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the specified object as a component in this list at the specified
|
||||
* index.
|
||||
*
|
||||
* @param obj the component to insert
|
||||
* @param index where to insert the new component
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
@Override
|
||||
public void insertElementAt(Object obj, int index) {
|
||||
if (!(obj instanceof CheckBoxListItem)) {
|
||||
super.insertElementAt(new CheckBoxListItem(obj), index);
|
||||
} else {
|
||||
super.insertElementAt(obj, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last component of the list. Throws a NoSuchElementException
|
||||
* if this vector has no components.
|
||||
*
|
||||
* @return the last component of the list
|
||||
* @throws NoSuchElementException
|
||||
*/
|
||||
@Override
|
||||
public Object lastElement() {
|
||||
return ((CheckBoxListItem) super.lastElement()).getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last occurrence of elem.
|
||||
*
|
||||
* @param elem the desired component
|
||||
* @return the index of the last occurrence of elem in the list; returns -1
|
||||
* if the object is not found
|
||||
*/
|
||||
@Override
|
||||
public int lastIndexOf(Object elem) {
|
||||
if (!(elem instanceof CheckBoxListItem)) {
|
||||
return super.lastIndexOf(new CheckBoxListItem(elem));
|
||||
} else {
|
||||
return super.lastIndexOf(elem);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches backwards for elem, starting from the specified index, and
|
||||
* returns an index to it.
|
||||
*
|
||||
* @param elem the desired component
|
||||
* @param index the index to start searching from
|
||||
* @return the index of the last occurrence of the elem in this list at
|
||||
* position less than index; returns -1 if the object is not found
|
||||
*/
|
||||
@Override
|
||||
public int lastIndexOf(Object elem, int index) {
|
||||
if (!(elem instanceof CheckBoxListItem)) {
|
||||
return super.lastIndexOf(new CheckBoxListItem(elem), index);
|
||||
} else {
|
||||
return super.lastIndexOf(elem, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the element at the specified position in this list. Returns the
|
||||
* element that was removed from the list.
|
||||
*
|
||||
* @param index the index of the element to removed
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
@Override
|
||||
public Object remove(int index) {
|
||||
return ((CheckBoxListItem) super.remove(index)).getContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the first (lowest-indexed) occurrence of the argument from this
|
||||
* list.
|
||||
*
|
||||
* @param obj the component to be removed
|
||||
* @return true if the argument was a component of this list; false
|
||||
* otherwise
|
||||
*/
|
||||
@Override
|
||||
public boolean removeElement(Object obj) {
|
||||
if (!(obj instanceof CheckBoxListItem)) {
|
||||
return super.removeElement(new CheckBoxListItem(obj));
|
||||
} else {
|
||||
return super.removeElement(obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the element at the specified position in this list with the
|
||||
* specified element.
|
||||
*
|
||||
* @param index index of element to replace
|
||||
* @param element element to be stored at the specified position
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
@Override
|
||||
public Object set(int index, Object element) {
|
||||
if (!(element instanceof CheckBoxListItem)) {
|
||||
return ((CheckBoxListItem) super.set(index, new CheckBoxListItem(
|
||||
element))).getContent();
|
||||
} else {
|
||||
return ((CheckBoxListItem) super.set(index, element)).getContent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the component at the specified index of this list to be the
|
||||
* specified object. The previous component at that position is discarded.
|
||||
*
|
||||
* @param obj what the component is to be set to
|
||||
* @param index the specified index
|
||||
* @throws ArrayIndexOutOfBoundsException
|
||||
*/
|
||||
@Override
|
||||
public void setElementAt(Object obj, int index) {
|
||||
if (!(obj instanceof CheckBoxListItem)) {
|
||||
super.setElementAt(new CheckBoxListItem(obj), index);
|
||||
} else {
|
||||
super.setElementAt(obj, index);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array containing all of the elements in this list in the
|
||||
* correct order.
|
||||
*
|
||||
* @return an array containing the elements of the list
|
||||
*/
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
Object[] result;
|
||||
Object[] internal;
|
||||
int i;
|
||||
|
||||
internal = super.toArray();
|
||||
result = new Object[internal.length];
|
||||
|
||||
for (i = 0; i < internal.length; i++) {
|
||||
result[i] = ((CheckBoxListItem) internal[i]).getContent();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the checked state of the element at the given index
|
||||
*
|
||||
* @param index the index of the element to return the checked state for
|
||||
* @return the checked state of the specifed element
|
||||
*/
|
||||
public boolean getChecked(int index) {
|
||||
return ((CheckBoxListItem) super.getElementAt(index)).getChecked();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the checked state of the element at the given index
|
||||
*
|
||||
* @param index the index of the element to set the checked state for
|
||||
* @param checked the new checked state
|
||||
*/
|
||||
public void setChecked(int index, boolean checked) {
|
||||
((CheckBoxListItem) super.getElementAt(index)).setChecked(checked);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A specialized CellRenderer for the CheckBoxList
|
||||
*
|
||||
* @author fracpete (fracpete at waikato dot ac dot nz)
|
||||
* @version $Revision: 10219 $
|
||||
* @see CheckBoxList
|
||||
*/
|
||||
public class CheckBoxListRenderer extends JCheckBox implements
|
||||
ListCellRenderer {
|
||||
|
||||
/** for serialization */
|
||||
private static final long serialVersionUID = 1059591605858524586L;
|
||||
|
||||
/**
|
||||
* Return a component that has been configured to display the specified
|
||||
* value.
|
||||
*
|
||||
* @param list The JList we're painting.
|
||||
* @param value The value returned by list.getModel().getElementAt(index).
|
||||
* @param index The cells index.
|
||||
* @param isSelected True if the specified cell was selected.
|
||||
* @param cellHasFocus True if the specified cell has the focus.
|
||||
* @return A component whose paint() method will render the specified value.
|
||||
*/
|
||||
@Override
|
||||
public Component getListCellRendererComponent(JList list, Object value,
|
||||
int index, boolean isSelected, boolean cellHasFocus) {
|
||||
|
||||
setText(value.toString());
|
||||
setSelected(((CheckBoxList) list).getChecked(index));
|
||||
setBackground(isSelected ? list.getSelectionBackground() : list
|
||||
.getBackground());
|
||||
setForeground(isSelected ? list.getSelectionForeground() : list
|
||||
.getForeground());
|
||||
setFocusPainted(false);
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* initializes the list with an empty CheckBoxListModel
|
||||
*/
|
||||
public CheckBoxList() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* initializes the list with the given CheckBoxListModel
|
||||
*
|
||||
* @param model the model to initialize with
|
||||
*/
|
||||
public CheckBoxList(CheckBoxListModel model) {
|
||||
super();
|
||||
|
||||
if (model == null) {
|
||||
model = this.new CheckBoxListModel();
|
||||
}
|
||||
|
||||
setModel(model);
|
||||
setCellRenderer(new CheckBoxListRenderer());
|
||||
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
int index = locationToIndex(e.getPoint());
|
||||
|
||||
if (index != -1) {
|
||||
setChecked(index, !getChecked(index));
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
if ((e.getKeyChar() == ' ') && (e.getModifiers() == 0)) {
|
||||
int index = getSelectedIndex();
|
||||
setChecked(index, !getChecked(index));
|
||||
e.consume();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the model - must be an instance of CheckBoxListModel
|
||||
*
|
||||
* @param model the model to use
|
||||
* @throws IllegalArgumentException if the model is not an instance of
|
||||
* CheckBoxListModel
|
||||
* @see CheckBoxListModel
|
||||
*/
|
||||
@Override
|
||||
public void setModel(ListModel model) {
|
||||
if (!(model instanceof CheckBoxListModel)) {
|
||||
if (model instanceof javax.swing.DefaultListModel) {
|
||||
super.setModel((CheckBoxListModel)model);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
"Model must be an instance of CheckBoxListModel!");
|
||||
}
|
||||
}
|
||||
else {
|
||||
super.setModel(model);
|
||||
}
|
||||
}
|
||||
|
||||
/*public void setModel(DefaultListModel model) {
|
||||
throw new IllegalArgumentException(
|
||||
"Model must be an ins12313tance of CheckBoxListModel!");
|
||||
}*/
|
||||
/**
|
||||
* Constructs a CheckBoxListModel from an array of objects and then applies
|
||||
* setModel to it.
|
||||
*
|
||||
* @param listData the data to use
|
||||
*/
|
||||
@Override
|
||||
public void setListData(Object[] listData) {
|
||||
setModel(new CheckBoxListModel(listData));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a CheckBoxListModel from a Vector and then applies setModel to
|
||||
* it.
|
||||
*/
|
||||
@Override
|
||||
public void setListData(@SuppressWarnings("rawtypes") Vector listData) {
|
||||
setModel(new CheckBoxListModel(listData));
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the checked state of the element at the given index
|
||||
*
|
||||
* @param index the index of the element to return the checked state for
|
||||
* @return the checked state of the specifed element
|
||||
*/
|
||||
public boolean getChecked(int index) {
|
||||
return ((CheckBoxListModel) getModel()).getChecked(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the checked state of the element at the given index
|
||||
*
|
||||
* @param index the index of the element to set the checked state for
|
||||
* @param checked the new checked state
|
||||
*/
|
||||
public void setChecked(int index, boolean checked) {
|
||||
((CheckBoxListModel) getModel()).setChecked(index, checked);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array with the indices of all checked items
|
||||
*
|
||||
* @return the indices of all items that are currently checked
|
||||
*/
|
||||
public int[] getCheckedIndices() {
|
||||
Vector<Integer> list;
|
||||
int[] result;
|
||||
int i;
|
||||
|
||||
// traverse over model
|
||||
list = new Vector<Integer>();
|
||||
for (i = 0; i < getModel().getSize(); i++) {
|
||||
if (getChecked(i)) {
|
||||
list.add(new Integer(i));
|
||||
}
|
||||
}
|
||||
|
||||
// generate result array
|
||||
result = new int[list.size()];
|
||||
for (i = 0; i < list.size(); i++) {
|
||||
result[i] = list.get(i).intValue();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
|
||||
<SyntheticProperties>
|
||||
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
|
||||
</SyntheticProperties>
|
||||
<AuxValues>
|
||||
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
|
||||
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
|
||||
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
|
||||
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
|
||||
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
|
||||
</AuxValues>
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" attributes="0">
|
||||
<Component id="scrollList" alignment="1" max="32767" attributes="0"/>
|
||||
<Component id="panelCommands" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="panelHeader" alignment="0" max="32767" attributes="0"/>
|
||||
<Component id="panelSearch" alignment="1" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
<Component id="panelHeader" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="panelSearch" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="scrollList" min="-2" pref="246" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="panelCommands" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Container class="javax.swing.JPanel" name="panelHeader">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="labelMessage" alignment="1" pref="210" max="32767" attributes="0"/>
|
||||
<Component id="labelSubMessage" alignment="1" pref="210" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="labelMessage" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="labelSubMessage" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="labelMessage">
|
||||
<Properties>
|
||||
<Property name="horizontalAlignment" type="int" value="0"/>
|
||||
<Property name="text" type="java.lang.String" value="<html><div style='text-align: center;'>example long message example long message example long message example long message example long message</div></html>"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JLabel" name="labelSubMessage">
|
||||
<Properties>
|
||||
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
|
||||
<FontInfo relative="true">
|
||||
<Font bold="true" component="labelSubMessage" italic="true" property="font" relativeSize="true" size="0"/>
|
||||
</FontInfo>
|
||||
</Property>
|
||||
<Property name="horizontalAlignment" type="int" value="0"/>
|
||||
<Property name="text" type="java.lang.String" value="<html><div style='text-align: center;'>example long message example long</div></html>"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="panelSearch">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
<Component id="labelSearch" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="editSearch" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="labelSearch" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="editSearch" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JLabel" name="labelSearch">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Search:"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="editSearch">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="sample search text"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JScrollPane" name="scrollList">
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JList" name="listChoices">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.ListModel" editor="org.netbeans.modules.form.editors2.ListModelEditor">
|
||||
<StringArray count="3">
|
||||
<StringItem index="0" value="item1"/>
|
||||
<StringItem index="1" value="item2"/>
|
||||
<StringItem index="2" value="item3"/>
|
||||
</StringArray>
|
||||
</Property>
|
||||
</Properties>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value=""/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
<Container class="javax.swing.JPanel" name="panelCommands">
|
||||
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" attributes="0">
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="btOK" linkSize="3" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btCancel" linkSize="3" min="-2" pref="70" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="btCancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="btOK" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="btOK">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Choose"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btOKActionPerformed"/>
|
||||
</Events>
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_AddingCodePost" type="java.lang.String" value="getRootPane().setDefaultButton(btOK);"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="btCancel">
|
||||
<Properties>
|
||||
<Property name="text" type="java.lang.String" value="Cancel"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btCancelActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
|
@ -0,0 +1,654 @@
|
|||
/*
|
||||
* 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<T> extends MageDialog {
|
||||
|
||||
Choice choice;
|
||||
ArrayList<KeyValueItem> allItems = new ArrayList<>();
|
||||
//ArrayList<?> allItems = new ArrayList<>();
|
||||
DefaultListModel<KeyValueItem> dataModel =new DefaultListModel();
|
||||
CheckBoxList.CheckBoxListModel m_dataModel;
|
||||
|
||||
CheckBoxList tList;
|
||||
T tListChoices;
|
||||
|
||||
final private static String HTML_TEMPLATE = "<html><div style='text-align: center;'>%s</div></html>";
|
||||
|
||||
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<String, String> entry: choice.getKeyChoices().entrySet()) {
|
||||
|
||||
if(tList != null){
|
||||
/*for(int index=0;index<this.allItems.size();index++)
|
||||
{
|
||||
|
||||
}*/
|
||||
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()){
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// sorting
|
||||
if(choice.isSortEnabled()){
|
||||
Collections.sort(this.allItems, new Comparator<KeyValueItem>() {
|
||||
@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")
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//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("<html><div style='text-align: center;'>example long message example long message example long message example long message example long message</div></html>");
|
||||
|
||||
labelSubMessage.setFont(labelSubMessage.getFont().deriveFont((labelSubMessage.getFont().getStyle() | java.awt.Font.ITALIC) | java.awt.Font.BOLD));
|
||||
labelSubMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
|
||||
labelSubMessage.setText("<html><div style='text-align: center;'>example long message example long</div></html>");
|
||||
|
||||
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();
|
||||
}// </editor-fold>//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
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
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
|
||||
*/
|
||||
public static CheckBoxList showFastSearchForStringComboBox(JComboBox combo, String chooseMessage){
|
||||
// fast search/choice dialog for string combobox
|
||||
|
||||
CheckBoxList langList= new CheckBoxList();
|
||||
java.util.List<String> myList = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
|
||||
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(); 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<CheckBoxList> 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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue