|
||||||||||
| 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.JComboBox
edu.neu.ccs.gui.Dropdown
Class Dropdown provides the base functionality
for dropdown lists.
The class extends the functionality of JComboBox.
In turn, this class is the base class for DropdownView
and for StringObjectDropdown.
| Nested Class Summary |
| Nested classes inherited from class javax.swing.JComboBox |
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager |
| Nested classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
| Nested classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
| Nested classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
protected static String |
DEFAULT_SELECTION
Default initially selected label for a dropdown view. |
static int |
DEFAULT_WIDTH
The default preferred width used in constructors if there is no other data with which to set the width. |
protected String |
defaultViewState
The default view state. |
protected Vector |
itemList
The list of current items. |
protected int |
minimumWidth
The current minimum width for automatic width computations. |
static String |
PREFERRED_WIDTH
Bound property name for the set preferred width property. |
protected int |
preferredWidth
The current preferred width if one is enabled or -1 if preferred width is disabled. |
| Fields inherited from class javax.swing.JComboBox |
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder |
| 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.Container |
|
| Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface edu.neu.ccs.gui.Displayable |
DEFAULT_VIEW_STATE, VIEW_STATE |
| Fields inherited from interface edu.neu.ccs.util.JPTConstants |
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE |
| Fields inherited from interface javax.swing.SwingConstants |
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
Dropdown()
Constructs a view with no initial items. |
|
Dropdown(Font font)
Constructs a view with no initial items and the given font. |
|
Dropdown(Font font,
int minWidth)
Constructs a view with no initial items, the given font, and the given minimum width. |
|
Dropdown(int minWidth)
Constructs a view with no initial items and the given minimum width. |
|
Dropdown(String[] items)
Constructs a view with the given array of items, for which the first item is selected by default. |
|
Dropdown(String[] items,
Font font)
Constructs a view with the given array of items, for which the first item is selected by default and with the given font. |
|
Dropdown(String[] items,
Font font,
int minWidth)
Constructs a view with the given array of items, for which the first item is selected by default and with the given font and minimum width. |
|
Dropdown(String[] items,
int minWidth)
Constructs a view with the given array of items, for which the first item is selected by default and with the given minimum width. |
|
Dropdown(String[] items,
String selection)
Constructs a view with the given array of items, for which the given selection is selected by default. |
|
Dropdown(String[] items,
String selection,
boolean editable)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given editable state. |
|
Dropdown(String[] items,
String selection,
Font font)
Constructs a view with the given array of items, for which the given selection is selected by default and with the given font. |
|
Dropdown(String[] items,
String selection,
Font font,
boolean editable)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given font and editable state. |
|
Dropdown(String[] items,
String selection,
Font font,
int minWidth)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given font and minimum width. |
|
Dropdown(String[] items,
String selection,
Font font,
int minWidth,
boolean editable)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given font, width, and editable state. |
|
Dropdown(String[] items,
String selection,
int minWidth)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given minimum width. |
|
Dropdown(String[] items,
String selection,
int minWidth,
boolean editable)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given width and editable state. |
|
| Method Summary | |
void |
addItem(Object item)
Adds the item to the view by calling the method in the parent and also maintains a record that this item was added. |
void |
addItems(String[] items)
Adds the given String array of items to the view. |
void |
autoSetPreferredWidth()
Automatically sets the preferred width based on the current setting of the minimum width, the current items in the dropdown list, and the current font. |
static Font |
getDefaultFont()
Returns the default font for a JComboBox. |
String |
getDefaultViewState()
Returns a String representation of the default
view state for this object. |
String[] |
getItems()
Returns an array of all items currently installed in the view. |
int |
getMinimumWidth()
Returns the current minimum width setting. |
Dimension |
getPreferredSize()
Returns the preferred size of this view. |
int |
getPreferredWidth()
Returns the preferred width setting of this view. |
String |
getViewState()
Returns the current contents of the view display. |
protected void |
initializeDropdown(String[] items,
String selection,
Font font,
int minWidth,
boolean editable)
The initializer. |
void |
insertItemAt(Object item,
int index)
Inserts an item into the item list at a given index by calling the method in the parent and also maintains a record that this item was added at that position. |
void |
refresh()
Refreshes the component in its parent window by calling autoSetPreferredWidth()
and then repacking the parent window. |
void |
refreshComponent()
Refreshes the component by repacking the parent window. |
void |
removeAllItems()
Removes all items from the view by calling the method in the parent and also maintains a record that all items were removed. |
void |
removeItem(Object item)
Removes the item from the view by calling the method in the parent and also maintains a record that this item was removed. |
void |
removeItemAt(int index)
Removes an item from the item list at a given index by calling the method in the parent and also maintains a record that this item was removed from that position. |
void |
removeItems(String[] items)
Removes the given array of items from the view. |
void |
reset()
Resets the view state of this object to the default view state for this object. |
void |
setDefaultViewState(String data)
Sets the default view state for this object to the data state represented by the given String data. |
void |
setFont(Font font)
Sets the font for this component. |
void |
setItems(String[] items)
Removes all items in the view and then adds the given String array of items to the view. |
void |
setMinimumWidth(int minWidth)
Sets the minimum width for use in the method autoSetPreferredWidth. |
void |
setPreferredWidth(int width)
Sets the preferred width of text portion of the view to the given width if the given width is positive. |
void |
setPreferredWidth(int minWidth,
int samWidth)
Sets the preferred width of the text portion of the view to be at least the given minimum width and sufficiently wide to include strings whose width is no greater than the given sample width. |
void |
setPreferredWidth(int minWidth,
String sample)
Sets the preferred width of the text portion of the view using the given minimum width and sample string. |
void |
setViewState(String data)
Attempts to set the display area of this view to the given String data. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface edu.neu.ccs.gui.Displayable |
setEnabled |
| Field Detail |
public static final String PREFERRED_WIDTH
public static final int DEFAULT_WIDTH
protected static final String DEFAULT_SELECTION
protected int preferredWidth
protected int minimumWidth
protected Vector itemList
protected String defaultViewState
| Constructor Detail |
public Dropdown()
Other constructors:
- Dropdown(int)
- Dropdown(Font)
- Dropdown(Font, int)
- Dropdown(String[])
- Dropdown(String[], int)
- Dropdown(String[], Font)
- Dropdown(String[], Font, int)
- Dropdown(String[], String)
- Dropdown(String[], String, int)
- Dropdown(String[], String, Font)
- Dropdown(String[], String, Font, int)
- Dropdown(String[], String, boolean)
- Dropdown(String[], String, int, boolean)
- Dropdown(String[], String, Font, boolean)
- Dropdown(String[], String, Font, int, boolean)
public Dropdown(int minWidth)
minWidth - the preferred minimum widthDropdown()public Dropdown(Font font)
font - the font for the viewDropdown()
public Dropdown(Font font,
int minWidth)
font - the font for the viewminWidth - the preferred minimum widthDropdown()public Dropdown(String[] items)
Constructs a view with the given array of items, for which the first item is selected by default.
If the given array of items is null,
no items are initially added to the view.
items - the array of dropdown itemsDropdown()
public Dropdown(String[] items,
int minWidth)
Constructs a view with the given array of items, for which the first item is selected by default and with the given minimum width.
If the given array of items is null,
no items are initially added to the view.
items - the array of dropdown itemsminWidth - the preferred minimum widthDropdown()
public Dropdown(String[] items,
Font font)
Constructs a view with the given array of items, for which the first item is selected by default and with the given font.
If the given array of items is null,
no items are initially added to the view.
items - the array of dropdown itemsfont - the font for the viewDropdown()
public Dropdown(String[] items,
Font font,
int minWidth)
Constructs a view with the given array of items, for which the first item is selected by default and with the given font and minimum width.
If the given array of items is null,
no items are initially added to the view.
items - the array of dropdown itemsfont - the font for the viewminWidth - the preferred minimum widthDropdown()
public Dropdown(String[] items,
String selection)
Constructs a view with the given array of items, for which the given selection is selected by default.
If the given array of items is null,
no items are initially added to the view.
If the view is not editable and the selection is not in the array of items then the selection will set the default state but will not be displayed.
items - the array of dropdown itemsselection - the default initial choiceDropdown()
public Dropdown(String[] items,
String selection,
int minWidth)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given minimum width.
If the given array of items is null,
no items are initially added to the view.
If the view is not editable and the selection is not in the array of items then the selection will set the default state but will not be displayed.
items - the array of dropdown itemsselection - the default initial choiceminWidth - the preferred minimum widthDropdown()
public Dropdown(String[] items,
String selection,
Font font)
Constructs a view with the given array of items, for which the given selection is selected by default and with the given font.
If the given array of items is null,
no items are initially added to the view.
If the view is not editable and the selection is not in the array of items then the selection will set the default state but will not be displayed.
items - the array of dropdown itemsselection - the default initial choicefont - the font for the viewDropdown()
public Dropdown(String[] items,
String selection,
Font font,
int minWidth)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given font and minimum width.
If the given array of items is null,
no items are initially added to the view.
If the view is not editable and the selection is not in the array of items then the selection will set the default state but will not be displayed.
items - the array of dropdown itemsselection - the default initial choicefont - the font for the viewminWidth - the preferred minimum widthDropdown()
public Dropdown(String[] items,
String selection,
boolean editable)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given editable state.
If the given array of items is null,
no items are initially added to the view.
If the view is not editable and the selection is not in the array of items then the selection will set the default state but will not be displayed.
items - the array of dropdown itemsselection - the label for the initial default choiceeditable - whether or not the view is user editableDropdown()
public Dropdown(String[] items,
String selection,
int minWidth,
boolean editable)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given width and editable state.
If the given array of items is null,
no items are initially added to the view.
If the view is not editable and the selection is not in the array of items then the selection will set the default state but will not be displayed.
items - the array of dropdown itemsselection - the label for the initial default choiceminWidth - the preferred minimum widtheditable - whether or not the view is user editableDropdown()
public Dropdown(String[] items,
String selection,
Font font,
boolean editable)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given font and editable state.
If the given array of items is null,
no items are initially added to the view.
If the view is not editable and the selection is not in the array of items then the selection will set the default state but will not be displayed.
items - the array of dropdown itemsselection - the label for the initial default choicefont - the font for the vieweditable - whether or not the view is user editableDropdown()
public Dropdown(String[] items,
String selection,
Font font,
int minWidth,
boolean editable)
Constructs a view with the given array of items, for which the given selection is selected by default, and with the given font, width, and editable state.
If the given array of items is null,
no items are initially added to the view.
If the view is not editable and the selection is not in the array of items then the selection will set the default state but will not be displayed.
items - the array of dropdown itemsselection - the label for the initial default choicefont - the font for the viewminWidth - the preferred minimum widtheditable - whether or not the view is user editableDropdown()| Method Detail |
protected void initializeDropdown(String[] items,
String selection,
Font font,
int minWidth,
boolean editable)
items - the array of dropdown itemsselection - the label for the initial default choicefont - the font for the viewminWidth - the preferred minimum widtheditable - whether or not the view is user editablepublic void addItem(Object item)
Adds the item to the view by calling the method in the parent and also maintains a record that this item was added.
This override of an inherited method will only add the item
if it is a non-null instance of String.
To avoid multiple refresh operations after each add operation, this method does not auto refresh.
item - the item to add
public void insertItemAt(Object item,
int index)
Inserts an item into the item list at a given index by calling the method in the parent and also maintains a record that this item was added at that position.
This override of an inherited method will only insert the item
if it is a non-null instance of String.
To avoid multiple refresh operations after each insert operation, this method does not auto refresh.
item - the item to addindex - the position at which to add the itempublic void removeItem(Object item)
Removes the item from the view by calling the method in the parent and also maintains a record that this item was removed.
This override of an inherited method will only remove the item
if it is a non-null instance of String.
To avoid multiple refresh operations after each remove operation, this method does not auto refresh.
item - the item to removepublic void removeItemAt(int index)
Removes an item from the item list at a given index by calling the method in the parent and also maintains a record that this item was removed from that position.
To avoid multiple refresh operations after each remove operation, this method does not auto refresh.
index - the position at which to remove the itempublic void removeAllItems()
Removes all items from the view by calling the method in the parent and also maintains a record that all items were removed.
public void addItems(String[] items)
Adds the given String array of items to the view.
Calls refresh() if items are added.
If the items array is null, then does nothing.
items - the items to be addedpublic void setItems(String[] items)
Removes all items in the view and then adds the given
String array of items to the view.
Calls refresh() if items are added.
If the items array is null, then simply removes
all items in the view and leaves the view empty.
items - the items to be added after removing existing itemspublic void removeItems(String[] items)
Removes the given array of items from the view.
If the items array is null, then does nothing.
items - the items to be removedpublic String[] getItems()
public Dimension getPreferredSize()
Returns the preferred size of this view.
This method proceeds as follows.
The preferred size is calculated by the super class method. Then, if the preferred width set in this class is positive, the width field of the preferred size is replaced by the sum of the preferred width and the height field of the preferred size. The preferred size then is returned.
This calculation is done so that the preferred width controls the width of the text portion of the dropdown and the actual width includes room for the control.
public int getPreferredWidth()
Returns the preferred width setting of this view.
The value returned is positive or -1.
If the value is -1 then it is not used to compute the preferred size.
public void autoSetPreferredWidth()
Automatically sets the preferred width based on the current setting of the minimum width, the current items in the dropdown list, and the current font.
It is recommended that this method be used to set the width
of the dropdown rather than an explicit call to one of the
methods setPreferredWidth. This method is called
in the constructors and in the method refresh().
public void setMinimumWidth(int minWidth)
Sets the minimum width for use in the method
autoSetPreferredWidth.
This minimum width will be interpreted later`as follows.
public int getMinimumWidth()
public void setPreferredWidth(int width)
Sets the preferred width of text portion of the view to the given width if the given width is positive.
If the given width is zero, sets the preferred width of the text portion of the view to DEFAULT_WIDTH.
If the given width is negative, sets the preferred width to -1 and the preferred size of the view will be computed entirely from the data of the super class.
Refreshes the component in its parent view.
It is recommended that the user call the method
autoSetPreferredWidth rather than call this method
directly. This method is public for backward compatibility and
to permit the user to set an absolute preferred width if that
behavior is really desired.
Fires property change PREFERRED_WIDTH.
width - the desired preferred width
public void setPreferredWidth(int minWidth,
String sample)
Sets the preferred width of the text portion of the view using the given minimum width and sample string.
This method proceeds as follows.
If the sample string is null or of length zero,
then the preferred width is set via the call:
setPreferredWidth(minWidth).
Otherwise, if minWidth is zero, it is set to DEFAULT_WIDTH.
Then, the method getSampleWidth is called using
the current font of the view and the sample string. The
preferred width is then set to be the maximum of minWidth and
the sample width.
Always calls setMinimumWidth(minWidth) to save the
minimum width setting.
Refreshes the component in its parent view.
It is recommended that the user call the method
autoSetPreferredWidth rather than call this method
directly. This method is public for backward compatibility and
to permit the user to set a width larger than the width of any
string installed in the dropdown list.
Fires property change PREFERRED_WIDTH.
minWidth - the minimum widthsample - the sample string used to calculate the width
public void setPreferredWidth(int minWidth,
int samWidth)
Sets the preferred width of the text portion of the view to be at least the given minimum width and sufficiently wide to include strings whose width is no greater than the given sample width.
Always calls setMinimumWidth(minWidth) to save the
minimum width setting.
Refreshes the component in its parent view.
It is recommended that the user call the method
autoSetPreferredWidth rather than call this method
directly. This method is public for backward compatibility and
to permit the user to set a width larger than the width of any
string installed in the dropdown list.
Fires property change PREFERRED_WIDTH.
minWidth - the minimum widthsamWidth - the maximum width of one or more sample stringssetPreferredWidth(int),
setPreferredWidth(int, String)public void setFont(Font font)
Sets the font for this component.
If the given font is null then it is set to
getDefaultFont().
Fires property change FONT.
font - the font to set for this viewpublic static Font getDefaultFont()
public void setViewState(String data)
Attempts to set the display area of this view to the given
String data.
If isEditable() returns true then
sets the editable display area to the String data.
If isEditable() returns false then
changes the display area to the String data only
if data is in the dropdown list.
In either case, if data is in the dropdown list then will also set the selected index to the first occurence of data in the dropdown list.
If data is null, then does nothing.
If the current view state already equals data then also does nothing.
Fires property change VIEW_STATE.
setViewState in interface Displayabledata - the String to be selectedgetViewState()public String getViewState()
getViewState in interface DisplayableStringsetViewState(String)public void setDefaultViewState(String data)
String data.
setDefaultViewState in interface Displayabledata - the new default data state for this objectgetDefaultViewState(),
reset()public String getDefaultViewState()
String representation of the default
view state for this object.
getDefaultViewState in interface DisplayableStringsetDefaultViewState(String),
reset()public void reset()
reset in interface DisplayableDisplayable.setViewState(String),
Displayable.getDefaultViewState()public void refresh()
Refreshes the component in its parent window
by calling autoSetPreferredWidth()
and then repacking the parent window.
public void refreshComponent()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||