public class PrefPanel
extends javax.swing.JPanel
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.out.println(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 } });
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
Modifier and Type | Class and Description |
---|---|
static class |
PrefPanel.Dialog
A convenience class for constructing a standalone JDialog window that has a PrefPanel inside it.
|
javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
PrefPanel(java.lang.String name,
PreferencesExt prefs)
Constructor.
|
PrefPanel(java.lang.String name,
java.util.prefs.Preferences prefs,
PersistenceManager storeData)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
accept()
Call Field.accept() on all Fields.
|
void |
addActionListener(java.awt.event.ActionListener l)
Add listener: action event sent if "apply" button is pressed
|
Field.BeanTableField |
addBeanTableField(java.lang.String fldName,
java.lang.String label,
java.util.ArrayList beans,
java.lang.Class beanClass,
int col,
int row,
java.lang.String constraint) |
void |
addButton(javax.swing.JComponent b)
Add a button to the button panel
|
Field.CheckBox |
addCheckBoxField(java.lang.String fldName,
java.lang.String label,
boolean defValue)
Add a boolean field as a checkbox.
|
Field.CheckBox |
addCheckBoxField(java.lang.String fldName,
java.lang.String label,
boolean defValue,
int col,
int row) |
void |
addComponent(java.awt.Component comp,
int col,
int row,
java.lang.String constraint)
Add a Component.
|
Field.Date |
addDateField(java.lang.String fldName,
java.lang.String label,
java.util.Date defValue)
Add a field that edits a date
|
Field.Date |
addDateField(java.lang.String fldName,
java.lang.String label,
java.util.Date defValue,
int col,
int row,
java.lang.String constraint) |
Field.Double |
addDoubleField(java.lang.String fldName,
java.lang.String label,
double defValue)
Add a field that edits a double
|
Field.Double |
addDoubleField(java.lang.String fldName,
java.lang.String label,
double defValue,
int nfracDig,
int col,
int row,
java.lang.String constraint) |
Field.Double |
addDoubleField(java.lang.String fldName,
java.lang.String label,
double defValue,
int col,
int row,
java.lang.String constraint) |
void |
addEmptyRow(int row,
int size)
Add a seperator after the last field added.
|
Field.EnumCombo |
addEnumComboField(java.lang.String fldName,
java.lang.String label,
java.util.Collection defValues,
boolean editable) |
Field.EnumCombo |
addEnumComboField(java.lang.String fldName,
java.lang.String label,
java.util.Collection defValues,
boolean editable,
int col,
int row,
java.lang.String constraint) |
Field |
addField(Field fld)
Add a field created by the user.
|
Field |
addField(Field fld,
int col,
int row,
java.lang.String constraint) |
void |
addHeading(java.lang.String heading)
Add a heading that takes no input
|
void |
addHeading(java.lang.String heading,
int row)
Add a heading at the specified row.
|
Field.Int |
addIntField(java.lang.String fldName,
java.lang.String label,
int defValue)
Add a field that edits an integer
|
Field.Password |
addPasswordField(java.lang.String fldName,
java.lang.String label,
java.lang.String defValue)
Add a password text field.
|
void |
addSeparator()
Add a seperator after the last field added.
|
Field.TextArea |
addTextAreaField(java.lang.String fldName,
java.lang.String label,
java.lang.String def,
int nrows)
Add a TextArea field.
|
Field.TextArea |
addTextAreaField(java.lang.String fldName,
java.lang.String label,
java.lang.String def,
int nrows,
int col,
int row,
java.lang.String constraint) |
Field.TextCombo |
addTextComboField(java.lang.String fldName,
java.lang.String label,
java.util.Collection defValues,
int nKeep,
boolean editable)
Add a text combobox field.
|
Field.TextCombo |
addTextComboField(java.lang.String fldName,
java.lang.String label,
java.util.Collection defValues,
int nKeep,
boolean editable,
int col,
int row,
java.lang.String constraint) |
Field.Text |
addTextField(java.lang.String fldName,
java.lang.String label,
java.lang.String defValue)
Add a text field.
|
Field.Text |
addTextField(java.lang.String fldName,
java.lang.String label,
java.lang.String defValue,
int col,
int row,
java.lang.String constraint) |
static java.awt.Frame |
findActiveFrame() |
void |
finish()
Call this when you have finish constructing the panel, adding buttons in default spot
|
void |
finish(boolean addButtons)
Call this when you have finish constructing the panel.
|
void |
finish(boolean addButtons,
java.lang.String where)
Call when finished adding components to the PrefPanel.
|
Field |
getField(java.lang.String name)
Find the field with the specified name.
|
java.util.Iterator<Field> |
getFields()
Iterator over the fields
|
java.lang.Object |
getFieldValue(java.lang.String name)
Get current value of the named field
|
java.lang.String |
getName()
Return the name of the PrefPanel.
|
void |
removeActionListener(java.awt.event.ActionListener l)
Remove listener
|
void |
setCursor(int col,
int row)
Start a new column.
|
void |
setEnabled(boolean enable)
Set enabled on all the fields in the prefPanel
|
void |
setFieldValue(java.lang.String name,
java.lang.Object value)
Set the current value of the named field
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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
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
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, getPeer, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public PrefPanel(java.lang.String name, PreferencesExt prefs)
name
- may be null.prefs
- keep values in here; may be null.public PrefPanel(java.lang.String name, java.util.prefs.Preferences prefs, PersistenceManager storeData)
name
- may be null.storeData
- keep values in here; may be null.public void addActionListener(java.awt.event.ActionListener l)
public void removeActionListener(java.awt.event.ActionListener l)
public boolean accept()
public void setEnabled(boolean enable)
setEnabled
in class javax.swing.JComponent
enable
- enable if truepublic java.lang.String getName()
getName
in class java.awt.Component
public java.util.Iterator<Field> getFields()
public Field getField(java.lang.String name)
name
- of Fieldpublic java.lang.Object getFieldValue(java.lang.String name)
name
- of fieldpublic void setFieldValue(java.lang.String name, java.lang.Object value)
name
- of fieldvalue
- of fieldpublic void addButton(javax.swing.JComponent b)
public Field addField(Field fld)
fld
- add this field.public Field.BeanTableField addBeanTableField(java.lang.String fldName, java.lang.String label, java.util.ArrayList beans, java.lang.Class beanClass, int col, int row, java.lang.String constraint)
public Field.CheckBox addCheckBoxField(java.lang.String fldName, java.lang.String label, boolean defValue)
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default valuepublic Field.CheckBox addCheckBoxField(java.lang.String fldName, java.lang.String label, boolean defValue, int col, int row)
public Field.Date addDateField(java.lang.String fldName, java.lang.String label, java.util.Date defValue)
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default valuepublic Field.Date addDateField(java.lang.String fldName, java.lang.String label, java.util.Date defValue, int col, int row, java.lang.String constraint)
public Field.Double addDoubleField(java.lang.String fldName, java.lang.String label, double defValue)
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default valuepublic Field.Double addDoubleField(java.lang.String fldName, java.lang.String label, double defValue, int col, int row, java.lang.String constraint)
public Field.Double addDoubleField(java.lang.String fldName, java.lang.String label, double defValue, int nfracDig, int col, int row, java.lang.String constraint)
public Field.EnumCombo addEnumComboField(java.lang.String fldName, java.lang.String label, java.util.Collection defValues, boolean editable, int col, int row, java.lang.String constraint)
public Field.EnumCombo addEnumComboField(java.lang.String fldName, java.lang.String label, java.util.Collection defValues, boolean editable)
public Field.Int addIntField(java.lang.String fldName, java.lang.String label, int defValue)
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default valuepublic Field.Password addPasswordField(java.lang.String fldName, java.lang.String label, java.lang.String defValue)
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default valuepublic Field.Text addTextField(java.lang.String fldName, java.lang.String label, java.lang.String defValue)
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldefValue
- default valuepublic Field.Text addTextField(java.lang.String fldName, java.lang.String label, java.lang.String defValue, int col, int row, java.lang.String constraint)
public Field.TextCombo addTextComboField(java.lang.String fldName, java.lang.String label, java.util.Collection defValues, int nKeep, boolean editable)
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.public Field.TextCombo addTextComboField(java.lang.String fldName, java.lang.String label, java.util.Collection defValues, int nKeep, boolean editable, int col, int row, java.lang.String constraint)
public Field.TextArea addTextAreaField(java.lang.String fldName, java.lang.String label, java.lang.String def, int nrows)
fldName
- the name to store the data in the PersistenceManagerDatalabel
- used as the label on the paneldef
- default valuenrows
- number of rowspublic Field.TextArea addTextAreaField(java.lang.String fldName, java.lang.String label, java.lang.String def, int nrows, int col, int row, java.lang.String constraint)
public void addHeading(java.lang.String heading)
public void addHeading(java.lang.String heading, int row)
public void addComponent(java.awt.Component comp, int col, int row, java.lang.String constraint)
public void addSeparator()
public void addEmptyRow(int row, int size)
public void setCursor(int col, int row)
public void finish()
public void finish(boolean addButtons)
addButtons
- if true, add buttons in default spotpublic void finish(boolean addButtons, java.lang.String where)
addButtons
- if true, add buttonswhere
- BorderLayout.NORTH, SOUTH, EAST, WESTpublic static java.awt.Frame findActiveFrame()