Package ucar.ui.prefs
Class PrefPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- ucar.ui.prefs.PrefPanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
public class PrefPanel extends JPanel
Create a User Preferences Panel or Dialog. A PrefPanel manages a set of Fields with convenience methods for rapidly creating User Dialogs whose values are made persistent by a Preferences Store. All Fields contained in the PrefPanel share the same Preferences, and so must have unique names. Send ActionEvent when "accept" button is pressed. Can also listen on individual Fields. You must call one finish() method exactly once, when you are done adding Fields.Example of use:
PreferencesExt store = null; try { xstore = XMLStore.createFromFile("E:/dev/prefs/test/panel/panel.xml", null); store = xstore.getPreferences(); } catch (Exception e) { System.exit(1); } PrefPanel pp = new PrefPanel("test", store); pp.addTextField("name", "name", "defValue"); pp.newColumn(); pp.addTextField("name2", "name2", "defValue22"); pp.newColumn(); pp.addTextField("name3", "name3", "defValue22 asd jalskdjalksjd"); pp.finish(); pp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // accept was called } });
Form layout
The PrefPanel is layed out with the jgoodies FormLayout layout manager and PanelBuilder, which use a row, colummn grid. Fields in the same column are aligned.There are 2 ways to do form layout: implicit and explicit. With implicit, the position is implicitly specified by the order the fields are added, using, for example:
addDoubleField(String fldName, String label, double defValue)
The fields are all added in a column. To start a new column, use setCursor().With explicit, you specify the row and col, and an optional constraint:
addDoubleField(String fldName, String label, double defValue, int col, int row, String constraint)
Row and column numbers are 0 based. Each field has a width of 2 columns (one for the label and one for the component) and a height of 1 row, unless you specify otherwise using a constraint. A heading takes up an entire row, spanning all columns- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PrefPanel.Dialog
A convenience class for constructing a standalone JDialog window that has a PrefPanel inside it.-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
-
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
-
Constructor Summary
Constructors Constructor Description PrefPanel(String name, Preferences prefs, PersistenceManager storeData)
Constructor.PrefPanel(String name, PreferencesExt prefs)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept()
Call Field.accept() on all Fields.void
addActionListener(ActionListener l)
Add listener: action event sent if "apply" button is pressedField.BeanTableField
addBeanTableField(String fldName, String label, ArrayList beans, Class beanClass, int col, int row, String constraint)
void
addButton(JComponent b)
Add a button to the button panelField.CheckBox
addCheckBoxField(String fldName, String label, boolean defValue)
Add a boolean field as a checkbox.Field.CheckBox
addCheckBoxField(String fldName, String label, boolean defValue, int col, int row)
void
addComponent(Component comp, int col, int row, String constraint)
Add a Component.Field.Date
addDateField(String fldName, String label, Date defValue)
Add a field that edits a dateField.Date
addDateField(String fldName, String label, Date defValue, int col, int row, String constraint)
Field.Double
addDoubleField(String fldName, String label, double defValue)
Add a field that edits a doubleField.Double
addDoubleField(String fldName, String label, double defValue, int nfracDig, int col, int row, String constraint)
Field.Double
addDoubleField(String fldName, String label, double defValue, int col, int row, String constraint)
void
addEmptyRow(int row, int size)
Add a seperator after the last field added.Field.EnumCombo
addEnumComboField(String fldName, String label, Collection defValues, boolean editable)
Field.EnumCombo
addEnumComboField(String fldName, String label, Collection defValues, boolean editable, int col, int row, String constraint)
Field
addField(Field fld)
Add a field created by the user.Field
addField(Field fld, int col, int row, String constraint)
void
addHeading(String heading)
Add a heading that takes no inputvoid
addHeading(String heading, int row)
Add a heading at the specified row.Field.Int
addIntField(String fldName, String label, int defValue)
Add a field that edits an integerField.Password
addPasswordField(String fldName, String label, String defValue)
Add a password text field.void
addSeparator()
Add a seperator after the last field added.Field.TextArea
addTextAreaField(String fldName, String label, String def, int nrows)
Add a TextArea field.Field.TextArea
addTextAreaField(String fldName, String label, String def, int nrows, int col, int row, String constraint)
Field.TextCombo
addTextComboField(String fldName, String label, Collection defValues, int nKeep, boolean editable)
Add a text combobox field.Field.TextCombo
addTextComboField(String fldName, String label, Collection defValues, int nKeep, boolean editable, int col, int row, String constraint)
Field.Text
addTextField(String fldName, String label, String defValue)
Add a text field.Field.Text
addTextField(String fldName, String label, String defValue, int col, int row, String constraint)
static Frame
findActiveFrame()
void
finish()
Call this when you have finish constructing the panel, adding buttons in default spotvoid
finish(boolean addButtons)
Call this when you have finish constructing the panel.void
finish(boolean addButtons, String where)
Call when finished adding components to the PrefPanel.Field
getField(String name)
Find the field with the specified name.Iterator<Field>
getFields()
Iterator over the fieldsObject
getFieldValue(String name)
Get current value of the named fieldString
getName()
Return the name of the PrefPanel.void
removeActionListener(ActionListener l)
Remove listenervoid
setCursor(int col, int row)
Start a new column.void
setEnabled(boolean enable)
Set enabled on all the fields in the prefPanelvoid
setFieldValue(String name, Object value)
Set the current value of the named field-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
-
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
-
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Constructor Detail
-
PrefPanel
public PrefPanel(String name, PreferencesExt prefs)
Constructor.- Parameters:
name
- may be null.prefs
- keep values in here; may be null.
-
PrefPanel
public PrefPanel(String name, Preferences prefs, PersistenceManager storeData)
Constructor.- Parameters:
name
- may be null.storeData
- keep values in here; may be null.
-
-
Method Detail
-
addActionListener
public void addActionListener(ActionListener l)
Add listener: action event sent if "apply" button is pressed
-
removeActionListener
public void removeActionListener(ActionListener l)
Remove listener
-
accept
public boolean accept()
Call Field.accept() on all Fields. This puts any edits into the Store, and fires PropertyChangeEvents if any values change, and sends an ActionEvent to any listeners.
-
setEnabled
public void setEnabled(boolean enable)
Set enabled on all the fields in the prefPanel- Overrides:
setEnabled
in classJComponent
- Parameters:
enable
- enable if true
-
getName
public String getName()
Return the name of the PrefPanel.
-
getField
@Nullable public Field getField(String name)
Find the field with the specified name.- Parameters:
name
- of Field- Returns:
- Field or null if not found
-
getFieldValue
public Object getFieldValue(String name)
Get current value of the named field- Parameters:
name
- of field- Returns:
- value of named field
-
setFieldValue
public void setFieldValue(String name, Object value)
Set the current value of the named field- Parameters:
name
- of fieldvalue
- of field
-
addButton
public void addButton(JComponent b)
Add a button to the button panel
-
addField
public Field addField(Field fld)
Add a field created by the user.- Parameters:
fld
- add this field.
-
addBeanTableField
public Field.BeanTableField addBeanTableField(String fldName, String label, ArrayList beans, Class beanClass, int col, int row, String constraint)
-
addCheckBoxField
public Field.CheckBox addCheckBoxField(String fldName, String label, boolean defValue)
Add a boolean field as a checkbox.- Parameters:
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default value
-
addCheckBoxField
public Field.CheckBox addCheckBoxField(String fldName, String label, boolean defValue, int col, int row)
-
addDateField
public Field.Date addDateField(String fldName, String label, Date defValue)
Add a field that edits a date- Parameters:
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default value
-
addDateField
public Field.Date addDateField(String fldName, String label, Date defValue, int col, int row, String constraint)
-
addDoubleField
public Field.Double addDoubleField(String fldName, String label, double defValue)
Add a field that edits a double- Parameters:
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default value
-
addDoubleField
public Field.Double addDoubleField(String fldName, String label, double defValue, int col, int row, String constraint)
-
addDoubleField
public Field.Double addDoubleField(String fldName, String label, double defValue, int nfracDig, int col, int row, String constraint)
-
addEnumComboField
public Field.EnumCombo addEnumComboField(String fldName, String label, Collection defValues, boolean editable, int col, int row, String constraint)
-
addEnumComboField
public Field.EnumCombo addEnumComboField(String fldName, String label, Collection defValues, boolean editable)
-
addIntField
public Field.Int addIntField(String fldName, String label, int defValue)
Add a field that edits an integer- Parameters:
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default value
-
addPasswordField
public Field.Password addPasswordField(String fldName, String label, String defValue)
Add a password text field.- Parameters:
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default value
-
addTextField
public Field.Text addTextField(String fldName, String label, String defValue)
Add a text field.- Parameters:
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default value- Returns:
- the Field.Text object that was added
-
addTextField
public Field.Text addTextField(String fldName, String label, String defValue, int col, int row, String constraint)
-
addTextComboField
public Field.TextCombo addTextComboField(String fldName, String label, Collection defValues, int nKeep, boolean editable)
Add a text combobox field.- Parameters:
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValues
- list of default values (Strings) to include in the comboBox. May be null. These are added to the combobox (at the end) no matter how many there are.nKeep
- number of most recently used values to keepeditable
- whether the user can add new entries the list to select from.
-
addTextComboField
public Field.TextCombo addTextComboField(String fldName, String label, Collection defValues, int nKeep, boolean editable, int col, int row, String constraint)
-
addTextAreaField
public Field.TextArea addTextAreaField(String fldName, String label, String def, int nrows)
Add a TextArea field.- Parameters:
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldef
- default valuenrows
- number of rows
-
addTextAreaField
public Field.TextArea addTextAreaField(String fldName, String label, String def, int nrows, int col, int row, String constraint)
-
addHeading
public void addHeading(String heading)
Add a heading that takes no input
-
addHeading
public void addHeading(String heading, int row)
Add a heading at the specified row. this spans all columns
-
addComponent
public void addComponent(Component comp, int col, int row, String constraint)
Add a Component.
-
addSeparator
public void addSeparator()
Add a seperator after the last field added.
-
addEmptyRow
public void addEmptyRow(int row, int size)
Add a seperator after the last field added.
-
setCursor
public void setCursor(int col, int row)
Start a new column. Everything added goes into a vertical column until another call to newColumn().
-
finish
public void finish()
Call this when you have finish constructing the panel, adding buttons in default spot
-
finish
public void finish(boolean addButtons)
Call this when you have finish constructing the panel.- Parameters:
addButtons
- if true, add buttons in default spot
-
finish
public void finish(boolean addButtons, String where)
Call when finished adding components to the PrefPanel.- Parameters:
addButtons
- if true, add buttonswhere
- BorderLayout.NORTH, SOUTH, EAST, WEST
-
findActiveFrame
@Nullable public static Frame findActiveFrame()
-
-