Back to index

wims  3.65+svn20090927
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Package Functions | Private Attributes
ptolemy.gui.Query Class Reference

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

Inheritance diagram for ptolemy.gui.Query:
Inheritance graph
[legend]
Collaboration diagram for ptolemy.gui.Query:
Collaboration graph
[legend]

List of all members.

Classes

class  QueryActionListener
 Listener for "line" and radio button entries. More...
class  QueryColorChooser
 Panel containing an entry box and color chooser. More...
class  QueryFileChooser
 Panel containing an entry box and file chooser. More...
class  QueryFocusListener
 Listener for line entries, for when they lose the focus. More...
class  QueryItemListener
 Listener for "CheckBox" and "Choice" entries. More...
class  QueryScrollPane
 Inner class to tie textArea to scroll pane. More...
class  SliderListener
 Listener for changes in slider. More...

Public Member Functions

 Query ()
 Construct a panel with no entries in it.
void addCheckBox (String name, String label, boolean defaultValue)
 Create an on-off check box.
void addChoice (String name, String label, String[] values, String defaultChoice)
 Create an uneditable choice menu.
void addChoice (String name, String label, String[] values, String defaultChoice, boolean editable)
 Create a choice menu.
void addChoice (String name, String label, String[] values, String defaultChoice, boolean editable, final Color background, final Color foreground)
 Create a choice menu.
void addColorChooser (String name, String label, String defaultColor)
 Create a ColorChooser.
void addDisplay (String name, String label, String theValue)
 Create a simple one-line text display, a non-editable value that is set externally using the setDisplay() method.
void addFileChooser (String name, String label, String defaultName, URI base, 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 (String name, String label, String defaultName, URI base, File startingDirectory, boolean allowFiles, boolean allowDirectories)
 Create a FileChooser with default colors (white in the foreground, black in the background).
void addFileChooser (String name, String label, String defaultName, URI base, File startingDirectory, Color background, Color foreground)
 Create a FileChooser that selects files only, not directories.
void addFileChooser (String name, String label, String defaultName, URI base, File startingDirectory, boolean allowFiles, boolean allowDirectories, Color background, Color foreground)
 Create a FileChooser.
void addLine (String name, String label, String defaultValue)
 Create a single-line entry box with the specified name, label, and default value.
void addLine (String name, String label, String defaultValue, Color background, Color foreground)
 Create a single-line entry box with the specified name, label, default value, and background color.
void addPassword (String name, String label, String defaultValue)
 Create a single-line password box with the specified name, label, and default value.
void addPassword (String name, String label, String defaultValue, Color background, 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 (String name, String label, String[] values, String defaultValue)
 Create a bank of radio buttons.
void addSelectButtons (String name, String label, String[] values, Set initiallySelected)
 Create a bank of buttons that provides a list of choices, any subset of which may be chosen at a time.
void addSlider (String name, String label, int defaultValue, int minimum, int maximum) throws IllegalArgumentException
 Create a slider with the specified name, label, default value, maximum, and minimum.
void addTextArea (String name, String label, String theValue)
 Create a text area.
void addTextArea (String name, String label, String theValue, Color background, Color foreground)
 Create a text area.
void addTextArea (String name, String label, String theValue, Color background, Color foreground, int height, int width)
 Create a text area with the specified height and width (in characters).
boolean booleanValue (String name) throws NoSuchElementException, IllegalArgumentException
 Get the current value in the entry with the given name and return as a boolean.
double doubleValue (String name) throws IllegalArgumentException, NoSuchElementException, NumberFormatException
 Get the current value in the entry with the given name and return as a double value.
boolean getBooleanValue (String name) throws NoSuchElementException, IllegalArgumentException
 Get the current value in the entry with the given name and return as a boolean.
char[] getCharArrayValue (String name) throws NoSuchElementException, IllegalArgumentException
 Get the current value in the entry with the given name and return as an array of characters.
double getDoubleValue (String name) throws IllegalArgumentException, NoSuchElementException, NumberFormatException
 Get the current value in the entry with the given name and return as a double value.
int getIntValue (String name) throws IllegalArgumentException, NoSuchElementException, NumberFormatException
 Get the current value in the entry with the given name and return as an integer.
Dimension getMaximumSize ()
 Return the preferred height, but set the width to the maximum possible value.
String getStringValue (String name) throws NoSuchElementException, IllegalArgumentException
 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().
int intValue (String name) throws IllegalArgumentException, NoSuchElementException, NumberFormatException
 Get the current value in the entry with the given name and return as an integer.
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 (String name, String value) throws NoSuchElementException, IllegalArgumentException
 Set the value in the entry with the given name.
void setAndNotify (String name, String value) throws NoSuchElementException, IllegalArgumentException
 Set the value in the entry with the given name and notify listeners.
void setBackground (Color color)
 Set the background color for all the widgets.
void setBoolean (String name, boolean value) throws NoSuchElementException, IllegalArgumentException
 Set the current value in the entry with the given name.
void setColumns (int columns)
 Specify the number of columns to use.
void setDisplay (String name, String value) throws NoSuchElementException, IllegalArgumentException
 Set the displayed text of an entry that has been added using addDisplay.
void setEnabled (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 setLine (String name, String value)
 Set the displayed text of an item that has been added using addLine.
void setMessage (String message)
 Specify a message to be displayed above the query.
void setSlider (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 (String name, String tip)
 Specify a tool tip to appear when the mouse lingers over the label.
String stringValue (String name) throws NoSuchElementException, IllegalArgumentException
 Get the current value in the entry with the given name, and return as a String.

Static Public Member Functions

static Color stringToColor (String description)
 Convert the specified string to a color.

Static Public Attributes

static final int DEFAULT_ENTRY_HEIGHT = 10
 The default height of entries created with addText().
static final int DEFAULT_ENTRY_WIDTH = 30
 The default width of entries created with addLine().

Protected Member Functions

void _addPair (String name, JLabel label, Component widget, Object entry)
 Add a label and a widget to the panel.

Protected Attributes

Color _background = null
 The background color as set by setBackground().
GridBagConstraints _constraints
 Standard constraints for use with _grid.
GridBagLayout _grid
 Layout control.
Vector _listeners
 List of registered listeners.

Package Functions

void _notifyListeners (String name)
 Notify all registered listeners that something changed for the specified entry, if it indeed has changed.

Private Attributes

int _columns = 1
Map _entries = new HashMap()
JPanel _entryPanel = new JPanel()
JScrollPane _entryScrollPane
int _height = DEFAULT_ENTRY_HEIGHT
Map _labels = new HashMap()
Insets _leftPadding = new Insets(0, 10, 0, 0)
JTextArea _messageArea = null
JScrollPane _messageScrollPane
boolean _messageScrollPaneAdded = false
Insets _noPadding = new Insets(0, 0, 0, 0)
Map _previous = new HashMap()
int _widgetsHeight = 20
int _width = DEFAULT_ENTRY_WIDTH

Detailed Description

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");
 
Author:
Edward A. Lee, Manda Sutijono, Elaine Cheong
Version:
Id:
Query.java,v 1.127 2007/12/16 07:29:47 cxh Exp
Since:
Ptolemy II 0.3 .ProposedRating Yellow (eal) .AcceptedRating Red (eal)

Definition at line 105 of file Query.java.


Constructor & Destructor Documentation

Construct a panel with no entries in it.

Definition at line 108 of file Query.java.

                   {
        _grid = new GridBagLayout();
        _constraints = new GridBagConstraints();
        _constraints.fill = GridBagConstraints.HORIZONTAL;

        // If the next line is commented out, then the PtolemyApplet
        // model parameters will have an entry that is less than one
        // character wide unless the window is made to be fairly large.
        _constraints.weightx = 1.0;
        _constraints.anchor = GridBagConstraints.NORTHWEST;
        _entryPanel.setLayout(_grid);

        // It's not clear whether the following has any real significance...
        // _entryPanel.setOpaque(true);
        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        _entryPanel.setAlignmentX(Component.LEFT_ALIGNMENT);

        // Add a message panel into which a message can be placed using
        // setMessage().
        _messageArea = new JTextArea("");
        _messageArea.setFont(new Font("SansSerif", Font.PLAIN, 12));
        _messageArea.setEditable(false);
        _messageArea.setLineWrap(true);
        _messageArea.setWrapStyleWord(true);

        // It seems like setLineWrap is somewhat broken.  Really,
        // setLineWrap works best with scrollbars.  We have
        // a couple of choices: use scrollbars or hack in something
        // that guesses the number of lines.  Note that to
        // use scrollbars, the tutorial at
        // http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html#textarea
        // suggests: "If you put a text area in a scroll pane, be
        // sure to set the scroll pane's preferred size or use a
        // text area constructor that sets the number of rows and
        // columns for the text area."
        _messageArea.setBackground(null);

        _messageArea.setAlignmentX(Component.LEFT_ALIGNMENT);

        _messageScrollPane = new JScrollPane(_messageArea);
        _messageScrollPane
                .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

        // Get rid of the border.
        _messageScrollPane.setBorder(BorderFactory.createEmptyBorder());
        _messageScrollPane.getViewport().setBackground(null);

        // Useful for debugging:
        //_messageScrollPane.setBorder(
        //                    BorderFactory.createLineBorder(Color.pink));
        // We add the _messageScrollPane when we first use it.
        _entryScrollPane = new JScrollPane(_entryPanel);

        // Get rid of the border.
        _entryScrollPane.setBorder(BorderFactory.createEmptyBorder());
        _entryScrollPane.getViewport().setBackground(null);
        _entryScrollPane.setBackground(null);
        add(_entryScrollPane);

        // Setting the background to null allegedly means it inherits the
        // background color from the container.
        _entryPanel.setBackground(null);
    }

Member Function Documentation

void ptolemy.gui.Query._addPair ( String  name,
JLabel  label,
Component  widget,
Object  entry 
) [inline, protected]

Add a label and a widget to the panel.

Parameters:
nameThe name of the entry.
labelThe label.
widgetThe interactive entry to the right of the label.
entryThe object that contains user data.

Definition at line 1496 of file Query.java.

                          {
        // Surely there is a better layout manager in swing...
        // Note that Box and BoxLayout do not work because they do not
        // support gridded layout.
        _constraints.gridwidth = 1;
        _constraints.insets = _leftPadding;
        _grid.setConstraints(label, _constraints);
        _entryPanel.add(label);

        _constraints.insets = _noPadding;

        if ((_columns > 1) && (((_entries.size() + 1) % _columns) != 0)) {
            _constraints.gridwidth = 1;
        } else {
            _constraints.gridwidth = GridBagConstraints.REMAINDER;
        }

        _grid.setConstraints(widget, _constraints);
        _entryPanel.add(widget);

        _entries.put(name, entry);
        _labels.put(name, label);
        _previous.put(name, getStringValue(name));

        Dimension preferredSize = _entryPanel.getPreferredSize();

        // Add some slop to the width to take in to account
        // the width of the vertical scrollbar.
        preferredSize.width += 25;

        // Applets seem to need this, see CT/SigmaDelta
        _widgetsHeight += widget.getPreferredSize().height;
        preferredSize.height = _widgetsHeight;

        Toolkit tk = Toolkit.getDefaultToolkit();

        if (preferredSize.height > tk.getScreenSize().height) {
            // Fudge factor to keep this window smaller than the screen
            // height.  CGSUnitBase and the Code Generator are good tests.
            preferredSize.height = (int) (tk.getScreenSize().height * 0.75);
            _entryScrollPane.setPreferredSize(preferredSize);
        }

        _entryScrollPane.setPreferredSize(preferredSize);

        // Call revalidate for the scrollbar.
        _entryPanel.revalidate();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.gui.Query._notifyListeners ( String  name) [inline, package]

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:
nameThe entry that may have changed.

Definition at line 1574 of file Query.java.

                                       {
        if (_listeners != null) {
            String previous = (String) _previous.get(name);
            String newValue = getStringValue(name);

            if (newValue.equals(previous)) {
                return;
            }

            // Store the new value to prevent repeated notification.
            // This must be done before listeners are notified, because
            // the notified listeners might do something that again triggers
            // notification, and we do not want that notification to occur
            // if the value has not changed.
            _previous.put(name, newValue);

            Enumeration listeners = _listeners.elements();

            while (listeners.hasMoreElements()) {
                QueryListener queryListener = (QueryListener) (listeners
                        .nextElement());
                queryListener.changed(name);
            }
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.gui.Query.addCheckBox ( String  name,
String  label,
boolean  defaultValue 
) [inline]

Create an on-off check box.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
defaultValueThe default value (true for on).

Definition at line 181 of file Query.java.

                                                                             {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        JCheckBox checkbox = new JCheckBox();
        checkbox.setBackground(_background);
        checkbox.setOpaque(false);
        checkbox.setSelected(defaultValue);
        _addPair(name, lbl, checkbox, checkbox);

        // Add the listener last so that there is no notification
        // of the first value.
        checkbox.addItemListener(new QueryItemListener(name));
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.gui.Query.addChoice ( String  name,
String  label,
String[]  values,
String  defaultChoice 
) [inline]

Create an uneditable choice menu.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
valuesThe list of possible choices.
defaultChoiceDefault choice.

Definition at line 202 of file Query.java.

                                  {
        addChoice(name, label, values, defaultChoice, false);
    }

Here is the caller graph for this function:

void ptolemy.gui.Query.addChoice ( String  name,
String  label,
String[]  values,
String  defaultChoice,
boolean  editable 
) [inline]

Create a choice menu.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
valuesThe list of possible choices.
defaultChoiceDefault choice.
editableTrue if an arbitrary choice can be entered, in addition to the choices in values.

Definition at line 215 of file Query.java.

                                                    {
        addChoice(name, label, values, defaultChoice, editable, Color.white,
                Color.black);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addChoice ( String  name,
String  label,
String[]  values,
String  defaultChoice,
boolean  editable,
final Color  background,
final Color  foreground 
) [inline]

Create a choice menu.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
valuesThe list of possible choices.
defaultChoiceDefault choice.
editableTrue if an arbitrary choice can be entered, in addition to the choices in values.
backgroundThe background color for the editable part.
foregroundThe foreground color for the editable part.

Definition at line 231 of file Query.java.

                                    {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        JComboBox combobox = new JComboBox(values);
        combobox.setEditable(editable);

        // NOTE: Typical of Swing, the following does not set
        // the background color. So we have to specify a
        // custom editor.  #$(#&$#(@#!!
        // combobox.setBackground(background);
        combobox.setEditor(new BasicComboBoxEditor() {
            public Component getEditorComponent() {
                Component result = super.getEditorComponent();
                result.setBackground(background);
                result.setForeground(foreground);
                return result;
            }
        });
        combobox.setSelectedItem(defaultChoice);
        _addPair(name, lbl, combobox, combobox);

        // Add the listener last so that there is no notification
        // of the first value.
        combobox.addItemListener(new QueryItemListener(name));
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addColorChooser ( String  name,
String  label,
String  defaultColor 
) [inline]

Create a ColorChooser.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
defaultColorThe default color to use.

Definition at line 265 of file Query.java.

                                                                                {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        QueryColorChooser colorChooser = new QueryColorChooser(name,
                defaultColor);
        _addPair(name, lbl, colorChooser, colorChooser);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addDisplay ( String  name,
String  label,
String  theValue 
) [inline]

Create a simple one-line text display, a non-editable value that is set externally using the setDisplay() method.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
theValueDefault string to display.

Definition at line 280 of file Query.java.

                                                                       {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        // NOTE: JLabel would be a reasonable choice here, but at
        // least in the current version of swing, JLabel.setText() does
        // not work.
        JTextArea displayField = new JTextArea(theValue, 1, 10);
        displayField.setEditable(false);
        displayField.setBackground(_background);
        _addPair(name, lbl, displayField, displayField);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addFileChooser ( String  name,
String  label,
String  defaultName,
URI  base,
File  startingDirectory 
) [inline]

Create a FileChooser that selects files only, not directories, and has the default colors (white in the background, black in the foreground).

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
defaultNameThe default file name to use.
baseThe URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectoryThe directory to open the file chooser in.

Definition at line 303 of file Query.java.

                                              {
        addFileChooser(name, label, defaultName, base, startingDirectory, true,
                false, Color.white, Color.black);
    }

Here is the caller graph for this function:

void ptolemy.gui.Query.addFileChooser ( String  name,
String  label,
String  defaultName,
URI  base,
File  startingDirectory,
boolean  allowFiles,
boolean  allowDirectories 
) [inline]

Create a FileChooser with default colors (white in the foreground, black in the background).

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
defaultNameThe default file name to use.
baseThe URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectoryThe directory to open the file chooser in.
allowFilesTrue if regular files may be chosen.
allowDirectoriesTrue if directories may be chosen.

Definition at line 320 of file Query.java.

                                      {
        addFileChooser(name, label, defaultName, base, startingDirectory,
                allowFiles, allowDirectories, Color.white, Color.black);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addFileChooser ( String  name,
String  label,
String  defaultName,
URI  base,
File  startingDirectory,
Color  background,
Color  foreground 
) [inline]

Create a FileChooser that selects files only, not directories.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
defaultNameThe default file name to use.
baseThe URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectoryThe directory to open the file chooser in.
backgroundThe background color for the text entry box.
foregroundThe foreground color for the text entry box.

Definition at line 337 of file Query.java.

                                                                                  {
        addFileChooser(name, label, defaultName, base, startingDirectory, true,
                false, background, foreground);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addFileChooser ( String  name,
String  label,
String  defaultName,
URI  base,
File  startingDirectory,
boolean  allowFiles,
boolean  allowDirectories,
Color  background,
Color  foreground 
) [inline]

Create a FileChooser.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
defaultNameThe default file name to use.
baseThe URI with respect to which to give relative file names, or null to give absolute file name.
startingDirectoryThe directory to open the file chooser in.
allowFilesTrue if regular files may be chosen.
allowDirectoriesTrue if directories may be chosen.
backgroundThe background color for the text entry box.
foregroundThe foreground color for the text entry box.

Definition at line 355 of file Query.java.

                                                                          {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        QueryFileChooser fileChooser = new QueryFileChooser(name, defaultName,
                base, startingDirectory, allowFiles, allowDirectories,
                background, foreground);
        _addPair(name, lbl, fileChooser, fileChooser);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addLine ( String  name,
String  label,
String  defaultValue 
) [inline]

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:
nameThe name used to identify the entry (when accessing the entry).
labelThe label to attach to the entry.
defaultValueDefault value to appear in the entry box.

Definition at line 375 of file Query.java.

                                                                        {
        addLine(name, label, defaultValue, Color.white, Color.black);
    }

Here is the caller graph for this function:

void ptolemy.gui.Query.addLine ( String  name,
String  label,
String  defaultValue,
Color  background,
Color  foreground 
) [inline]

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:
nameThe name used to identify the entry (when accessing the entry).
labelThe label to attach to the entry.
defaultValueDefault value to appear in the entry box.
backgroundThe background color.
foregroundThe foreground color.

Definition at line 389 of file Query.java.

                                                {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        JTextField entryBox = new JTextField(defaultValue, _width);
        entryBox.setBackground(background);
        entryBox.setForeground(foreground);
        _addPair(name, lbl, entryBox, entryBox);

        // Add the listener last so that there is no notification
        // of the first value.
        entryBox.addActionListener(new QueryActionListener(name));

        // Add a listener for loss of focus.  When the entry gains
        // and then loses focus, listeners are notified of an update,
        // but only if the value has changed since the last notification.
        // FIXME: Unfortunately, Java calls this listener some random
        // time after the window has been closed.  It is not even a
        // a queued event when the window is closed.  Thus, we have
        // a subtle bug where if you enter a value in a line, do not
        // hit return, and then click on the X to close the window,
        // the value is restored to the original, and then sometime
        // later, the focus is lost and the entered value becomes
        // the value of the parameter.  I don't know of any workaround.
        entryBox.addFocusListener(new QueryFocusListener(name));
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addPassword ( String  name,
String  label,
String  defaultValue 
) [inline]

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:
nameThe name used to identify the entry (when accessing the entry).
labelThe label to attach to the entry.
defaultValueDefault value to appear in the entry box.
Since:
Ptolemy II 3.1

Definition at line 428 of file Query.java.

                                                                            {
        addPassword(name, label, defaultValue, Color.white, Color.black);
    }
void ptolemy.gui.Query.addPassword ( String  name,
String  label,
String  defaultValue,
Color  background,
Color  foreground 
) [inline]

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:
nameThe name used to identify the entry (when accessing the entry).
labelThe label to attach to the entry.
defaultValueDefault value to appear in the entry box.
backgroundThe background color.
foregroundThe foreground color.
Since:
Ptolemy II 3.1

Definition at line 452 of file Query.java.

                                                {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        JPasswordField entryBox = new JPasswordField(defaultValue, _width);
        entryBox.setBackground(background);
        entryBox.setForeground(foreground);
        _addPair(name, lbl, entryBox, entryBox);

        // Add the listener last so that there is no notification
        // of the first value.
        entryBox.addActionListener(new QueryActionListener(name));

        // Add a listener for loss of focus.  When the entry gains
        // and then loses focus, listeners are notified of an update,
        // but only if the value has changed since the last notification.
        // FIXME: Unfortunately, Java calls this listener some random
        // time after the window has been closed.  It is not even a
        // a queued event when the window is closed.  Thus, we have
        // a subtle bug where if you enter a value in a line, do not
        // hit return, and then click on the X to close the window,
        // the value is restored to the original, and then sometime
        // later, the focus is lost and the entered value becomes
        // the value of the parameter.  I don't know of any workaround.
        entryBox.addFocusListener(new QueryFocusListener(name));
    }

Here is the call graph for this function:

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:
listenerThe listener to add.
See also:
removeQueryListener(QueryListener)

Definition at line 494 of file Query.java.

                                                         {
        if (_listeners == null) {
            _listeners = new Vector();
        }

        if (_listeners.contains(listener)) {
            return;
        }

        _listeners.add(listener);
    }

Here is the caller graph for this function:

void ptolemy.gui.Query.addRadioButtons ( String  name,
String  label,
String[]  values,
String  defaultValue 
) [inline]

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:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
valuesThe list of possible choices.
defaultValueDefault value.

Definition at line 513 of file Query.java.

                                 {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        FlowLayout flow = new FlowLayout();
        flow.setAlignment(FlowLayout.LEFT);

        // This must be a JPanel, not a Panel, or the scroll bars won't work.
        JPanel buttonPanel = new JPanel(flow);

        ButtonGroup group = new ButtonGroup();
        QueryActionListener listener = new QueryActionListener(name);

        // Regrettably, ButtonGroup provides no method to find out
        // which button is selected, so we have to go through a
        // song and dance here...
        JRadioButton[] buttons = new JRadioButton[values.length];

        for (int i = 0; i < values.length; i++) {
            JRadioButton checkbox = new JRadioButton(values[i]);
            buttons[i] = checkbox;
            checkbox.setBackground(_background);

            // The following (essentially) undocumented method does nothing...
            // checkbox.setContentAreaFilled(true);
            checkbox.setOpaque(false);

            if (values[i].equals(defaultValue)) {
                checkbox.setSelected(true);
            }

            group.add(checkbox);
            buttonPanel.add(checkbox);

            // Add the listener last so that there is no notification
            // of the first value.
            checkbox.addActionListener(listener);
        }

        _addPair(name, lbl, buttonPanel, buttons);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.gui.Query.addSelectButtons ( String  name,
String  label,
String[]  values,
Set  initiallySelected 
) [inline]

Create a bank of buttons that provides a list of choices, any subset of which may be chosen at a time.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
valuesThe list of possible choices.
initiallySelectedThe initially selected choices, or null to indicate that none are selected.

Definition at line 564 of file Query.java.

                                   {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        FlowLayout flow = new FlowLayout();
        flow.setAlignment(FlowLayout.LEFT);

        // This must be a JPanel, not a Panel, or the scroll bars won't work.
        JPanel buttonPanel = new JPanel(flow);

        QueryActionListener listener = new QueryActionListener(name);

        if (initiallySelected == null) {
            initiallySelected = new HashSet();
        }

        JRadioButton[] buttons = new JRadioButton[values.length];

        for (int i = 0; i < values.length; i++) {
            JRadioButton checkbox = new JRadioButton(values[i]);
            buttons[i] = checkbox;
            checkbox.setBackground(_background);

            // The following (essentially) undocumented method does nothing...
            // checkbox.setContentAreaFilled(true);
            checkbox.setOpaque(false);

            if (initiallySelected.contains(values[i])) {
                checkbox.setSelected(true);
            }

            buttonPanel.add(checkbox);

            // Add the listener last so that there is no notification
            // of the first value.
            checkbox.addActionListener(listener);
        }

        _addPair(name, lbl, buttonPanel, buttons);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addSlider ( String  name,
String  label,
int  defaultValue,
int  minimum,
int  maximum 
) throws IllegalArgumentException [inline]

Create a slider with the specified name, label, default value, maximum, and minimum.

Parameters:
nameThe name used to identify the slider.
labelThe label to attach to the slider.
defaultValueInitial position of slider.
maximumMaximum value of slider.
minimumMinimum value of slider.
Exceptions:
IllegalArgumentExceptionIf the desired default value is not between the minimum and maximum.

Definition at line 616 of file Query.java.

                                                                      {
        JLabel lbl = new JLabel(label + ": ");

        if (minimum > maximum) {
            int temp = minimum;
            minimum = maximum;
            maximum = temp;
        }

        if ((defaultValue > maximum) || (defaultValue < minimum)) {
            throw new IllegalArgumentException("Desired default " + "value \""
                    + defaultValue + "\" does not fall "
                    + "between the minimum and maximum.");
        }

        JSlider slider = new JSlider(minimum, maximum, defaultValue);
        _addPair(name, lbl, slider, slider);
        slider.addChangeListener(new SliderListener(name));
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addTextArea ( String  name,
String  label,
String  theValue 
) [inline]

Create a text area.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
theValueThe value of this text area

Definition at line 642 of file Query.java.

                                                                        {
        addTextArea(name, label, theValue, Color.white, Color.black, _height,
                _width);
    }

Here is the caller graph for this function:

void ptolemy.gui.Query.addTextArea ( String  name,
String  label,
String  theValue,
Color  background,
Color  foreground 
) [inline]

Create a text area.

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
theValueThe value of this text area.
backgroundThe background color.
foregroundThe foreground color.

Definition at line 654 of file Query.java.

                                                {
        addTextArea(name, label, theValue, background, foreground, _height,
                _width);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.addTextArea ( String  name,
String  label,
String  theValue,
Color  background,
Color  foreground,
int  height,
int  width 
) [inline]

Create a text area with the specified height and width (in characters).

Parameters:
nameThe name used to identify the entry (when calling get).
labelThe label to attach to the entry.
theValueThe value of this text area.
backgroundThe background color.
foregroundThe foreground color.
heightThe height.
widthThe width.

Definition at line 670 of file Query.java.

                                                                       {
        JLabel lbl = new JLabel(label + ": ");
        lbl.setBackground(_background);

        JTextArea textArea = new JTextArea(theValue, height, width);
        textArea.setEditable(true);
        textArea.setBackground(background);
        textArea.setForeground(foreground);

        QueryScrollPane textPane = new QueryScrollPane(textArea);
        _addPair(name, lbl, textPane, textPane);
        textArea.addFocusListener(new QueryFocusListener(name));
    }

Here is the call graph for this function:

boolean ptolemy.gui.Query.booleanValue ( String  name) throws NoSuchElementException, IllegalArgumentException [inline]

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:
nameThe name of the entry.
Deprecated:
Use getBooleanValue(String name) instead.
Returns:
The state of the checkbox.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a checkbox. This is a runtime exception, so it need not be declared explicitly.

Definition at line 698 of file Query.java.

                                     {
        return getBooleanValue(name);
    }

Here is the call graph for this function:

double ptolemy.gui.Query.doubleValue ( String  name) throws IllegalArgumentException, NoSuchElementException, NumberFormatException [inline]

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:
nameThe name of the entry.
Deprecated:
Use getDoubleValue(String name) instead.
Returns:
The value currently in the entry as a double.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
NumberFormatExceptionIf the value of the entry cannot be converted to a double. This is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a line. This is a runtime exception, so it need not be declared explicitly.

Definition at line 720 of file Query.java.

                                                          {
        return getDoubleValue(name);
    }

Here is the call graph for this function:

boolean ptolemy.gui.Query.getBooleanValue ( String  name) throws NoSuchElementException, IllegalArgumentException [inline]

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:
nameThe name of the entry.
Returns:
The state of the checkbox.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a checkbox. This is a runtime exception, so it need not be declared explicitly.

Definition at line 737 of file Query.java.

                                     {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + "\" in the query box.");
        }

        if (result instanceof JToggleButton) {
            return ((JToggleButton) result).isSelected();
        } else {
            throw new IllegalArgumentException("Item named \"" + name
                    + "\" is not a radio button, and hence does not have "
                    + "a boolean value.");
        }
    }

Here is the caller graph for this function:

char [] ptolemy.gui.Query.getCharArrayValue ( String  name) throws NoSuchElementException, IllegalArgumentException [inline]

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:
nameThe name of the entry.
Returns:
The state of the entry
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf 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

Definition at line 770 of file Query.java.

                                     {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + "\" in the query box.");
        }

        if (result instanceof JPasswordField) {
            // Calling JPasswordField.getText() is deprecated
            return ((JPasswordField) result).getPassword();
        } else {
            return getStringValue(name).toCharArray();
        }
    }

Here is the call graph for this function:

double ptolemy.gui.Query.getDoubleValue ( String  name) throws IllegalArgumentException, NoSuchElementException, NumberFormatException [inline]

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:
nameThe name of the entry.
Returns:
The value currently in the entry as a double.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
NumberFormatExceptionIf the value of the entry cannot be converted to a double. This is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a line. This is a runtime exception, so it need not be declared explicitly.

Definition at line 803 of file Query.java.

                                                          {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + " \" in the query box.");
        }

        if (result instanceof JPasswordField) {
            // Note that JPasswordField extends JTextField, so
            // we should check for JPasswordField first.
            throw new IllegalArgumentException("For security reasons, "
                    + "calling getDoubleValue() on a password field is "
                    + "not permitted.  Instead, call getCharArrayValue()");
        } else if (result instanceof JTextField) {
            return (Double.valueOf(((JTextField) result).getText()))
                    .doubleValue();
        } else {
            throw new IllegalArgumentException("Item named \"" + name
                    + "\" is not a text line, and hence cannot be converted "
                    + "to a double value.");
        }
    }

Here is the caller graph for this function:

int ptolemy.gui.Query.getIntValue ( String  name) throws IllegalArgumentException, NoSuchElementException, NumberFormatException [inline]

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:
nameThe name of the entry.
Returns:
The value currently in the entry as an integer.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
NumberFormatExceptionIf the value of the entry cannot be converted to an integer. This is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a choice, line, or slider. This is a runtime exception, so it need not be declared explicitly.

Definition at line 845 of file Query.java.

                                                          {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + " \" in the query box.");
        }

        if (result instanceof JPasswordField) {
            // Note that JPasswordField extends JTextField, so
            // we should check for JPasswordField first.
            throw new IllegalArgumentException("For security reasons, "
                    + "calling getIntValue() on a password field is "
                    + "not permitted.  Instead, call getCharArrayValue()");
        } else if (result instanceof JTextField) {
            return (Integer.valueOf(((JTextField) result).getText()))
                    .intValue();
        } else if (result instanceof JSlider) {
            return ((JSlider) result).getValue();
        } else if (result instanceof JComboBox) {
            return ((JComboBox) result).getSelectedIndex();
        } else if (result instanceof JToggleButton[]) {
            // Regrettably, ButtonGroup gives no way to determine
            // which button is selected, so we have to search...
            JToggleButton[] buttons = (JToggleButton[]) result;

            for (int i = 0; i < buttons.length; i++) {
                if (buttons[i].isSelected()) {
                    return i;
                }
            }

            // In theory, we shouldn't get here, but the compiler
            // is unhappy without a return.
            return -1;
        } else {
            throw new IllegalArgumentException("Item named \"" + name
                    + "\" is not a text line or slider, and hence "
                    + "cannot be converted to " + "an integer value.");
        }
    }

Here is the caller graph for this function:

Dimension ptolemy.gui.Query.getMaximumSize ( ) [inline]

Return the preferred height, but set the width to the maximum possible value.

Currently (JDK 1.3), only BoxLayout pays any attention to getMaximumSize().

Returns:
The maximum desired size.

Definition at line 894 of file Query.java.

                                      {
        // Unfortunately, if we don't have a message, then we end up with
        // an empty space that is difficult to control the size of, which
        // requires us to set the maximum size to be the same as
        // the preferred size
        // If you change this, be sure to try applets that have both
        // horizontal and vertical layout.
        Dimension preferred = getPreferredSize();
        preferred.width = Short.MAX_VALUE;
        return preferred;
    }
String ptolemy.gui.Query.getStringValue ( String  name) throws NoSuchElementException, IllegalArgumentException [inline]

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:
nameThe name of the entry.
Returns:
The value currently in the entry as a String.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry type does not have a string representation (this should not be thrown).

Definition at line 920 of file Query.java.

                                     {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + " \" in the query box.");
        }

        if (result instanceof JTextField) {
            return ((JTextField) result).getText();
        } else if (result instanceof QueryColorChooser) {
            return ((QueryColorChooser) result).getSelectedColor();
        } else if (result instanceof QueryFileChooser) {
            return ((QueryFileChooser) result).getSelectedFileName();
        } else if (result instanceof JTextArea) {
            return ((JTextArea) result).getText();
        } else if (result instanceof JToggleButton) {
            // JRadioButton and JCheckButton are subclasses of JToggleButton
            JToggleButton toggleButton = (JToggleButton) result;

            if (toggleButton.isSelected()) {
                return "true";
            } else {
                return "false";
            }
        } else if (result instanceof JSlider) {
            return "" + ((JSlider) result).getValue();
        } else if (result instanceof JComboBox) {
            return (String) (((JComboBox) result).getSelectedItem());
        } else if (result instanceof JToggleButton[]) {
            // JRadioButton and JCheckButton are subclasses of JToggleButton
            // Regrettably, ButtonGroup gives no way to determine
            // which button is selected, so we have to search...
            JToggleButton[] buttons = (JToggleButton[]) result;
            StringBuffer toReturn = null;

            for (int i = 0; i < buttons.length; i++) {
                if (buttons[i].isSelected()) {
                    if (toReturn == null) {
                        toReturn = new StringBuffer(buttons[i].getText());
                    } else {
                        toReturn.append(", " + buttons[i].getText());
                    }
                }
            }

            if (toReturn == null) {
                toReturn = new StringBuffer();
            }

            return toReturn.toString();
        } else if (result instanceof QueryScrollPane) {
            return ((QueryScrollPane) result).getText();
        } else {
            throw new IllegalArgumentException("Query class cannot generate"
                    + " a string representation for entries of type "
                    + result.getClass());
        }
    }

Here is the caller graph for this function:

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)

Definition at line 988 of file Query.java.

                               {
        return _height;
    }

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)

Definition at line 998 of file Query.java.

                              {
        return _width;
    }
int ptolemy.gui.Query.intValue ( String  name) throws IllegalArgumentException, NoSuchElementException, NumberFormatException [inline]

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:
nameThe name of the entry.
Deprecated:
Use getIntValue(String name) instead.
Returns:
The value currently in the entry as an integer.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
NumberFormatExceptionIf the value of the entry cannot be converted to an integer. This is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a choice, line, or slider. This is a runtime exception, so it need not be declared explicitly.

Definition at line 1020 of file Query.java.

                                                          {
        return getIntValue(name);
    }

Here is the call graph for this function:

Notify listeners of the current value of all entries, unless those entries have not changed since the last notification.

Definition at line 1028 of file Query.java.

                                  {
        Iterator names = _entries.keySet().iterator();

        while (names.hasNext()) {
            String name = (String) names.next();
            _notifyListeners(name);
        }
    }

Here is the call graph for this function:

Remove a listener.

If the listener has not been added, then do nothing.

Parameters:
listenerThe listener to remove.
See also:
addQueryListener(QueryListener)

Definition at line 1042 of file Query.java.

                                                            {
        if (_listeners == null) {
            return;
        }

        _listeners.remove(listener);
    }
void ptolemy.gui.Query.set ( String  name,
String  value 
) throws NoSuchElementException, IllegalArgumentException [inline]

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:
nameThe name used to identify the entry (when calling get).
valueThe value to set the entry to.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the value does not parse to the appropriate type.

Definition at line 1063 of file Query.java.

                                     {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + " \" in the query box.");
        }

        // FIXME: Surely there is a better way to do this...
        // We should define a set of inner classes, one for each entry type.
        // Currently, this has to be updated each time a new entry type
        // is added.
        if (result instanceof JTextField) {
            ((JTextField) result).setText(value);
        } else if (result instanceof JTextArea) {
            ((JTextArea) result).setText(value);
        } else if (result instanceof QueryScrollPane) {
            ((QueryScrollPane) result).setText(value);
        } else if (result instanceof JToggleButton) {
            // JRadioButton and JCheckButton are subclasses of JToggleButton
            Boolean flag = Boolean.valueOf(value);
            setBoolean(name, flag.booleanValue());
        } else if (result instanceof JSlider) {
            Integer parsed = Integer.valueOf(value);
            ((JSlider) result).setValue(parsed.intValue());
        } else if (result instanceof JComboBox) {
            ((JComboBox) result).setSelectedItem(value);
        } else if (result instanceof JToggleButton[]) {
            // First, parse the value, which may be a comma-separated list.
            Set selectedValues = new HashSet();
            StringTokenizer tokenizer = new StringTokenizer(value, ",");

            while (tokenizer.hasMoreTokens()) {
                selectedValues.add(tokenizer.nextToken().trim());
            }

            JToggleButton[] buttons = (JToggleButton[]) result;

            for (int i = 0; i < buttons.length; i++) {
                if (selectedValues.contains(buttons[i].getText())) {
                    buttons[i].setSelected(true);
                } else {
                    buttons[i].setSelected(false);
                }
            }
        } else if (result instanceof QueryColorChooser) {
            ((QueryColorChooser) result).setColor(value);
        } else if (result instanceof QueryFileChooser) {
            ((QueryFileChooser) result).setFileName(value);
        } else {
            throw new IllegalArgumentException("Query class cannot set"
                    + " a string representation for entries of type "
                    + result.getClass());
        }

        // Record the new value as if it was the previously notified
        // value.  Thus, any future change from this value will trigger
        // notification.
        _previous.put(name, value);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.setAndNotify ( String  name,
String  value 
) throws NoSuchElementException, IllegalArgumentException [inline]

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:
nameThe name used to identify the entry (when calling get).
valueThe value to set the entry to.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the value does not parse to the appropriate type.

Definition at line 1136 of file Query.java.

                                                                    {
        set(name, value);
        _notifyListeners(name);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.setBackground ( Color  color) [inline]

Set the background color for all the widgets.

Parameters:
colorThe background color.

Definition at line 1145 of file Query.java.

                                           {
        super.setBackground(color);
        _background = color;

        // Set the background of any components that already exist.
        Component[] components = getComponents();

        for (int i = 0; i < components.length; i++) {
            if (!(components[i] instanceof JTextField)) {
                components[i].setBackground(_background);
            }
        }
    }
void ptolemy.gui.Query.setBoolean ( String  name,
boolean  value 
) throws NoSuchElementException, IllegalArgumentException [inline]

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:
nameThe name of the entry.
valueThe new value of the entry.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a checkbox. This is a runtime exception, so it need not be declared explicitly.

Definition at line 1171 of file Query.java.

                                                                    {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + "\" in the query box.");
        }

        if (result instanceof JToggleButton) {
            // JRadioButton and JCheckButton are subclasses of JToggleButton
            ((JToggleButton) result).setSelected(value);
        } else {
            throw new IllegalArgumentException("Item named \"" + name
                    + "\" is not a radio button, and hence does not have "
                    + "a boolean value.");
        }

        _notifyListeners(name);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void ptolemy.gui.Query.setColumns ( int  columns) [inline]

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:
columnsThe number of columns.

Definition at line 1199 of file Query.java.

                                        {
        if (columns <= 0) {
            throw new IllegalArgumentException(
                    "Query.setColumns() requires a strictly positive "
                            + "argument.");
        }

        _columns = columns;
    }
void ptolemy.gui.Query.setDisplay ( String  name,
String  value 
) throws NoSuchElementException, IllegalArgumentException [inline]

Set the displayed text of an entry that has been added using addDisplay.

Notify listeners that the value has changed.

Parameters:
nameThe name of the entry.
valueThe string to display.
Exceptions:
NoSuchElementExceptionIf there is no entry with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a display. This is a runtime exception, so it need not be declared explicitly.

Definition at line 1221 of file Query.java.

                                                                    {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + " \" in the query box.");
        }

        if (result instanceof JTextArea) {
            JTextArea label = (JTextArea) result;
            label.setText(value);
        } else {
            throw new IllegalArgumentException("Item named \"" + name
                    + "\" is not a display, and hence cannot be set using "
                    + "setDisplay().");
        }

        _notifyListeners(name);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.setEnabled ( String  name,
boolean  value 
) [inline]

For line, display, check box, slider, radio button, or choice entries made, if the second argument is false, then it will be disabled.

Parameters:
nameThe name of the entry.
valueIf false, disables the entry.

Definition at line 1248 of file Query.java.

                                                       {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + " \" in the query box.");
        }

        if (result instanceof JComponent) {
            ((JComponent) result).setEnabled(value);
        } else if (result instanceof JToggleButton[]) {
            JToggleButton[] buttons = (JToggleButton[]) result;

            for (int i = 0; i < buttons.length; i++) {
                buttons[i].setEnabled(value);
            }
        }
    }
void ptolemy.gui.Query.setLine ( String  name,
String  value 
) [inline]

Set the displayed text of an item that has been added using addLine.

Notify listeners that the value has changed.

Parameters:
nameThe name of the entry.
valueThe string to display.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a display. This is a runtime exception, so it need not be declared explicitly.

Definition at line 1278 of file Query.java.

                                                   {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + " \" in the query box.");
        }

        if (result instanceof JTextField) {
            JTextField line = (JTextField) result;
            line.setText(value);
        } else {
            throw new IllegalArgumentException("Item named \"" + name
                    + "\" is not a line, and hence cannot be set using "
                    + "setLine().");
        }

        _notifyListeners(name);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.setMessage ( String  message) [inline]

Specify a message to be displayed above the query.

Parameters:
messageThe message to display.

Definition at line 1301 of file Query.java.

                                           {
        if (!_messageScrollPaneAdded) {
            _messageScrollPaneAdded = true;
            add(_messageScrollPane, 1);

            // Add a spacer.
            add(Box.createRigidArea(new Dimension(0, 10)), 2);
        }

        _messageArea.setText(message);

        // I'm not sure why we need to add 1 here?
        int lineCount = _messageArea.getLineCount() + 1;

        // Keep the line count to less than 30 lines.  If
        // we have more than 30 lines, we get a scroll bar.
        if (lineCount > 30) {
            lineCount = 30;
        }

        _messageArea.setRows(lineCount);
        _messageArea.setColumns(_width);

        // In case size has changed.
        validate();
    }
void ptolemy.gui.Query.setSlider ( String  name,
int  value 
) [inline]

Set the position of an item that has been added using addSlider.

Notify listeners that the value has changed.

Parameters:
nameThe name of the entry.
valueThe value to set the slider position.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry is not a slider. This is a runtime exception, so it need not be declared explicitly.

Definition at line 1339 of file Query.java.

                                                  {
        Object result = _entries.get(name);

        if (result == null) {
            throw new NoSuchElementException("No item named \"" + name
                    + " \" in the query box.");
        }

        if (result instanceof JSlider) {
            JSlider theSlider = (JSlider) result;

            // Set the new slider position.
            theSlider.setValue(value);
        } else {
            throw new IllegalArgumentException("Item named \"" + name
                    + "\" is not a slider, and hence cannot be set using "
                    + "setSlider().");
        }

        _notifyListeners(name);
    }

Here is the call graph for this function:

void ptolemy.gui.Query.setTextHeight ( int  characters) [inline]

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:
charactersThe preferred height.
See also:
addTextArea(String, String, String)
getTextHeight()

Definition at line 1368 of file Query.java.

                                              {
        _height = characters;
    }
void ptolemy.gui.Query.setTextWidth ( int  characters) [inline]

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:
charactersThe preferred width.
See also:
getTextWidth()

Definition at line 1378 of file Query.java.

                                             {
        _width = characters;
    }

Here is the caller graph for this function:

void ptolemy.gui.Query.setToolTip ( String  name,
String  tip 
) [inline]

Specify a tool tip to appear when the mouse lingers over the label.

Parameters:
nameThe name of the entry.
tipThe text of the tool tip.

Definition at line 1386 of file Query.java.

                                                    {
        JLabel label = (JLabel) _labels.get(name);

        if (label != null) {
            label.setToolTipText(tip);
        }
    }
static Color ptolemy.gui.Query.stringToColor ( String  description) [inline, static]

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:
descriptionThe description of the color, or white if any parse error occurs.
Returns:
A string representing the color.

Definition at line 1402 of file Query.java.

                                                          {
        String[] specArray = description.split("[{},]");
        float red = 0f;
        float green = 0f;
        float blue = 0f;
        float alpha = 1.0f;

        // If any exceptions occur during the attempt to parse,
        // then just use the default color.
        try {
            int i = 0;

            // Ignore any blank strings that this simple parsing produces.
            while (specArray[i].trim().equals("")) {
                i++;
            }

            if (specArray.length > i) {
                red = Float.parseFloat(specArray[i]);
            }

            i++;

            while (specArray[i].trim().equals("")) {
                i++;
            }

            if (specArray.length > i) {
                green = Float.parseFloat(specArray[i]);
            }

            i++;

            while (specArray[i].trim().equals("")) {
                i++;
            }

            if (specArray.length > i) {
                blue = Float.parseFloat(specArray[i]);
            }

            i++;

            while (specArray[i].trim().equals("")) {
                i++;
            }

            if (specArray.length > i) {
                alpha = Float.parseFloat(specArray[i]);
            }
        } catch (Exception ex) {
            // Ignore and use default color.
        }
        return new Color(red, green, blue, alpha);
    }

Here is the caller graph for this function:

String ptolemy.gui.Query.stringValue ( String  name) throws NoSuchElementException, IllegalArgumentException [inline]

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:
nameThe name of the entry.
Deprecated:
Use getStringValue(String name) instead.
Returns:
The value currently in the entry as a String.
Exceptions:
NoSuchElementExceptionIf there is no item with the specified name. Note that this is a runtime exception, so it need not be declared explicitly.
IllegalArgumentExceptionIf the entry type does not have a string representation (this should not be thrown).

Definition at line 1473 of file Query.java.

                                     {
        return getStringValue(name);
    }

Here is the call graph for this function:


Member Data Documentation

Color ptolemy.gui.Query._background = null [protected]

The background color as set by setBackground().

This defaults to null, which indicates that the background is the same as the container.

Definition at line 1553 of file Query.java.

int ptolemy.gui.Query._columns = 1 [private]

Definition at line 1603 of file Query.java.

GridBagConstraints ptolemy.gui.Query._constraints [protected]

Standard constraints for use with _grid.

Definition at line 1556 of file Query.java.

Map ptolemy.gui.Query._entries = new HashMap() [private]

Definition at line 1606 of file Query.java.

JPanel ptolemy.gui.Query._entryPanel = new JPanel() [private]

Definition at line 1609 of file Query.java.

JScrollPane ptolemy.gui.Query._entryScrollPane [private]

Definition at line 1612 of file Query.java.

GridBagLayout ptolemy.gui.Query._grid [protected]

Layout control.

Definition at line 1559 of file Query.java.

Definition at line 1615 of file Query.java.

Map ptolemy.gui.Query._labels = new HashMap() [private]

Definition at line 1618 of file Query.java.

Insets ptolemy.gui.Query._leftPadding = new Insets(0, 10, 0, 0) [private]

Definition at line 1621 of file Query.java.

Vector ptolemy.gui.Query._listeners [protected]

List of registered listeners.

Definition at line 1562 of file Query.java.

JTextArea ptolemy.gui.Query._messageArea = null [private]

Definition at line 1624 of file Query.java.

JScrollPane ptolemy.gui.Query._messageScrollPane [private]

Definition at line 1627 of file Query.java.

Definition at line 1630 of file Query.java.

Insets ptolemy.gui.Query._noPadding = new Insets(0, 0, 0, 0) [private]

Definition at line 1633 of file Query.java.

Map ptolemy.gui.Query._previous = new HashMap() [private]

Definition at line 1636 of file Query.java.

Definition at line 1641 of file Query.java.

Definition at line 1644 of file Query.java.

final int ptolemy.gui.Query.DEFAULT_ENTRY_HEIGHT = 10 [static]

The default height of entries created with addText().

Definition at line 1482 of file Query.java.

final int ptolemy.gui.Query.DEFAULT_ENTRY_WIDTH = 30 [static]

The default width of entries created with addLine().

Definition at line 1485 of file Query.java.


The documentation for this class was generated from the following file: