AROM-2_2_13

helix.util.ui
Class HParametersDialog

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Dialog
                          |
                          +--javax.swing.JDialog
                                |
                                +--helix.util.ui.OKCancelDialog
                                      |
                                      +--helix.util.ui.HParametersDialog
All Implemented Interfaces:
Accessible, ActionListener, EventListener, ImageObserver, MenuContainer, RootPaneContainer, Serializable, WindowConstants

public class HParametersDialog
extends helix.util.ui.OKCancelDialog

HParametersDialog is an user dialog that allows to ask inputs.
The dialog is rely on a set of Parameter object. Each Parameter represents an input in the dialog.
A parameter is created upon a HParametersDialog and his rendered by different way (textfield, combo box, checkbox, textfield group, radio panel).
It is possible to listen to parameters change (directly from user's change).
For each created parameter, a view (ParameterView) is created and is responsible to renders graphically. By default, the size of the view depends of parameter label, but it can be changed with adjustViewToInput() method.

	// defines a preferences node
	Preferences node = Preferences.userRoot().node( "ParametersDialogSample");
	// creates an input dialog with a cancel and default button
      // a "Initial" button will be created because there is a Preferences node
      // it may have initial value different from application default value
	HParametersDialog dialog = new HInputDialog(frame, "this is the title",
                                                  "Enter your information"
	                                            true, true, node);
	
	// adds a first parameter that is rendered by a textfield
	Parameter p1 = dialog.addTextfield("param1", "Enter your name", "", false);
	p1.setValue("changed value outside");
	// adds a second parameter whith a constraint to the value 
	Parameter p2 = dialog.addTextfield("param2", "Enter your age", 
	                                   "18", new IntegerConstraint(), true);
	Parameter p3 = dialog.addCheckBox("param3", "lobotomisé ?", new Boolean(true), true);
	Parameter p4 = dialog.addRadioPanel("param4", "sexe", 
					      new Object[] {"homme", "femme"}, "homme");
	Parameter p5 = dialog.addComboBox("param5", "sexe", 
					    new Object[] {"homme", "femme"}, "homme");
	
	// start the modal dialog
	dialog.start();
	
	System.out.println("p1 = " + p1.getValue());
	System.out.println("p2 = " + p2.getValue());
	System.out.println("p3 = " + p3.getValue());
	System.out.println("p4 = " + p4.getValue());
	System.out.println("p5 = " + p5.getValue());
 

Version:
$Id: HParametersDialog.java,v 1.12 2003/11/05 10:12:27 ciron Exp $
See Also:
Serialized Form

Field Summary
 
Fields inherited from class helix.util.ui.OKCancelDialog
PREFERENCES_POSITION_KEY, RESOURCES
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
HParametersDialog(Frame parent, String title, String dialogLabel, boolean cancelEnable, boolean resetEnable)
          Creates a new modal HParametersDialog.
HParametersDialog(Frame parent, String title, String dialogLabel, boolean cancelEnable, boolean resetEnable, boolean initialEnable, java.util.prefs.Preferences node)
          Creates a new modal HParametersDialog.
 
Method Summary
 void actionPerformed(ActionEvent e)
           
 BooleanParameter addCheckBox(String key, String label, Boolean defaultValue, boolean isPrefSaved)
          Adds a Checkbox parameter.
 Parameter addComboBox(String key, String label, Object[] values, Object defaultValue)
          Adds a choice parameter.
 ListParameter addList(String key, String label, Object[] defaultValues)
          Adds a list parameter.
 Parameter addRadioPanel(String key, String label, Object[] values, Object defaultValue)
          Adds a choice parameter.
 StringParameter addTextfield(String key, String label, String defaultValue, boolean isPrefSaved)
          Adds a textfield parameter without constraint upon the input value.
 StringParameter addTextfield(String key, String label, String defaultValue, Constraints constraint, boolean isPrefSaved)
          Adds a textfield parameter with a onstraint upon the input value.
 ListParameter addTextfieldsGroup(String key, String label, String[] defaultValues)
          Adds a textfield groups parameter.
 void adjustViewToInput(Parameter p)
          Adjust view to parameter input component.
static Dimension computePreferredSize(JComponent component, String str)
          Computes the preferred with for component to display the string argument.
 Parameter getParameter(int index)
          Returns the parameter at specified index.
 Parameter getParameter(String key)
          Returns the parameter of specified key.
 int getParameterCount()
          Returns the number of parameter in this input dialog.
 ParameterView getParameterView(String key)
          Returns the parameter view of Parameter specified by key.
 boolean start()
          Displays this dialog.
 
Methods inherited from class helix.util.ui.OKCancelDialog
addComponent, dispose, getCancelButton, getCustomButton, getCustomButtons, getOKButton, getPanel, getPreferences, hasPreferences
 
Methods inherited from class javax.swing.JDialog
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, update
 
Methods inherited from class java.awt.Dialog
addNotify, getTitle, hide, isModal, isResizable, isUndecorated, setModal, setResizable, setTitle, setUndecorated, show
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, removeNotify, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HParametersDialog

public HParametersDialog(Frame parent,
                         String title,
                         String dialogLabel,
                         boolean cancelEnable,
                         boolean resetEnable)
Creates a new modal HParametersDialog.
The dialog is modal and not resizable.

Parameters:
parent - parent frame (may be null)
title - dialog title
dialogLabel - the title of the input panel (may be null)
cancelEnable - indicates wether cancel button is present or not
resetEnable - indicates wether reset button is present or not

HParametersDialog

public HParametersDialog(Frame parent,
                         String title,
                         String dialogLabel,
                         boolean cancelEnable,
                         boolean resetEnable,
                         boolean initialEnable,
                         java.util.prefs.Preferences node)
Creates a new modal HParametersDialog.

Parameters:
parent - parent frame (may be null)
title - dialog title
dialogLabel - the title of the input panel (may be null)
cancelEnable - indicates wether cancel button is present or not
resetEnable - indicates wether reset button is present or not
initialEnable - indicates wether initial button is present or not
node - preferences node where to store values
Method Detail

getParameter

public Parameter getParameter(int index)
                       throws IndexOutOfBoundsException
Returns the parameter at specified index.

Parameters:
index -
Returns:
Parameter
Throws:
IndexOutOfBoundsException - if invalid index.

start

public boolean start()
Displays this dialog.


addTextfield

public StringParameter addTextfield(String key,
                                    String label,
                                    String defaultValue,
                                    boolean isPrefSaved)
Adds a textfield parameter without constraint upon the input value.

Parameters:
key -
label -
defaultValue -
isPrefSaved - indicates if value of this parameter is related to user preferences
Returns:
StringParameter

addTextfield

public StringParameter addTextfield(String key,
                                    String label,
                                    String defaultValue,
                                    Constraints constraint,
                                    boolean isPrefSaved)
                             throws IllegalArgumentException
Adds a textfield parameter with a onstraint upon the input value.

Parameters:
key -
label -
defaultValue -
constraint -
isPrefSaved - indicates if value of this parameter is related to user preferences
Returns:
StringParameter
IllegalArgumentException

addComboBox

public Parameter addComboBox(String key,
                             String label,
                             Object[] values,
                             Object defaultValue)
                      throws IllegalArgumentException
Adds a choice parameter.

Parameters:
key -
label -
values -
defaultValue -
Returns:
Parameter
IllegalArgumentException

addCheckBox

public BooleanParameter addCheckBox(String key,
                                    String label,
                                    Boolean defaultValue,
                                    boolean isPrefSaved)
                             throws IllegalArgumentException
Adds a Checkbox parameter.

Parameters:
key -
label -
defaultValue -
isPrefSaved - indicates if value of this parameter is related to user preferences
Returns:
BooleanParameter
IllegalArgumentException

addRadioPanel

public Parameter addRadioPanel(String key,
                               String label,
                               Object[] values,
                               Object defaultValue)
                        throws IllegalArgumentException
Adds a choice parameter.

Parameters:
key -
label -
values -
defaultValue -
Returns:
IllegalArgumentException

addTextfieldsGroup

public ListParameter addTextfieldsGroup(String key,
                                        String label,
                                        String[] defaultValues)
Adds a textfield groups parameter.

Parameters:
key -
label -
defaultValues -
Returns:
ListParameter

addList

public ListParameter addList(String key,
                             String label,
                             Object[] defaultValues)
Adds a list parameter.

Parameters:
key -
label -
defaultValues -
Returns:
ListParameter

getParameterCount

public int getParameterCount()
Returns the number of parameter in this input dialog.

Returns:
int

getParameter

public Parameter getParameter(String key)
Returns the parameter of specified key.

Parameters:
key -
Returns:
found parameter, null otherwise

getParameterView

public ParameterView getParameterView(String key)
Returns the parameter view of Parameter specified by key.

Parameters:
key -
Returns:
found parameter view, null otherwise

adjustViewToInput

public void adjustViewToInput(Parameter p)
Adjust view to parameter input component.


computePreferredSize

public static Dimension computePreferredSize(JComponent component,
                                             String str)
Computes the preferred with for component to display the string argument.

Parameters:
component -
str -
Returns:
Dimension

actionPerformed

public void actionPerformed(ActionEvent e)
Specified by:
actionPerformed in interface ActionListener
Overrides:
actionPerformed in class helix.util.ui.OKCancelDialog

AROM-2_2_13