home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-10-25 | 22.4 KB | 569 lines |
- /*
- * Copyright 1998 Symantec Corporation, All Rights Reserved.
- */
-
- package com.symantec.itools.vcafe.openapi;
-
- import java.io.File;
- import java.util.Enumeration;
- import java.awt.Image;
- import java.awt.datatransfer.Transferable;
- import com.symantec.itools.vcafe.openapi.datatransfer.TransferableVisualObjects;
- import com.symantec.itools.vcafe.openapi.dtreflect.DTClass;
-
- /**
- * The API used to represent and access an object that can be visually manipulated in the Visual
- * Cafe environment. Examples of this include java objects (classes, Components), and non-java
- * objects (folders, project templates, etc).
- *
- * Each <code>VisualObject</code> has a set of <code>VisualProperties</code>.
- *
- * A plug-in can obtain a list, or library, of these objects from a <code>VisualProject</code> by using the
- * <code>getObjectLibrary</code> method. A plug-in can use the methods in the <code>VisualObject</code> class to update
- * properties and other attribues.
- *
- * The implementation of all of <code>VisualObject</code>'s abstract methods first calls
- * checkValidity(). Any method could therefore throw an <code>InvalidVisualObjectException</code>.
- * This exception extends <code>RuntimeException</code>, so doesn't have to be explicity declared or
- * caught. A <code>VisualObject</code> can become invalid if it is removed from its project, or its
- * project is closed, and the corresponding <code>VisualObjectListener</code> message is ignored, for example.
- *
- * @see VisualProject#getObjectLibrary
- * @see VisualCafe#getComponentLibrary
- * @see VisualRepository
- * @see InvalidVisualObjectException
- *
- * @author Symantec Internet Tools Division
- * @version 1.0
- * @since VCafe 3.0
- */
-
- public abstract class VisualObject implements Cloneable {
-
- /**
- * Flag indicating this object is "invisible". An invisble object is one that doesn't paint
- * to the screen at runtime.
- * @see #isInvisible
- */
- public static final int VPO_INVISIBLE = (1<<0);
- public static final int VPO_STARTER = (1<<1);
- public static final int VPO_IS_DEFAULT = (1<<2);
- /**
- * Flag indicating this object is a "root obejct". A root object appears at the top level in
- * project windows and has associated java source code.
- * @see #isRootObject
- */
- public static final int VPO_ROOT_OBJECT = (1<<3);
- public static final int VPO_NO_NAME = (1<<4);
- public static final int VPO_PARSER_ONLY = (1<<5);
- public static final int VPO_DESIGN_TIME_ONLY = (1<<6);
- public static final int VPO_ADDED = (1<<7);
- public static final int VPO_CONTAINER_ONLY = (1<<8);
- public static final int VPO_USER_OBJECT = (1<<9);
- public static final int VPO_IS_ARRAY = (1<<10);
- /**
- * Flag indicating this object is a project template or folder.
- * @see VisualCafe#getProjectTemplates
- */
- public static final int VPO_PROJ_TEMPL_FOLDER = (1<<11);
- public static final int VPO_ERROR = (1<<12);
- /**
- * Flag indicating this object is displayed on the toolbar.
- */
- public static final int VPO_ADDED_TO_TOOLBAR = (1<<13);
- public static final int VPO_CUSTOMIZER_HIDDENSTATE = (1<<14);
- /**
- * Flag indicating this object is serializable
- */
- public static final int VPO_SERIALIZABLE = (1<<15);
- public static final int VPO_NOINITDECLCONNTROLS = (1<<16);
- public static final int VPO_CUSTOM_VIEW = (1<<17);
-
-
- /**
- * Gets the instance name of this object, e.g., "checkbox1".
- *
- * @return the instance name.
- */
- public abstract String getName();
-
- /**
- * Gets the package name of this object, e.g., "java.awt".
- *
- * @return the package name.
- */
- public abstract String getPackageName();
-
- /**
- * Gets the description of this object.
- *
- * @return the description of the visual object.
- */
- public abstract String getDescription();
-
- /**
- * Obtains the flags of this object.
- *
- * @return an integer which combines all this object's flags.
- */
- public abstract int getFlags();
-
-
- /**
- * Gets this <code>VisualObject</code>'s unique numeric ID within its <code>VisualRepository</code>.
- * The ID can be zero if the the object is not in a <code>VisualRepository</code>. This can
- * be the case if a new <code>VisualObject</code> has just been created an not yet inserted.
- * @return a unique numeric ID within its <code>VisualRepository</code>, or zero.
- */
- public abstract int getObjectID();
-
- /**
- * Gets the full java class name of this object, e.g. returns "java.awt.Checkbox".
- * @return this object's full java class name.
- */
- public abstract String getClassName();
-
- /**
- * Gets the short java class name of this object, e.g. returns "Checkbox".
- * @return this object's short java class name.
- */
- public abstract String getShortClassName();
-
- /**
- * Gets the default name of this object.
- * Usually the same as <code>getShortClassName()</code>, but some components describe two
- * types of objects.
- * For example, <code>java.awt.Checkbox</code> can return either "Checkbox" or "RadioButton".
- * @return this object's default name.
- */
- public abstract String getDefaultName();
-
- /**
- * Gets the java class name of this object's superclass.
- * @return this object's superclass's name.
- */
- public abstract String getSuperClassName();
-
- /**
- * Determineswhether this object is an instance of the given class.
- * @param className a full class name
- * @return <code>true</code> if this object is an instance of <code>className</code>, <code>false</code> otherwise.
- */
- public abstract boolean isInstanceOf(String className);
-
- /**
- * Determines whether this object represents a java object (as opposed to a folder,
- * project template, etc).
- * @return <code>true</code> if so, <code>false</code> otherwise.
- */
- public abstract boolean isJavaObject();
-
- /**
- * Determines whether this object is "invisible", i.e., should be ignored.
- * An invisible object is one that doesn't paint to the screen at runtime.
- * Invisible objects sometimes appear in the component library.
- * @return <code>true</code> if so, <code>false</code> otherwise.
- */
- public boolean isInvisible() {
- return (getFlags() & VPO_INVISIBLE) != 0;
- }
-
- /**
- * Determines whether this object is a "root object".
- * A root object appears at the top level in project windows and has associated java source code.
- *
- * @return <code>true</code> if so, <code>false</code> otherwise.
- */
- public boolean isRootObject() {
- return (getFlags() & VPO_ROOT_OBJECT) != 0;
- }
-
- /**
- * Gets the first child (component) of the object.
- * <p>
- * To traverse a visual object hierarchy downwards, use
- * <code>getFirstChild()</code> followed by <code>getSibling()</code>, recursively.
- *
- * @see #getSibling
- * @return the first child object or <code>null</code> if no children.
- */
- public abstract VisualObject getFirstChild();
-
- /**
- * Gets the parent (container) of the object.
- * <p>
- * To traverse a visual object heirarchy upwards, use
- * <code>getParent()</code> recursively until <code>isRootObject()</code> is <code>true</code>.
- * <p>
- * The parent of a root object has no visual significance.
- *
- * @return parent of this visual object or <code>null</code> if no parent.
- */
- public abstract VisualObject getParent();
-
- /**
- * Gets this object's next sibling.
- * Siblings have the same parent object.
- *
- * @return the next sibling of this visual object or <code>null</code> if none.
- */
- public abstract VisualObject getSibling();
-
- /**
- * Gets the child object with matching name, searching recursively.
- * @param name the name of the child to find.
- * @return the child, or <code>null</code> if none.
- */
- public abstract VisualObject findChildByName(String name);
-
- /**
- * Gets this object's root object.
- * The returned object is either this object itself or the first of its parents for which
- * <code>isRootObject()</code> returns <code>true</code>.
- * @return the root object, or <code>null</code> if none is found.
- */
- public abstract VisualObject getRootObject();
-
- /**
- * Detemines whether this object is the same as or a parent of the given object.
- * @param object the given object.
- * @return <code>true</code> if the object is the same as the argument
- * object or one of its parents, <code>false</code> otherwise.
- */
- public abstract boolean isSameOrChild(VisualObject object);
-
- /**
- * Deletes this visual object.
- * <p>
- * This visual object is delinked from the parent/child/sibling hierarchy,
- * removed from its project and discarded.
- */
- public abstract void delete();
-
- /**
- * An <code>insert</code> "insertionOperation" value indicating the object will be moved from its
- * current location and inserted in the new location.
- * @see #insert
- */
- public static final int MOVE_OBJECT_OPERATION = 0;
- /**
- * An <code>insert</code> "insertionOperation" value indicating a copy of the object will inserted.
- * @see #insert
- */
- public static final int COPY_OBJECT_OPERATION = 1;
- /**
- * An <code>insert</code> "before" value indicating a copy of the object will be appended at the end
- * of the parent object's list of children.
- * @see #insert
- */
- public static final VisualObject INSERT_AT_END = null;
-
- /**
- * Inserts the object as a child of this visual object
- * and before the specified visual object.
- *
- * @param object object to be inserted.
- * @param before object that will follow inserted object in sibling list.
- * if <code>INSERT_AD_END</code>, the object is inserted at the end.
- * @param insertOperation <code>MOVE_OBJECT_OPERATION</code> - to move the object from its current location
- * and insert it at the new location, or <code>COPY_OBJECT_OPERATION</code> - to insert a copy of the object
- * at the new location.
- * @return <code>true</code> if the object was successfully moved/copied, <code>false</code> if the operation failed.
- * @see #canInsert
- */
- public abstract boolean insert(VisualObject object, VisualObject before, int insertOperation);
-
- /**
- * Determines whether an object can be inserted as a component of this object.
- *
- * @param object object to be tested.
- * @return <code>true</code> if this object can contain argument object, <code>false</code> otherwise.
- * @see #insert
- */
- public abstract boolean canInsert(VisualObject object);
-
- /**
- * Gets the name of this object's customizer class.
- * A customizer provides the GUI used to customize this <code>VisualObject</code>. It is a type
- * of Component.
- * @return the name of this object's customizer class.
- */
- public abstract String getCustomizerClassName();
-
- /**
- * Gets the name of the JAR file containing the code for this bean.
- * @return the JAR filename.
- */
- public abstract String getJarName();
-
- /**
- * Gets the JAR file containing the code for this bean.
- * @return the JAR file.
- */
- public abstract File getJarFile();
-
- /**
- * Gets the <code>VisualProject</code> that this <code>VisualObject</code> belongs to.
- * @return the <code>VisualProject</code> that contains this object, or <code>null</code> if this object is in the
- * Component Library.
- */
- public abstract VisualProject getVisualProject();
-
- /**
- * Gets the <code>VisualRepository</code> that contains this object.
- * This can be a project's Object Library, the Component
- * Library, or <code>null</code> if the object hasn't been inserted.
- * @return a <code>VisualRepository</code> identifying the Component Library, a <code>VisualProject</code>'s
- * Object Library, or <code>null</code>.
- */
- public abstract VisualRepository getVisualRepository();
-
- /**
- * Gets the id of the <code>ProjectFile</code> that contains this <code>VisualObject</code>.
- * @return the id of <code>ProjectFile</code> that contains this object, or <code>-1</code> if
- * this object is in the Component Library.
- */
- public abstract int getProjectFileID();
-
- /**
- * Gets the <code>ProjectFile</code> that contains this <code>VisualObject</code>.
- * @return the <code>ProjectFile</code> that contains this object, or <code>null</code> if
- * this object is in the Component Library.
- */
- public abstract ProjectFile getProjectFile();
-
- /**
- * Gets a <code>VisualProperty</code> given its internal name.
- * Internal names typically begin with "ipn". For example, the internal property name for
- * <code>JMenuItem.text</code> is "ipntext".
- *
- * @param internalPropertyName the locale-independent property name.
- * @return the <code>VisualProperty</code> or <code>null</code> if there is no property with that name.
- */
- public abstract VisualProperty findProperty(String internalPropertyName);
-
- /**
- * Gets this object's the first visible <code>VisualProperty</code>.
- * @return the first visible <code>VisualProperty</code>, or <code>null</code> if none.
- * @see VisualProperty#getSibling
- * @see VisualProperty#getFirstChild
- */
- public abstract VisualProperty getFirstProperty();
-
- /**
- * Gets this object's default <code>VisualProperty</code>.
- *
- * This is the property that will be selected in the property list by default.
- * @return the <code>VisualProperty</code>, or <code>null</code> if none.
- */
- public abstract VisualProperty getDefaultProperty();
-
-
- /**
- * Determines the number of <code>VisualProperties</code> this <code>VisualObject</code> has.
- * @return the number of <code>VisualProperties</code>, or 0 if this <code>VisualObject</code> has no properties.
- * @see #getProperty
- * @see #getProperties
- */
- public abstract int getNumProperties();
-
- /**
- * Gets the <code>VisualProperty</code> with the specified zero-based index.
- * @param index the specified zero-based index.
- * @return the specified <code>VisualProperty</code> object.
- * @throws <code>ArrayIndexOutOfBoundsException</code> if the index is out of range.
- * @see #getProperties
- * @see #getNumProperties
- */
- public abstract VisualProperty getProperty(int index);
-
- /**
- * Gets all of the <code>VisualProperties</code> of this object. If none exist then a zero-length array is returned.
- *
- * @return an array of <code>VisualProperty</code> objects.
- * @see #getProperty
- * @see #getNumProperties
- */
- public abstract VisualProperty[] getProperties();
-
- /**
- * Enumerates the top level, visible <code>VisualProperties</code>. The <code>Enumeration</code> elements are
- * <code>VisualProperty</code> objects. An <code>Enumeration</code> is returned even if this <code>VisualObject</code>
- * has no properties.
- *
- * @return an <code>Enumeration</code> of <code>VisualProperty</code> objects.
- */
- public abstract Enumeration enumerateProperties();
-
- /**
- * Opens an appropriate editor for this <code>VisualObject</code>.
- */
- public abstract void invokeEditor();
-
- /**
- * Opens a source editor for this <code>VisualObject</code>'s source file.
- */
- public abstract void invokeSourceEditor();
-
- /**
- * Performs a deep copy of this <code>VisualObject</code> and all its descendents.
- * The new Object is not added to the project.
- * @return a new copy of this <code>VisualObject</code>.
- */
- public abstract Object clone();
-
- /**
- * Gets an <code>Image</code> for an icon that represents this <code>VisualObject</code>.
- * @param iconKind the kind of icon to return. Can be one of the four
- * kinds in java.beans.BeanInfo: ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, or
- * ICON_MONO_32x32.
- * @return an Image for this <code>VisualObject</code>.
- */
- public abstract Image getIcon(int iconKind);
-
- /**
- * Determines if the contents of Visual Cafe's clipboard can be pasted
- * onto/into this <code>VisualObject</code>.
- * @return <code>false</code> if the clipboard doesn't contain <code>VisualObjects</code>, or this
- * <code>VisualObject</code> cannot accept the <code>VisualObjects</code> on the clipboard.
- * @see com.symantec.itools.vcafe.openapi.datatransfer.VisualCafeClipboard
- * @see com.symantec.itools.vcafe.openapi.datatransfer.TransferableVisualObjects
- */
- public abstract boolean canPasteClipboardContents();
-
- /**
- * Copies this <code>VisualObject</code> to Visual Cafe's clipboard.
- * The <code>VisualObject</code>'s <code>toString()</code> representation is used as the <code>StringSelection</code> text.
- * @see com.symantec.itools.vcafe.openapi.datatransfer.VisualCafeClipboard
- * @see com.symantec.itools.vcafe.openapi.datatransfer.TransferableVisualObjects
- */
- public abstract void copyToClipboard();
-
- /**
- * Copies this <code>VisualObject</code> to Visual Cafe's clipboard.
- * @param textValue the <code>String</code> to be used as the <code>StringSelection</code> text
- * @see com.symantec.itools.vcafe.openapi.datatransfer.VisualCafeClipboard
- * @see com.symantec.itools.vcafe.openapi.datatransfer.TransferableVisualObjects
- */
- public abstract void copyToClipboard(String textValue);
-
-
- /**
- * Determines if this <code>VisualObject</code> corresponds to a valid object in its <code>VisualProject</code>.
- * @return <code>true</code> if so, <code>false</code> otherwise.
- * @see #checkValidity
- */
- public abstract boolean isValid();
-
-
- /**
- * Determines if this <code>VisualObject</code> corresponds to a valid object in its <code>VisualProject</code>.
- * <code>isValid()</code> is similar, but returns a boolean value indicating validity instead of throwing an
- * <code>InvalidVisualObjectException</code> if the validity check fails.
- * Note that the implementation of all of <code>VisualObject</code>'s abstract methods first call
- * checkValidity(). Any method could therefore throw an <code>InvalidVisualObjectException</code>.
- *
- * @exception InvalidVisualObjectException when using a <code>VisualObject</code> has been removed from its project,
- * or its project has been closed, for example.
- * @see #isValid
- */
- public void checkValidity() throws InvalidVisualObjectException {
- if (!isValid()) throw new InvalidVisualObjectException();
- }
-
- /**
- * Gets the design-time reflection's DTClass object for this <code>VisualObject</code>'s type.
- * The Design-Time Reflection package (com.symantec.itools.vcafe.openapi.dtreflect) provides services
- * analogous to the Java reflection API, but is based upon parse information gathered by Visual Cafe.
- * Thus, classes reflected upon need not be compiled or in a compilable state.
- * @return the <code>DTClass</code> of this object.
- * @see com.symantec.itools.vcafe.openapi.dtreflect.DTClass
- */
- public abstract DTClass getDTClassObject();
-
- /**
- * Gets the <code>java.lang.Class</code> object for this <code>VisualObject</code>'s type.
- * @return the <code>Class</code> of this object.
- */
- public abstract Class getClassObject() throws ClassNotFoundException;
-
-
- /**
- * Creates a new <code>Object</code> that represents this <code>VisualObject</code>, with all of the
- * properties set appropriately.
- * For example, if this <code>VisualObject</code> describes a <code>java.awt.Checkbox</code>,
- * a new checkbox is created and returned.
- *
- * @param thePropertyInstanceGetter an object that is used to determine Object Reference Properties
- * @return a newly created <code>Object</code> defined by this <code>VisualObject</code>
- */
- public abstract Object instantiate(PropertyInstanceGetter thePropertyInstanceGetter)
- throws ClassNotFoundException, InstantiationException, IllegalAccessException;
-
- /**
- * Updates the value of the Java object's property at the specified index to match the
- * value of the corresponding <code>VisualProperty</code> in this <code>VisualObject</code>.
- * @param propertyIndex the index of the property to update.
- * @param instance the corresponding Java object to update.
- * @param theInstanceGetter an object that is used to determine Object Reference Properties.
- * @return the instance object if the Java object's property was updated successfully (this may be the same object
- * as the instance parameter, but may be a re-created object if necessary. <code>null</code> is returned if the property
- * was not updated successfully.
- * @exception ArrayIndexOutOfBoundsException if the <code>propertyIndex</code> is out of range.
- */
- public abstract Object updateInstanceProperty(int propertyIndex, Object instance, PropertyInstanceGetter thePropertyInstanceGetter)
- throws ClassNotFoundException, InstantiationException, IllegalAccessException;
-
- /**
- * Sets this <code>VisualObject</code> as active in the Property List of Visual Cafe.
- *
- * @see VisualCafe#setActiveObjects
- */
- public abstract void setActiveObject();
-
- /**
- * Sets this <code>VisualObject</code> as active in the Property List of Visual Cafe.
- *
- * @param forceDefaultProperty force the default property for the object to be selected.
- * if <code>false</code>, the previously selected property remains selected
- * (if it exists for this object).
- * @see VisualCafe#setActiveObjects(boolean)
- */
- public abstract void setActiveObject(boolean forceDefaultProperty);
-
- /**
- * Add a <code>VisualObjectListener</code> to this <code>VisualObject</code>.
- * All changes to this <code>VisualObject</code> (and optionally to its children) are broadcast
- * to the listeners registered with it.
- * @param listener the object that receives notifications of changes to the <code>VisualObject</code>.
- * @param children <code>true</code> if the listener wishes to receive notifications of changes to
- * this <code>VisualObject</code>'s children as well.
- *
- * @see VisualObjectListener
- * @see #removeVisualObjectListener
- * @see VisualCafe#removeVisualObjectListener
- */
- public abstract void addVisualObjectListener(VisualObjectListener listener, boolean children);
-
- /**
- * Remove a listener from this visual object.
- * Stop receiving notifications of changes to this object
- * @param listener the object that was receiving notifications
- *
- * @see VisualObjectListener
- * @see #addVisualObjectListener
- * @see VisualCafe#removeVisualObjectListener
- */
- public abstract void removeVisualObjectListener(VisualObjectListener listener);
-
- /**
- * Gets a <code>String</code> that represents this object.
- * @return the <code>String</code>.
- */
- public String toString() {
- if (!isValid()) return "invalid VisualObject: " + super.toString();
- return "VisualObject[name=" + getName() + ",isJavaObject=" + isJavaObject() + ",class=" + getClassName() + "]";
- }
-
- }
-