001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/PluginPreference.java,v 1.1 2005/04/20 21:04:41 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is Java 3D(tm) Fly Through.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dfly.plugins;
019:
020: import org.jdesktop.j3dfly.J3dFlyContext;
021: import java.beans.*;
022:
023: /**
024: * Base class for all Plugin Preferences. All the methods in PluginPreferences
025: * which follow the Bean pattern naming convention will have their state
026: * saved in the xml preference files.
027: *
028: * If you don't want the state of a property saved in the preference file then
029: * either don't use the Bean naming pattern or mark the property as transient.
030: * Note the transient keyword has no effect on the XMLEncoder,
031: * instead you need to set the a Property of transient=True in the
032: * property descriptor. THis is done automatically for this class
033: * in the PluginPreferenceControl, however if you create a subclass
034: * that uses transient data you will have to create a BeanInfo class
035: * and set the appropriate properties.
036: *
037: * @author Paul Byrne
038: * @version $Revision: 1.1 $
039: */
040: public abstract class PluginPreference extends Object implements
041: java.io.Serializable {
042:
043: /** When a plugin is enabled it's gui is active and
044: * it has an effect on the scene graph. When it's not enabled it
045: * should have NO effect on the scene graph.
046: */
047: protected boolean enabled = true;
048:
049: /** An installed Plugin appears in the set of installed plugins and
050: * it GUI components will be installed, unless it's enabled it will
051: * have no effect on the scene graph
052: */
053: protected boolean installed = true;
054:
055: /**
056: * Should this plugin install itself in the menubar
057: */
058: protected boolean installInMenu = true;
059:
060: /**
061: * The plugin instantiated from these preferences
062: */
063: protected transient J3dFlyPlugin plugin = null;
064:
065: protected transient J3dFlyContext context = null;
066:
067: /**
068: * Indicates where this Plugin was installed from
069: * either SYSTEM, USER or FILE
070: */
071: protected transient int installedFrom;
072: public static final int SYSTEM = 1;
073: public static final int USER = 2;
074: public static final int FILE = 3;
075: public static final int LOADER = 4;
076:
077: /** Creates new PluginPreference */
078: public PluginPreference() {
079: enabled = true;
080: installed = true;
081: }
082:
083: public PluginPreference(boolean enabled, boolean installed) {
084: this .enabled = enabled;
085: this .installed = installed;
086: }
087:
088: /** Getter for property enabled.
089: * @return Value of property enabled.
090: */
091: public boolean isEnabled() {
092: return enabled;
093: }
094:
095: /** Setter for property enabled.
096: * @param enabled New value of property enabled.
097: */
098: public void setEnabled(boolean enabled) {
099: this .enabled = enabled;
100: if (plugin != null)
101: plugin.setEnabled(enabled);
102: }
103:
104: /** Getter for property installed.
105: * @return Value of property installed.
106: */
107: public boolean isInstalled() {
108: return installed;
109: }
110:
111: /**
112: * Install the plugin.
113: *
114: * Note this method also set the installed property.
115: * When the preference is loaded from the xml preference
116: * files the installed property will be set, however the
117: * PluginPreferenceControl will still call setInstalled(true)
118: * later to actually install the plugin.
119: *
120: * @param installed New value of property installed.
121: */
122: public void setInstalled(boolean installed) {
123: this .installed = installed;
124: if (installed) {
125: if (plugin == null)
126: plugin = instantiatePlugin();
127: plugin.installPlugin(this , context);
128: } else {
129: if (plugin != null)
130: plugin.uninstallPlugin();
131: }
132: }
133:
134: /**
135: * Set the context for this plugin
136: */
137: public void setContext(J3dFlyContext context) {
138: this .context = context;
139: }
140:
141: public J3dFlyContext getContext() {
142: return context;
143: }
144:
145: /**
146: * Set where this plugin was installed from
147: * either SYSTEM, USER or FILE
148: */
149: public void setInstalledFrom(int from) {
150: installedFrom = from;
151: }
152:
153: /**
154: * Returns where this plugin was installed from
155: * either SYSTEM, USER or FILE
156: */
157: public int getInstalledFrom() {
158: return installedFrom;
159: }
160:
161: /**
162: * Returns where this plugin was installed from in String form
163: * either System, Usert or File
164: */
165: public String getInstalledFromStr() {
166: switch (installedFrom) {
167: case 1:
168: return "System";
169: case 2:
170: return "User";
171: case 3:
172: return "File";
173: case 4:
174: return "Loader";
175: }
176:
177: throw new RuntimeException("Invalid InstallFrom setting "
178: + this );
179: }
180:
181: /**
182: * Instiate and return the Plugin
183: *
184: * May return null if plugin is unavailable
185: */
186: public abstract J3dFlyPlugin instantiatePlugin();
187:
188: /**
189: * Return the name of the Plugin for this prefernece.
190: * This is the name that will appear in the list of plugins
191: */
192: public abstract String getName();
193:
194: /**
195: * Return a description of this plugin
196: */
197: public abstract String getDescription();
198:
199: /**
200: * Return the plugin instantiated from this preference
201: */
202: public J3dFlyPlugin getPlugin() {
203: return plugin;
204: }
205:
206: /**
207: * Set if this plugin should install itself in the menubar
208: */
209: public void setInstallInMenu(boolean install) {
210: installInMenu = install;
211: }
212:
213: /**
214: * Should this plugin installed itself in the menu bar
215: */
216: public boolean isInstallInMenu() {
217: return installInMenu;
218: }
219: }
|