ptolemy.gui
Class Query

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by ptolemy.gui.Query
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class Query
extends javax.swing.JPanel

Create a query with various types of entry boxes and controls. Each type of entry box has a colon and space appended to the end of its label, to ensure uniformity. Here is one example of creating a query with a radio button:

 query = new Query();
 getContentPane().add(query);
 String[] options = {"water", "soda", "juice", "none"};
 query.addRadioButtons("radio", "Radio buttons", options, "water");
 

Since:
Ptolemy II 0.3
Version:
$Id: Query.java 57046 2010-01-27 23:35:53Z cxh $
Author:
Edward A. Lee, Manda Sutijono, Elaine Cheong, Contributor: Peter Reutemann
See Also:
Serialized Form
Accepted Rating:
Red (eal)
Proposed Rating:
Yellow (eal)

Nested Class Summary
static class Query.QueryActionListener
          Listener for "line" and radio button entries.
static class Query.QueryColorChooser
          Panel containing an entry box and color chooser.
static class Query.QueryFileChooser
          Panel containing an entry box and file chooser.
static class Query.QueryFocusListener
          Listener for line entries, for when they lose the focus.
static class Query.QueryItemListener
          Listener for "CheckBox" and "Choice" entries.
(package private) static class Query.QueryScrollPane
          Inner class to tie textArea to scroll pane.
static class Query.SliderListener
          Listener for changes in slider.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.awt.Color _background
          The background color as set by setBackground().
private  int _columns
           
protected  java.awt.GridBagConstraints _constraints
          Standard constraints for use with _grid.
protected  java.util.Map _entries
          The hashtable of items in the query.
private  javax.swing.JPanel _entryPanel
           
private  javax.swing.JScrollPane _entryScrollPane
           
protected  java.awt.GridBagLayout _grid
          Layout control.
private  int _height
           
private  java.awt.Insets _insets
           
private  java.util.Map _labels
           
private  java.awt.Insets _leftPadding
           
protected  java.util.Vector _listeners
          List of registered listeners.
private  javax.swing.JTextArea _messageArea
           
private  javax.swing.JScrollPane _messageScrollPane
           
private  boolean _messageScrollPaneAdded
           
private  java.util.Map _previous
           
private  int _widgetsHeight
           
private  int _width
           
static int DEFAULT_ENTRY_HEIGHT
          The default height of entries created with addText().
static int DEFAULT_ENTRY_WIDTH
          The default width of entries created with addLine().
 
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
Query()
          Construct a panel with no entries in it.
 
Method Summary
protected  void _addPair(java.lang.String name, javax.swing.JLabel label, java.awt.Component widget, java.lang.Object entry)
          Add a label and a widget to the panel.
(package private)  void _notifyListeners(java.lang.String name)
          Notify all registered listeners that something changed for the specified entry, if it indeed has changed.
protected  void _recalculatePreferredSize(java.awt.Component widget)
          Recalculate the preferred size of the entry panel.
 javax.swing.JCheckBox addCheckBox(java.lang.String name, java.lang.String label, boolean defaultValue)
          Create an on-off check box.
 void addChoice(java.lang.String name, java.lang.String label, java.lang.Object[] values, java.lang.Object defaultChoice)
          Create an uneditable choice menu.
 void addChoice(java.lang.String name, java.lang.String label, java.lang.Object[] values, java.lang.Object defaultChoice, boolean editable)
          Create a choice menu.
 javax.swing.JComboBox addChoice(java.lang.String name, java.lang.String label, java.lang.Object[] values, java.lang.Object defaultChoice, boolean editable, java.awt.Color background, java.awt.Color foreground)
          Create a choice menu.
 Query.QueryColorChooser addColorChooser(java.lang.String name, java.lang.String label, java.lang.String defaultColor)
          Create a ColorChooser.
 javax.swing.JTextArea addDisplay(java.lang.String name, java.lang.String label, java.lang.String theValue)
          Create a simple one-line text display, a non-editable value that is set externally using the setDisplay() method.
 void addFileChooser(java.lang.String name, java.lang.String label, java.lang.String defaultName, java.net.URI base, java.io.File startingDirectory)
          Create a FileChooser that selects files only, not directories, and has the default colors (white in the background, black in the foreground).
 void addFileChooser(java.lang.String name, java.lang.String label, java.lang.String defaultName, java.net.URI base, java.io.File startingDirectory, boolean save)
          Create a FileChooser that selects files only, not directories, and has the default colors (white in the background, black in the foreground).
 void addFileChooser(java.lang.String name, java.lang.String label, java.lang.String defaultName, java.net.URI base, java.io.File startingDirectory, boolean allowFiles, boolean allowDirectories)
          Create a FileChooser with default colors (white in the foreground, black in the background).
 Query.QueryFileChooser addFileChooser(java.lang.String name, java.lang.String label, java.lang.String defaultName, java.net.URI base, java.io.File startingDirectory, boolean allowFiles, boolean allowDirectories, boolean save, java.awt.Color background, java.awt.Color foreground)
          Create a FileChooser.
 Query.QueryFileChooser addFileChooser(java.lang.String name, java.lang.String label, java.lang.String defaultName, java.net.URI base, java.io.File startingDirectory, boolean allowFiles, boolean allowDirectories, java.awt.Color background, java.awt.Color foreground)
          Create a FileChooser.
 void addFileChooser(java.lang.String name, java.lang.String label, java.lang.String defaultName, java.net.URI base, java.io.File startingDirectory, java.awt.Color background, java.awt.Color foreground)
          Create a FileChooser that selects files only, not directories.
 void addLine(java.lang.String name, java.lang.String label, java.lang.String defaultValue)
          Create a single-line entry box with the specified name, label, and default value.
 void addLine(java.lang.String name, java.lang.String label, java.lang.String defaultValue, java.awt.Color background, java.awt.Color foreground)
          Create a single-line entry box with the specified name, label, default value, and background color.
 javax.swing.JPasswordField addPassword(java.lang.String name, java.lang.String label, java.lang.String defaultValue)
          Create a single-line password box with the specified name, label, and default value.
 javax.swing.JPasswordField addPassword(java.lang.String name, java.lang.String label, java.lang.String defaultValue, java.awt.Color background, java.awt.Color foreground)
          Create a single-line password box with the specified name, label, and default value.
 void addQueryListener(QueryListener listener)
          Add a listener.
 void addRadioButtons(java.lang.String name, java.lang.String label, java.lang.String[] values, java.lang.String defaultValue)
          Create a bank of radio buttons.
 void addSelectButtons(java.lang.String name, java.lang.String label, java.lang.String[] values, java.util.Set initiallySelected)
          Create a bank of buttons that provides a list of choices, any subset of which may be chosen at a time.
 void addSeparator()
          Create a horizontal separator between components.
 javax.swing.JSlider addSlider(java.lang.String name, java.lang.String label, int defaultValue, int minimum, int maximum)
          Create a slider with the specified name, label, default value, maximum, and minimum.
 void addText(java.lang.String text, java.awt.Color color, int alignment)
          Add text to the query.
 void addTextArea(java.lang.String name, java.lang.String label, java.lang.String theValue)
          Create a text area.
 void addTextArea(java.lang.String name, java.lang.String label, java.lang.String theValue, java.awt.Color background, java.awt.Color foreground)
          Create a text area.
 javax.swing.JTextArea addTextArea(java.lang.String name, java.lang.String label, java.lang.String theValue, java.awt.Color background, java.awt.Color foreground, int height, int width)
          Create a text area with the specified height and width (in characters).
 boolean booleanValue(java.lang.String name)
          Deprecated. Use getBooleanValue(String name) instead.
 double doubleValue(java.lang.String name)
          Deprecated. Use getDoubleValue(String name) instead.
 boolean getBooleanValue(java.lang.String name)
          Get the current value in the entry with the given name and return as a boolean.
 char[] getCharArrayValue(java.lang.String name)
          Get the current value in the entry with the given name and return as an array of characters.
 double getDoubleValue(java.lang.String name)
          Get the current value in the entry with the given name and return as a double value.
 int getIntValue(java.lang.String name)
          Get the current value in the entry with the given name and return as an integer.
 java.awt.Dimension getMaximumSize()
          Return the preferred height, but set the width to the maximum possible value.
 java.lang.Object getObjectValue(java.lang.String name)
          Get the current value in the entry with the given name, and return as an Object.
 java.lang.String getStringValue(java.lang.String name)
          Get the current value in the entry with the given name, and return as a String.
 int getTextHeight()
          Get the preferred number of lines to be used for entry boxes created in using addTextArea().
 int getTextWidth()
          Get the preferred width in characters to be used for entry boxes created in using addLine().
 boolean hasEntry(java.lang.String name)
          Return whether an entry exists with the specified name.
 int intValue(java.lang.String name)
          Deprecated. Use getIntValue(String name) instead.
 void notifyListeners()
          Notify listeners of the current value of all entries, unless those entries have not changed since the last notification.
 void removeQueryListener(QueryListener listener)
          Remove a listener.
 void set(java.lang.String name, java.lang.String value)
          Set the value in the entry with the given name.
 void setAndNotify(java.lang.String name, java.lang.String value)
          Set the value in the entry with the given name and notify listeners.
 void setBackground(java.awt.Color color)
          Set the background color for all the widgets.
 void setBoolean(java.lang.String name, boolean value)
          Set the current value in the entry with the given name.
 void setColumns(int columns)
          Specify the number of columns to use.
 void setDisplay(java.lang.String name, java.lang.String value)
          Set the displayed text of an entry that has been added using addDisplay.
 void setEnabled(java.lang.String name, boolean value)
          For line, display, check box, slider, radio button, or choice entries made, if the second argument is false, then it will be disabled.
 void setInsets(java.awt.Insets insets)
          Set the insets for the GridBagLayout manager used to layout the components.
 void setLine(java.lang.String name, java.lang.String value)
          Set the displayed text of an item that has been added using addLine.
 void setMessage(java.lang.String message)
          Specify a message to be displayed above the query.
 void setSlider(java.lang.String name, int value)
          Set the position of an item that has been added using addSlider.
 void setTextHeight(int characters)
          Specify the preferred height to be used for entry boxes created in using addTextArea().
 void setTextWidth(int characters)
          Specify the preferred width to be used for entry boxes created in using addLine().
 void setToolTip(java.lang.String name, java.lang.String tip)
          Specify a tool tip to appear when the mouse lingers over the label.
static java.awt.Color stringToColor(java.lang.String description)
          Convert the specified string to a color.
 java.lang.String stringValue(java.lang.String name)
          Deprecated. Use getStringValue(String name) instead.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_ENTRY_HEIGHT

public static final int DEFAULT_ENTRY_HEIGHT
The default height of entries created with addText().

See Also:
Constant Field Values

DEFAULT_ENTRY_WIDTH

public static final int DEFAULT_ENTRY_WIDTH
The default width of entries created with addLine().

See Also:
Constant Field Values

_background

protected java.awt.Color _background
The background color as set by setBackground(). This defaults to null, which indicates that the background is the same as the container.


_constraints

protected java.awt.GridBagConstraints _constraints
Standard constraints for use with _grid.


_entries

protected java.util.Map _entries
The hashtable of items in the query.


_grid

protected java.awt.GridBagLayout _grid
Layout control.


_listeners

protected java.util.Vector _listeners
List of registered listeners.


_columns

private int _columns

_entryPanel

private javax.swing.JPanel _entryPanel

_entryScrollPane

private javax.swing.JScrollPane _entryScrollPane

_height

private int _height

_labels

private java.util.Map _labels

_leftPadding

private java.awt.Insets _leftPadding

_messageArea

private javax.swing.JTextArea _messageArea

_messageScrollPane

private javax.swing.JScrollPane _messageScrollPane

_messageScrollPaneAdded

private boolean _messageScrollPaneAdded

_insets

private java.awt.Insets _insets

_previous

private java.util.Map _previous

_widgetsHeight

private int _widgetsHeight

_width

private int _width
Constructor Detail

Query

public Query()
Construct a panel with no entries in it.

Method Detail

addCheckBox

public javax.swing.JCheckBox addCheckBox(java.lang.String name,
                                         java.lang.String label,
                                         boolean defaultValue)
Create an on-off check box.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
defaultValue - The default value (true for on).
Returns:
The check box.

addChoice

public void addChoice(java.lang.String name,
                      java.lang.String label,
                      java.lang.Object[] values,
                      java.lang.Object defaultChoice)
Create an uneditable choice menu.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
values - The list of possible choices.
defaultChoice - Default choice.

addChoice

public void addChoice(java.lang.String name,
                      java.lang.String label,
                      java.lang.Object[] values,
                      java.lang.Object defaultChoice,
                      boolean editable)
Create a choice menu.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
values - The list of possible choices.
defaultChoice - Default choice.
editable - True if an arbitrary choice can be entered, in addition to the choices in values.

addChoice

public javax.swing.JComboBox addChoice(java.lang.String name,
                                       java.lang.String label,
                                       java.lang.Object[] values,
                                       java.lang.Object defaultChoice,
                                       boolean editable,
                                       java.awt.Color background,
                                       java.awt.Color foreground)
Create a choice menu.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
values - The list of possible choices.
defaultChoice - Default choice.
editable - True if an arbitrary choice can be entered, in addition to the choices in values.
background - The background color for the editable part.
foreground - The foreground color for the editable part.
Returns:
The combo box for the choice.

addColorChooser

public Query.QueryColorChooser addColorChooser(java.lang.String name,
                                               java.lang.String label,
                                               java.lang.String defaultColor)
Create a ColorChooser.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
defaultColor - The default color to use.
Returns:
The color chooser.

addDisplay

public javax.swing.JTextArea addDisplay(java.lang.String name,
                                        java.lang.String label,
                                        java.lang.String theValue)
Create a simple one-line text display, a non-editable value that is set externally using the setDisplay() method.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
theValue - Default string to display.
Returns:
The text area that displays the value.

addFileChooser

public void addFileChooser(java.lang.String name,
                           java.lang.String label,
                           java.lang.String defaultName,
                           java.net.URI base,
                           java.io.File startingDirectory)
Create a FileChooser that selects files only, not directories, and has the default colors (white in the background, black in the foreground).

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
defaultName - The default file name to use.
base - The URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectory - The directory to open the file chooser in.

addFileChooser

public void addFileChooser(java.lang.String name,
                           java.lang.String label,
                           java.lang.String defaultName,
                           java.net.URI base,
                           java.io.File startingDirectory,
                           boolean save)
Create a FileChooser that selects files only, not directories, and has the default colors (white in the background, black in the foreground).

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
defaultName - The default file name to use.
base - The URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectory - The directory to open the file chooser in.
save - Whether the file is to be saved or opened.

addFileChooser

public void addFileChooser(java.lang.String name,
                           java.lang.String label,
                           java.lang.String defaultName,
                           java.net.URI base,
                           java.io.File startingDirectory,
                           boolean allowFiles,
                           boolean allowDirectories)
Create a FileChooser with default colors (white in the foreground, black in the background).

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
defaultName - The default file name to use.
base - The URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectory - The directory to open the file chooser in.
allowFiles - True if regular files may be chosen.
allowDirectories - True if directories may be chosen.

addFileChooser

public void addFileChooser(java.lang.String name,
                           java.lang.String label,
                           java.lang.String defaultName,
                           java.net.URI base,
                           java.io.File startingDirectory,
                           java.awt.Color background,
                           java.awt.Color foreground)
Create a FileChooser that selects files only, not directories.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
defaultName - The default file name to use.
base - The URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectory - The directory to open the file chooser in.
background - The background color for the text entry box.
foreground - The foreground color for the text entry box.

addFileChooser

public Query.QueryFileChooser addFileChooser(java.lang.String name,
                                             java.lang.String label,
                                             java.lang.String defaultName,
                                             java.net.URI base,
                                             java.io.File startingDirectory,
                                             boolean allowFiles,
                                             boolean allowDirectories,
                                             java.awt.Color background,
                                             java.awt.Color foreground)
Create a FileChooser.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
defaultName - The default file name to use.
base - The URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectory - The directory to open the file chooser in.
allowFiles - True if regular files may be chosen.
allowDirectories - True if directories may be chosen.
background - The background color for the text entry box.
foreground - The foreground color for the text entry box.
Returns:
The file chooser.

addFileChooser

public Query.QueryFileChooser addFileChooser(java.lang.String name,
                                             java.lang.String label,
                                             java.lang.String defaultName,
                                             java.net.URI base,
                                             java.io.File startingDirectory,
                                             boolean allowFiles,
                                             boolean allowDirectories,
                                             boolean save,
                                             java.awt.Color background,
                                             java.awt.Color foreground)
Create a FileChooser.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
defaultName - The default file name to use.
base - The URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectory - The directory to open the file chooser in.
allowFiles - True if regular files may be chosen.
allowDirectories - True if directories may be chosen.
save - Whether the file is to be saved or opened.
background - The background color for the text entry box.
foreground - The foreground color for the text entry box.
Returns:
The file chooser.

addLine

public void addLine(java.lang.String name,
                    java.lang.String label,
                    java.lang.String defaultValue)
Create a single-line entry box with the specified name, label, and default value. To control the width of the box, call setTextWidth() first.

Parameters:
name - The name used to identify the entry (when accessing the entry).
label - The label to attach to the entry.
defaultValue - Default value to appear in the entry box.

addLine

public void addLine(java.lang.String name,
                    java.lang.String label,
                    java.lang.String defaultValue,
                    java.awt.Color background,
                    java.awt.Color foreground)
Create a single-line entry box with the specified name, label, default value, and background color. To control the width of the box, call setTextWidth() first.

Parameters:
name - The name used to identify the entry (when accessing the entry).
label - The label to attach to the entry.
defaultValue - Default value to appear in the entry box.
background - The background color.
foreground - The foreground color.

addPassword

public javax.swing.JPasswordField addPassword(java.lang.String name,
                                              java.lang.String label,
                                              java.lang.String defaultValue)
Create a single-line password box with the specified name, label, and default value. To control the width of the box, call setTextWidth() first. A value that is entered in the password box should be accessed using getCharArrayValue(). The value returned by stringValue() is whatever you specify as a defaultValue.

Parameters:
name - The name used to identify the entry (when accessing the entry).
label - The label to attach to the entry.
defaultValue - Default value to appear in the entry box.
Returns:
The password field for the input.
Since:
Ptolemy II 3.1

addPassword

public javax.swing.JPasswordField addPassword(java.lang.String name,
                                              java.lang.String label,
                                              java.lang.String defaultValue,
                                              java.awt.Color background,
                                              java.awt.Color foreground)
Create a single-line password box with the specified name, label, and default value. To control the width of the box, call setTextWidth() first. To get the value, call getCharArrayValue(). Calling getStringValue() on a password entry will result in an error because it is less secure to pass around passwords as Strings than as arrays of characters.

The underlying class that is used to implement the password facility is javax.swing.JPasswordField. For details about how to use JPasswordField, see the Java Tutorial

Parameters:
name - The name used to identify the entry (when accessing the entry).
label - The label to attach to the entry.
defaultValue - Default value to appear in the entry box.
background - The background color.
foreground - The foreground color.
Returns:
The password field for the input.
Since:
Ptolemy II 3.1

addQueryListener

public void addQueryListener(QueryListener listener)
Add a listener. The changed() method of the listener will be called when any of the entries is changed. Note that "line" entries only trigger this call when Return or Enter is pressed, or when the entry gains and then loses the keyboard focus. Notice that the currently selected line loses focus when the panel is destroyed, so notification of any changes that have been made will be done at that time. That notification will occur in the UI thread, and may be later than expected. Notification due to loss of focus only occurs if the value of the entry has changed since the last notification. If the listener has already been added, then do nothing.

Parameters:
listener - The listener to add.
See Also:
removeQueryListener(QueryListener)

addRadioButtons

public void addRadioButtons(java.lang.String name,
                            java.lang.String label,
                            java.lang.String[] values,
                            java.lang.String defaultValue)
Create a bank of radio buttons. A radio button provides a list of choices, only one of which may be chosen at a time.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
values - The list of possible choices.
defaultValue - Default value.

addSelectButtons

public void addSelectButtons(java.lang.String name,
                             java.lang.String label,
                             java.lang.String[] values,
                             java.util.Set initiallySelected)
Create a bank of buttons that provides a list of choices, any subset of which may be chosen at a time.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
values - The list of possible choices.
initiallySelected - The initially selected choices, or null to indicate that none are selected.

addSeparator

public void addSeparator()
Create a horizontal separator between components.


addSlider

public javax.swing.JSlider addSlider(java.lang.String name,
                                     java.lang.String label,
                                     int defaultValue,
                                     int minimum,
                                     int maximum)
                              throws java.lang.IllegalArgumentException
Create a slider with the specified name, label, default value, maximum, and minimum.

Parameters:
name - The name used to identify the slider.
label - The label to attach to the slider.
defaultValue - Initial position of slider.
maximum - Maximum value of slider.
minimum - Minimum value of slider.
Returns:
The slider.
Throws:
java.lang.IllegalArgumentException - If the desired default value is not between the minimum and maximum.

addText

public void addText(java.lang.String text,
                    java.awt.Color color,
                    int alignment)
Add text to the query.

Parameters:
text - The text to be added.
color - The olor of the text to be added.
alignment - The alignment, which is a value suitable for the JPanel() constructor.

addTextArea

public void addTextArea(java.lang.String name,
                        java.lang.String label,
                        java.lang.String theValue)
Create a text area.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
theValue - The value of this text area

addTextArea

public void addTextArea(java.lang.String name,
                        java.lang.String label,
                        java.lang.String theValue,
                        java.awt.Color background,
                        java.awt.Color foreground)
Create a text area.

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
theValue - The value of this text area.
background - The background color.
foreground - The foreground color.

addTextArea

public javax.swing.JTextArea addTextArea(java.lang.String name,
                                         java.lang.String label,
                                         java.lang.String theValue,
                                         java.awt.Color background,
                                         java.awt.Color foreground,
                                         int height,
                                         int width)
Create a text area with the specified height and width (in characters).

Parameters:
name - The name used to identify the entry (when calling get).
label - The label to attach to the entry.
theValue - The value of this text area.
background - The background color.
foreground - The foreground color.
height - The height.
width - The width.
Returns:
The text area.

booleanValue

public boolean booleanValue(java.lang.String name)
                     throws java.util.NoSuchElementException,
                            java.lang.IllegalArgumentException
Deprecated. Use getBooleanValue(String name) instead.

Get the current value in the entry with the given name and return as a boolean. If the entry is not a checkbox, then throw an exception.

Parameters:
name - The name of the entry.
Returns:
The state of the checkbox.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a checkbox. This is a runtime exception, so it need not be declared explicitly.

doubleValue

public double doubleValue(java.lang.String name)
                   throws java.lang.IllegalArgumentException,
                          java.util.NoSuchElementException,
                          java.lang.NumberFormatException
Deprecated. Use getDoubleValue(String name) instead.

Get the current value in the entry with the given name and return as a double value. If the entry is not a line, then throw an exception. If the value of the entry is not a double, then throw an exception.

Parameters:
name - The name of the entry.
Returns:
The value currently in the entry as a double.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.NumberFormatException - If the value of the entry cannot be converted to a double. This is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a line. This is a runtime exception, so it need not be declared explicitly.

getBooleanValue

public boolean getBooleanValue(java.lang.String name)
                        throws java.util.NoSuchElementException,
                               java.lang.IllegalArgumentException
Get the current value in the entry with the given name and return as a boolean. If the entry is not a checkbox, then throw an exception.

Parameters:
name - The name of the entry.
Returns:
The state of the checkbox.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a checkbox. This is a runtime exception, so it need not be declared explicitly.

getCharArrayValue

public char[] getCharArrayValue(java.lang.String name)
                         throws java.util.NoSuchElementException,
                                java.lang.IllegalArgumentException
Get the current value in the entry with the given name and return as an array of characters.

If the entry is a password field, then it is recommended for strong security that each element of the array be set to 0 after use.

Parameters:
name - The name of the entry.
Returns:
The state of the entry
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry type does not have a string representation (this should not be thrown). This is a runtime exception, so it need not be declared explicitly.
Since:
Ptolemy II 3.1

getDoubleValue

public double getDoubleValue(java.lang.String name)
                      throws java.lang.IllegalArgumentException,
                             java.util.NoSuchElementException,
                             java.lang.NumberFormatException
Get the current value in the entry with the given name and return as a double value. If the entry is not a line, then throw an exception. If the value of the entry is not a double, then throw an exception.

Parameters:
name - The name of the entry.
Returns:
The value currently in the entry as a double.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.NumberFormatException - If the value of the entry cannot be converted to a double. This is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a line. This is a runtime exception, so it need not be declared explicitly.

getIntValue

public int getIntValue(java.lang.String name)
                throws java.lang.IllegalArgumentException,
                       java.util.NoSuchElementException,
                       java.lang.NumberFormatException
Get the current value in the entry with the given name and return as an integer. If the entry is not a line, choice, or slider, then throw an exception. If it is a choice or radio button, then return the index of the first selected item.

Parameters:
name - The name of the entry.
Returns:
The value currently in the entry as an integer.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.NumberFormatException - If the value of the entry cannot be converted to an integer. This is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a choice, line, or slider. This is a runtime exception, so it need not be declared explicitly.

getMaximumSize

public java.awt.Dimension getMaximumSize()
Return the preferred height, but set the width to the maximum possible value. Currently (JDK 1.3), only BoxLayout pays any attention to getMaximumSize().

Overrides:
getMaximumSize in class javax.swing.JComponent
Returns:
The maximum desired size.

getObjectValue

public java.lang.Object getObjectValue(java.lang.String name)
                                throws java.util.NoSuchElementException,
                                       java.lang.IllegalArgumentException
Get the current value in the entry with the given name, and return as an Object. This is different from getStringValue(String) in that if the entry is a combo box, the selected object is returned, which need not be a string. All entry types support this. Note that this method should be called from the event dispatch thread, since it needs to query to UI widgets for their current values. If it is called from another thread, there is no assurance that the value returned will be the current value.

Parameters:
name - The name of the entry.
Returns:
The value currently in the entry as a String.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry type does not have a string representation (this should not be thrown).

getStringValue

public java.lang.String getStringValue(java.lang.String name)
                                throws java.util.NoSuchElementException,
                                       java.lang.IllegalArgumentException
Get the current value in the entry with the given name, and return as a String. All entry types support this. Note that this method should be called from the event dispatch thread, since it needs to query to UI widgets for their current values. If it is called from another thread, there is no assurance that the value returned will be the current value.

Parameters:
name - The name of the entry.
Returns:
The value currently in the entry as a String.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry type does not have a string representation (this should not be thrown).

getTextHeight

public int getTextHeight()
Get the preferred number of lines to be used for entry boxes created in using addTextArea(). The preferred height is set using setTextHeight().

Returns:
The preferred height in lines.
See Also:
addTextArea(String, String, String), setTextHeight(int)

getTextWidth

public int getTextWidth()
Get the preferred width in characters to be used for entry boxes created in using addLine(). The preferred width is set using setTextWidth().

Returns:
The preferred width of an entry box in characters.
See Also:
setTextWidth(int)

hasEntry

public boolean hasEntry(java.lang.String name)
Return whether an entry exists with the specified name.

Parameters:
name - The name.
Returns:
True if the entry exists; false otherwise.

intValue

public int intValue(java.lang.String name)
             throws java.lang.IllegalArgumentException,
                    java.util.NoSuchElementException,
                    java.lang.NumberFormatException
Deprecated. Use getIntValue(String name) instead.

Get the current value in the entry with the given name and return as an integer. If the entry is not a line, choice, or slider, then throw an exception. If it is a choice or radio button, then return the index of the first selected item.

Parameters:
name - The name of the entry.
Returns:
The value currently in the entry as an integer.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.NumberFormatException - If the value of the entry cannot be converted to an integer. This is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a choice, line, or slider. This is a runtime exception, so it need not be declared explicitly.

notifyListeners

public void notifyListeners()
Notify listeners of the current value of all entries, unless those entries have not changed since the last notification.


removeQueryListener

public void removeQueryListener(QueryListener listener)
Remove a listener. If the listener has not been added, then do nothing.

Parameters:
listener - The listener to remove.
See Also:
addQueryListener(QueryListener)

set

public void set(java.lang.String name,
                java.lang.String value)
         throws java.util.NoSuchElementException,
                java.lang.IllegalArgumentException
Set the value in the entry with the given name. The second argument must be a string that can be parsed to the proper type for the given entry, or an exception is thrown. Note that this does NOT trigger the notification of listeners, and intended to allow a way to set the query to reflect the current state.

Parameters:
name - The name used to identify the entry (when calling get).
value - The value to set the entry to.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the value does not parse to the appropriate type.

setAndNotify

public void setAndNotify(java.lang.String name,
                         java.lang.String value)
                  throws java.util.NoSuchElementException,
                         java.lang.IllegalArgumentException
Set the value in the entry with the given name and notify listeners. The second argument must be a string that can be parsed to the proper type for the given entry, or an exception is thrown.

Parameters:
name - The name used to identify the entry (when calling get).
value - The value to set the entry to.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the value does not parse to the appropriate type.

setBackground

public void setBackground(java.awt.Color color)
Set the background color for all the widgets.

Overrides:
setBackground in class javax.swing.JComponent
Parameters:
color - The background color.

setBoolean

public void setBoolean(java.lang.String name,
                       boolean value)
                throws java.util.NoSuchElementException,
                       java.lang.IllegalArgumentException
Set the current value in the entry with the given name. If the entry is not a checkbox, then throw an exception. Notify listeners that the value has changed.

Parameters:
name - The name of the entry.
value - The new value of the entry.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a checkbox. This is a runtime exception, so it need not be declared explicitly.

setColumns

public void setColumns(int columns)
Specify the number of columns to use. The default is one. If an integer larger than one is specified here, then the queries will be arranged using the specified number of columns. As queries are added, they are put in the first row until that row is full. Then they are put in the second row, etc.

Parameters:
columns - The number of columns.

setDisplay

public void setDisplay(java.lang.String name,
                       java.lang.String value)
                throws java.util.NoSuchElementException,
                       java.lang.IllegalArgumentException
Set the displayed text of an entry that has been added using addDisplay. Notify listeners that the value has changed.

Parameters:
name - The name of the entry.
value - The string to display.
Throws:
java.util.NoSuchElementException - If there is no entry with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a display. This is a runtime exception, so it need not be declared explicitly.

setEnabled

public void setEnabled(java.lang.String name,
                       boolean value)
For line, display, check box, slider, radio button, or choice entries made, if the second argument is false, then it will be disabled.

Parameters:
name - The name of the entry.
value - If false, disables the entry.

setInsets

public void setInsets(java.awt.Insets insets)
Set the insets for the GridBagLayout manager used to layout the components.

Parameters:
insets - The insets.

setLine

public void setLine(java.lang.String name,
                    java.lang.String value)
Set the displayed text of an item that has been added using addLine. Notify listeners that the value has changed.

Parameters:
name - The name of the entry.
value - The string to display.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a display. This is a runtime exception, so it need not be declared explicitly.

setMessage

public void setMessage(java.lang.String message)
Specify a message to be displayed above the query.

Parameters:
message - The message to display.

setSlider

public void setSlider(java.lang.String name,
                      int value)
Set the position of an item that has been added using addSlider. Notify listeners that the value has changed.

Parameters:
name - The name of the entry.
value - The value to set the slider position.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry is not a slider. This is a runtime exception, so it need not be declared explicitly.

setTextHeight

public void setTextHeight(int characters)
Specify the preferred height to be used for entry boxes created in using addTextArea(). If this is called multiple times, then it only affects subsequent calls.

Parameters:
characters - The preferred height.
See Also:
addTextArea(String, String, String), getTextHeight()

setTextWidth

public void setTextWidth(int characters)
Specify the preferred width to be used for entry boxes created in using addLine(). If this is called multiple times, then it only affects subsequent calls.

Parameters:
characters - The preferred width.
See Also:
getTextWidth()

setToolTip

public void setToolTip(java.lang.String name,
                       java.lang.String tip)
Specify a tool tip to appear when the mouse lingers over the label.

Parameters:
name - The name of the entry.
tip - The text of the tool tip.

stringToColor

public static java.awt.Color stringToColor(java.lang.String description)
Convert the specified string to a color. The string has the form "{r, g, b, a}", where each of the letters is a number between 0.0 and 1.0, representing red, green, blue, and alpha.

Parameters:
description - The description of the color, or white if any parse error occurs.
Returns:
A string representing the color.

stringValue

public java.lang.String stringValue(java.lang.String name)
                             throws java.util.NoSuchElementException,
                                    java.lang.IllegalArgumentException
Deprecated. Use getStringValue(String name) instead.

Get the current value in the entry with the given name, and return as a String. All entry types support this. Note that this method should be called from the event dispatch thread, since it needs to query to UI widgets for their current values. If it is called from another thread, there is no assurance that the value returned will be the current value.

Parameters:
name - The name of the entry.
Returns:
The value currently in the entry as a String.
Throws:
java.util.NoSuchElementException - If there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
java.lang.IllegalArgumentException - If the entry type does not have a string representation (this should not be thrown).

_addPair

protected void _addPair(java.lang.String name,
                        javax.swing.JLabel label,
                        java.awt.Component widget,
                        java.lang.Object entry)
Add a label and a widget to the panel.

Parameters:
name - The name of the entry.
label - The label.
widget - The interactive entry to the right of the label.
entry - The object that contains user data.

_recalculatePreferredSize

protected void _recalculatePreferredSize(java.awt.Component widget)
Recalculate the preferred size of the entry panel.

Parameters:
widget - The widget added to the entry panel.

_notifyListeners

void _notifyListeners(java.lang.String name)
Notify all registered listeners that something changed for the specified entry, if it indeed has changed. The getStringValue() method is used to check the current value against the previously notified value, or the original value if there have been no notifications.

Parameters:
name - The entry that may have changed.