001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/VPFlyBehaviorPlugin.java,v 1.1 2005/04/20 21:04:45 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 org.jdesktop.j3dfly.J3dFlyController;
022: import org.jdesktop.j3dfly.event.VPBehaviorPluginEvent;
023: import org.jdesktop.j3dfly.utils.vpbehaviors.VPDefaultCollision;
024: import org.jdesktop.j3dfly.utils.vpbehaviors.VPDriveCollision;
025:
026: import javax.media.j3d.BoundingSphere;
027: import javax.vecmath.Point3d;
028:
029: import org.jdesktop.j3dfly.utils.vpbehaviors.FlyBehavior;
030:
031: /**
032: * This is a Template for a J3dFly Plugin.
033: *
034: * To make it easy to generate comlex menu's for a plugin this code
035: * 'tricks' Netbeans into thinking this is a GUI component and hence
036: * allows the Netbeans GUI editor to be used to edit the menu.
037: *
038: * @author Paul Byrne
039: * @version $Revision: 1.1 $
040: */
041: public class VPFlyBehaviorPlugin extends VPBehaviorPlugin {
042:
043: private java.lang.ref.SoftReference panelReference = null;
044:
045: /** Creates new form PluginTemplate */
046: public VPFlyBehaviorPlugin() {
047: super ();
048: }
049:
050: /** This method is called from within the constructor to
051: * initialize the form.
052: * WARNING: Do NOT modify this code. The content of this method is
053: * always regenerated by the Form Editor.
054: */
055: private void initComponents() {//GEN-BEGIN:initComponents
056: menuBar = new javax.swing.JMenuBar();
057: pluginMenu = new javax.swing.JMenu();
058:
059: pluginMenu.setText("Menu");
060: menuBar.add(pluginMenu);
061:
062: }//GEN-END:initComponents
063:
064: /**
065: * Returns the control panel for this plugin, or null if there
066: * is no control panel
067: */
068: public javax.swing.JPanel getControlPanel() {
069:
070: if (panelReference == null || panelReference.get() == null)
071: panelReference = new java.lang.ref.SoftReference(
072: new J3dFlyMouseBehaviorControlPanel(
073: (J3dFlyMouseBehaviorPluginPreference) pluginPref));
074:
075: return (javax.swing.JPanel) panelReference.get();
076: }
077:
078: public String getMenuString() {
079: return "Fly";
080: }
081:
082: public String getTooltipText() {
083: return "Fly Behavior";
084: }
085:
086: /**
087: * Install the plugin and add it's menu item to the menu
088: */
089: public void installPlugin(PluginPreference pluginPref,
090: J3dFlyContext j3dflyContext) {
091: super .installPlugin(pluginPref, j3dflyContext);
092: pluginPref.getContext().getEventProcessor().postEvent(
093: new VPBehaviorPluginEvent(this ,
094: VPBehaviorPluginEvent.INSTALLED));
095: }
096:
097: /**
098: * Uninstall this plugin
099: */
100: public void uninstallPlugin() {
101: super .uninstallPlugin();
102: pluginPref.getContext().getEventProcessor().postEvent(
103: new VPBehaviorPluginEvent(this ,
104: VPBehaviorPluginEvent.UNINSTALLED));
105: }
106:
107: /**
108: * Returns the class of the plugin preference.
109: *
110: * Plugins that require more preference information should provide a
111: * subclass of PluginPrefernece that contains all the extra preference
112: * data. This class must be Serializable.
113: */
114: public Class getPluginPreferenceClass() {
115: return VPFlyBehaviorPluginPreference.class;
116: }
117:
118: /**
119: * Called to set this behavior to be active or inactive.
120: *
121: * Only one VP Behavior can be active at a given time. This is managed
122: * by J3dFlyController
123: */
124: public void setActive(boolean active) {
125: super .setActive(active);
126:
127: J3dFlyController control = pluginPref.getContext().getJ3dFly()
128: .getController();
129:
130: if (active) {
131: FlyBehavior fly = new FlyBehavior(pluginPref.getContext()
132: .getUniverse().getViewer().getView());
133: pluginPref.getContext().getUniverse().getViewingPlatform()
134: .setViewPlatformBehavior(fly);
135: fly.setSchedulingBounds(new BoundingSphere(new Point3d(),
136: Double.POSITIVE_INFINITY));
137: ((J3dFlyMouseBehaviorPluginPreference) pluginPref).behavior = fly;
138:
139: fly
140: .setAngleStep(((J3dFlyMouseBehaviorPluginPreference) pluginPref)
141: .getAngleStep());
142: fly
143: .setForwardStep(((J3dFlyMouseBehaviorPluginPreference) pluginPref)
144: .getForwardStep());
145: if (control.getCollisionController() != null) {
146: if (!(control.getCollisionController() instanceof VPDefaultCollision))
147: control
148: .changeCollisionController(new VPDefaultCollision());
149: fly.setCollisionControl(control
150: .getCollisionController());
151: }
152:
153: pluginPref.getContext().getEventProcessor().postEvent(
154: new VPBehaviorPluginEvent(this ,
155: VPBehaviorPluginEvent.ACTIVATED));
156: } else {
157: pluginPref.getContext().getEventProcessor().postEvent(
158: new VPBehaviorPluginEvent(this ,
159: VPBehaviorPluginEvent.DEACTIVATED));
160: pluginPref.getContext().getUniverse().getViewingPlatform()
161: .setViewPlatformBehavior(null);
162: ((J3dFlyMouseBehaviorPluginPreference) pluginPref).behavior = null;
163: }
164: }
165:
166: /**
167: * Return the Icon for the toolbar button
168: */
169: public javax.swing.Icon getToolbarIcon() {
170: return new javax.swing.ImageIcon(getClass().getResource(
171: "/org/jdesktop/j3dfly/icons/flyIcon.gif"));
172: }
173:
174: public static class VPFlyBehaviorPluginPreference extends
175: J3dFlyMouseBehaviorPluginPreference {
176: public VPFlyBehaviorPluginPreference() {
177: super ();
178: }
179:
180: public VPFlyBehaviorPluginPreference(boolean enabled,
181: boolean installed) {
182: super (enabled, installed);
183: }
184:
185: public J3dFlyPlugin instantiatePlugin() {
186: return new VPFlyBehaviorPlugin();
187: }
188:
189: /**
190: * Return a description of this plugin
191: */
192: public String getDescription() {
193: return "A Viewing Platform Fly behavior";
194: }
195:
196: /**
197: * Return the name of the Plugin for this prefernece.
198: * This is the name that will appear in the list of plugins
199: */
200: public String getName() {
201: return "VP Fly Behavior";
202: }
203:
204: }
205:
206: // Variables declaration - do not modify//GEN-BEGIN:variables
207: private javax.swing.JMenuBar menuBar;
208: private javax.swing.JMenu pluginMenu;
209: // End of variables declaration//GEN-END:variables
210:
211: }
|