001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/VPHoverBehaviorPlugin.java,v 1.1 2005/04/20 21:04:46 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 VPHoverBehaviorPlugin extends VPBehaviorPlugin {
042:
043: private java.lang.ref.SoftReference panelReference = null;
044:
045: /** Creates new form PluginTemplate */
046: public VPHoverBehaviorPlugin() {
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: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
056: private void initComponents() {
057: menuBar = new javax.swing.JMenuBar();
058: pluginMenu = new javax.swing.JMenu();
059:
060: pluginMenu.setText("Menu");
061: menuBar.add(pluginMenu);
062:
063: }
064:
065: // </editor-fold>//GEN-END:initComponents
066:
067: /**
068: * Returns the control panel for this plugin, or null if there
069: * is no control panel
070: */
071: public javax.swing.JPanel getControlPanel() {
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 "Hover";
083: }
084:
085: /**
086: * Install the plugin and add it's menu item to the menu
087: */
088: public void installPlugin(PluginPreference pluginPref,
089: J3dFlyContext j3dflyContext) {
090: super .installPlugin(pluginPref, j3dflyContext);
091: pluginPref.getContext().getEventProcessor().postEvent(
092: new VPBehaviorPluginEvent(this ,
093: VPBehaviorPluginEvent.INSTALLED));
094: }
095:
096: /**
097: * Uninstall this plugin
098: */
099: public void uninstallPlugin() {
100: super .uninstallPlugin();
101: pluginPref.getContext().getEventProcessor().postEvent(
102: new VPBehaviorPluginEvent(this ,
103: VPBehaviorPluginEvent.UNINSTALLED));
104: }
105:
106: /**
107: * Returns the class of the plugin preference.
108: *
109: * Plugins that require more preference information should provide a
110: * subclass of PluginPrefernece that contains all the extra preference
111: * data. This class must be Serializable.
112: */
113: public Class getPluginPreferenceClass() {
114: return VPHoverBehaviorPluginPreference.class;
115: }
116:
117: /**
118: * Called to set this behavior to be active or inactive.
119: *
120: * Only one VP Behavior can be active at a given time. This is managed
121: * by J3dFlyController
122: */
123: public void setActive(boolean active) {
124: super .setActive(active);
125:
126: J3dFlyController control = pluginPref.getContext().getJ3dFly()
127: .getController();
128: if (active) {
129: HoverBehavior hover = new HoverBehavior(pluginPref
130: .getContext().getUniverse().getViewer().getView());
131: pluginPref.getContext().getUniverse().getViewingPlatform()
132: .setViewPlatformBehavior(hover);
133: hover.setSchedulingBounds(new BoundingSphere(new Point3d(),
134: Double.POSITIVE_INFINITY));
135: if (control.getCollisionController() != null) {
136: if (control.getCollisionController() instanceof VPDriveCollision)
137: control
138: .changeCollisionController(new VPDefaultCollision());
139: hover.setCollisionControl(control
140: .getCollisionController());
141: }
142: ((J3dFlyMouseBehaviorPluginPreference) pluginPref).behavior = hover;
143: pluginPref.getContext().getUniverse().getViewingPlatform()
144: .setViewPlatformBehavior(hover);
145: pluginPref.getContext().getEventProcessor().postEvent(
146: new VPBehaviorPluginEvent(this ,
147: VPBehaviorPluginEvent.ACTIVATED));
148: } else {
149: pluginPref.getContext().getEventProcessor().postEvent(
150: new VPBehaviorPluginEvent(this ,
151: VPBehaviorPluginEvent.DEACTIVATED));
152: pluginPref.getContext().getUniverse().getViewingPlatform()
153: .setViewPlatformBehavior(null);
154: ((J3dFlyMouseBehaviorPluginPreference) pluginPref).behavior = null;
155: }
156: }
157:
158: /**
159: * Return the Icon for the toolbar button
160: */
161: public javax.swing.Icon getToolbarIcon() {
162: return new javax.swing.ImageIcon(getClass().getResource(
163: "/org/jdesktop/j3dfly/icons/hoverIcon.gif"));
164: }
165:
166: /**
167: * Return the tooltip string for the Menu and Toolbar
168: */
169: public String getTooltipText() {
170: return "Hover Behavior";
171: }
172:
173: public static class VPHoverBehaviorPluginPreference extends
174: J3dFlyMouseBehaviorPluginPreference {
175: public VPHoverBehaviorPluginPreference() {
176: super ();
177: }
178:
179: public VPHoverBehaviorPluginPreference(boolean enabled,
180: boolean installed) {
181: super (enabled, installed);
182: }
183:
184: public J3dFlyPlugin instantiatePlugin() {
185: return new VPHoverBehaviorPlugin();
186: }
187:
188: /**
189: * Return a description of this plugin
190: */
191: public String getDescription() {
192: return "A Viewing Platform Hover behavior";
193: }
194:
195: /**
196: * Return the name of the Plugin for this prefernece.
197: * This is the name that will appear in the list of plugins
198: */
199: public String getName() {
200: return "VP Hover Behavior";
201: }
202:
203: }
204:
205: // Variables declaration - do not modify//GEN-BEGIN:variables
206: private javax.swing.JMenuBar menuBar;
207: private javax.swing.JMenu pluginMenu;
208: // End of variables declaration//GEN-END:variables
209:
210: }
|