qflib 0.98.1

de.qfs.lib.option
Class OptionEdit

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--de.qfs.lib.option.OptionEdit
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
BooleanOptionEdit, ChoiceOptionEdit, KeyOptionEdit, SimpleOptionEdit, TableOptionEdit

public abstract class OptionEdit
extends javax.swing.JPanel

An OptionEdit is a component used to edit an Option's value.

An OptionGroup can be used to group OptionEdits into a larger component, which in turn can be used inside an OptionDialog. The layout and labels of the OptionEdits and OptionGroups are determined by a set of resources set with Option.setResources. See the package documentation for details about the resource names used.

OptionEdit uses a ClassWrapper to create specialiced OptionEdits via makeEdit. The AWT component name of an OptionEdit created with makeEdit is initialized to "OptionEdit-<name>" where <name> is the name of the option being edited. It is up to the derived classes to set expressive names on their child components in the style "Label-<name>", "Text-<name>" etc.

You will rarely need to use this class directly, except for deriving a specialized OptionEdit for a custom Option of your own design.

Version:
$Revision: 1.14 $
Author:
Gregor Schmid
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  boolean disabled
          Whether the edit is permanently disabled.
protected  OptionGroup group
          The OptionGroup to which the edit belongs.
protected  Option option
          The Option to edit.
 
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
protected OptionEdit()
          Hidden constructor.
 
Method Summary
static void addPackage(java.lang.String packagename)
          Add a package to be searched for OptionEdit classes, to enable OptionEdits for user defined Options outside of the de.qfs.lib.option package.
abstract  boolean checkValue()
          Check the currently entered value of the OptionEdit.
protected  boolean getBoolean(java.lang.String res, boolean dflt)
          Get a boolean resource from the Option resources.
protected  int getInt(java.lang.String res, int dflt)
          Get an int resource from the Option resources.
 Option getOption()
          Get the Option that is being edited by this OptionEdit.
 OptionGroup getOptionGroup()
          Get the OptionGroup to which the edit belongs.
protected  java.lang.String getString(java.lang.String res, java.lang.String dflt)
          Get a String resource from the Option resources.
 double getWeight()
          Get the y-weight for the OptionEdit.
protected abstract  void init()
          Initialize the OptionEdit.
 boolean isDisabled()
          Query whether the edit is permanently disabled.
static OptionEdit makeEdit(Option option)
          A factory method that dynamically creates an OptionEdit for an Option.
abstract  void readValue()
          Read the currently entered value and store it in the Option.
 void setDisabled(boolean disabled)
          Set whether theedit is permanently disabled.
 void setOptionGroup(OptionGroup group)
          Set the OptionGroup to which the edit belongs.
abstract  void update(Option option)
          Update the display of the edit component after a possible change of its Option or the Option's value.
 void update(OptionSet options)
          Update the display of the edit component after a possible change of its Option or the Option's value.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, 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, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

disabled

protected boolean disabled
Whether the edit is permanently disabled. If this flag is true, setEnabled will be forced to disable the edit.

option

protected Option option
The Option to edit.

group

protected OptionGroup group
The OptionGroup to which the edit belongs.
Constructor Detail

OptionEdit

protected OptionEdit()
Hidden constructor. Use makeEdit to create OptionEdits.
Method Detail

makeEdit

public static OptionEdit makeEdit(Option option)
A factory method that dynamically creates an OptionEdit for an Option. The class of the edit component will be determined either by the resource named option.name.edit.class, or by adding "Edit" to the (unqualified) class name of the Option. If you want to provide OptionEdits for new Option types outside the de.qfs.lib.option package you can either do so by setting the resource, by having your Option implement ClassWrapperAware or by adding the package of your OptionEdit with addPackage.

After the OptionEdit instance is created its option member is set and it is initialized through init.

Parameters:
option - The object to create an OptionEdit for.
Returns:
The new OptionEdit or null if no matching class could be found.
See Also:
ClassWrapper

addPackage

public static void addPackage(java.lang.String packagename)
Add a package to be searched for OptionEdit classes, to enable OptionEdits for user defined Options outside of the de.qfs.lib.option package. Packages added later are considered more specific and are searched first.
Parameters:
packagename - The name of the package to add.
See Also:
ClassWrapper.addPackage(java.lang.String)

getOption

public Option getOption()
Get the Option that is being edited by this OptionEdit.
Returns:
The Option being edited.

update

public void update(OptionSet options)
Update the display of the edit component after a possible change of its Option or the Option's value.
Parameters:
options - The OptionSet containing the (possibly new) option.

isDisabled

public boolean isDisabled()
Query whether the edit is permanently disabled. In this case it will force calls to setEnabled to disable the group.
Returns:
True if the OptionGroup is disabled.
Since:
0.98.0

setDisabled

public void setDisabled(boolean disabled)
Set whether theedit is permanently disabled. In this case it will force calls to setEnabled to disable the group.
Parameters:
disabled - True to disable the group. If true, setEnabled(false) is called automatically.
Since:
0.98.0

getOptionGroup

public OptionGroup getOptionGroup()
Get the OptionGroup to which the edit belongs.
Returns:
The edit's OptionGroup.
Since:
0.98.0

setOptionGroup

public void setOptionGroup(OptionGroup group)
Set the OptionGroup to which the edit belongs.
Parameters:
group - The OptionGroup to set.
Since:
0.98.0

getWeight

public double getWeight()
Get the y-weight for the OptionEdit.
Returns:
The default weight is 0.0, unless overridden in a derived class.
Since:
0.98.0

init

protected abstract void init()
Initialize the OptionEdit. This method is called by the makeEdit factory method after the option member has been set.

Must be implemented by a derived class.


update

public abstract void update(Option option)
Update the display of the edit component after a possible change of its Option or the Option's value.

Must be implemented by a derived class.

Parameters:
option - The (possibly new) option.

checkValue

public abstract boolean checkValue()
Check the currently entered value of the OptionEdit. If the value is not valid, request the focus. The OptionEdit should check the value against its own constraints as well as pass it to Option.checkValue.

Must be implemented by a derived class.

Returns:
True if the value is valid, false otherwise.

readValue

public abstract void readValue()
Read the currently entered value and store it in the Option.

Must be implemented by a derived class.


getString

protected java.lang.String getString(java.lang.String res,
                                     java.lang.String dflt)
Get a String resource from the Option resources. The resource name is built as "option.group.groupname.res"
Parameters:
res - The last part of the resource name.
dflt - Default value if the resource is undefined.
Returns:
The sresource value.
Since:
0.98.1

getBoolean

protected boolean getBoolean(java.lang.String res,
                             boolean dflt)
Get a boolean resource from the Option resources. The resource name is built as "option.group.groupname.res"
Parameters:
res - The last part of the resource name.
dflt - Default value if the resource is undefined.
Returns:
The sresource value.
Since:
0.98.1

getInt

protected int getInt(java.lang.String res,
                     int dflt)
Get an int resource from the Option resources. The resource name is built as "option.group.groupname.res"
Parameters:
res - The last part of the resource name.
dflt - Default value if the resource is undefined.
Returns:
The sresource value.
Since:
0.98.1

qflib 0.98.1