| Method from net.sourceforge.jbird.awt.ListChooser Detail: |
public void addArrayActionListener(IntarrayListener item) {
arraylistener.addListener(item);
}
|
protected final void beep() {
if (beeper != null) {
beeper.receiveNull();
} else {
Toolkit.getDefaultToolkit().beep();
}
}
Use this method to scold users. Calls the receiveNull
method of beeper if beeper is not null. Otherwise, it
just beeps. Use setBeeper to control behavior. |
public final void buildList(String[] itemnames) {
buildList(itemnames, Collator.getInstance(), false);
}
|
public final void buildList(String[] itemnames,
CollationKeyArray cka) {
collator = cka.collator;
clearList();
names = (String[])itemnames.clone();
int i;
for (i=0; i < itemnames.length; i++) {
picklist.add(names[i]);
}
picklist.makeVisible(0);
keylist = cka;
setEnabledChoices(true);
}
Use this method when itemnames is already sorted and
you've already built a sorted CollationKeyArray |
public final void buildList(String[] itemnames,
Collator coll,
boolean presorted) {
collator = (Collator) coll.clone();
clearList();
//System.out.println("buildList: cloning names");
names = (String[])itemnames.clone();
//System.out.println("buildList: names cloned");
//System.out.println("buildList: adding names to picklist");
int i;
for (i=0; i < itemnames.length; i++) {
picklist.add(names[i]);
}
//System.out.println("buildList: added names to picklist");
picklist.makeVisible(0);
//System.out.println("buildList: building collationkeyarray");
keylist = new CollationKeyArray(itemnames, collator);
//System.out.println("buildList: built collationkeyarray");
if (! presorted) {
//System.out.println("buildList: sorting keys");
keylist.sortArray();
//System.out.println("buildList: finished sorting");
}
setEnabledChoices(true);
}
|
protected void common() {
title.setAlignment(Label.LEFT);
selectedname.setForeground(unselectedcolor);
listlistener = new ListAction();
picklist.addActionListener(listlistener);
setEnabledChoices(false);
itemlistener = new ClickOnList();
picklist.addItemListener(itemlistener);
TextWrangler textwrangler = new TextWrangler();
typefield.addTextListener(textwrangler);
}
Tasks that are common to all constructors. |
public void deselectItem(int item) {
if (item == -1) {
return;
}
if (! picklist.isIndexSelected(item)) {
return;
}
picklist.deselect(item);
updateSelectedItemInfo();
}
Unselect item based on row number in List. |
public static GridBagConstraints[] getHorizontalConstraints() {
GridBagConstraints[] gbc = new GridBagConstraints[6];
// title
gbc[0] = new GridBagConstraints(0, // gridx
0, // gridy
1, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.NONE,
// fill
new Insets(5,0,2,0), // insets
//new Insets(5,5,2,5), // insets
0, // ipadx
0); // ipady
// selected value
gbc[1] = new GridBagConstraints(1, // gridx
0, // gridy
6, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.WEST,
// anchor
GridBagConstraints.HORIZONTAL,
// fill
new Insets(5,0,2,0), // insets
0, // ipadx
0); // ipady
// type title
gbc[2] = new GridBagConstraints(1, // gridx
2, // gridy
3, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.NONE,
// fill
new Insets(5,0,0,0), // insets
0, // ipadx
0); // ipady
// picker title
gbc[4] = new GridBagConstraints(4, // gridx
2, // gridy
3, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.NONE,
// fill
new Insets(5,0,0,0), // insets
0, // ipadx
0); // ipady
// keyboard input field
gbc[3] = new GridBagConstraints(1, // gridx
3, // gridy
3, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.NONE,
// fill
new Insets(1,0,5,0), // insets
0, // ipadx
0); // ipady
// picker
gbc[5] = new GridBagConstraints(4, // gridx
3, // gridy
3, // gridwidth
6, // gridheight
1.0, // weightx,
1.0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.BOTH,
// fill
new Insets(1,3,5,5), // insets
0, // ipadx
0); // ipady
return gbc;
}
Return an array of GridBagConstraints that lays out
a ListChooser with keyboard input on the left and
picker on the right.
The picker should always be much taller than the keyboard
input field. Empty space in the lower left
quadrant is useful placing buttons and other
components that might be used in subclasses of
ListChooser. |
public int getNameCompletion(int value) {
return fieldcompletion;
}
|
public final Color getSelectedColor() {
return selectedcolor;
}
Return color of selected value. |
public String[] getSelectedNames() {
return picklist.getSelectedItems();
}
Return a string array of the selected items
This method returns information exactly as does the
getSelectedItems method of objects of type List |
public final Color getUnselectedColor() {
return unselectedcolor;
}
Return color of non-selected message. |
public static GridBagConstraints[] getVerticalConstraints() {
GridBagConstraints[] gbc = new GridBagConstraints[6];
// title
gbc[0] = new GridBagConstraints(0, // gridx
0, // gridy
1, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.NONE,
// fill
new Insets(5,0,2,0), // insets
//new Insets(5,5,2,5), // insets
0, // ipadx
0); // ipady
// selected value
gbc[1] = new GridBagConstraints(1, // gridx
0, // gridy
3, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.WEST,
// anchor
GridBagConstraints.HORIZONTAL,
// fill
new Insets(5,0,2,5), // insets
0, // ipadx
0); // ipady
// type title
gbc[2] = new GridBagConstraints(1, // gridx
2, // gridy
3, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.NONE,
// fill
new Insets(5,5,0,5), // insets
0, // ipadx
0); // ipady
// picker title
gbc[4] = new GridBagConstraints(1, // gridx orig 4
4, // gridy orig 2
3, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.NONE,
// fill
new Insets(5,5,0,5), // insets
0, // ipadx
0); // ipady
// keyboard input field
gbc[3] = new GridBagConstraints(1, // gridx
3, // gridy
3, // gridwidth
1, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.HORIZONTAL,
// fill
new Insets(1,0,5,5), // insets
0, // ipadx
0); // ipady
// picker
gbc[5] = new GridBagConstraints(1, // gridx orig 4
5, // gridy orig 3
3, // gridwidth
6, // gridheight
0, // weightx,
0, // weighty,
GridBagConstraints.CENTER,
// anchor
GridBagConstraints.HORIZONTAL,
// fill
new Insets(1,0,5,5), // insets
0, // ipadx
0); // ipady
return gbc;
}
Return an array of GridBagConstraints that will layout
members of a ListChooser vertically, with keyboard chooser
over picker. |
public boolean isEnabledChoices() {
return canchoose;
}
Return boolean indication of whether ListChoice is enabled. |
public boolean isMultipleMode() {
return picklist.isMultipleMode();
}
Returns boolean indicator of whether multiple selections
are allowed. |
public void localize(ResourceBundle bund) {
typetitle.setText((String)bund.getObject("Enter_f_keyboard"));
picktitle.setText((String)bund.getObject("Pick"));
}
|
public void localize(String kbdtxt,
String picktxt) {
typetitle.setText(kbdtxt);
picktitle.setText(picktxt);
}
|
public void narrowPossibilities(String value) {
narrowPossibilities(value, fieldcompletion);
}
|
public void narrowPossibilities(String value,
int completion) {
//System.out.println("narrow possibilities on " + value + "X");
if (names.length < = 0) {
lasttextentry = "";
return;
}
boolean issinglemode = ! picklist.isMultipleMode();
if (value.length() == 0) { // value empty
picklist.makeVisible(0);
if (issinglemode && selecteditems != null &&
selecteditems.length == 1) {
deselectItem(selecteditems[0]);
}
lasttextentry = "";
return;
}
int sortedat = keylist.searchFor(value);
int realat = keylist.originalIndex(sortedat);
if (realat >= 0) { // Exact match
picklist.makeVisible(realat);
selectItem(realat);
return;
}
// if a match existed, it is no more
if (issinglemode && selecteditems != null && selecteditems.length == 1){
deselectItem(selecteditems[0]);
}
// quit if no name completion
if (completion < 2 ) {
lasttextentry = value;
return;
}
// quit if backspace
if ((lasttextentry.length() - value.length() >= 1)) { // is shorter
if (lasttextentry.startsWith(value)) { // is the same
lasttextentry = value;
return;
}
}
// Convert negative indices
sortedat = - ( sortedat + 1 );
realat = - ( realat + 1 );
if (realat == names.length) {
picklist.makeVisible(names.length-1);
beep();
lasttextentry = value;
return;
}
picklist.makeVisible(realat);
// count the number of elements that
// begin with the value
int matchcount = countBeginners(value, sortedat);
if (matchcount == 0) {
if ( (lasttextentry.length() - value.length()) != 1) {
beep();
}
lasttextentry = value;
return;
}
if (matchcount == 1) { // only one match - a winner
selectItem(realat);
return;
}
if ( completion < 3) {
return;
}
// no exact match - may be common chars
String[] commonbegin = new String[matchcount];
int i;
int sortedati = sortedat;
for (i = 0; i < matchcount; i++) {
commonbegin[i] = names[keylist.originalIndex(sortedati)];
sortedati ++;
}
int commoncount = MyStringArray.commonChars(commonbegin,value.length(),
collator);
commonbegin = null;
if (commoncount > 0) {
commoncount += value.length();
if (commoncount == names[realat].length()) {
selectItem(realat);
return;
}
lasttextentry = names[realat].substring(0, commoncount);//decoy
setTypefieldTextNoNotice(lasttextentry);
return;
}
lasttextentry = value;
return;
}
|
public void removeArrayActionListener(IntarrayListener item) {
arraylistener.removeListener(item);
}
|
public final void requestTextFocus() {
typefield.requestFocus();
}
Calls requestFocus method of the text field.
Implements TextFocus. |
public void selectItem(int index) {
if (index < 0) {
return;
}
if (picklist.isIndexSelected(index)) {
return;
}
skiplist = true;
picklist.select(index);
updateSelectedItemInfo();
}
Select item by row number in List. |
public final void setBeeper(NullListener beeper) {
this.beeper = beeper;
}
Provide a NullListener that will perform suitable acts
when the ListChooser wishes to beep. By default
the ListChooser beeps. Provide a null value to restore
default behavior. |
public void setEnabledChoices(boolean b) {
typefield.setEnabled(b);
picklist.setEnabled(b);
canchoose = b;
}
Enable or disble ListChoice for use by users. |
public void setMultipleMode(boolean multmode) {
if (multmode == picklist.isMultipleMode()) { // no change
return;
}
// arbitrarily reduce selected items if going false
while (!multmode && selecteditems.length > 1) { // will this work?
int take = selecteditems.length - 1;
deselectItem(take);
}
picklist.setMultipleMode(multmode);
}
Set multiple selection mode according to multmode. |
public void setNameCompletion(int value) {
if (value != fieldcompletion && value >= 0 && value < 4) {
if (fieldcompletion == 1) {
dismantleKeyListener();
}
if (value == 1) {
setupKeyListener();
}
fieldcompletion = value;
}
}
|
public void setNextFocus(TextFocus component) {
if (return_listener == null && component != null) {
return_listener = new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
char kt = ke.getKeyChar();
if (kt == '\n" && next_text_focus != null) {
next_text_focus.requestTextFocus();
}
}
};
typefield.addKeyListener(return_listener);
}
next_text_focus = component;
}
Set the component that will receive focus when
the user presses return in the typefield of
this component.
Implements TextFocus. |
public final void setSelectedColor(Color color) {
selectedcolor = color;
if (picklist.getSelectedIndex() >= 0) {
selectedname.setForeground(selectedcolor);
}
}
Set color of selected value. |
public final void setTitle(String text) {
title.setText(text);
}
|
public void setTypefieldText(String value) {
newtextvalue = value;
Runnable setnew = new Runnable() {
public void run () {
typefield.setText(newtextvalue);
if (typefield.isDisplayable()) {
typefield.setCaretPosition(newtextvalue.length());
}
}
};
SwingUtilities.invokeLater(setnew);
}
|
public void setTypefieldTextNoNotice(String value) {
lasttextentry = value;
skiptext = true;
setTypefieldText(value);
}
|
public final void setUnselectedColor(Color color) {
unselectedcolor = color;
if (picklist.getSelectedIndex() < 0) {
selectedname.setForeground(unselectedcolor);
}
}
Set color of non-selected message. |
public void updateSelectedItemInfo() {
selecteditems = picklist.getSelectedIndexes();
selectednames = picklist.getSelectedItems();
if (selecteditems.length == 0) {
selectedname.setText("none selected");
selectedname.setForeground(unselectedcolor);
} else if (selecteditems.length == 1) {
selectedname.setForeground(selectedcolor);
int selecteditem = selecteditems[0];
selectedname.setText(names[selecteditem]);
lasttextentry = names[selecteditem];// decoy text listeners
setTypefieldTextNoNotice(lasttextentry);
} else {
selectedname.setForeground(selectedcolor);
selectedname.setText(nformatter.format(selecteditems.length) +
" items selected");
}
//if (selecteditems.length > 0) {
//int i;
//System.out.println("seletcted items in list");
//for (i=0; i < selecteditems.length; i++ ) {
//System.out.println("\t" + names[selecteditems[i]]);
//}
//}
//System.out.println("updateSelectedIteminfo - notifying Array listeners");
notifyArrayListeners(selecteditems);
}
Reset the label and notify listeners based on state of
ListChooser. |