001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/ViewControlPlugin.java,v 1.1 2005/04/20 21:04:47 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 javax.media.j3d.View;
022:
023: /**
024: * This is a Template for a J3dFly Plugin.
025: *
026: * To make it easy to generate comlex menu's for a plugin this code
027: * 'tricks' Netbeans into thinking this is a GUI component and hence
028: * allows the Netbeans GUI editor to be used to edit the menu.
029: *
030: * @author Paul Byrne
031: * @version $Revision: 1.1 $
032: */
033: public class ViewControlPlugin extends J3dFlyPlugin {
034:
035: private java.lang.ref.SoftReference panelReference = null;
036:
037: /** Creates new form PluginTemplate */
038: public ViewControlPlugin() {
039: super ();
040: }
041:
042: /** This method is called from within the constructor to
043: * initialize the form.
044: * WARNING: Do NOT modify this code. The content of this method is
045: * always regenerated by the Form Editor.
046: */
047: private void initComponents() {//GEN-BEGIN:initComponents
048: menuBar = new javax.swing.JMenuBar();
049: pluginMenu = new javax.swing.JMenu();
050: sortTransparencyCBMI = new javax.swing.JCheckBoxMenuItem();
051: sceneAntialiasingCBMI = new javax.swing.JCheckBoxMenuItem();
052: showControlsMI = new javax.swing.JMenuItem();
053:
054: pluginMenu.setText("View Controls");
055: sortTransparencyCBMI.setText("Sort Transparencies");
056: sortTransparencyCBMI
057: .addActionListener(new java.awt.event.ActionListener() {
058: public void actionPerformed(
059: java.awt.event.ActionEvent evt) {
060: sortTransparencyCBMIActionPerformed(evt);
061: }
062: });
063:
064: pluginMenu.add(sortTransparencyCBMI);
065: sceneAntialiasingCBMI.setText("Scene Antialiasing");
066: sceneAntialiasingCBMI
067: .addActionListener(new java.awt.event.ActionListener() {
068: public void actionPerformed(
069: java.awt.event.ActionEvent evt) {
070: sceneAntialiasingCBMIActionPerformed(evt);
071: }
072: });
073:
074: pluginMenu.add(sceneAntialiasingCBMI);
075: showControlsMI.setText("Controls...");
076: showControlsMI
077: .addActionListener(new java.awt.event.ActionListener() {
078: public void actionPerformed(
079: java.awt.event.ActionEvent evt) {
080: showControlsMIActionPerformed(evt);
081: }
082: });
083:
084: pluginMenu.add(showControlsMI);
085: menuBar.add(pluginMenu);
086:
087: }//GEN-END:initComponents
088:
089: private void sceneAntialiasingCBMIActionPerformed(
090: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sceneAntialiasingCBMIActionPerformed
091: // Add your handling code here:
092: setSceneAntialiasingEnabled(sceneAntialiasingCBMI.isSelected());
093: }//GEN-LAST:event_sceneAntialiasingCBMIActionPerformed
094:
095: private void sortTransparencyCBMIActionPerformed(
096: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sortTransparencyCBMIActionPerformed
097: // Add your handling code here:
098: setTransparencySortingEnabled(sortTransparencyCBMI.isSelected());
099: }//GEN-LAST:event_sortTransparencyCBMIActionPerformed
100:
101: private void showControlsMIActionPerformed(
102: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showControlsMIActionPerformed
103: // Add your handling code here:
104: showControls();
105: }//GEN-LAST:event_showControlsMIActionPerformed
106:
107: void setSceneAntialiasingEnabled(boolean enabled) {
108: sceneAntialiasingCBMI.setSelected(enabled);
109: getJ3dFlyContext().getUniverse().getViewer().getView()
110: .setSceneAntialiasingEnable(enabled);
111: }
112:
113: void setTransparencySortingEnabled(boolean enabled) {
114: sortTransparencyCBMI.setSelected(enabled);
115: if (enabled)
116: getJ3dFlyContext().getUniverse().getViewer().getView()
117: .setTransparencySortingPolicy(
118: View.TRANSPARENCY_SORT_GEOMETRY);
119: else
120: getJ3dFlyContext().getUniverse().getViewer().getView()
121: .setTransparencySortingPolicy(
122: View.TRANSPARENCY_SORT_NONE);
123: }
124:
125: void setMinimumFrameCylcleTime(long minTime) {
126: getJ3dFlyContext().getUniverse().getViewer().getView()
127: .setMinimumFrameCycleTime(minTime);
128: }
129:
130: void setWindowResizePolicy(int policy) {
131: getJ3dFlyContext().getUniverse().getViewer().getView()
132: .setWindowResizePolicy(policy);
133: }
134:
135: void setFrontClipDistance(double distance) {
136: getJ3dFlyContext().getUniverse().getViewer().getView()
137: .setFrontClipDistance(distance);
138: }
139:
140: void setBackClipDistance(double distance) {
141: getJ3dFlyContext().getUniverse().getViewer().getView()
142: .setBackClipDistance(distance);
143: }
144:
145: /**
146: * Get the title of the plugin
147: */
148: public String getPluginTitle() {
149: // Change this to return the name of the plugin
150: return "View Controls";
151: }
152:
153: /**
154: * Returns the control panel for this plugin, or null if there
155: * is no control panel
156: */
157: public javax.swing.JPanel getControlPanel() {
158:
159: // Uncomment this code and change XXXX to instantiate the panel for
160: // this Plugin if it has one, otherwise return null
161:
162: if (panelReference == null || panelReference.get() == null)
163: panelReference = new java.lang.ref.SoftReference(
164: new ViewControlPanel(this ));
165:
166: return (javax.swing.JPanel) panelReference.get();
167:
168: //return null;
169: }
170:
171: /**
172: * Install the plugin and add it's menu item to the menu
173: */
174: public void installPlugin(PluginPreference pluginPref,
175: J3dFlyContext j3dflyContext) {
176: super .installPlugin(pluginPref, j3dflyContext);
177: initComponents();
178:
179: menuBar.removeAll();
180: menuBar = null;
181:
182: View view = getJ3dFlyContext().getUniverse().getViewer()
183: .getView();
184: sceneAntialiasingCBMI.setSelected(view
185: .getSceneAntialiasingEnable());
186: if (view.getTransparencySortingPolicy() == View.TRANSPARENCY_SORT_NONE)
187: sortTransparencyCBMI.setSelected(false);
188: else
189: sortTransparencyCBMI.setSelected(true);
190:
191: // By default the menu item for this plugin will be added to
192: // the plugins Menu in the main menu bar for the application.
193: // You must set the super.menu object to point to the menu item
194: // you want displayed.
195:
196: // Set the menu item for this plugin to be another menu
197: menu = pluginMenu;
198: getMenu("Plugins").add(menu);
199: }
200:
201: /**
202: * Uninstall this plugin
203: */
204: public void uninstallPlugin() {
205: super .uninstallPlugin();
206: getMenu("Plugins").remove(menu);
207: menu = null;
208: }
209:
210: /**
211: * Returns the class of the plugin preference.
212: *
213: * Plugins that require more preference information should provide a
214: * subclass of PluginPrefernece that contains all the extra preference
215: * data. This class must be Serializable.
216: */
217: public Class getPluginPreferenceClass() {
218: return ViewControlPluginPreference.class;
219: }
220:
221: public static class ViewControlPluginPreference extends
222: PluginPreference {
223: public ViewControlPluginPreference() {
224: super ();
225: }
226:
227: public ViewControlPluginPreference(boolean enabled,
228: boolean installed) {
229: super (enabled, installed);
230: }
231:
232: public J3dFlyPlugin instantiatePlugin() {
233: plugin = new ViewControlPlugin();
234: return plugin;
235: }
236:
237: /**
238: * Return the name of the Plugin for this prefernece.
239: * This is the name that will appear in the list of plugins
240: */
241: public String getName() {
242: return "View Control";
243: }
244:
245: /**
246: * Return a description of this plugin
247: */
248: public String getDescription() {
249: return "Controls for various View parameters";
250: }
251:
252: }
253:
254: // Variables declaration - do not modify//GEN-BEGIN:variables
255: private javax.swing.JMenuBar menuBar;
256: private javax.swing.JMenu pluginMenu;
257: private javax.swing.JMenuItem showControlsMI;
258: private javax.swing.JCheckBoxMenuItem sceneAntialiasingCBMI;
259: private javax.swing.JCheckBoxMenuItem sortTransparencyCBMI;
260: // End of variables declaration//GEN-END:variables
261:
262: }
|