AttributeManager.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* Copyright (C) 1996 Active Software, Inc.
* All rights reserved.
*
* @(#) AttributeManager.java 1.83 - last change made 07/29/97
*/
/*
* NOTE: Whenever a new public or protected variable is added to this
* class
* the name of the variable must be added to the reserved words list
* in the
* Root class so that the user doesn't use it in one of the
* generated Root
* sub-classes.
*/
/**
* The AttributeManager class is a base class for objects that
* have attributes. The Shadow and Group classes are sub-classed
* from AttributeManager.
* <p>
* The attributes available for this
* class are listed below. In the type column, type names beginning
* with "sunsoft.jws.visual.rt" have been abbreviated to begin
* with "rt".
*
* <pre>
* name type default value
* -----------------------------------------------------------------------
* name java.lang.String null
* < /pre>
*
* @version 1.83, 07/29/97
*/
public class AttributeManager {
/**
* Flags
*/
/**
* Indicates a readonly attribute. An attempt
* to set the attribute will result in an error.
*/
public static final int READONLY = 0x1;
/**
* Flags attributes that will not be shown in the Visual Java
* attribute editor.
*/
public static final int HIDDEN = 0x2;
/**
* Flags attributes that will not be stored in the
* save file.
*/
public static final int TRANSIENT = 0x4;
/**
* The parent will be notified by calling updateContainerAttribute
* on the parent whenever a CONTAINER attribute is changed.
*/
public static final int CONTAINER = 0x8;
/**
* This flag indicates that the default value for the attribute
* matches the default value for the AWT body. If this flag is
* set, the setOnBody method will not be called during
* creation unless the value is actually changed.
* <p>
* Similarly for groups, if the DEFAULT flag is set, then
* setOnGroup will only be called during initialization if the
* attribute has actually changed. Otherwise setOnGroup will
* be called regardless of whether the attribute has changed.
* <p>
* Note: This flag should only be used where performance is a
* concern, since resetting the default value on the AWT body
* should not change its behavior.
* <p>
*/
public static final int DEFAULT = 0x10;
/**
* This flag tells the attribute manager to not refetch the value
* of the attribute list during the refetchAttributes call. This
* is useful for the AWT component fonts and colors that are
* inherited from their parent when set to null.
* If this flag were not set for those attributes, then they
* would end up everywhere in the save file.
*/
public static final int DONTFETCH = 0x20;
/**
* This flag tells the attribute editor's slot that it should
* not use
* a type editor for this attribute, even if there is one
* registered.
*/
public static final int NOEDITOR = 0x400;
/**
* The table where attributes are stored.
* Attributes may be added to this list during construction, but
* should not be added at any other time.
*/
protected AttributeList attributes;
/**
* The parent of this object.
*/
/**
* A flag that is true once create() has been performed on a shadow
* object and remains so until destroy() is called.
*/
boolean isCreated = false;
/**
* Flag for storing the return value of inDesignerRoot while we
* are created. This speeds up the check in sendToOps.
*/
/**
* Creates the attributes list and assigns a unique name to this
* attribute manager. Attributes may be added to the list of
* attributes
* in sub-class constructors, but should not be added at any
* other time.
*/
public AttributeManager() {
attributes = new AttributeList();
// name will be set around the time this object is added
// to a container
// operations for defining callbacks
}
/**
* Returns the parent for this attribute manager.
*/
public AMContainer getParent() {
return parent;
}
/**
* Sets the parent for this attribute manager.
*/
}
/**
* Returns true if we are not running inside the designer.
*/
public boolean isLive() {
while (r != null) {
if (r.isLoadedRoot())
return false;
break;
}
return true;
}
/**
* Returns true if this instance is a direct descendant
* of the designer root. Being a direct descendant means
* that there are no intermediate groups between this
* attribute manager and the root.
* The designer root is the root that is built inside
* Visual Java.
*/
public boolean inDesignerRoot() {
if (inDesignerRoot != null)
return inDesignerRoot.booleanValue();
else
return checkDesignerRoot();
}
private boolean checkDesignerRoot() {
}
/**
* Returns a type name suitable for use in making unique names for
* instances of this class (or one of its sub-classes). This should
* be overridden in sub-classes to give more useful names.
*/
protected String getUserTypeName() {
return (/* NOI18N */"manager");
}
/**
* Puts an attribute's value directly into the attribute table.
*/
if (a == null)
"sunsoft.jws.visual.rt.base.AttributeManager.SetInvalidAttribute", key));
"sunsoft.jws.visual.rt.base.AttributeManager.ReadonlyAttribute", key));
}
/**
* Gets an attribute's value directly from the attribute table.
*/
if (a == null)
"sunsoft.jws.visual.rt.base.AttributeManager.GetInvalidAttribute", key));
return (a.getValue());
}
/**
* Sets an attribute in this object's attribute list. This may be
* overridden in sub-classes to introduce special behavior for the
* setting of some attributes.
*/
// update the the global register for unsaved changes
if (inDesignerRoot())
DesignerAccess.setChangesMade(true);
}
/**
* Gets an attribute from this shadow object's attribute list. This
* may be overridden in sub-classes to introduce special behavior
* for the getting of some attributes.
*/
return (getFromTable(key));
}
/**
* Returns the type string for the attribute,
* or null if the attribute does not exist.
*/
else
return null;
}
/**
* Returns true if the attribute has the flag set, otherwise false.
*/
else
return 0;
}
/**
* Returns true if the attribute exists, otherwise return false.
*/
}
/**
* Return true if the attribute exists and the type matches,
* otherwise return false.
*/
else
return false;
}
/**
* Apply all the CONTAINER attributes in the child to the
* given parent.
*/
{
while (e.hasMoreElements()) {
a.getValue());
}
}
/**
* Return a reference to the entire table of attributes.
*/
public AttributeList getAttributeList() {
// Perhaps the attribute list should be cloned here.
// But this would
// cause a performance loss. Anyone using getAttributeList
// should NOT modify the values of any of the attributes,
// especially those
// that have the DONTFETCH flag set.
return attributes;
}
}
/**
* Calls get for all the attributes, and then stores the values
* directly in the attribute hash table. This ensures that the
* list of attributes is up to date.
*/
public void refetchAttributeList() {
while (e.hasMoreElements()) {
}
}
}
/*
* Finds a component recursively by name.
*/
return null;
return this;
if (this instanceof AMContainer) {
/* JSTYLED */
e.hasMoreElements(); ) {
e.nextElement();
if (s != null)
return s;
}
}
return null;
}
/**
* Finds a component from its full path name.
*/
else
return null;
}
/**
* Returns the body for a shadow after resolving it.
*/
return null;
return null;
}
/**
* Returns the name for this attribute manager.
*/
}
/**
* Returns a hierarchy name based on the group tree.
*/
public String getFullName() {
}
return name;
}
/**
* Initialize the object. Only useful for groups.
*/
public void initialize() {
}
/**
* Create the object. The AWT components are constructed
* during creation.
*/
public void create() {
isCreated = true;
// if this is a container create its children
if (this instanceof AMContainer)
((AMContainer) this).createChildren();
}
/**
* Returns true if the attribute manager is created.
*/
public boolean isCreated() {
return isCreated;
}
/**
* Recreates this object after a CONSTRUCTOR attribute has been set
* (overridden in Shadow).
*/
public void recreate() {
}
/**
* This method is overridden in most sub-classes. It should be the
* opposite of create() and should have the same ability to be
* called safely multiple times.
*/
public void destroy() {
isCreated = false;
// destroy all the children of this shadow object
if (this instanceof AMContainer)
((AMContainer) this).destroyChildren();
}
/**
* Returns a string that shows the hierarchy of shadow objects.
* Starts first one (the caller) off as the top level.
*/
return (hierarchy(0));
}
/**
* Returns a string that shows the hierarchy of shadow objects.
*/
for (int i = 0; i < level; i++)
if (this instanceof AMContainer) {
/* JSTYLED */
e.hasMoreElements(); )
}
}
/**
* Returns a String that represents the value of this Object.
*/
+ ((this instanceof AMContainer) ?
/* NOI18N */"container" : /* NOI18N */"nonContainer")
+ /* NOI18N */"]");
}
/**
* Returns the root for this object, or null if these is no root.
*/
AttributeManager mgr = this;
}
/**
* Returns the group for this object, or null if there is none.
*/
else
return null;
}
/**
* Returns the group that is forwarding the specified attribute
* to this attribute manager. Return null if the attribute is not
* being forwarded from any group.
*/
}
return group;
}
}
return null;
}
/**
* replicate is used by Visual Java for cut and paste.
*/
public AttributeManager replicate() {
// Create a new instance of the AttributeManager
try {
}
catch (InstantiationException ex) {
// Perhaps this should be an Exception?
+ /* NOI18N */" " + this);
}
catch (IllegalAccessException ex) {
// Perhaps this should be an Exception?
+ /* NOI18N */" " + this);
}
return null;
// Copy the attribute list
while (e.hasMoreElements()) {
}
// Replicate the children
if (this instanceof AMContainer) {
e = ((AMContainer)this).getChildList();
while (e.hasMoreElements()) {
e.nextElement();
}
}
return newMgr;
}
//
// Events
//
/**
* Posts a message to this object's parent.
*/
}
/**
* Posts a message to this object.
*/
if (inDesignerRoot())
}
// Don't handle GROUP actions
continue;
}
}
}
/**
* May be overridden by subclasses that want to act
* on messages that are sent to this object.
*/
else
return false;
}
/**
* May be overridden by subclasses that want to act
* on AWT events that are sent to this object.
*/
case Event.MOUSE_ENTER:
case Event.MOUSE_EXIT:
case Event.MOUSE_MOVE:
case Event.MOUSE_DOWN:
case Event.MOUSE_DRAG:
case Event.KEY_ACTION:
case Event.KEY_RELEASE:
case Event.KEY_ACTION_RELEASE:
case Event.ACTION_EVENT:
case Event.LOST_FOCUS:
default:
return false;
}
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
return false;
}
/**
* isLayoutMode - Are we in layout mode?
*/
private boolean layoutMode = false;
/**
* Returns a boolean indicating if this object is in layout mode.
*/
public boolean isLayoutMode() {
return layoutMode;
}
/**
* Called when Visual Java switches to layout mode.
*/
public void layoutMode() {
layoutMode = true;
}
/**
* Called when Visual Java switches to preview mode.
*/
public void previewMode() {
layoutMode = false;
}
/**
* Called after addNotify and before the window is reshaped.
*/
protected void preValidate() {
}
}