001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/FileHandlerPlugin.java,v 1.3 2007/04/10 03:48:58 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 java.awt.event.KeyEvent;
021: import javax.swing.ButtonGroup;
022: import org.jdesktop.j3dfly.J3dFlyContext;
023: import org.jdesktop.j3dfly.event.CollisionEnableEvent;
024: import org.jdesktop.j3dfly.event.EventProcessor;
025:
026: import javax.media.j3d.BranchGroup;
027:
028: /**
029: *
030: * @author Paul Byrne
031: * @version $Revision: 1.3 $
032: */
033: public class FileHandlerPlugin extends J3dFlyPlugin {
034:
035: /** Creates new form J3dFlyMenu */
036: public FileHandlerPlugin() {
037: super ();
038:
039: javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(false);
040: initComponents();
041: menuBar.remove(fileMenu);
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 FileHandlerPluginPreference.class;
053: }
054:
055: public void installPlugin(PluginPreference pluginPref,
056: J3dFlyContext j3dflyContext) {
057: super .installPlugin(pluginPref, j3dflyContext);
058: if (pluginPref.isInstallInMenu())
059: j3dflyContext.getMainMenuBar().add(fileMenu);
060: }
061:
062: public void uninstallPlugin() {
063: super .uninstallPlugin();
064: if (pluginPref.isInstallInMenu())
065: j3dflyContext.getMainMenuBar().remove(fileMenu);
066: }
067:
068: /** This method is called from within the constructor to
069: * initialize the form.
070: * WARNING: Do NOT modify this code. The content of this method is
071: * always regenerated by the FormEditor.
072: */
073: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
074: private void initComponents() {
075: java.awt.GridBagConstraints gridBagConstraints;
076:
077: menuBar = new javax.swing.JMenuBar();
078: fileMenu = new javax.swing.JMenu();
079: loadMI = new javax.swing.JMenuItem();
080: importMI = new javax.swing.JMenuItem();
081: saveMI = new javax.swing.JMenuItem();
082: saveAsMI = new javax.swing.JMenuItem();
083: saveOptionsMI = new javax.swing.JMenuItem();
084: clearSceneMI = new javax.swing.JMenuItem();
085: jSeparator1 = new javax.swing.JSeparator();
086: configureLoadersMI = new javax.swing.JMenuItem();
087: jSeparator2 = new javax.swing.JSeparator();
088: exitMI = new javax.swing.JMenuItem();
089: saveOptionsDialog = new javax.swing.JDialog();
090: jPanel1 = new javax.swing.JPanel();
091: streamCB = new javax.swing.JCheckBox();
092: noJ3dFlyObjCB = new javax.swing.JCheckBox();
093: applyB = new javax.swing.JButton();
094:
095: fileMenu.setMnemonic(KeyEvent.VK_F);
096: fileMenu.setText("File");
097: loadMI.setMnemonic(KeyEvent.VK_L);
098: loadMI.setText("Load...");
099: loadMI
100: .setToolTipText("Load new data, clearing the universe first");
101: loadMI.addActionListener(new java.awt.event.ActionListener() {
102: public void actionPerformed(java.awt.event.ActionEvent evt) {
103: loadMIActionPerformed(evt);
104: }
105: });
106:
107: fileMenu.add(loadMI);
108:
109: importMI.setText("Import...");
110: importMI
111: .setToolTipText("Import new data into the existing universe");
112: importMI.addActionListener(new java.awt.event.ActionListener() {
113: public void actionPerformed(java.awt.event.ActionEvent evt) {
114: importMIActionPerformed(evt);
115: }
116: });
117:
118: fileMenu.add(importMI);
119:
120: saveMI.setText("Save");
121: fileMenu.add(saveMI);
122:
123: saveAsMI.setText("Save As...");
124: saveAsMI.addActionListener(new java.awt.event.ActionListener() {
125: public void actionPerformed(java.awt.event.ActionEvent evt) {
126: saveAsMIActionPerformed(evt);
127: }
128: });
129:
130: fileMenu.add(saveAsMI);
131:
132: saveOptionsMI.setText("Save Options...");
133: saveOptionsMI
134: .addActionListener(new java.awt.event.ActionListener() {
135: public void actionPerformed(
136: java.awt.event.ActionEvent evt) {
137: saveOptionsMIActionPerformed(evt);
138: }
139: });
140:
141: fileMenu.add(saveOptionsMI);
142:
143: clearSceneMI.setText("Clear");
144: clearSceneMI.setToolTipText("Clear the universe");
145: clearSceneMI
146: .addActionListener(new java.awt.event.ActionListener() {
147: public void actionPerformed(
148: java.awt.event.ActionEvent evt) {
149: clearSceneMIActionPerformed(evt);
150: }
151: });
152:
153: fileMenu.add(clearSceneMI);
154:
155: fileMenu.add(jSeparator1);
156:
157: configureLoadersMI.setText("Configure Loaders");
158: configureLoadersMI
159: .addActionListener(new java.awt.event.ActionListener() {
160: public void actionPerformed(
161: java.awt.event.ActionEvent evt) {
162: configureLoadersMIActionPerformed(evt);
163: }
164: });
165:
166: fileMenu.add(configureLoadersMI);
167:
168: fileMenu.add(jSeparator2);
169:
170: exitMI.setText("Exit");
171: exitMI.addActionListener(new java.awt.event.ActionListener() {
172: public void actionPerformed(java.awt.event.ActionEvent evt) {
173: exitMIActionPerformed(evt);
174: }
175: });
176:
177: fileMenu.add(exitMI);
178:
179: menuBar.add(fileMenu);
180:
181: saveOptionsDialog.setName("Save Options");
182: jPanel1.setLayout(new java.awt.GridBagLayout());
183:
184: streamCB.setText(" Save As Stream");
185: streamCB
186: .setToolTipText("Save the file as a SceneGraphIO Stream");
187: streamCB.setBorder(javax.swing.BorderFactory.createEmptyBorder(
188: 0, 0, 0, 0));
189: streamCB.setMargin(new java.awt.Insets(0, 0, 0, 0));
190: gridBagConstraints = new java.awt.GridBagConstraints();
191: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
192: jPanel1.add(streamCB, gridBagConstraints);
193:
194: noJ3dFlyObjCB.setText(" Remove J3dFly objects");
195: noJ3dFlyObjCB
196: .setToolTipText("Standard Java 3D and Java objects in graph only");
197: noJ3dFlyObjCB.setBorder(javax.swing.BorderFactory
198: .createEmptyBorder(0, 0, 0, 0));
199: noJ3dFlyObjCB.setEnabled(false);
200: noJ3dFlyObjCB.setMargin(new java.awt.Insets(0, 0, 0, 0));
201: gridBagConstraints = new java.awt.GridBagConstraints();
202: gridBagConstraints.gridx = 0;
203: gridBagConstraints.gridy = 1;
204: gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 0);
205: jPanel1.add(noJ3dFlyObjCB, gridBagConstraints);
206:
207: applyB.setText("Apply");
208: applyB.addActionListener(new java.awt.event.ActionListener() {
209: public void actionPerformed(java.awt.event.ActionEvent evt) {
210: applyBActionPerformed(evt);
211: }
212: });
213:
214: gridBagConstraints = new java.awt.GridBagConstraints();
215: gridBagConstraints.gridx = 0;
216: gridBagConstraints.gridy = 2;
217: gridBagConstraints.insets = new java.awt.Insets(9, 0, 0, 0);
218: jPanel1.add(applyB, gridBagConstraints);
219:
220: saveOptionsDialog.getContentPane().add(jPanel1,
221: java.awt.BorderLayout.CENTER);
222:
223: }// </editor-fold>//GEN-END:initComponents
224:
225: private void applyBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyBActionPerformed
226: saveOptionsDialog.setVisible(false);
227: if (streamCB.isSelected())
228: j3dflyContext.getJ3dFly().getController()
229: .setDefaultFileExtension("j3s");
230: else
231: j3dflyContext.getJ3dFly().getController()
232: .setDefaultFileExtension("j3f");
233:
234: }//GEN-LAST:event_applyBActionPerformed
235:
236: private void saveOptionsMIActionPerformed(
237: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveOptionsMIActionPerformed
238: saveOptionsDialog.setSize(200, 140);
239: saveOptionsDialog.setVisible(true);
240: }//GEN-LAST:event_saveOptionsMIActionPerformed
241:
242: private void importMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importMIActionPerformed
243: // Add your handling code here:
244: j3dflyContext.getJ3dFly().getController().loadScene();
245: }//GEN-LAST:event_importMIActionPerformed
246:
247: private void clearSceneMIActionPerformed(
248: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearSceneMIActionPerformed
249: // Add your handling code here:
250: j3dflyContext.getJ3dFly().getController().clearUniverse();
251: }//GEN-LAST:event_clearSceneMIActionPerformed
252:
253: private void exitMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMIActionPerformed
254: // Add your handling code here:
255: System.exit(0);
256: }//GEN-LAST:event_exitMIActionPerformed
257:
258: private void configureLoadersMIActionPerformed(
259: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configureLoadersMIActionPerformed
260: // Add your handling code here:
261: j3dflyContext.getJ3dFly().getController()
262: .configureLoaders(null);
263: }//GEN-LAST:event_configureLoadersMIActionPerformed
264:
265: private void saveAsMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMIActionPerformed
266: // Add your handling code here:
267: boolean asStream = streamCB.isSelected();
268: boolean removeJ3dFlyObj = noJ3dFlyObjCB.isSelected();
269: j3dflyContext.getJ3dFly().getController().saveAsScene(asStream,
270: removeJ3dFlyObj);
271: }//GEN-LAST:event_saveAsMIActionPerformed
272:
273: private void loadMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadMIActionPerformed
274: // Add your handling code here:
275: j3dflyContext.getJ3dFly().getController().clearUniverse();
276: j3dflyContext.getJ3dFly().getController().loadScene();
277: }//GEN-LAST:event_loadMIActionPerformed
278:
279: /**
280: * Netbeans thinks this class is a subclass of JFrame, it's not so add
281: * this NOP method to allow compilation in Netbeans
282: */
283: private void setJMenuBar(javax.swing.JMenuBar mb) {
284: }
285:
286: /**
287: * Returns the control panel for this plugin, or null if there
288: * is no control panel
289: */
290: public javax.swing.JPanel getControlPanel() {
291: return null;
292: }
293:
294: /**
295: * Get the title of the plugin
296: */
297: public String getPluginTitle() {
298: return "File Handler";
299: }
300:
301: public static class FileHandlerPluginPreference extends
302: PluginPreference {
303: public FileHandlerPluginPreference() {
304: super ();
305: }
306:
307: public FileHandlerPluginPreference(boolean enabled,
308: boolean installed) {
309: super (enabled, installed);
310: }
311:
312: public J3dFlyPlugin instantiatePlugin() {
313: return new FileHandlerPlugin();
314: }
315:
316: /**
317: * Return a description of this plugin
318: */
319: public String getDescription() {
320: return "Provides File IO controls";
321: }
322:
323: /**
324: * Return the name of the Plugin for this prefernece.
325: * This is the name that will appear in the list of plugins
326: */
327: public String getName() {
328: return "File Handler";
329: }
330:
331: }
332:
333: // Variables declaration - do not modify//GEN-BEGIN:variables
334: private javax.swing.JButton applyB;
335: private javax.swing.JMenuItem clearSceneMI;
336: private javax.swing.JMenuItem configureLoadersMI;
337: private javax.swing.JMenuItem exitMI;
338: private javax.swing.JMenu fileMenu;
339: private javax.swing.JMenuItem importMI;
340: private javax.swing.JPanel jPanel1;
341: private javax.swing.JSeparator jSeparator1;
342: private javax.swing.JSeparator jSeparator2;
343: private javax.swing.JMenuItem loadMI;
344: private javax.swing.JMenuBar menuBar;
345: private javax.swing.JCheckBox noJ3dFlyObjCB;
346: private javax.swing.JMenuItem saveAsMI;
347: private javax.swing.JMenuItem saveMI;
348: private javax.swing.JDialog saveOptionsDialog;
349: private javax.swing.JMenuItem saveOptionsMI;
350: private javax.swing.JCheckBox streamCB;
351: // End of variables declaration//GEN-END:variables
352:
353: }
|