com.tensegrity.gui.component
Class AttributeEditorProperties

java.lang.Object
  extended bycom.tensegrity.gui.component.AttributeEditorProperties
All Implemented Interfaces:
java.util.EventListener, java.beans.PropertyChangeListener

public class AttributeEditorProperties
extends java.lang.Object
implements java.beans.PropertyChangeListener

The AttributeEditorProperties class maintains the properties of an AttributeTable, such as hidden Attributes and Enumerations. Use the methods of this class to determine whether Attributes should be hidden, mark certain attributes to be hidden, retrieve all predefined enumerations or store newly created ones. Basically this class encapsulates a simple properties file.

This class is usually created by the AttributeEditor itself and can then be retrieved by calling the AttributeEditor.getEditorProperties() method.

This class is used to set up the behavior of an AttributeEditor. It controls the sorting, visibility and mutability of attributes. It also contains a map of generic settings that can be freely defined by an AttributeEditor implementation. All settings are stored in a properties file if persistence is not deactivated (e.g. by calling the constructor with null as the filename value).

An AttributeEditor using this class may support the following configuration settings listed in the constants. Implementations of the AttributeEditor interface should list the supported properties in the JavaDoc.

The visibility of an Attribute can be queried and set by calling the following methods.

The mutability of an Attribute can be queried and set by calling the following methods.

Note: You should not make an Attribute mutable in the editor if it has been returned immutable from the AttributableOnSet.

The following methods control the persistence of the properties and other configurations stored in an AttributeEditorProperties instance:

It is possible to specify new attribute display names with the following methods:

The following methods can be used to retrieve or set the properties that define the AttributeEditor behavior. Which properties are supported depends on the AttributeEditor that is used. A basic list of properties is shown in the usage documentation.

To manage the sort order in the AttributeEditor you should use these methods:

Version:
$Id: AttributeEditorProperties.java,v 1.51 2006/03/02 11:40:58 BurkhardWick Exp $
Author:
BurkhardWick, Gilles Iachelini

Nested Class Summary
static class AttributeEditorProperties.Enum
          Class Enum encapsulates a Constraint instance and a String.
 
Field Summary
static java.lang.String DEFAULT_FILENAME
          Default filename for the properties file is set to attributeEditor.properties.
static java.lang.String PROPERTYNAME_AUTOEXPANDCATEGORIES
          If this value is true, all categories will be expanded when showing the AttributeTree for the first time.
static java.lang.String PROPERTYNAME_DYNAMICROWHEIGHT
          Set this property to true in order to enable different row heights.
static java.lang.String PROPERTYNAME_ENABLE_WRITEPROTECTION
          The method isMutable(String) is called to determine the mutable state of an Attribute when this property is enabled.
static java.lang.String PROPERTYNAME_MERGEELEMENTTYPES
          Use this property to merge the element types so that Attributes from different types of AttributableOnSets can be edited in a multi-selection, even though the root element of the structure - which usually represents the name of the type - is different.
static java.lang.String PROPERTYNAME_RENAMINGALLOWED
          Set this property to true if the user should be able to rename attributes in the tree, for example by pressing F2 or clicking in the first column of a selected line.
static java.lang.String PROPERTYNAME_SHOWCATEGORIES
          If this property is set to false, all category elements in the tree are hidden.
static java.lang.String PROPERTYNAME_USEEXACTMATCHING
          If this property is set to true, attribute editor states will exactly match the selected AttributableOnSet instance.
static int SORTMODE_ASCENDING
          Sort mode: ascending
static int SORTMODE_DESCENDING
          Sort mode: descending
static int SORTMODE_NONE
          Sort mode: ascending
 
Constructor Summary
AttributeEditorProperties(AttributeEditor editor)
          Creates a new AttributeEditorProperties instance.
AttributeEditorProperties(AttributeEditor editor, java.lang.String filename)
          Creates a new AttributeEditorProperties instance based on the given properties file specified by the parameter filename.
 
Method Summary
 void addChangeListener(AttributeEditorPropertiesListener aepl)
          Adds a listener that will be notified if one ore more of the properties changed.
 void addFilter(java.lang.String filter)
          Adds a filter to the list that is used to determine the visibility of attributes.
 void addNamedConstraint(AttributeEditorProperties.Enum enm)
          Method addEnum adds the given enum constraint to the internal list and updates the property file.
 void addNamedConstraint(Constraint constraint, java.lang.String name)
          This method adds the given constraint and updates the property file.
 void assertProperty(java.lang.String propertyName, java.lang.Object value)
          Asserts the existence of the property with the given name and creates it with the value provided if it does not already exist.
 boolean checkAgainstFilters(java.lang.String attributePath)
          Checks if an attribute should be visible in the editor according to the list of filters.
 void clearFilters()
          Removes all filters from the list, so all attributes (that are not part of the hidden attributes list) are shown in the editor.
 boolean containsCustomName(java.lang.String pathName)
          Returns true if the custom rename map for attribute names contains the given path name.
 boolean containsEnum(java.lang.String enumTitle)
          Returns true, if the given enumTitle parameter can be found in the internal list of enumerations.
 void disablePropertyPersistence()
          Disables property persistence.
 void enablePropertyPersistence()
          Enables property persistence.
 AttributeEditorTranslator getAttributeEditorTranslator()
          Returns the attribute editor translator that is used for translation of attribute names to a localized string.
 boolean getBoolean(java.lang.String name, boolean defValue)
          Returns the boolean value of the specified property name.
 java.util.Collection getHiddenAttributes()
          This method returns a Collection of strings which represent the names of all hidden attributes.
 java.lang.String getName(java.lang.String pathName)
          Returns the user-defined name or localization for the given set or category name.
 java.lang.String getName(java.lang.String pathName, boolean useCustomNames)
          Returns the user-defined name or localization for the given set or category name.
 java.util.List getNamedConstraints()
          This method returns a List of all named constraints.
 java.lang.Object getPropery(java.lang.String name)
          Returns a generic object stored as a property in this instance using the given name.
 java.util.Collection getShowFilters()
          This method returns a Collection of strings which represent the filters for all attributes to show.
 java.util.Comparator getSortComparator()
          Returns the sort comparator that can be used to sort the items in the edited AttributeSet.
 int getSortMode()
          Returns the currently used sort mode.
 java.lang.String getValue(java.lang.String pathName, java.lang.String value)
          Returns the user-defined value for the given set or category name.
 void hideAttribute(java.lang.String name)
          Deprecated. use setVisible(String, boolean) instead!
 boolean isHidden(java.lang.String name)
          Deprecated. use isVisible(String) instead.
 boolean isHidingEnabled()
          Returns true if the overall hiding mechanism is enabled, otherwise false.
 boolean isMutable(java.lang.String name)
          Returns the mutable state of the specified editor attribute.
 boolean isPropertyPersistenceEnabled()
          Returns a boolean that indicates whether the settings of the AttributeEditorProperties instance are automatically stored inside a file or not.
 boolean isUsingFilters()
          Returns true, if the visibility is determined using a list of filters.
 boolean isVisible(java.lang.String name)
          Returns true if the given name is in the list of hiddenAttributeNames, otherwise false.
protected  void propertiesChanged()
          Called whenever a property or setting changed, so the table can be notified and the values can be stored to the file.
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
 void readProperties()
          Loads the property file if one exists and initializes the internal hiddenAttributesNames list.
 void removeChangeListener(AttributeEditorPropertiesListener aepl)
          Removes a listener that will be notified if one ore more of the properties changed.
 void removeFilter(java.lang.String filter)
          Removes a previously added filter from the list.
 void removeNamedConstraint(AttributeEditorProperties.Enum enm)
          Method removeNamedConstraint removes a given constraint from the internal List.
 void renameAttribute(java.lang.String pathName, java.lang.String newName)
          Adds a rename entry for the given full path name of a category.
 void renameAttribute(java.lang.String pathName, java.lang.String newName, java.util.Locale locale)
          Adds a rename entry for the given full path name of a category.
 void setAttributeEditorTranslator(AttributeEditorTranslator attributeEditorTranslator)
          Assigns the attribute editor translator to use for translation of attribute names to a localized string.
 void setHidingEnabled(boolean enabled)
          Method setEnabled allows users to turn off the hiding-mechanism of attributes, which are marked as hidden through this Properties class.
 void setMutable(java.lang.String name, boolean mutable)
          Sets the mutable state of an Attribute for the editor.
 void setProperty(java.lang.String name, java.lang.Object value)
          Call this method to store additional editor configuration attributes.
 void setSortMode(int sortMode)
          Sets the sort mode that should be used.
 void setVisible(java.lang.String name, boolean visible)
          Sets the visibility of an Attribute for the corresponding editor and updates the properties file.
 void showAttribute(java.lang.String name)
          Deprecated. use setVisible(String, boolean) instead!
 void updateNamedConstraint(AttributeEditorProperties.Enum enm)
          Updates an enumeration entry in the internal list, by removing the element and then adding it.
 void writeProperties()
          If a valid PropertiesFile is available and the persistence is enabled this method writes out all information containing the states of the attributes (visibility, mutability), the rename map and all generic properties that have been set using the setProperty(String, Object) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTYNAME_SHOWCATEGORIES

public static final java.lang.String PROPERTYNAME_SHOWCATEGORIES
If this property is set to false, all category elements in the tree are hidden. Default = Boolean.TRUE

See Also:
Constant Field Values

PROPERTYNAME_USEEXACTMATCHING

public static final java.lang.String PROPERTYNAME_USEEXACTMATCHING
If this property is set to true, attribute editor states will exactly match the selected AttributableOnSet instance. Default = Boolean.TRUE

See Also:
Constant Field Values

PROPERTYNAME_MERGEELEMENTTYPES

public static final java.lang.String PROPERTYNAME_MERGEELEMENTTYPES
Use this property to merge the element types so that Attributes from different types of AttributableOnSets can be edited in a multi-selection, even though the root element of the structure - which usually represents the name of the type - is different. Default =Boolean.FALSE

See Also:
Constant Field Values

PROPERTYNAME_RENAMINGALLOWED

public static final java.lang.String PROPERTYNAME_RENAMINGALLOWED
Set this property to true if the user should be able to rename attributes in the tree, for example by pressing F2 or clicking in the first column of a selected line. Default = Boolean.TRUE

See Also:
Constant Field Values

PROPERTYNAME_ENABLE_WRITEPROTECTION

public static final java.lang.String PROPERTYNAME_ENABLE_WRITEPROTECTION
The method isMutable(String) is called to determine the mutable state of an Attribute when this property is enabled.
Note: Attributes that are returned from the AttributableOnSet should not be set to mutable by the editor. Only mutable attributes may be changed to immutable to prevent the user from editing. Default = Boolean.FALSE

See Also:
Constant Field Values

PROPERTYNAME_DYNAMICROWHEIGHT

public static final java.lang.String PROPERTYNAME_DYNAMICROWHEIGHT
Set this property to true in order to enable different row heights. For example, some of the renderers for attribute types need more vertical space. Default = Boolean.FALSE

See Also:
Constant Field Values

PROPERTYNAME_AUTOEXPANDCATEGORIES

public static final java.lang.String PROPERTYNAME_AUTOEXPANDCATEGORIES
If this value is true, all categories will be expanded when showing the AttributeTree for the first time. Additionally, no stored tree state is available for the current element type. Default = Boolean.FALSE

See Also:
Constant Field Values

SORTMODE_NONE

public static final int SORTMODE_NONE
Sort mode: ascending

See Also:
Constant Field Values

SORTMODE_ASCENDING

public static final int SORTMODE_ASCENDING
Sort mode: ascending

See Also:
Constant Field Values

SORTMODE_DESCENDING

public static final int SORTMODE_DESCENDING
Sort mode: descending

See Also:
Constant Field Values

DEFAULT_FILENAME

public static final java.lang.String DEFAULT_FILENAME
Default filename for the properties file is set to attributeEditor.properties.

See Also:
Constant Field Values
Constructor Detail

AttributeEditorProperties

public AttributeEditorProperties(AttributeEditor editor)
Creates a new AttributeEditorProperties instance.

Parameters:
editor - The editor these settings apply to

AttributeEditorProperties

public AttributeEditorProperties(AttributeEditor editor,
                                 java.lang.String filename)
Creates a new AttributeEditorProperties instance based on the given properties file specified by the parameter filename.

Parameters:
editor - The editor this instance will belong to
filename - The name of the properties file for this class.
Method Detail

readProperties

public void readProperties()
Loads the property file if one exists and initializes the internal hiddenAttributesNames list.

Find more information in the class documentation


isHidden

public boolean isHidden(java.lang.String name)
Deprecated. use isVisible(String) instead.

Method isHidden returns true, if the given name is in the list of hiddenAttributeNames, otherwise false.

Parameters:
name - the attribute to check.
Returns:
boolean true, if attributes with this name should be hidden.

setMutable

public void setMutable(java.lang.String name,
                       boolean mutable)
Sets the mutable state of an Attribute for the editor. Note that you cannot turn an immutable Attribute returned from an AttributableOnSet into a mutable one for the editor.

Parameters:
name - The full path name of the attribute
mutable - false, to write protect the attribute in the editor true, to remove the name from the map and use the mutable state returned by the AttributableOnSet

Find more information in the class documentation


isMutable

public boolean isMutable(java.lang.String name)
Returns the mutable state of the specified editor attribute. Please be aware that the Attribute may still be immutable even thought this method returns true.

Parameters:
name - The full path name of the attribute
Returns:
true, if the mutable state is not changed in the editor false, if the attribute will not be editable by the editor

Find more information in the class documentation


isVisible

public boolean isVisible(java.lang.String name)
Returns true if the given name is in the list of hiddenAttributeNames, otherwise false.

Parameters:
name - the attribute to check.
Returns:
boolean true if an attribute with this name should be hidden.

Find more information in the class documentation


setVisible

public void setVisible(java.lang.String name,
                       boolean visible)
Sets the visibility of an Attribute for the corresponding editor and updates the properties file.

Parameters:
name - the name of the attribute which visibility should be changes.
visible - true, to show the attribute and false to hide it

Find more information in the class documentation


addFilter

public void addFilter(java.lang.String filter)
Adds a filter to the list that is used to determine the visibility of attributes. The filter can contain the wildcards '*' and '?' and works like a filename pattern. The whole pathname of an attribute is matched against it. It at least one filter is added, only matching attributes are shown. You can remove the entries by using removeFilter(String) or clearFilters().

Parameters:
filter - The filter string to add
See Also:
removeFilter(String), clearFilters(), checkAgainstFilters(String)

removeFilter

public void removeFilter(java.lang.String filter)
Removes a previously added filter from the list.

Parameters:
filter - the filter to remove
See Also:
addFilter(String), clearFilters(), checkAgainstFilters(String)

clearFilters

public void clearFilters()
Removes all filters from the list, so all attributes (that are not part of the hidden attributes list) are shown in the editor.

See Also:
addFilter(String), removeFilter(String)

isUsingFilters

public boolean isUsingFilters()
Returns true, if the visibility is determined using a list of filters.

Returns:
true, if the visibility is determined using a list of filters.

checkAgainstFilters

public boolean checkAgainstFilters(java.lang.String attributePath)
Checks if an attribute should be visible in the editor according to the list of filters. The method will return true if the list is empty or the given pathname matches any of the patterns in the list. To make it possible to add filters for attributes in specific sets or in all sets another wildcard '**' has been added which means a 'random number of path elements'. e.g. "**:a*" -> matches all attributes starting with a lowercase 'a' in all categories "**:Geometry:**" -> matches all attributes below the category 'Geometry' "RectangleNode:**:Custom:**" -> matches all attributes below 'Custom' in the set with the root 'RectangleNode' "RectangleNode:**" -> matches all attributes under the root 'RectangleNode' "RectangleNode:*" -> matches all attributes DIRECTLY under the root 'RectangleNode'

Parameters:
attributePath - The pathname to check
Returns:
true if the list is empty or the given pathname matches any of the patterns in the list

isPropertyPersistenceEnabled

public boolean isPropertyPersistenceEnabled()
Returns a boolean that indicates whether the settings of the AttributeEditorProperties instance are automatically stored inside a file or not.

Returns:
boolean flag that indicates whether settings are stored into a file or not

Find more information in the class documentation


enablePropertyPersistence

public void enablePropertyPersistence()
Enables property persistence. This means that the settings of the AttributeEditorProperties are automatically stored inside a file.

Find more information in the class documentation


disablePropertyPersistence

public void disablePropertyPersistence()
Disables property persistence. This means that the settings of the AttributeEditorProperties will not be automatically stored inside a file. Notice: an existing AttributeEditorProperties file will not be deleted when disabling property persistence.

Find more information in the class documentation


writeProperties

public void writeProperties()
                     throws java.io.IOException
If a valid PropertiesFile is available and the persistence is enabled this method writes out all information containing the states of the attributes (visibility, mutability), the rename map and all generic properties that have been set using the setProperty(String, Object) method.

Throws:
java.io.IOException - When there is an io error while writing data

Find more information in the class documentation


getHiddenAttributes

public java.util.Collection getHiddenAttributes()
This method returns a Collection of strings which represent the names of all hidden attributes.

Returns:
a Collection containing the full names of the hidden attributes

Find more information in the class documentation


getShowFilters

public java.util.Collection getShowFilters()
This method returns a Collection of strings which represent the filters for all attributes to show.

Returns:
a Collection of strings which represent the filters for all attributes to show.

Find more information in the class documentation


setHidingEnabled

public void setHidingEnabled(boolean enabled)
Method setEnabled allows users to turn off the hiding-mechanism of attributes, which are marked as hidden through this Properties class. If set to false, isHidden will always return false either to indicate that no attribute has to be hidden. By calling this method you won't harm any other functionality of this class (such writeProperties or such). This method simply sets a flag, which modifies the behaviour of the isHidden method.

Parameters:
enabled - true to enable the property driven hiding mechanism, false to turn that off.

Find more information in the class documentation


isHidingEnabled

public boolean isHidingEnabled()
Returns true if the overall hiding mechanism is enabled, otherwise false.

Returns:
boolean a boolean which indicates whether the hiding mechanism is enabled or not.

Find more information in the class documentation


getNamedConstraints

public java.util.List getNamedConstraints()
This method returns a List of all named constraints.

Returns:
all named constraints.

addNamedConstraint

public void addNamedConstraint(Constraint constraint,
                               java.lang.String name)
This method adds the given constraint and updates the property file.

Parameters:
constraint - The Constraint instance describing the enumeration.
name - A human readable name for the given enumeration.

containsEnum

public boolean containsEnum(java.lang.String enumTitle)
Returns true, if the given enumTitle parameter can be found in the internal list of enumerations.

Parameters:
enumTitle - the title to look for.
Returns:
true, if found, otherwise false.

addNamedConstraint

public void addNamedConstraint(AttributeEditorProperties.Enum enm)
Method addEnum adds the given enum constraint to the internal list and updates the property file.


removeNamedConstraint

public void removeNamedConstraint(AttributeEditorProperties.Enum enm)
Method removeNamedConstraint removes a given constraint from the internal List.


updateNamedConstraint

public void updateNamedConstraint(AttributeEditorProperties.Enum enm)
Updates an enumeration entry in the internal list, by removing the element and then adding it.


renameAttribute

public void renameAttribute(java.lang.String pathName,
                            java.lang.String newName)
Adds a rename entry for the given full path name of a category. or attribute.

Parameters:
pathName - The full path name of the category or attribute to rename
newName - The new name of the item (only the name, not the full path)

Find more information in the class documentation


renameAttribute

public void renameAttribute(java.lang.String pathName,
                            java.lang.String newName,
                            java.util.Locale locale)
Adds a rename entry for the given full path name of a category. or attribute.

Parameters:
pathName - The full path name of the category or attribute to rename
newName - The new name of the item (only the name, not the full path)
locale - The locale to add set custom name for

Find more information in the class documentation


containsCustomName

public boolean containsCustomName(java.lang.String pathName)
Returns true if the custom rename map for attribute names contains the given path name.

Parameters:
pathName - The path name of the attribute to look for
Returns:
true if the given path name has a customized name

getName

public java.lang.String getName(java.lang.String pathName)
Returns the user-defined name or localization for the given set or category name.

Parameters:
pathName - The full path name of the category or attribute
Returns:
The name of the attribute or category which might be unchanged, if there is no rename entry for it

Find more information in the class documentation


getName

public java.lang.String getName(java.lang.String pathName,
                                boolean useCustomNames)
Returns the user-defined name or localization for the given set or category name.

Parameters:
pathName - The full path name of the category or attribute
useCustomNames - If this parameter is true the custom names map is used. Otherwise only the language resources are used to find a localized name.
Returns:
The name of the attribute or category which might be unchanged, if there is no rename entry for it

Find more information in the class documentation


getValue

public java.lang.String getValue(java.lang.String pathName,
                                 java.lang.String value)
Returns the user-defined value for the given set or category name.

Parameters:
pathName - The full path name of the category or attribute
value - The value
Returns:
The name of the attribute or category which might be unchanged, if there is no rename entry for it

Find more information in the class documentation


setProperty

public void setProperty(java.lang.String name,
                        java.lang.Object value)
Call this method to store additional editor configuration attributes.

Parameters:
name - The name of the property
value - The value of the property

Find more information in the class documentation


getBoolean

public boolean getBoolean(java.lang.String name,
                          boolean defValue)
Returns the boolean value of the specified property name. If no (boolean) value is stored under the given name, the default value is returned.

Parameters:
name - The name of the property to check
defValue - The default value to return instead
Returns:
The result

Find more information in the class documentation


assertProperty

public void assertProperty(java.lang.String propertyName,
                           java.lang.Object value)
Asserts the existence of the property with the given name and creates it with the value provided if it does not already exist.

Parameters:
propertyName - The name of the property to assert
value - The value to use, if it doesn't exist

Find more information in the class documentation


getPropery

public java.lang.Object getPropery(java.lang.String name)
Returns a generic object stored as a property in this instance using the given name.

Parameters:
name - The name of the property to retrieve
Returns:
The property stored under the given name

Find more information in the class documentation


getSortComparator

public java.util.Comparator getSortComparator()
Returns the sort comparator that can be used to sort the items in the edited AttributeSet. The comparator returned depends on the sort mode, so you will have to call this method again after the sort mode changed.

Returns:
A usable comparator or null, if sort mode is none.

Find more information in the class documentation


setSortMode

public void setSortMode(int sortMode)
Sets the sort mode that should be used.

Parameters:
sortMode - The sort mode to use.

Find more information in the class documentation


getSortMode

public int getSortMode()
Returns the currently used sort mode.

Returns:
The currently used sort mode.

Find more information in the class documentation


propertiesChanged

protected void propertiesChanged()
Called whenever a property or setting changed, so the table can be notified and the values can be stored to the file.


hideAttribute

public void hideAttribute(java.lang.String name)
Deprecated. use setVisible(String, boolean) instead!

Method hideAttribute adds the given name to the internal hiddenAttributeNames list and updates the properties file.

Parameters:
name - the name of the attribute which should be hidden.

showAttribute

public void showAttribute(java.lang.String name)
Deprecated. use setVisible(String, boolean) instead!

Method showAttribute removes the given name from the internal hiddenAttributeNames list and updates the properties file.

Parameters:
name - the name of the attribute which should no longer be hidden.

addChangeListener

public void addChangeListener(AttributeEditorPropertiesListener aepl)
Adds a listener that will be notified if one ore more of the properties changed.

Parameters:
aepl - The listener to add

removeChangeListener

public void removeChangeListener(AttributeEditorPropertiesListener aepl)
Removes a listener that will be notified if one ore more of the properties changed.

Parameters:
aepl - The listener to remove

setAttributeEditorTranslator

public void setAttributeEditorTranslator(AttributeEditorTranslator attributeEditorTranslator)
Assigns the attribute editor translator to use for translation of attribute names to a localized string.

Parameters:
attributeEditorTranslator - The translator to set

getAttributeEditorTranslator

public AttributeEditorTranslator getAttributeEditorTranslator()
Returns the attribute editor translator that is used for translation of attribute names to a localized string.

Returns:
the attribute translator in use or null if none is assigned

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener


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