001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/VPDriveBehaviorPlugin.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.HoverBehavior;
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 VPDriveBehaviorPlugin extends VPBehaviorPlugin {
042:
043: private java.lang.ref.SoftReference panelReference = null;
044:
045: /** Creates new form PluginTemplate */
046: public VPDriveBehaviorPlugin() {
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: // Uncomment this code and change XXXX to instantiate the panel for
071: // this Plugin if it has one, otherwise return null
072:
073: if (panelReference == null || panelReference.get() == null)
074: panelReference = new java.lang.ref.SoftReference(
075: new J3dFlyMouseBehaviorControlPanel(
076: (J3dFlyMouseBehaviorPluginPreference) pluginPref));
077:
078: return (javax.swing.JPanel) panelReference.get();
079: }
080:
081: public String getMenuString() {
082: return "Drive";
083: }
084:
085: public String getTooltipText() {
086: return "Drive Behavior";
087: }
088:
089: /**
090: * Install the plugin and add it's menu item to the menu
091: */
092: public void installPlugin(PluginPreference pluginPref,
093: J3dFlyContext j3dflyContext) {
094: super .installPlugin(pluginPref, j3dflyContext);
095: pluginPref.getContext().getEventProcessor().postEvent(
096: new VPBehaviorPluginEvent(this ,
097: VPBehaviorPluginEvent.INSTALLED));
098: }
099:
100: /**
101: * Uninstall this plugin
102: */
103: public void uninstallPlugin() {
104: super .uninstallPlugin();
105: pluginPref.getContext().getEventProcessor().postEvent(
106: new VPBehaviorPluginEvent(this ,
107: VPBehaviorPluginEvent.UNINSTALLED));
108: }
109:
110: /**
111: * Returns the class of the plugin preference.
112: *
113: * Plugins that require more preference information should provide a
114: * subclass of PluginPrefernece that contains all the extra preference
115: * data. This class must be Serializable.
116: */
117: public Class getPluginPreferenceClass() {
118: return VPDriveBehaviorPluginPreference.class;
119: }
120:
121: /**
122: * Called to set this behavior to be active or inactive.
123: *
124: * Only one VP Behavior can be active at a given time. This is managed
125: * by J3dFlyController
126: */
127: public void setActive(boolean active) {
128: super .setActive(active);
129:
130: J3dFlyController control = pluginPref.getContext().getJ3dFly()
131: .getController();
132:
133: if (active) {
134: HoverBehavior hover = new HoverBehavior(pluginPref
135: .getContext().getUniverse().getViewer().getView());
136: pluginPref.getContext().getUniverse().getViewingPlatform()
137: .setViewPlatformBehavior(hover);
138: hover.setSchedulingBounds(new BoundingSphere(new Point3d(),
139: Double.POSITIVE_INFINITY));
140: if (control.getCollisionController() != null) {
141: if (!(control.getCollisionController() instanceof VPDriveCollision))
142: control
143: .changeCollisionController(new VPDriveCollision());
144: hover.setCollisionControl(control
145: .getCollisionController());
146: }
147: ((J3dFlyMouseBehaviorPluginPreference) pluginPref).behavior = hover;
148:
149: control.setCollisionEnabled(true);
150:
151: pluginPref.getContext().getUniverse().getViewingPlatform()
152: .setViewPlatformBehavior(hover);
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/driveIcon.gif"));
172: }
173:
174: public static class VPDriveBehaviorPluginPreference extends
175: J3dFlyMouseBehaviorPluginPreference {
176: public VPDriveBehaviorPluginPreference() {
177: super ();
178: }
179:
180: public VPDriveBehaviorPluginPreference(boolean enabled,
181: boolean installed) {
182: super (enabled, installed);
183: }
184:
185: public J3dFlyPlugin instantiatePlugin() {
186: return new VPDriveBehaviorPlugin();
187: }
188:
189: /**
190: * Return a description of this plugin
191: */
192: public String getDescription() {
193: return "A Viewing Platform Driving 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 Drive 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: }
|