QJCC homepage

biz.chitec.quarterback.swing
Class PropertiesEditorXML

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bybiz.chitec.quarterback.swing.PropertiesEditorXML
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class PropertiesEditorXML
extends javax.swing.JPanel

An I18N-aware editor widget for Properties or similar stuff configured by an XML description. Useable for all kinds of configuration settings where the settings are stored in a Properties or a Map object. The editor is a "standard" JPanel from the outside. The properties are feeded in and read out using the setProperties() or getProperties() method or something similar. The editor shows the editing fields either flat on the panel or in several tabs in a tabbed pane.

The outfit of the editor is controlled by an XML description. That one is either given directly in the constructor or in the init() method. the XML file is only vaguely defined, there is currently no DTD or something like this. The following five tags are allowed:

The evaluation of tag names and attribute names happens case-independant.

The editor gets all of its printable strings from a ResourceBundle. That one is given at construction time and evaluated using the RB class. If PropertiesEditorXML got a prefix during initialisation, every request to the ResourceBundle is prepended by that prefix, followed by a dot. The bundle should contain a ".label" entry for each name which is taken for the label left to the editing component. Additionally, a ".help" entry can be provided for showing some online help. All additional names, e.g. page tab titles or combo box entries, are taken without any further prefixes (apart from the global one described above).

PropertiesEditorXML uses the SAX framework for parsing the XML input. If you want to set the XML parser class explicitly, use the statix setXMLParserClass() method in advance to any instantiation. PropertiesEditorXML keeps only one XML parser instance for all editors, so all editors must be instantiated from the same thread (usually the AWT event dispatching thread).

For dynamic configurations, three item types exist: CUSTOMCOMBO, EXTERNALCOMBO, and EXTERNALDOUBLECOMBO. The "custom" type takes a list of Strings and shows them verbatim. It is feeded by directly by setCustomCombo(), which gets the key of the property as parameter. The data is taken only for this combo box.

The two "external" types are working differently. First, they work with Lists of NumberedStrings. So, only the numeric value is stored, but a String is presented. Then, these selection take their alternatives from a map of containers.

The class features a static method editProperties(), which renders a complete modal dialog allowing the editing of a given Properties bundle. It can be used as a convenience shortcut for many standard configuration scenarios.

PropertiesEditorXML is a very powerful and versatile class. It is the next step in a long list of such configuration editor classes in the QJCC and its predecessors. Its direct ancestor, PropertiesEditor, did almost the same things, but was completely ResourceBundle driven. After all, this lead to horrible and absolutely unmaintainable ResourceBundle files. Therefore, PropertiesEditorXML now tries to cleanup this situation.

Version:
$Id: 7c7fea94f21e97c27544a2ef6f81c0d05f380704 $
Author:
cantamen/Dirk Hillbrecht 2004-2005. Distributed under the terms of the GNU LGPL.
See Also:
Serialized Form

Nested Class Summary
static class PropertiesEditorXML.DotLabelResourceBundle
          Helper class which allows to use resource bundles where the resource names do not have the ".label" suffix in their key.
private static interface PropertiesEditorXML.ExternalCombo
           
private  class PropertiesEditorXML.ExternalComboBox
           
private  class PropertiesEditorXML.ExternalDoubleComboBox
           
private  class PropertiesEditorXML.FileNameChoice
          Editor component to set up a font setting.
private  class PropertiesEditorXML.FontChoice
          Editor component to set up a font setting.
private  class PropertiesEditorXML.HelpTextPresenter
          Clever focus listener for elements to show appropriate help.
private  class PropertiesEditorXML.KeyStrokeEditor
           
private static class PropertiesEditorXML.LookAndFeelComboBox
          Editor field for selecting a "Look'n'feel".
private  class PropertiesEditorXML.MultiLineEditor
           
private static class PropertiesEditorXML.MyFileFilter
          File filter looking for file extensions or directories only.
private  class PropertiesEditorXML.PropertyControlBuilder
          The XML parsing callback container.
private  class PropertiesEditorXML.PropertyControlElement
          Holder of one widget to control a property.
 
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
private  java.util.ResourceBundle baserb
           
private static int BOOL
           
private static int COMBO
           
private static int CUSTOMCOMBO
           
private  java.util.Map customcombos
           
private static int EXTERNALCOMBO
           
private  java.util.Set externalcombos
           
private  java.util.Map externaldata
           
private static int EXTERNALDOUBLECOMBO
           
private static int FILENAME
           
private static int FLOAT
           
private static int FONT
           
private static java.lang.String[] fontnames
           
private  JLabeller footer
           
private  javax.swing.JComponent helppane
           
private  javax.swing.JTextArea helptextarea
           
private  PropertiesEditorXML.HelpTextPresenter helptextpresenter
           
private static int INT
           
private static javax.swing.ComboBoxModel interimcbm
           
private static int KEYSTROKE
           
private  KeyStrokeReader keystrokereader
           
private static int LNF
           
private static int LOCALE
           
private static int MULTILINE
           
private  java.lang.String prefix
           
private  java.util.List propertycontrolers
           
private static java.util.List proptypelist
           
private  java.util.ResourceBundle rb
           
private static boolean reloadxmlreader
           
private static int SLAFTHEME
           
private static java.lang.String[] slafthemes
           
private static int STRING
           
private static org.xml.sax.XMLReader xmlreader
           
private static java.lang.String xmlreaderclassname
           
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
  PropertiesEditorXML()
          Initializes with own ResourceBundle only and empty prefix.
  PropertiesEditorXML(java.util.ResourceBundle rbx)
          Constructor for the PropertiesEditor object.
  PropertiesEditorXML(java.util.ResourceBundle rbx, org.xml.sax.InputSource isx)
          Initializes with ResourceBundle, empty prefix and the XML source for the layout.
  PropertiesEditorXML(java.util.ResourceBundle rbx, java.lang.String prefixx)
          Constructor for the PropertiesEditor object
  PropertiesEditorXML(java.util.ResourceBundle rbx, java.lang.String prefixx, org.xml.sax.InputSource isx)
          Initializes with ResourceBundle, prefix and the XML source for the layout.
protected PropertiesEditorXML(java.lang.String prefix)
          Initializes with own ResourceBundle only and a custom prefix.
 
Method Summary
static void editProperties(java.util.Properties inputprops, java.awt.Frame parent, java.util.ResourceBundle rb, org.xml.sax.InputSource is, java.lang.String prefix, java.util.Map customs, java.awt.event.ActionListener al)
          Shows a complete modal dialog allowing to edit the given properties.
 java.util.Properties fillProperties(java.util.Properties props)
          Fill properties of editor into existing Properties.
private static java.awt.Component getFocusComponentForJComboBox(javax.swing.JComboBox box)
          Helper method to work around a problem with Metal-JCombo-boxes and focus handling.
 java.util.Map getMap()
          Deprecated. Use getProperties() instead
 java.util.Properties getProperties()
          Get all properties back from the editor.
private  java.lang.String getRBStringWithPrefix(java.lang.String x)
           
protected  java.util.Map getValues(java.util.Map props)
          Get all the values internally.
 void init(org.xml.sax.InputSource is)
          Initializes the visible layout using the given XML-driven InputSource.
 void setCustomCombo(java.lang.String prop, java.util.List content)
          Sets the selectable alternatives for a custom combo field.
 void setExternalData(java.util.Map edx)
          Sets the selections for EXTERNALCOMBO and EXTERNALDOUBLECOMBO The given Map contains the keys for the respective selection elements of the properties dialog.
 void setFooter(JLabeller f)
          Set a footer to print error messages to.
 void setMap(java.util.Map props)
          Deprecated. Use setProperties instead.
 void setProperties(java.util.Map props)
          Set data to show.
 void setProperties(java.util.Map props, boolean forceset)
          Set data to show.
 void setResourceBundle(java.util.ResourceBundle rbx)
          Sets the ResourceBundle with the Propertie's localized names explicitly.
static void setXMLParserClass(java.lang.String parserclassname)
          Sets the XML parser class explicitly and internally initializes the parser.
static void setXMLReaderReload(boolean b)
          If true, reloads the XML reader each time a Properties editor is opened.
 void showHelp(boolean doshow)
          Should help window been shown?
 
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, getName, 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
 

Field Detail

interimcbm

private static final javax.swing.ComboBoxModel interimcbm

slafthemes

private static final java.lang.String[] slafthemes

INT

private static final int INT
See Also:
Constant Field Values

STRING

private static final int STRING
See Also:
Constant Field Values

BOOL

private static final int BOOL
See Also:
Constant Field Values

COMBO

private static final int COMBO
See Also:
Constant Field Values

FONT

private static final int FONT
See Also:
Constant Field Values

LNF

private static final int LNF
See Also:
Constant Field Values

SLAFTHEME

private static final int SLAFTHEME
See Also:
Constant Field Values

CUSTOMCOMBO

private static final int CUSTOMCOMBO
See Also:
Constant Field Values

FILENAME

private static final int FILENAME
See Also:
Constant Field Values

LOCALE

private static final int LOCALE
See Also:
Constant Field Values

EXTERNALCOMBO

private static final int EXTERNALCOMBO
See Also:
Constant Field Values

EXTERNALDOUBLECOMBO

private static final int EXTERNALDOUBLECOMBO
See Also:
Constant Field Values

MULTILINE

private static final int MULTILINE
See Also:
Constant Field Values

FLOAT

private static final int FLOAT
See Also:
Constant Field Values

KEYSTROKE

private static final int KEYSTROKE
See Also:
Constant Field Values

proptypelist

private static final java.util.List proptypelist

fontnames

private static java.lang.String[] fontnames

xmlreader

private static org.xml.sax.XMLReader xmlreader

xmlreaderclassname

private static java.lang.String xmlreaderclassname

reloadxmlreader

private static boolean reloadxmlreader

propertycontrolers

private java.util.List propertycontrolers

customcombos

private java.util.Map customcombos

externalcombos

private java.util.Set externalcombos

externaldata

private java.util.Map externaldata

baserb

private java.util.ResourceBundle baserb

rb

private java.util.ResourceBundle rb

footer

private JLabeller footer

helptextarea

private javax.swing.JTextArea helptextarea

helppane

private javax.swing.JComponent helppane

prefix

private java.lang.String prefix

helptextpresenter

private PropertiesEditorXML.HelpTextPresenter helptextpresenter

keystrokereader

private KeyStrokeReader keystrokereader
Constructor Detail

PropertiesEditorXML

public PropertiesEditorXML(java.util.ResourceBundle rbx,
                           java.lang.String prefixx)
Constructor for the PropertiesEditor object

Parameters:
rbx - The resource bundle with the properties configuration
prefixx - The ressources' names prefix

PropertiesEditorXML

public PropertiesEditorXML(java.util.ResourceBundle rbx)
Constructor for the PropertiesEditor object. Initializes with empty prefix

Parameters:
rbx - The resource bundle with the properties configuration

PropertiesEditorXML

protected PropertiesEditorXML(java.lang.String prefix)
Initializes with own ResourceBundle only and a custom prefix. This is only sensible for derived classes which bring their own ResourceBundle with them.

Parameters:
prefix - prefix for all entries in the ResourceBundle

PropertiesEditorXML

public PropertiesEditorXML()
Initializes with own ResourceBundle only and empty prefix.


PropertiesEditorXML

public PropertiesEditorXML(java.util.ResourceBundle rbx,
                           java.lang.String prefixx,
                           org.xml.sax.InputSource isx)
Initializes with ResourceBundle, prefix and the XML source for the layout.


PropertiesEditorXML

public PropertiesEditorXML(java.util.ResourceBundle rbx,
                           org.xml.sax.InputSource isx)
Initializes with ResourceBundle, empty prefix and the XML source for the layout.

Method Detail

setXMLParserClass

public static void setXMLParserClass(java.lang.String parserclassname)
                              throws org.xml.sax.SAXException
Sets the XML parser class explicitly and internally initializes the parser. This method must be called if the XML parser should NOT be determined by the SAX framework itself using the environment property "org.xml.sax.parser". The XML parser is initialized from given class name.

Parameters:
parserclassname - Name of the XML parser class
Throws:
org.xml.sax.SAXException - Thrown if the parser could not be initialized for any reason

setXMLReaderReload

public static void setXMLReaderReload(boolean b)
If true, reloads the XML reader each time a Properties editor is opened. Needed for certain broken parsers (Piccolo...)

Parameters:
b -

setResourceBundle

public void setResourceBundle(java.util.ResourceBundle rbx)
Sets the ResourceBundle with the Propertie's localized names explicitly. This method can be called indepedently from the constructor but it must be called before the init() method is executed.

Parameters:
rbx - ResourceBundle with the localized names of the properties

init

public void init(org.xml.sax.InputSource is)
Initializes the visible layout using the given XML-driven InputSource. If no specific parser class has been set before using setXMLParserClass, this method initializes the XML parser in the first call itself.

Note: PropertiesEditorXML does only use ONE XML parser for all parsing attempts done ever. Therefore, init() must never be called in parallel from different threads. As it will be called usually in the AWT event tread, this should not be that big problem anyway.

Parameters:
is - The input source with the XML data describing the properties editor.

setFooter

public void setFooter(JLabeller f)
Set a footer to print error messages to.

Parameters:
f - The new footer value

showHelp

public void showHelp(boolean doshow)
Should help window been shown?

Parameters:
doshow - true to show, false to hide

setCustomCombo

public void setCustomCombo(java.lang.String prop,
                           java.util.List content)
Sets the selectable alternatives for a custom combo field. Should be called before the data to show is loaded. If called afterwards, tries to preserve selection.

Parameters:
prop - The property name for which the alternatives are given.
content - The selectable alternatives. Will be shown in given order.

setExternalData

public void setExternalData(java.util.Map edx)
Sets the selections for EXTERNALCOMBO and EXTERNALDOUBLECOMBO The given Map contains the keys for the respective selection elements of the properties dialog. For single combo boxes, the value of the key is a List of NumberedStrings. These are put into the ComboBox. For double combo boxes, each key's value is an alternating List of NumberedStrings and Lists containing themselves NumberedStrings again. The direct NumberedStrings are the selections of the left ComboBox, the Lists of NumberedStrings are the selections of the right ComboBox which are shown if the associated value of the left ComboBox is selected.

Parameters:
edx - Map of settings for selections

setMap

public void setMap(java.util.Map props)
Deprecated. Use setProperties instead.

Set data to show.

Parameters:
props - The new hashtable value

setProperties

public void setProperties(java.util.Map props,
                          boolean forceset)
Set data to show. The fields on the Editor are filled with the data in the Properties object. Without forceset, only the fields which are mentioned in the given map are actually changed. If forceset is set, all fields are forced to a value. In this case, if no data exist for a certain setting, the control is set to blank, false or the first available choice.

Parameters:
props - The new properties value
forceset - Flag whether all fields should be set or only the ones which have values in the given map.

setProperties

public void setProperties(java.util.Map props)
Set data to show. All fields on the Editor are filled with the data in the Properties object. If no data exist for a certain setting, the control is set to blank, false or the first available choice.

Parameters:
props - The new properties value

getProperties

public java.util.Properties getProperties()
Get all properties back from the editor.

Returns:
The properties value

getMap

public java.util.Map getMap()
Deprecated. Use getProperties() instead

Get all properties back from the editor.

Returns:
The hashtable value

fillProperties

public java.util.Properties fillProperties(java.util.Properties props)
Fill properties of editor into existing Properties. Note that this will overwrite all selectable parameters with the values inserted here.

Parameters:
props - The Properties table to write in
Returns:
The changed Properties class

getValues

protected java.util.Map getValues(java.util.Map props)
Get all the values internally. Does the work for getProperties() and getMap().

Parameters:
props - Description of the Parameter
Returns:
The values value

getRBStringWithPrefix

private java.lang.String getRBStringWithPrefix(java.lang.String x)

getFocusComponentForJComboBox

private static java.awt.Component getFocusComponentForJComboBox(javax.swing.JComboBox box)
Helper method to work around a problem with Metal-JCombo-boxes and focus handling. See Java bug parade #4243641.

Parameters:
box - Description of the Parameter
Returns:
The focusComponentForJComboBox value

editProperties

public static final void editProperties(java.util.Properties inputprops,
                                        java.awt.Frame parent,
                                        java.util.ResourceBundle rb,
                                        org.xml.sax.InputSource is,
                                        java.lang.String prefix,
                                        java.util.Map customs,
                                        java.awt.event.ActionListener al)
Shows a complete modal dialog allowing to edit the given properties.

Parameters:
inputprops - Properties to load into the dialog.
parent - Parent frame for the dialog.
rb - ResourceBundle with all i18n'd Strings to show.
is - InputSource with the XML-based layout descriptions.
prefix - Prefix for the ResourceBundle strings. May be empty or null.
customs - Content for the CUSTOMCOMBO-controls. May be null.
al - ActionListener called when OK is pressed. EventSource is the PropertiesEditor, the ActionListener has store the data from the dialog somehow. May be null, but that does not make that much sense...

QJCC homepage