dsto.dfc.swing.forms
Class MultiplexFormEditor

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by dsto.dfc.swing.forms.FormPanel
                      extended by dsto.dfc.swing.forms.MultiplexFormEditor
All Implemented Interfaces:
Form, FormEditor, FormEditorListener, Disposable, ImageObserver, MenuContainer, Customizer, Serializable, EventListener, Accessible

public class MultiplexFormEditor
extends FormPanel
implements FormEditorListener, Disposable

A form editor that allows selection from a number of different predefined value types. The possible values are presented in a tab pane, with the editor for each sort of value in each tab. As the user selects different tabs, the editor value is switched to the value contained in the tab, and the new value's editor is activated, allowing the user to customize the value.

Editors may be added by adding "template" editor values via addEditorValue(java.lang.Object), which adds the value as a template for new ones and adds an editor for the value using its BeanInfo customizer. A slightly more intuitive way is to simply add an editor using Component.add (editor, null), ensuring first that the editor has a sensible default value loaded (ie not null). This also allows editors to be added using visual GUI designers.

The tab name and icon for the editor are chosen from the icon and display name specified by the editor's BeanInfo. If none are specified, and the editor value is Iconic, then the icon and name from this is used instead. Example

This editor could be used in the case where a property of type Book is being edited on a BookOrder bean. If Book is an interface with two concrete implementations, Novel and Magazine, this editor could be used as follows:


 ArrayList bookTemplates = new ArrayList ();

 bookTemplates.add (new Magazine ("New Magazine"));
 bookTemplates.add (new Novel ("New Novel"));

 MultiplexFormEditor bookEditor =
   new MultiplexFormEditor (bookTemplates);

 Form orderForm = ...;
 BookOrder order = ...;

 orderForm.addEditor ("book", bookEditor);
 orderForm.setEditorValue (order);

 
This would allow the user to select either a Novel or a Magazine as the value of "book" on a BookOrder and to set whatever specific properties are available on each.

Version:
$Revision$
See Also:
Serialized Form

Nested Class Summary
 
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
protected  FormEditor activeEditor
           
protected  ArrayList editors
           
protected  ArrayList editorValues
           
protected  boolean tabListenerEnabled
           
protected  JTabbedPane tabPane
           
 
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
MultiplexFormEditor()
           
MultiplexFormEditor(List editorValues)
          Creates a new MultiplexFormEditor.
 
Method Summary
 void addEditorValue(Object newValue)
          Add a new editor template value.
protected  void addImpl(Component component, Object constraint, int index)
           
protected  void addNewEditor(FormEditor editor)
          Adds a FormEditor to the end of the editor list.
 void commitEdits()
          Commit any changes not already committed into the value of this editor (eg a text editor will attempt to perform any uncommitted text conversions at this point).
 void dispose()
          Dispose of the object (unregister listeners, close open resources etc).
 void editCommitRequested(ChangeEvent e)
          Signals that the editor is ready to commit a value into the model.
 void editCommitted(ChangeEvent e)
          Signals that an edit has been committed into the model.
 Component getEditorComponent()
          Get the component, if any, that acts as a UI for this editor.
 Object getEditorValue()
          Get the current value from the form editor.
protected  int getIndexForValue(Class valueClass)
          Get the index for a given editor class (corresponds to index into strategies list and index of editor tab in tab pane).
 JTabbedPane getTabPane()
           
 boolean isDirectEdit()
          True if the editor directly edits the value passed in with setValue ().
 void setEditorValue(Object newValue)
          Sets the current editor value.
protected  void tabChanged(ChangeEvent e)
          Called when selected tab changes.
 
Methods inherited from class dsto.dfc.swing.forms.FormPanel
addEditor, addEditor, addFormEditorListener, fireEditComitted, fireEditCommitRequested, fireEditCommitted, getEditorDescription, getPreferredValueType, isDeferredCommit, removeEditor, removeFormEditorListener, setDeferredCommit, setDirectEdit, setObject
 
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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, setEnabled, 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, 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, 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, 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, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.beans.Customizer
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

tabPane

protected JTabbedPane tabPane

activeEditor

protected FormEditor activeEditor

editorValues

protected ArrayList editorValues

editors

protected ArrayList editors

tabListenerEnabled

protected boolean tabListenerEnabled
Constructor Detail

MultiplexFormEditor

public MultiplexFormEditor()

MultiplexFormEditor

public MultiplexFormEditor(List editorValues)
Creates a new MultiplexFormEditor.

Parameters:
editorValues - The editor template values. These should be of different classes and must also be cloneable (preferably Copyable). A tab and an editor is created for each value type. The editor is the value's Bean customizer, which must also implement the FormEditor interface. The name and icon for the tab come either via the Iconic interface (if implemented) or from the JavaBean 16x16 icon and display name.
See Also:
addEditorValue(java.lang.Object)
Method Detail

dispose

public void dispose()
Description copied from interface: Disposable
Dispose of the object (unregister listeners, close open resources etc). It should be safe to call this method more than once. Note for beans that support client event listeners: if there are listeners registered when this is called, this method should do nothing.

Specified by:
dispose in interface Disposable
Overrides:
dispose in class FormPanel

addImpl

protected void addImpl(Component component,
                       Object constraint,
                       int index)
Overrides:
addImpl in class Container

addEditorValue

public void addEditorValue(Object newValue)
Add a new editor template value.

See Also:
MultiplexFormEditor(List)

getTabPane

public JTabbedPane getTabPane()

isDirectEdit

public boolean isDirectEdit()
Description copied from interface: FormEditor
True if the editor directly edits the value passed in with setValue (). If false, the parent editor will be reponsible for retrieving the value from the editor and storing it.

Specified by:
isDirectEdit in interface FormEditor
Overrides:
isDirectEdit in class FormPanel

setEditorValue

public void setEditorValue(Object newValue)
                    throws IllegalFormatException
Sets the current editor value. If the value (current or new) is unknown, then it will be added to the list of known ones and a new customiser tab panel will be added for it.

Specified by:
setEditorValue in interface FormEditor
Overrides:
setEditorValue in class FormPanel
Parameters:
newValue - The value to display.
Throws:
IllegalFormatException - if the value was not in the correct format for display by this editor. The source specified by the exception should be this FormEditor instance or a child.

getEditorValue

public Object getEditorValue()
Description copied from interface: FormEditor
Get the current value from the form editor. At least one call to setValue () must be made beforehand.

Specified by:
getEditorValue in interface FormEditor
Overrides:
getEditorValue in class FormPanel

commitEdits

public void commitEdits()
                 throws IllegalFormatException
Description copied from interface: FormEditor
Commit any changes not already committed into the value of this editor (eg a text editor will attempt to perform any uncommitted text conversions at this point). Only editors that need support editing in non-atomic sessions (such as text fields) will generally do anything when this method is called. If commit is made that has not been signalled with a previous editCommitted event, the editor should fire an editCommitted event at this point. Composite editors, such as forms, will generally forward this request to their child editors.

Specified by:
commitEdits in interface FormEditor
Overrides:
commitEdits in class FormPanel
Throws:
IllegalFormatException - if the commit failed because of an illegal input or other error. The source specified by the exception should be the FormEditor instance that caused the error (ie either this editor or a child).

getEditorComponent

public Component getEditorComponent()
Description copied from interface: FormEditor
Get the component, if any, that acts as a UI for this editor. May return null if not associated with a component.

Specified by:
getEditorComponent in interface FormEditor
Overrides:
getEditorComponent in class FormPanel

editCommitted

public void editCommitted(ChangeEvent e)
Description copied from interface: FormEditorListener
Signals that an edit has been committed into the model.

Specified by:
editCommitted in interface FormEditorListener

editCommitRequested

public void editCommitRequested(ChangeEvent e)
Description copied from interface: FormEditorListener
Signals that the editor is ready to commit a value into the model. Parent editors monitor will invoke commitEdits () on the the requesting editor if appropriate.

Specified by:
editCommitRequested in interface FormEditorListener

addNewEditor

protected void addNewEditor(FormEditor editor)
Adds a FormEditor to the end of the editor list.


getIndexForValue

protected int getIndexForValue(Class valueClass)
Get the index for a given editor class (corresponds to index into strategies list and index of editor tab in tab pane).


tabChanged

protected void tabChanged(ChangeEvent e)
Called when selected tab changes.



Copyright © 2008 Commonwealth of Australia