ptolemy.actor.gui
Class PtolemyPreferences

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.data.expr.ScopeExtendingAttribute
              extended by ptolemy.actor.gui.PtolemyPreferences
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ScopeExtender, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

public class PtolemyPreferences
extends ScopeExtendingAttribute

Default preferences definition for Vergil. This is defined as a class rather than in MoML so that the inheritance mechanism prevents exported MoML for every model from duplicating this information.

Since:
Ptolemy II 5.2
Version:
$Id: PtolemyPreferences.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee, Contributor: Bert Rodiers
See Also:
Serialized Form
Accepted Rating:
Red (cxh)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
 ColorAttribute backgroundColor
          The background color.
static java.lang.String PREFERENCES_FILE_NAME
          The file name where user-defined preferences are stored.
static java.lang.String PREFERENCES_WITHIN_CONFIGURATION
          The location with the configuration of the preferences attribute.
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
PtolemyPreferences(NamedObj container, java.lang.String name)
          Construct an instance of the preferences attribute.
 
Method Summary
static PtolemyPreferences getPtolemyPreferencesWithinConfiguration(Configuration configuration)
          Get the PtolemyPreferences within the specified configuration.
static Token preferenceValue(NamedObj context, java.lang.String preferenceName)
          Check to see whether a preference of the specified name is defined in the specified context, and if it is, return its value.
static Token preferenceValueLocal(NamedObj context, java.lang.String preferenceName)
          Check to see whether a preference of the specified name is defined in the container of the specified context, either directly or within an instance of PtolemyPreferences, or globally, and if it is, return it's value.
 void save()
          Save the preference values in this instance to the user preferences file.
 void setAsDefault()
          Set the values in this instance of PtolemyPreferences to be the default values by creating entries in the Constants class so that these values are accessible to any expression.
static void setDefaultPreferences(Configuration configuration)
          Look for a default preferences object within the specified configuration, and set it as the default preferences.
 
Methods inherited from class ptolemy.data.expr.ScopeExtendingAttribute
setContainer
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, clone, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.data.expr.ScopeExtender
attributeList, getAttribute
 

Field Detail

backgroundColor

public ColorAttribute backgroundColor
The background color.


PREFERENCES_FILE_NAME

public static final java.lang.String PREFERENCES_FILE_NAME
The file name where user-defined preferences are stored.

See Also:
Constant Field Values

PREFERENCES_WITHIN_CONFIGURATION

public static final java.lang.String PREFERENCES_WITHIN_CONFIGURATION
The location with the configuration of the preferences attribute.

See Also:
Constant Field Values
Constructor Detail

PtolemyPreferences

public PtolemyPreferences(NamedObj container,
                          java.lang.String name)
                   throws IllegalActionException,
                          NameDuplicationException
Construct an instance of the preferences attribute.

Parameters:
container - The container.
name - The name.
Throws:
IllegalActionException - If the attribute is not of an acceptable class for the container, or if the name contains a period.
NameDuplicationException - If the name coincides with an attribute already in the container.
Method Detail

getPtolemyPreferencesWithinConfiguration

public static PtolemyPreferences getPtolemyPreferencesWithinConfiguration(Configuration configuration)
                                                                   throws IllegalActionException
Get the PtolemyPreferences within the specified configuration.

Parameters:
configuration - The configuration in which to search for PREFERENCES_WITHIN_CONFIGURATION
Returns:
The associated PtolemyPreferences or null if not found.
Throws:
IllegalActionException - If there is a problem getting the PREFERENCES_WITHIN_CONFIGURATION attribute.

preferenceValue

public static Token preferenceValue(NamedObj context,
                                    java.lang.String preferenceName)
Check to see whether a preference of the specified name is defined in the specified context, and if it is, return its value. Note that if there is an error in the expression for the preference, then this method will return null and report the error to standard out. This is done because we assume the error will normally be caught before this method is called.

Parameters:
context - The context for the preference.
preferenceName - The name of the preference.
Returns:
The value of the preference, or null if it is not set.

preferenceValueLocal

public static Token preferenceValueLocal(NamedObj context,
                                         java.lang.String preferenceName)
Check to see whether a preference of the specified name is defined in the container of the specified context, either directly or within an instance of PtolemyPreferences, or globally, and if it is, return it's value. Do not look any higher in the hierarchy. Note that if there is an error in the expression for the preference, then this method will return null and report the error to standard out. This is done because we assume the error will normally be caught before this method is called.

Parameters:
context - The context for the preference.
preferenceName - The name of the preference.
Returns:
The value of the preference, or null if it is not set.

save

public void save()
          throws java.io.IOException
Save the preference values in this instance to the user preferences file.

Throws:
java.io.IOException - If an error occurs writing the file.

setAsDefault

public void setAsDefault()
                  throws IllegalActionException
Set the values in this instance of PtolemyPreferences to be the default values by creating entries in the Constants class so that these values are accessible to any expression.

Throws:
IllegalActionException - If any expression for a preference cannot be evaluated.

setDefaultPreferences

public static void setDefaultPreferences(Configuration configuration)
Look for a default preferences object within the specified configuration, and set it as the default preferences. Then look for a user preferences file, and override the default preferences with the contents of that file. This method prints warning messages on standard out if there are problems with the preferences.

Parameters:
configuration - The specified configuration.