001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/experimental/J3dSkyPlugin.java,v 1.1 2005/04/20 21:04:27 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.experimental;
019:
020: import javax.media.j3d.BranchGroup;
021: import org.jdesktop.j3dfly.plugins.PluginPreference;
022: import org.jdesktop.j3dfly.plugins.J3dFlyPlugin;
023:
024: import org.jdesktop.j3dfly.utils.environment.J3dSkyControlPanel;
025: import org.jdesktop.j3dfly.utils.environment.J3dSky;
026: import org.jdesktop.j3dfly.J3dFlyContext;
027:
028: /**
029: *
030: * @author paulby
031: * @version
032: */
033: public class J3dSkyPlugin extends J3dFlyPlugin implements
034: java.awt.event.ActionListener {
035:
036: private java.lang.ref.SoftReference panelReference = null;
037: private J3dSky sky = null;
038:
039: /** Creates new EnvironmentPlugin */
040: public J3dSkyPlugin() {
041: super ();
042: }
043:
044: /**
045: * Returns the class of the plugin preference.
046: *
047: * Plugins that require more preference information should provide a
048: * subclass of PluginPrefernece that contains all the extra preference
049: * data. This class must be Serializable.
050: */
051: public Class getPluginPreferenceClass() {
052: return J3dSkyPluginPreference.class;
053: }
054:
055: public void installPlugin(PluginPreference pluginToolPref,
056: J3dFlyContext j3dflyContext) {
057: super .installPlugin(pluginToolPref, j3dflyContext);
058: if (pluginPref.isInstallInMenu())
059: getMenu("Plugins").add(getMenuItem());
060: sky = new J3dSky();
061: sky.setEnable(pluginToolPref.isEnabled());
062: sky.setCapability(BranchGroup.ALLOW_DETACH);
063:
064: j3dflyContext.getUniverse().getLocale().addBranchGraph(sky);
065: }
066:
067: public void uninstallPlugin() {
068: super .uninstallPlugin();
069: if (pluginPref.isInstallInMenu())
070: getMenu("Plugins").remove(getMenuItem());
071: j3dflyContext.getUniverse().getLocale().removeBranchGraph(sky);
072: }
073:
074: /**
075: * Enable/disable the plugin
076: */
077: public void setEnabled(boolean enabled) {
078: super .setEnabled(enabled);
079: sky.setEnable(enabled);
080: }
081:
082: /**
083: * Returns the control panel for this plugin
084: */
085: public javax.swing.JPanel getControlPanel() {
086: if (panelReference == null || panelReference.get() == null)
087: panelReference = new java.lang.ref.SoftReference(
088: new J3dSkyControlPanel(sky));
089:
090: return (J3dSkyControlPanel) panelReference.get();
091: }
092:
093: /**
094: * Returns the Menu Item (or JMenu) which controls this
095: * plugin. Null should be return for no menu entry
096: */
097: public javax.swing.JMenuItem getMenuItem() {
098: if (menu == null) {
099: menu = new javax.swing.JMenuItem("Sky Controls...");
100: menu.addActionListener(this );
101: }
102:
103: return menu;
104: }
105:
106: /**
107: * Get the title of the plugin
108: */
109: public String getPluginTitle() {
110: return "J3dSky";
111: }
112:
113: public void actionPerformed(java.awt.event.ActionEvent p1) {
114: showControls();
115: }
116:
117: public static class J3dSkyPluginPreference extends PluginPreference {
118: public J3dSkyPluginPreference() {
119: super ();
120: }
121:
122: public J3dSkyPluginPreference(boolean enabled, boolean installed) {
123: super (enabled, installed);
124: }
125:
126: public J3dFlyPlugin instantiatePlugin() {
127: return new J3dSkyPlugin();
128: }
129:
130: /**
131: * Return a description of this plugin
132: */
133: public String getDescription() {
134: return "Sample Sky simulator";
135: }
136:
137: /**
138: * Return the name of the Plugin for this prefernece.
139: * This is the name that will appear in the list of plugins
140: */
141: public String getName() {
142: return "J3dSky";
143: }
144:
145: }
146:
147: }
|