001: package net.xoetrope.builder.editor.plugin;
002:
003: import java.util.Hashtable;
004: import java.util.Vector;
005:
006: import java.awt.AWTEvent;
007: import java.awt.Component;
008: import java.awt.Frame;
009: import javax.swing.JDialog;
010: import javax.swing.JFrame;
011: import javax.swing.JMenu;
012: import javax.swing.JMenuItem;
013: import javax.swing.JPanel;
014: import javax.swing.event.MenuEvent;
015:
016: import net.xoetrope.builder.editor.XEditorProject;
017: import net.xoetrope.builder.editor.XPageResource;
018: import net.xoetrope.builder.editor.components.PropertyHelper;
019: import java.awt.Color;
020:
021: /**
022: * An abstract base class from which to build editor plugins. The plugins can
023: * interact with the editor in a number of different ways including appearing
024: * as dialogs, property windows or tab panes.
025: * <p> Copyright (c) Xoetrope Ltd., 2002-2003</p>
026: * <p> $Revision: 1.16 $</p>
027: * <p> License: see License.txt</p>
028: */
029: public abstract class XEditorPlugin implements Comparable {
030: public static final int PROJECT_PLUGIN = 0;
031: public static final int PAGE_EDITOR = 1;
032: public static final int PROPERTY_EDITOR = 3;
033:
034: public static final int UNINITIALIZED = 0;
035: public static final int CREATED = 1;
036: public static final int LOADED = 2;
037: public static final int ACTIVATED = 3;
038: public static final int DEACTIVATED = 4;
039: public static final int CLOSED = 5;
040:
041: public abstract void setFrame(JFrame appFrame);
042:
043: protected String pluginUrl = "";
044:
045: private Color pluginTabBackground = null;
046: private Color pluginTabForeground = null;
047:
048: /**
049: * Get the name of the plugin as it will appear on the plugin menu
050: * @return the short name
051: */
052: public abstract String getName();
053:
054: /**
055: * Get the names of the deployment jar file that house the plugin's runtime
056: * components
057: * @return the short name of the jar file
058: */
059: public abstract String[] getDeploymentJarNames();
060:
061: public abstract int getPluginType();
062:
063: /**
064: * Get the url for the plugin's jar file
065: * @return the plugin url string
066: */
067: public String getPluginUrl() {
068: return pluginUrl;
069: }
070:
071: /**
072: * Set the url for the plugin's jar file
073: * @param the new plugin url string
074: */
075: public void setPluginUrl(String newUrl) {
076: pluginUrl = newUrl;
077: }
078:
079: /**
080: * Gets the main menu to show on the main menu bar
081: * @return
082: */
083: public abstract JMenu getMenu();
084:
085: /**
086: * Get the menuItem or the sub menu that plugs into the plugins menu.
087: * @return the JMenu or JMenuItem or null if no menu is being provided. If no
088: * menu is provided then the plugins menu item will be derived from the plugin name
089: * and will activate or deactive the plugin.
090: */
091: public abstract JMenuItem getPluginMenu();
092:
093: /**
094: * Get the menuItem or the sub menu that plugs into the context/popup menu for
095: * the selected components. The functions on this menu should all operate on
096: * the selection or individual component selecte.
097: * @return the JMenu or JMenuItem or null if no menu is being provided.
098: */
099: public abstract JMenuItem getContextMenu();
100:
101: /**
102: * Get the panel that will plug into the main panel. The panel will be given a
103: * tab of its own on the editor's tabbar
104: * @return the main panel or null for no panel
105: */
106: public abstract JPanel getMainPanel();
107:
108: /**
109: * Gets the dialog for this plugin. The dialog must be modal. Once dismissed
110: * no further interaction with the plugin should take place
111: * @param applicationFrame the main application fram
112: * @return the dialog
113: */
114: public abstract JDialog getDialog(Frame applicationFrame);
115:
116: /**
117: * Get the panel that plugs into the right hand side splitter of the editor.
118: * The panel is intended to allow property editors to be located alongside the
119: * componen designer
120: * @return the panel or null if this plugin doesn't offer such a facility
121: */
122: public abstract JPanel getPropertiesPanel();
123:
124: /**
125: * Get an array of components to add to the toolbar
126: * @return
127: */
128: public abstract Component[] getToolbarComponents();
129:
130: /**
131: * Get the name used on the tabbar for a plugin's components
132: * @return the tab name
133: */
134: public abstract String getToolbarName();
135:
136: /**
137: * Get a flag indicating if the plugin creates a dialog
138: * @return true if the plugin presents a dialog
139: */
140: public abstract boolean isDialogPlugin();
141:
142: /**
143: * Process a menu commands for a plugin
144: * @param command the command id
145: * @param evt the original event
146: * @param selected the selected state of the toolbar or menu item or false if no state exists
147: */
148: public abstract int processCommand(int command, AWTEvent evt,
149: boolean selected);
150:
151: /**
152: * Tells the plugin to save its data
153: * @return 0 for success, non zero otherwise
154: */
155: public abstract int save();
156:
157: public abstract void setActiveProject(XEditorProject project);
158:
159: public abstract void setActivePage(XPageResource page);
160:
161: public abstract void setActiveComponents(Vector comps);
162:
163: /**
164: * Compares this XEditorPlugin to another Object. If the Object is a XEditorPlugin,
165: * this function behaves like <code>compareTo(String)</code>. Otherwise,
166: * it throws a <code>ClassCastException</code> (as XEditorPlugin are comparable
167: * only to other XEditorPlugin).
168: *
169: * @param o the <code>Object</code> to be compared.
170: * @return the value <code>0</code> if the plugin whose name
171: * lexicographically equal to this plugin's name; a value less than
172: * <code>0</code> if the argument is a name lexicographically
173: * greater than this plugin's name; and a value greater than
174: * <code>0</code> if the argument is a name lexicographically
175: * less than this plugin's name.
176: * @exception <code>ClassCastException</code> if the argument is not a
177: * <code>XEditorPlugin</code>.
178: * @see java.lang.Comparable
179: */
180: public int compareTo(Object o) {
181: return getName().compareTo(((XEditorPlugin) o).getName());
182: }
183:
184: /**
185: * Set the activation/deactivation state of the plugin
186: * @param newState the new state
187: */
188: public abstract void setState(int newState);
189:
190: /**
191: * Get the activation/deactivation state of the plugin
192: */
193: public abstract int getState();
194:
195: public abstract void cut();
196:
197: public abstract void copy();
198:
199: public abstract void paste();
200:
201: public abstract void delete();
202:
203: public void menuSelected(MenuEvent e) {
204: }
205:
206: /**
207: * Get a set of attributes belonging to this page.
208: * @param thePage the page whos attributes are being requested
209: * @return a Hashtable of keys and values or null if none are provided
210: */
211: public Hashtable getPageAttributes(XPageResource thePage) {
212: return null;
213: }
214:
215: /**
216: * Get a set of attributes belonging to this component.
217: * @param comp the component whos attributes are being requested
218: * @return a Hashtable of keys and values or null if none are provided
219: */
220: public Hashtable getComponentAttributes(Component comp) {
221: return null;
222: }
223:
224: /**
225: * Get the tab color
226: * @param foreGround true for the foreground color, false for the background color.
227: * @return the color or null for the default
228: */
229: public Color getTabColor(boolean foreGround) {
230: return foreGround ? pluginTabForeground : pluginTabBackground;
231: }
232:
233: /**
234: * Set the tab color
235: * @param foreGround true for the foreground color, false for the background color.
236: * @param clr the color
237: */
238: public void setTabColor(boolean foreGround, Color clr) {
239: if (foreGround)
240: pluginTabForeground = clr;
241: else
242: pluginTabBackground = clr;
243: }
244: }
|