001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 2004-2005 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.jmx.agentwizard;
042:
043: import java.awt.Component;
044: import java.util.ResourceBundle;
045: import javax.swing.event.*;
046:
047: import org.openide.WizardDescriptor;
048: import org.openide.util.HelpCtx;
049: import org.openide.util.NbBundle;
050: import org.openide.awt.Mnemonics;
051:
052: import org.netbeans.api.project.Project;
053: import org.netbeans.spi.project.ui.templates.support.Templates;
054:
055: import org.netbeans.modules.jmx.WizardConstants;
056: import org.netbeans.modules.jmx.GenericWizardPanel;
057:
058: import org.netbeans.modules.jmx.runtime.J2SEProjectType;
059:
060: /**
061: *
062: * Class handling the graphical part of the standard Agent wizard panel
063: *
064: */
065: public class AgentPanel extends javax.swing.JPanel {
066:
067: private AgentWizardPanel wiz;
068: private ResourceBundle bundle;
069: private static WizardDescriptor wizDesc;
070: private boolean agentNameSelected = false;
071: private boolean updateNameRunning = false;
072: private boolean mainSelected = false;
073: private boolean mainClassSelected = false;
074: private boolean codeExampleSelected = false;
075:
076: /**
077: * Create the wizard panel component and set up some basic properties.
078: * @param wiz <CODE>WizardDescriptor</CODE> a wizard
079: */
080: public AgentPanel(AgentWizardPanel wiz) {
081: this .wiz = wiz;
082: bundle = NbBundle.getBundle(JMXAgentIterator.class);
083: initComponents();
084:
085: Mnemonics.setLocalizedText(mainJCheckBox, bundle
086: .getString("LBL_chkMain.text"));//NOI18N
087: Mnemonics.setLocalizedText(codeExampleJCheckBox, bundle
088: .getString("LBL_chkCodeExample.text"));//NOI18N
089: Mnemonics.setLocalizedText(mainClassJCheckBox, bundle
090: .getString("LBL_chkMainClass.text"));//NOI18N
091:
092: // init flags
093: codeExampleSelected = codeExampleJCheckBox.isSelected();
094: mainSelected = mainJCheckBox.isSelected();
095: mainClassSelected = mainClassJCheckBox.isSelected();
096:
097: // Provide a name in the title bar.
098: setName(NbBundle
099: .getMessage(AgentPanel.class, "LBL_Agent_Panel")); //NOI18N
100:
101: // Accessibility
102: mainJCheckBox.getAccessibleContext().setAccessibleName(
103: bundle.getString("ACCESS_CREATE_MAIN_METHOD"));// NOI18N
104: mainJCheckBox
105: .getAccessibleContext()
106: .setAccessibleDescription(
107: bundle
108: .getString("ACCESS_CREATE_MAIN_METHOD_DESCRIPTION"));// NOI18N
109:
110: mainClassJCheckBox.getAccessibleContext().setAccessibleName(
111: bundle.getString("ACCESS_SET_MAIN_CLASS"));// NOI18N
112: mainClassJCheckBox
113: .getAccessibleContext()
114: .setAccessibleDescription(
115: bundle
116: .getString("ACCESS_SET_MAIN_CLASS_DESCRIPTION"));// NOI18N
117:
118: codeExampleJCheckBox.getAccessibleContext().setAccessibleName(
119: bundle.getString("ACCESS_GENERATE_SAMPLE"));// NOI18N
120: codeExampleJCheckBox
121: .getAccessibleContext()
122: .setAccessibleDescription(
123: bundle
124: .getString("ACCESS_GENERATE_SAMPLE_DESCRIPTION"));// NOI18N
125: }
126:
127: private static boolean shouldEnableMainProjectClass() {
128: Project project = Templates.getProject(wizDesc);
129: return J2SEProjectType.isProjectTypeSupported(project);
130: }
131:
132: /** This method is called from within the constructor to
133: * initialize the form.
134: * WARNING: Do NOT modify this code. The content of this method is
135: * always regenerated by the Form Editor.
136: */
137: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
138: private void initComponents() {
139: agentOptionsPanel = new javax.swing.JPanel();
140: mainJCheckBox = new javax.swing.JCheckBox();
141: mainClassJCheckBox = new javax.swing.JCheckBox();
142: codeExampleJCheckBox = new javax.swing.JCheckBox();
143:
144: setLayout(new java.awt.BorderLayout());
145:
146: agentOptionsPanel.setLayout(new javax.swing.BoxLayout(
147: agentOptionsPanel, javax.swing.BoxLayout.Y_AXIS));
148:
149: mainJCheckBox.setSelected(true);
150: mainJCheckBox.setName("agentMainMethodCheckBox");
151: mainJCheckBox
152: .addActionListener(new java.awt.event.ActionListener() {
153: public void actionPerformed(
154: java.awt.event.ActionEvent evt) {
155: mainJCheckBoxActionPerformed(evt);
156: }
157: });
158:
159: agentOptionsPanel.add(mainJCheckBox);
160:
161: mainClassJCheckBox.setSelected(true);
162: mainClassJCheckBox.setName("mainClass");
163: agentOptionsPanel.add(mainClassJCheckBox);
164:
165: codeExampleJCheckBox.setSelected(true);
166: codeExampleJCheckBox.setName("agentSampleCodeCheckBox");
167: codeExampleJCheckBox
168: .addActionListener(new java.awt.event.ActionListener() {
169: public void actionPerformed(
170: java.awt.event.ActionEvent evt) {
171: codeExampleJCheckBoxActionPerformed(evt);
172: }
173: });
174:
175: agentOptionsPanel.add(codeExampleJCheckBox);
176:
177: add(agentOptionsPanel, java.awt.BorderLayout.CENTER);
178:
179: }
180:
181: // </editor-fold>//GEN-END:initComponents
182:
183: private void codeExampleJCheckBoxActionPerformed(
184: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codeExampleJCheckBoxActionPerformed
185: codeExampleSelected = codeExampleJCheckBox.isSelected();
186: }//GEN-LAST:event_codeExampleJCheckBoxActionPerformed
187:
188: private void mainJCheckBoxActionPerformed(
189: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mainJCheckBoxActionPerformed
190: mainSelected = mainJCheckBox.isSelected();
191:
192: mainClassJCheckBox.setEnabled(mainSelected
193: && shouldEnableMainProjectClass());
194:
195: if (!mainSelected) {
196: mainClassSelected = mainClassJCheckBox.isSelected();
197: mainClassJCheckBox.setSelected(false);
198:
199: } else {
200: mainClassJCheckBox.setSelected(mainClassSelected);
201: }
202:
203: }//GEN-LAST:event_mainJCheckBoxActionPerformed
204:
205: // Variables declaration - do not modify//GEN-BEGIN:variables
206: private javax.swing.JPanel agentOptionsPanel;
207: private javax.swing.JCheckBox codeExampleJCheckBox;
208: private javax.swing.JCheckBox mainClassJCheckBox;
209: private javax.swing.JCheckBox mainJCheckBox;
210:
211: // End of variables declaration//GEN-END:variables
212:
213: /**
214: *
215: * Class handling the standard Agent wizard panel
216: *
217: */
218: public static class AgentWizardPanel extends GenericWizardPanel {
219: private AgentPanel panel = null;
220:
221: /**
222: * Returns the agent panel.
223: * @return <CODE>Component</CODE> the agent panel
224: */
225: public Component getComponent() {
226: return getPanel();
227: }
228:
229: private AgentPanel getPanel() {
230: if (panel == null) {
231: panel = new AgentPanel(this );
232: }
233: return panel;
234: }
235:
236: /**
237: * Returns if the main method generation is selected.
238: * @return <CODE>boolean</CODE> true if main method generation is selected
239: */
240: public boolean isMainSelected() {
241: return getPanel().mainSelected;
242: }
243:
244: /**
245: * Returns if the set as main class is selected.
246: * @return <CODE>boolean</CODE> true if set as main class is selected
247: */
248: public boolean isMainClassSelected() {
249: return getPanel().mainClassJCheckBox.isSelected();
250: }
251:
252: /**
253: * Returns if source code hints is selected.
254: * @return <CODE>boolean</CODE> true if source code hints is selected.
255: */
256: public boolean isCodeExampleSelected() {
257: return getPanel().codeExampleSelected;
258: }
259:
260: /**
261: * This method is called when a step is loaded.
262: * @param settings <CODE>Object</CODE> an object containing the wizard informations.
263: */
264: public void readSettings(Object settings) {
265: wizDesc = (WizardDescriptor) settings;
266: if (!shouldEnableMainProjectClass())
267: getPanel().mainClassJCheckBox.setEnabled(false);
268: }
269:
270: /**
271: * This method is called when the user quit a step.
272: * @param settings <CODE>Object</CODE> an object containing the wizard informations.
273: */
274: public void storeSettings(Object settings) {
275: WizardDescriptor wiz = (WizardDescriptor) settings;
276:
277: wiz.putProperty(
278: WizardConstants.PROP_AGENT_MAIN_METHOD_SELECTED,
279: new Boolean(isMainSelected()));
280: wiz.putProperty(
281: WizardConstants.PROP_AGENT_MAIN_CLASS_SELECTED,
282: new Boolean(isMainClassSelected()));
283: wiz.putProperty(
284: WizardConstants.PROP_AGENT_SAMPLE_CODE_SELECTED,
285: new Boolean(isCodeExampleSelected()));
286: }
287:
288: /**
289: * Returns the corresponding help context.
290: * @return <CODE>HelpCtx</CODE> the corresponding help context.
291: */
292: public HelpCtx getHelp() {
293: return new HelpCtx("tutorial"); //NOI18N
294: }
295:
296: }
297:
298: }
|