common.gui
Class EasyOptionPane

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byorg.gjt.sp.jedit.AbstractOptionPane
                      extended bycommon.gui.EasyOptionPane
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, org.gjt.sp.jedit.OptionPane, java.io.Serializable

public class EasyOptionPane
extends org.gjt.sp.jedit.AbstractOptionPane

An extension of AbstractOptionPane that makes it easier for implementing classes to create the gui by using a list of strings with the description of what the components should be.

The pane is created by passing to this class a list of strings that describe the components to be added. These strings follow the format: type,label,property[,config], where:

The following are the supported types and supported configuration strings:

Type Component Config String Saved Value
text JTextField None. Contents of text field.
file, dir or filedir FileTextField "true" if it should force the file to exist. Contents of text field. Use the appropriate type depending on the restriction you want in the file selection.
textarea JTextArea A string containing the number of rows of the textarea. By default, it's 5. Contents of text area.
checkbox JCheckBox None. "true" if check box is selected, "false" otherwise.
radio JRadioButton A string with the name of the radio button group where the group will be added. The group is created automatically. The index of the button in the group.
combo JComboBox A string with a colon-separated list of values available in the combo box. The string value of the selected item.
ecombo JComboBox (editable) A string with a colon-separated list of values available in the combo box. The string value of the selected item.
label JLabel None. The property string is also not used for this type None.
sep A separator line. The property string is not necessary for this type. None. None.

It is possible to use custom types. In this case, the subclass should override createComponent(String,String,String,String) and create the desired component.

By default, the properties are stored in jEdit's properties. The implementor can call setPropertyStore(Properties) to set the properties object from where the values will be read and to where they will be written. Just remembed to call this method before the _init() method is called, i.e., before the pane is shown.

By default, if the contents of a text field are empty, the class will treat that as asking to "unset" the property, so retrieving its value from the store will return null. To control that, call setEmptyToNull(boolean) appropriately.

Since:
CC 0.9.4
Version:
$Id$
Author:
Marcelo Vanzin
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class org.gjt.sp.jedit.AbstractOptionPane
gridBag, initialized, y
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
EasyOptionPane(java.lang.String name)
          Creates an empty option pane.
EasyOptionPane(java.lang.String name, java.util.List components)
          Creates an empty option pane with the given component list.
EasyOptionPane(java.lang.String name, java.lang.String components)
          Creates an empty option pane with the given component list.
 
Method Summary
 void _init()
           
 void _save()
           
protected  void cleanup()
          Removes all properties related to a component as defined in the component spec list.
protected  java.lang.Object createComponent(java.lang.String type, java.lang.String label, java.lang.String value, java.lang.String config)
          If an unknown type is found in the component spec, this method will be called.
protected  java.lang.Object getComponent(java.lang.String prop)
          Returns the instance of the component that has been linked to the given property name.
protected  java.lang.String getProperty(java.lang.String name, java.lang.String dflt)
          Returns the value of the named property in the internal property store, of the given default value if the value is null.
protected  java.lang.String parseComponent(java.lang.Object comp, java.lang.String name)
          This method is called to transform the contents of a component into a string to be persisted.
protected  void removeProperty(java.lang.String name)
          Removes the named property from the internal property store.
protected  void setComponentSpec(java.util.List components)
          Sets the internal component spec list.
 void setEmptyToNull(boolean flag)
          Sets whether empty strings in text fields should be converted to "null" when saving the values.
protected  void setProperty(java.lang.String name, java.lang.String val)
          Sets the value of the named property in the internal property store.
protected  void setPropertyStore(java.util.Properties p)
          Sets the properties object where the properties will be saved to.
 
Methods inherited from class org.gjt.sp.jedit.AbstractOptionPane
addComponent, addComponent, addComponent, addComponent, addComponent, addComponent, addSeparator, addSeparator, getComponent, getName, init, save
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EasyOptionPane

public EasyOptionPane(java.lang.String name)
Creates an empty option pane.

Parameters:
name - Internal options pane name.

EasyOptionPane

public EasyOptionPane(java.lang.String name,
                      java.lang.String components)
Creates an empty option pane with the given component list.

Parameters:
name - Internal options pane name.
components - String with whitespace-delimited component specs, as described in the javadoc for the class.

EasyOptionPane

public EasyOptionPane(java.lang.String name,
                      java.util.List components)
Creates an empty option pane with the given component list.

Parameters:
name - Internal options pane name.
components - List of component specs, as described in the javadoc for the class.
Method Detail

_init

public void _init()

_save

public void _save()

setEmptyToNull

public void setEmptyToNull(boolean flag)
Sets whether empty strings in text fields should be converted to "null" when saving the values. This means the property will be "unset" is it's empty.


setComponentSpec

protected void setComponentSpec(java.util.List components)
Sets the internal component spec list. This will overwrite the existing list, if any. The behavior of the pane is undefined if this is called after _init() has been called.


setPropertyStore

protected void setPropertyStore(java.util.Properties p)
Sets the properties object where the properties will be saved to. If the object is null, the jEdit properties store will be used.


getComponent

protected java.lang.Object getComponent(java.lang.String prop)
Returns the instance of the component that has been linked to the given property name. This will return null if called before _init(). This might not return a JComponent if the property is for a radio group (in which case it returns a ButtonGroup).


getProperty

protected java.lang.String getProperty(java.lang.String name,
                                       java.lang.String dflt)
Returns the value of the named property in the internal property store, of the given default value if the value is null.


setProperty

protected void setProperty(java.lang.String name,
                           java.lang.String val)
Sets the value of the named property in the internal property store.


removeProperty

protected void removeProperty(java.lang.String name)
Removes the named property from the internal property store.


cleanup

protected void cleanup()
Removes all properties related to a component as defined in the component spec list. If called before _init(), this does nothing.


createComponent

protected java.lang.Object createComponent(java.lang.String type,
                                           java.lang.String label,
                                           java.lang.String value,
                                           java.lang.String config)
If an unknown type is found in the component spec, this method will be called. If it returns any object, the object will be added to the component map, but nothing will be automatically added to the GUI. If null is returned, an error will be logged.

Parameters:
type - The type string from the spec.
label - The label string (not the key for lookup!).
value - The value of the property, retrieved from the store.
config - The config string from the spec.

parseComponent

protected java.lang.String parseComponent(java.lang.Object comp,
                                          java.lang.String name)
This method is called to transform the contents of a component into a string to be persisted. The default implementation understands all the available types described in this class's javadoc. If you need special treatment for some specific component, or you added a custom component that is not handled by the default implementation, override this method.

Parameters:
comp - The component added to the component map.
name - The name of the property attached to the component.