ptolemy.gui
Class Query

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--ptolemy.gui.Query

public class Query
extends javax.swing.JPanel

Create a query with various types of entry boxes and controls.

Version:
$Id: Query.java,v 1.14 1999/08/13 18:48:35 matisu Exp $
Author:
Edward A. Lee, Manda Sutijono
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
protected  java.awt.Color _background
          The background color as set by setBackground().
protected  java.awt.GridBagConstraints _constraints
          Standard constraints for use with _grid.
protected  java.awt.GridBagLayout _grid
          Layout control.
protected  java.util.Vector _listeners
          List of registered listeners.
static int DEFAULT_ENTRY_WIDTH
           
 
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
 
Constructor Summary
Query()
          Construct a panel with no queries in it.
 
Method Summary
protected  void _addPair(javax.swing.JLabel label, java.awt.Component widget)
          Add a label and a widget to the panel.
 void 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.String[] values, java.lang.String defaultValue)
          Create a choice menu.
 void addDisplay(java.lang.String name, java.lang.String label, java.lang.String defaultValue)
          Create a simple one-line text display, a non-editable value that is set externally using the setDisplay() method.
 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 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 addSlider(java.lang.String name, java.lang.String label, int defaultValue, int min, int max)
          Create a slider with the specified name, label, default value, maximum, and minimum.
 boolean booleanValue(java.lang.String name)
          Get the current value in the entry with the given name and return as a boolean.
 double doubleValue(java.lang.String name)
          Get the current value in the entry with the given name and return as a double value.
 int intValue(java.lang.String name)
          Get the current value in the entry with the given name and return as an integer.
 void removeQueryListener(QueryListener listener)
          Remove a listener.
 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 setDisplay(java.lang.String name, java.lang.String value)
          Set the displayed text of an item that has been added using addDisplay.
 void setEnabled(java.lang.String name, boolean boole)
          For entries for which it is appropriate, if the second argument is false, then it will be disabled.
 void setTextWidth(int characters)
          Specify the preferred width to be used for entry boxes created in using addLine().
 java.lang.String stringValue(java.lang.String name)
          Get the current value in the entry with the given name, and return as a String.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setCursor, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_ENTRY_WIDTH

public static final int DEFAULT_ENTRY_WIDTH

_background

protected java.awt.Color _background
The background color as set by setBackground(). This defaults to white.

_grid

protected java.awt.GridBagLayout _grid
Layout control.

_constraints

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

_listeners

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

Query

public Query()
Construct a panel with no queries in it.
Method Detail

addCheckBox

public void 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.

addChoice

public void addChoice(java.lang.String name,
                      java.lang.String label,
                      java.lang.String[] values,
                      java.lang.String defaultValue)
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.
defaultValue - Default value (true for on).

addDisplay

public void addDisplay(java.lang.String name,
                       java.lang.String label,
                       java.lang.String defaultValue)
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.
defaultValue - Default string to display.

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. To ensure uniformity, a colon and a space are appended to the end of the label.
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.

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 is pressed. If the listener has already been added, then do nothing.
Parameters:
listener - The listener to add.

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.
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.

addSlider

public void addSlider(java.lang.String name,
                      java.lang.String label,
                      int defaultValue,
                      int min,
                      int max)
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.
max - Maximum value of slider.
min - Minimum value of slider.

booleanValue

public boolean booleanValue(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.
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
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.
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.

intValue

public int intValue(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 selected item.
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.

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.

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.
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.

setDisplay

public void setDisplay(java.lang.String name,
                       java.lang.String value)
Set the displayed text of an item that has been added using addDisplay.
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.

setEnabled

public void setEnabled(java.lang.String name,
                       boolean boole)
For entries for which it is appropriate, if the second argument is false, then it will be disabled.
Parameters:
name - The name of the entry.
boole - If false, disables the entry.

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 only the largest value specified actually affects the layout.
Parameters:
characters - The preferred width.

stringValue

public java.lang.String stringValue(java.lang.String name)
                             throws java.util.NoSuchElementException
Get the current value in the entry with the given name, and return as a String. All entry types support this.
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(javax.swing.JLabel label,
                        java.awt.Component widget)
Add a label and a widget to the panel.
Parameters:
label - The label.
widget - The interactive entry to the right of the label.