001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/VPSplineInterpolatorPlugin.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:
024: import javax.media.j3d.BoundingSphere;
025: import javax.vecmath.Point3d;
026:
027: import org.jdesktop.j3dfly.utils.behaviors.KBSplineFromFileBG;
028: import org.jdesktop.j3dfly.utils.loadercontrol.ExampleFileFilter;
029:
030: /**
031: * This is a Template for a J3dFly Plugin.
032: *
033: * To make it easy to generate comlex menu's for a plugin this code
034: * 'tricks' Netbeans into thinking this is a GUI component and hence
035: * allows the Netbeans GUI editor to be used to edit the menu.
036: *
037: * @author Paul Byrne
038: * @version $Revision: 1.1 $
039: */
040: public class VPSplineInterpolatorPlugin extends VPBehaviorPlugin {
041:
042: private java.lang.ref.SoftReference panelReference = null;
043: private KBSplineFromFileBG interp = null;
044:
045: /** Creates new form PluginTemplate */
046: public VPSplineInterpolatorPlugin() {
047: super ();
048: initComponents();
049: menuBar.remove(pluginMenu);
050: menuBar = null;
051: }
052:
053: /** This method is called from within the constructor to
054: * initialize the form.
055: * WARNING: Do NOT modify this code. The content of this method is
056: * always regenerated by the Form Editor.
057: */
058: private void initComponents() {//GEN-BEGIN:initComponents
059: menuBar = new javax.swing.JMenuBar();
060: pluginMenu = new javax.swing.JMenu();
061: loadMI = new javax.swing.JMenuItem();
062:
063: pluginMenu.setText("KB Spline Properties");
064: loadMI.setText("Load...");
065: loadMI.setToolTipText("Load a new Spline");
066: loadMI.addActionListener(new java.awt.event.ActionListener() {
067: public void actionPerformed(java.awt.event.ActionEvent evt) {
068: loadMIActionPerformed(evt);
069: }
070: });
071:
072: pluginMenu.add(loadMI);
073: menuBar.add(pluginMenu);
074:
075: }//GEN-END:initComponents
076:
077: private void loadMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadMIActionPerformed
078: // Add your handling code here:
079: javax.swing.JFileChooser fileChooser = pluginPref.getContext()
080: .getJ3dFly().getController().getFileChooser();
081:
082: ExampleFileFilter j3dFilter = new ExampleFileFilter();
083: j3dFilter.setDescription("KB Spline Definition");
084: j3dFilter.addExtension("kbsp");
085:
086: fileChooser.setFileFilter(j3dFilter);
087:
088: int ret = fileChooser.showDialog(pluginPref.getContext()
089: .getJ3dFly().getController(), "Load KB Spline");
090:
091: java.io.File file = null;
092: if (ret == javax.swing.JFileChooser.APPROVE_OPTION) {
093: String filename = fileChooser.getSelectedFile()
094: .getAbsolutePath();
095: ((VPSplineInterpolatorPluginPreference) pluginPref)
096: .setSplineFilename(filename);
097: if (interp != null) {
098: try {
099: interp.loadFile(filename);
100: } catch (java.io.IOException e) {
101: javax.swing.JOptionPane.showMessageDialog(null,
102: "Error Loading file " + filename);
103: }
104: }
105: }
106:
107: }//GEN-LAST:event_loadMIActionPerformed
108:
109: /**
110: * Returns the control panel for this plugin, or null if there
111: * is no control panel
112: */
113: public javax.swing.JPanel getControlPanel() {
114:
115: if (panelReference == null || panelReference.get() == null)
116: panelReference = new java.lang.ref.SoftReference(
117: new J3dFlyMouseBehaviorControlPanel(
118: (J3dFlyMouseBehaviorPluginPreference) pluginPref));
119:
120: return (javax.swing.JPanel) panelReference.get();
121: }
122:
123: public String getMenuString() {
124: return "KB Spline";
125: }
126:
127: public String getTooltipText() {
128: return "KB Spline Interpolator";
129: }
130:
131: /**
132: * Install the plugin and add it's menu item to the menu
133: */
134: public void installPlugin(PluginPreference pluginPref,
135: J3dFlyContext j3dflyContext) {
136: super .installPlugin(pluginPref, j3dflyContext);
137: pluginPref.getContext().getEventProcessor().postEvent(
138: new VPBehaviorPluginEvent(this ,
139: VPBehaviorPluginEvent.INSTALLED));
140:
141: if (pluginPref.isInstallInMenu()) {
142: javax.swing.JMenu menu = getMenu("Viewing Platform");
143: if (menu != null) {
144: menu.add(new javax.swing.JSeparator());
145: menu.add(pluginMenu);
146: }
147: }
148: }
149:
150: /**
151: * Uninstall this plugin
152: */
153: public void uninstallPlugin() {
154: super .uninstallPlugin();
155: pluginPref.getContext().getEventProcessor().postEvent(
156: new VPBehaviorPluginEvent(this ,
157: VPBehaviorPluginEvent.UNINSTALLED));
158:
159: javax.swing.JMenu menu = getMenu("Viewing Platform");
160: if (menu != null) {
161: menu.remove(pluginMenu);
162: }
163:
164: }
165:
166: /**
167: * Returns the class of the plugin preference.
168: *
169: * Plugins that require more preference information should provide a
170: * subclass of PluginPrefernece that contains all the extra preference
171: * data. This class must be Serializable.
172: */
173: public Class getPluginPreferenceClass() {
174: return VPSplineInterpolatorPluginPreference.class;
175: }
176:
177: /**
178: * Called to set this behavior to be active or inactive.
179: *
180: * Only one VP Behavior can be active at a given time. This is managed
181: * by J3dFlyController
182: */
183: public void setActive(boolean active) {
184: super .setActive(active);
185:
186: J3dFlyController control = pluginPref.getContext().getJ3dFly()
187: .getController();
188:
189: if (active) {
190: if (((VPSplineInterpolatorPluginPreference) pluginPref)
191: .getSplineFilename() == null)
192: loadMIActionPerformed(null);
193:
194: interp = new KBSplineFromFileBG(pluginPref.getContext()
195: .getUniverse().getViewingPlatform()
196: .getViewPlatformTransform(),
197: ((VPSplineInterpolatorPluginPreference) pluginPref)
198: .getSplineFilename());
199: interp.setEnabled(true);
200: j3dflyContext.getUniverse().getLocale().addBranchGraph(
201: interp);
202:
203: pluginPref.getContext().getUniverse().getViewingPlatform()
204: .setViewPlatformBehavior(null);
205:
206: pluginPref.getContext().getEventProcessor().postEvent(
207: new VPBehaviorPluginEvent(this ,
208: VPBehaviorPluginEvent.ACTIVATED));
209: } else {
210: interp.setEnabled(false);
211: j3dflyContext.getUniverse().getLocale().removeBranchGraph(
212: interp);
213: interp = null;
214: pluginPref.getContext().getEventProcessor().postEvent(
215: new VPBehaviorPluginEvent(this ,
216: VPBehaviorPluginEvent.DEACTIVATED));
217: pluginPref.getContext().getUniverse().getViewingPlatform()
218: .setViewPlatformBehavior(null);
219: }
220: }
221:
222: /**
223: * Return the Icon for the toolbar button
224: */
225: public javax.swing.Icon getToolbarIcon() {
226: return null;
227: }
228:
229: public static class VPSplineInterpolatorPluginPreference extends
230: J3dFlyMouseBehaviorPluginPreference {
231:
232: /** Holds value of property splineFilename. */
233: private String splineFilename = null;
234:
235: public VPSplineInterpolatorPluginPreference() {
236: super ();
237: }
238:
239: public VPSplineInterpolatorPluginPreference(boolean enabled,
240: boolean installed) {
241: super (enabled, installed);
242: }
243:
244: public J3dFlyPlugin instantiatePlugin() {
245: return new VPSplineInterpolatorPlugin();
246: }
247:
248: /**
249: * Return a description of this plugin
250: */
251: public String getDescription() {
252: return "A Spline based Viewing Platform interpolator";
253: }
254:
255: /**
256: * Return the name of the Plugin for this prefernece.
257: * This is the name that will appear in the list of plugins
258: */
259: public String getName() {
260: return "VP Spline Interpolator";
261: }
262:
263: /** Getter for property splineFilename.
264: * @return Value of property splineFilename.
265: */
266: public String getSplineFilename() {
267: return this .splineFilename;
268: }
269:
270: /** Setter for property splineFilename.
271: * @param splineFilename New value of property splineFilename.
272: */
273: public void setSplineFilename(String splineFilename) {
274: this .splineFilename = splineFilename;
275: }
276:
277: }
278:
279: // Variables declaration - do not modify//GEN-BEGIN:variables
280: private javax.swing.JMenuBar menuBar;
281: private javax.swing.JMenu pluginMenu;
282: private javax.swing.JMenuItem loadMI;
283: // End of variables declaration//GEN-END:variables
284:
285: }
|