|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
gate.swing.JChoice
public class JChoice
A GUI component intended to allow quick selection from a set of
options. When the number of choices is small (i.e less or equal to
maximumFastChoices) then the options are represented as a
set of buttons in a flow layout. If more options are available, a
simple JComboBox is used instead.
| Nested Class Summary | |
|---|---|
private class |
JChoice.ListenerWrapper
An action listener that changes the source of events to be this object. |
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
private Map<AbstractButton,Object> |
buttonToValueMap
Keeps a mapping between the button and the corresponding option from the model. |
private JComboBox |
combo
The combobox used for a large number of choices. |
static int |
DEFAULT_MAX_FAST_CHOICES
The default value for the maximumFastChoices parameter. |
static int |
DEFAULT_MAX_WIDTH
The default value for the maximumWidth parameter. |
private Insets |
defaultButtonMargin
Margin used for choice buttons. |
private FlowLayout |
layout
The layout used by this container. |
private Map<EventListener,JChoice.ListenerWrapper> |
listenersMap
A map from wrapped action listeners to listener |
private int |
maximumFastChoices
The maximum number of options for which the flow of buttons is used instead of a combobox. |
private int |
maximumWidth
The maximum width allowed for this component. |
private ComboBoxModel |
model
The data model used for choices and selection. |
private ItemListener |
sharedItemListener
Internal item listener for both the combo and the buttons, used to keep the two in sync. |
| Fields inherited from class javax.swing.JComponent |
|---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
JChoice()
Creates a FastChoice with a default empty data model. |
|
JChoice(ComboBoxModel model)
Creates a FastChoice with the given data model. |
|
JChoice(Object[] items)
Creates a FastChoice with a default data model populated from the provided array of objects. |
|
| Method Summary | |
|---|---|
void |
addActionListener(ActionListener l)
|
void |
addItemListener(ItemListener listener)
|
void |
addListDataListener(ListDataListener l)
|
private void |
buildGui()
(Re)constructs the UI. |
Insets |
getDefaultButtonMargin()
|
Object |
getElementAt(int index)
|
int |
getItemCount()
|
int |
getMaximumFastChoices()
|
int |
getMaximumWidth()
|
ComboBoxModel |
getModel()
|
Dimension |
getPreferredSize()
|
Object |
getSelectedItem()
|
Object[] |
getSelectedObjects()
|
private void |
initLocalData()
Initialises some local values. |
static void |
main(String[] args)
|
void |
removeActionListener(ActionListener l)
|
void |
removeItemListener(ItemListener listener)
|
void |
removeListDataListener(ListDataListener l)
|
void |
setDefaultButtonMargin(Insets defaultButtonMargin)
|
void |
setMaximumFastChoices(int maximumFastChoices)
|
void |
setMaximumWidth(int maximumWidth)
|
void |
setModel(ComboBoxModel model)
|
void |
setSelectedItem(Object anItem)
|
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_MAX_WIDTH
maximumWidth parameter.
public static final int DEFAULT_MAX_FAST_CHOICES
maximumFastChoices parameter.
private int maximumFastChoices
DEFAULT_MAX_FAST_CHOICES
private Insets defaultButtonMargin
private int maximumWidth
DEFAULT_MAX_WIDTH. This is used to force the flow
layout do a multi-line layout, as by default it prefers to lay all
components in a single very wide line.
private FlowLayout layout
private JComboBox combo
private ItemListener sharedItemListener
private ComboBoxModel model
private Map<AbstractButton,Object> buttonToValueMap
private Map<EventListener,JChoice.ListenerWrapper> listenersMap
| Constructor Detail |
|---|
public JChoice()
public JChoice(ComboBoxModel model)
public JChoice(Object[] items)
| Method Detail |
|---|
public Object[] getSelectedObjects()
getSelectedObjects in interface ItemSelectableprivate void initLocalData()
public static void main(String[] args)
public void removeActionListener(ActionListener l)
l - JComboBox.removeActionListener(java.awt.event.ActionListener)public void removeItemListener(ItemListener listener)
removeItemListener in interface ItemSelectablelistener - JComboBox.removeItemListener(java.awt.event.ItemListener)public void addActionListener(ActionListener l)
l - JComboBox.addActionListener(java.awt.event.ActionListener)public void addItemListener(ItemListener listener)
addItemListener in interface ItemSelectablelistener - JComboBox.addItemListener(java.awt.event.ItemListener)private void buildGui()
maximumFastChoices, or the model)
has changed.
public void addListDataListener(ListDataListener l)
l - ListModel.addListDataListener(javax.swing.event.ListDataListener)public Object getElementAt(int index)
index -
ListModel.getElementAt(int)public Object getSelectedItem()
ComboBoxModel.getSelectedItem()public int getItemCount()
ListModel.getSize()public void removeListDataListener(ListDataListener l)
l - ListModel.removeListDataListener(javax.swing.event.ListDataListener)public void setSelectedItem(Object anItem)
anItem - ComboBoxModel.setSelectedItem(java.lang.Object)public Dimension getPreferredSize()
getPreferredSize in class JComponentpublic int getMaximumFastChoices()
public void setMaximumFastChoices(int maximumFastChoices)
maximumFastChoices - the maximumFastChoices to setpublic ComboBoxModel getModel()
public void setModel(ComboBoxModel model)
model - the model to setpublic int getMaximumWidth()
public void setMaximumWidth(int maximumWidth)
maximumWidth - the maximumWidth to setpublic Insets getDefaultButtonMargin()
public void setDefaultButtonMargin(Insets defaultButtonMargin)
defaultButtonMargin - the defaultButtonMargin to set
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||