com.tensegrity.gui
Class DefaultUIManager

java.lang.Object
  extended bycom.tensegrity.gui.DefaultUIManager
All Implemented Interfaces:
UIManager
Direct Known Subclasses:
DummyUIManager, SwtDefaultUIManager

public class DefaultUIManager
extends java.lang.Object
implements UIManager

An sample implementation on how a UIManager could look like.

Version:
$Id: DefaultUIManager.java,v 1.38 2006/03/14 14:46:33 MichaelKegel Exp $
Author:
GillesIachelini, BurkhardWick
See Also:
UIItemEvaluationList

Field Summary
 UIItemList itemList
          List of GUIItems which will be used to determine textual representation.
 
Constructor Summary
DefaultUIManager()
          Creates the UIManager.
 
Method Summary
 void apply(javax.swing.AbstractButton button, java.lang.String idText)
          Applies the text from the UIItem identified by the given id to the passed button instance.
 void apply(javax.swing.JLabel label, java.lang.String idText)
          Method apply applies a text resource to a JLabel.
 void apply(javax.swing.JLabel label, java.lang.String idText, java.awt.Component labelFor)
          Creates a new JLabel for a given Component by using the UIItems textual information as text for the label.
 void applyItem(java.lang.String id, java.lang.Object cp)
          Sets the values from the UIItem with the parameter id from the internal ItemList to the given Component.
 void applyItem(UIItemList guiItems, java.lang.String guiObjID, java.awt.Component guiObj)
          Invokes applyItem(Component,UIItem,Font,boolean) with the subcomponent flag set to false.
 boolean containsKey(java.lang.String key)
          Checks if the specified key has a corresponding localized text.
 java.lang.Object createIcon(java.lang.Class clazz, java.lang.String iconURL)
          Factory method for creating an Icon.
 java.lang.Object createLocalizedIcon(java.lang.Class refClass, java.lang.String iconURLKey)
          Factory method for creating a new icon.
static UIItem getItem(UIItemList listItems, java.lang.String id)
          Returns the UIItem from the UIItemList which matches the given id.
 UIItemList getItemList()
          Returns the UIItemList field.
 KeyStroke getKeyStroke(java.lang.String key)
          Factory method for creating a localized Keystroke from a key.
 java.lang.String getText(java.lang.String idText)
           This method returns the localized text corresponding to the passed id.
 java.lang.String getText(java.lang.String key, java.lang.Object[] objects)
          The method returns a String for a specific key in the property files.
 java.lang.String getTextWithoutMnemonicCharacter(java.lang.String id)
          Returns a string stored in the resources using the given id.
 void setLocale(java.util.Locale locale)
          Sets the locale for this UIManager.
 void setText(java.lang.String id, java.lang.String text)
          Puts a new mapping to the map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

itemList

public UIItemList itemList
List of GUIItems which will be used to determine textual representation. This list maps ID's to UIItems. When toggling between languages, the textual representors (GUIItem's) will be retrieved from this list, to apply the right translated text to a given component.

Constructor Detail

DefaultUIManager

public DefaultUIManager()
Creates the UIManager. A new ArrayList instance will be created and stored in in itemList.

Method Detail

applyItem

public void applyItem(java.lang.String id,
                      java.lang.Object cp)
Description copied from interface: UIManager
Sets the values from the UIItem with the parameter id from the internal ItemList to the given Component. Call this method everytime when you want to initialize the associated Component instance with the (new) values from the appropriate UIItem from the UIItemList. Used by the UIItemEvaluationList.apply() and UIItemEvaluationList.apply(int).

Specified by:
applyItem in interface UIManager
Parameters:
id - the id to be used for the component.
cp - a component to apply the values to. the class of this parameter is depending on the used ui toolkit and so it has to be cast to the concrete type by the corresponding implementation

getTextWithoutMnemonicCharacter

public java.lang.String getTextWithoutMnemonicCharacter(java.lang.String id)
Returns a string stored in the resources using the given id. If the string contains an accelerator sign ('&' mnemonic character) which is indicates the keyboard shortcut for button-type of controls like menuitems, buttons, etc.

Parameters:
id - The id to look for
Returns:
The resource string without '&' characters
See Also:
UIManager.getText(java.lang.String)

getText

public java.lang.String getText(java.lang.String idText)

This method returns the localized text corresponding to the passed id. Whereas getTextWithoutMnemonicCharacter(String) returns the localized text without the accelator indication used to find mnemonics, this method returns the text with the mnemonic indicator.

Specified by:
getText in interface UIManager
Parameters:
idText -
Returns:
loocalized text corresponding to the passed id, with the mnemonic indicator

setText

public final void setText(java.lang.String id,
                          java.lang.String text)
Puts a new mapping to the map.

Specified by:
setText in interface UIManager
Parameters:
id - id for the mapping.
text - text for the mapping.

apply

public void apply(javax.swing.JLabel label,
                  java.lang.String idText)
Method apply applies a text resource to a JLabel.

Parameters:
label - the JLabel instance of which you want to apply the new text to.
idText - The id of the UIItem which holds the new text for the given label
See Also:
apply(JLabel, String, Component)

apply

public void apply(javax.swing.JLabel label,
                  java.lang.String idText,
                  java.awt.Component labelFor)
Creates a new JLabel for a given Component by using the UIItems textual information as text for the label.

Parameters:
label - The label you want to set the text and component for.
idText - The id of the associated UIItem.
labelFor - the Component instance this label is for.

apply

public void apply(javax.swing.AbstractButton button,
                  java.lang.String idText)
Applies the text from the UIItem identified by the given id to the passed button instance.

Parameters:
button - The AbstractButton instance you want to apply the new text to.
idText - the id of the UIItem to get the text from.

getItem

public static UIItem getItem(UIItemList listItems,
                             java.lang.String id)
Returns the UIItem from the UIItemList which matches the given id.

Parameters:
listItems - The UIItemList where to search the element.
id - The id which identifies the UIItem.
Returns:
UIItem The UIItem with the id or null, if no such item has been found.
See Also:
UIItemList.get(String)

applyItem

public void applyItem(UIItemList guiItems,
                      java.lang.String guiObjID,
                      java.awt.Component guiObj)
Invokes applyItem(Component,UIItem,Font,boolean) with the subcomponent flag set to false.

Parameters:
guiItems - the UIItemList holding all items.
guiObjID - String with the Gui ID
guiObj - the Component to apply the gui item to.
See Also:
UIManager.applyItem(String, Object)

getItemList

public UIItemList getItemList()
Returns the UIItemList field.

Specified by:
getItemList in interface UIManager
Returns:
UIItemList the list, this UIManager uses to maintain its items.
See Also:
UIManager.getItemList()

setLocale

public void setLocale(java.util.Locale locale)
Description copied from interface: UIManager
Sets the locale for this UIManager. This method is required to be implemented by users of this class, to let the UIManager know, to change its default resource bundle.

Specified by:
setLocale in interface UIManager
Parameters:
locale - The new Locale for the default resources.

createIcon

public java.lang.Object createIcon(java.lang.Class clazz,
                                   java.lang.String iconURL)
Description copied from interface: UIManager
Factory method for creating an Icon.

Specified by:
createIcon in interface UIManager
Parameters:
clazz - The reference class for loading
iconURL - The url relative to refClass
Returns:
instance of Icon created from the given file. the class of this value is depending on the used ui toolkit and so it has to be cast to the concrete type by the corresponding implementation

createLocalizedIcon

public java.lang.Object createLocalizedIcon(java.lang.Class refClass,
                                            java.lang.String iconURLKey)
Description copied from interface: UIManager
Factory method for creating a new icon.

Specified by:
createLocalizedIcon in interface UIManager
Parameters:
refClass - The reference class for loading
iconURLKey - The key of the resource containing the url relative to refClass
Returns:
an instance of icon created from the given file. the class of this value is depending on the used ui toolkit and so it has to be cast to the concrete type by the corresponding implementation

getKeyStroke

public KeyStroke getKeyStroke(java.lang.String key)
Factory method for creating a localized Keystroke from a key. See javax.swing.KeyStroke.getKeyStroke() for details about the format. If no vaild key in the ResourceBundle is found this method returns silently null.

Specified by:
getKeyStroke in interface UIManager
Parameters:
key - the key to use in the ResourceBundle for getting the localized Text.
Returns:
the Keystroke described by the entry in the ResourceBundle or null if no entry was found
See Also:
KeyStroke.getKeyStroke(java.lang.String)

getText

public java.lang.String getText(java.lang.String key,
                                java.lang.Object[] objects)
Description copied from interface: UIManager
The method returns a String for a specific key in the property files. The objects in the objects parameter will be parsed like described in MessageFormat.

Specified by:
getText in interface UIManager
Parameters:
key - the id of the item of which you want to retrieve the text.
objects - An array of objects to be placed as defaults.
Returns:
The string associated with the given id.
See Also:
MessageFormat

containsKey

public boolean containsKey(java.lang.String key)
Description copied from interface: UIManager
Checks if the specified key has a corresponding localized text.

Specified by:
containsKey in interface UIManager
Parameters:
key -
Returns:
true if the given key has a localized text, false otherwise


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.