001: /*
002: * $Header: /cvs/j3dfly/J3dFly/src/org/jdesktop/j3dfly/plugins/PluginControlMenuPlugin.java,v 1.1 2005/04/20 21:04:40 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.swing.JDialog;
022: import java.awt.BorderLayout;
023:
024: /**
025: * This is a Template for a J3dFly Plugin.
026: *
027: * To make it easy to generate comlex menu's for a plugin this code
028: * 'tricks' Netbeans into thinking this is a GUI component and hence
029: * allows the Netbeans GUI editor to be used to edit the menu.
030: *
031: * @author Paul Byrne
032: * @version $Revision: 1.1 $
033: */
034: public class PluginControlMenuPlugin extends J3dFlyPlugin {
035:
036: private java.lang.ref.SoftReference panelReference = null;
037: private java.lang.ref.SoftReference dialogReference = null;
038: private JDialog dialog;
039:
040: /** Creates new form PluginTemplate */
041: public PluginControlMenuPlugin() {
042: super ();
043: }
044:
045: /** This method is called from within the constructor to
046: * initialize the form.
047: * WARNING: Do NOT modify this code. The content of this method is
048: * always regenerated by the Form Editor.
049: */
050: private void initComponents() {//GEN-BEGIN:initComponents
051: menuBar = new javax.swing.JMenuBar();
052: pluginMenu = new javax.swing.JMenu();
053: editMI = new javax.swing.JMenuItem();
054:
055: pluginMenu.setText("Preferences");
056: editMI.setText("Edit Plugin Preferences...");
057: editMI.addActionListener(new java.awt.event.ActionListener() {
058: public void actionPerformed(java.awt.event.ActionEvent evt) {
059: editMIActionPerformed(evt);
060: }
061: });
062:
063: pluginMenu.add(editMI);
064: menuBar.add(pluginMenu);
065:
066: }//GEN-END:initComponents
067:
068: private void editMIActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editMIActionPerformed
069: // Add your handling code here:
070: if (dialog != null)
071: return;
072:
073: dialog = new JDialog();
074: PluginPreferenceControlPanel pluginPrefPanel = new PluginPreferenceControlPanel(
075: j3dflyContext.getPluginPreferenceControl());
076: dialog.setTitle("Plugin Preferences");
077: dialog.getContentPane().setLayout(new BorderLayout());
078: dialog.getContentPane().add(pluginPrefPanel,
079: BorderLayout.CENTER);
080: pluginPrefPanel.editPluginPreferences();
081: dialogReference = new java.lang.ref.SoftReference(dialog);
082:
083: javax.swing.JPanel southPanel = new javax.swing.JPanel();
084: javax.swing.JButton okButton = new javax.swing.JButton("OK");
085: southPanel.add(okButton);
086: okButton.addActionListener(new java.awt.event.ActionListener() {
087: public void actionPerformed(java.awt.event.ActionEvent e) {
088: dialog.setVisible(false);
089: dialog.dispose();
090: dialog = null;
091: }
092: });
093:
094: dialog.getContentPane().add(southPanel, BorderLayout.SOUTH);
095:
096: dialog.pack();
097: dialog.setVisible(true);
098:
099: }//GEN-LAST:event_editMIActionPerformed
100:
101: /**
102: * Get the title of the plugin
103: */
104: public String getPluginTitle() {
105: // Change this to return the name of the plugin
106: return getClass().getName();
107: }
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: // Uncomment this code and change XXXX to instantiate the panel for
116: // this Plugin if it has one, otherwise return null
117:
118: //if (panelReference==null || panelReference.get()==null )
119: // panelReference = new java.lang.ref.SoftReference( new XXXXX() );
120:
121: //return (javax.swing.JPanel)panelReference.get();
122:
123: return null;
124: }
125:
126: /**
127: * Install the plugin and add it's menu item to the menu
128: */
129: public void installPlugin(PluginPreference pluginPref,
130: J3dFlyContext j3dflyContext) {
131: super .installPlugin(pluginPref, j3dflyContext);
132: initComponents();
133:
134: menuBar.removeAll();
135: menuBar = null;
136:
137: menu = pluginMenu;
138: if (pluginPref.isInstallInMenu())
139: getMenu("Plugins").add(menu);
140: }
141:
142: /**
143: * Uninstall this plugin
144: */
145: public void uninstallPlugin() {
146: super .uninstallPlugin();
147: if (pluginPref.isInstallInMenu())
148: getMenu("Plugins").remove(menu);
149: menu = null;
150: }
151:
152: /**
153: * Returns the class of the plugin preference.
154: *
155: * Plugins that require more preference information should provide a
156: * subclass of PluginPrefernece that contains all the extra preference
157: * data. This class must be Serializable.
158: */
159: public Class getPluginPreferenceClass() {
160: return PluginControlMenuPluginPreference.class;
161: }
162:
163: public static class PluginControlMenuPluginPreference extends
164: PluginPreference {
165: public PluginControlMenuPluginPreference() {
166: super ();
167: }
168:
169: public PluginControlMenuPluginPreference(boolean enabled,
170: boolean installed) {
171: super (enabled, installed);
172: }
173:
174: public J3dFlyPlugin instantiatePlugin() {
175: return new PluginControlMenuPlugin();
176: }
177:
178: /**
179: * Return the name of the Plugin for this prefernece.
180: * This is the name that will appear in the list of plugins
181: */
182: public String getName() {
183: return "Plugin Controls";
184: }
185:
186: /**
187: * Return a description of this plugin
188: */
189: public String getDescription() {
190: return "Provides infrastructure for editing all plugins";
191: }
192:
193: }
194:
195: // Variables declaration - do not modify//GEN-BEGIN:variables
196: private javax.swing.JMenuBar menuBar;
197: private javax.swing.JMenu pluginMenu;
198: private javax.swing.JMenuItem editMI;
199: // End of variables declaration//GEN-END:variables
200:
201: }
|