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 1997-2006 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:
042: package org.netbeans.modules.tomcat5.customizer;
043:
044: import java.awt.Font;
045: import java.io.File;
046: import javax.accessibility.AccessibleContext;
047: import javax.swing.JFileChooser;
048: import javax.swing.JSpinner;
049: import javax.swing.JTextField;
050: import javax.swing.SwingUtilities;
051: import org.openide.util.NbBundle;
052: import org.openide.util.Utilities;
053:
054: /**
055: * Customizer Startup tab.
056: *
057: * @author sherold
058: */
059: public class CustomizerStartup extends javax.swing.JPanel {
060:
061: private CustomizerDataSupport custData;
062:
063: private final File catalinaHome;
064:
065: /** Creates new form CustomizerStartup */
066: public CustomizerStartup(CustomizerDataSupport custData,
067: File catalinaHome) {
068: this .custData = custData;
069: this .catalinaHome = catalinaHome;
070:
071: initComponents();
072: if (Utilities.isWindows()) {
073: // force shutdown not supported on Windows
074: jCheckBox4.setEnabled(false);
075: } else {
076: // shared memory debugging transport supported only on Windows
077: jRadioButton1.setEnabled(false);
078: jTextField4.setEnabled(false);
079: }
080:
081: updateCustomScriptComponents();
082:
083: JTextField jSpinner1TextField = ((JSpinner.NumberEditor) jSpinner1
084: .getEditor()).getTextField();
085:
086: AccessibleContext ac = jSpinner1TextField
087: .getAccessibleContext();
088: ac.setAccessibleName(NbBundle.getMessage(
089: CustomizerStartup.class, "ACSN_SocketPortNum"));
090: ac.setAccessibleDescription(NbBundle.getMessage(
091: CustomizerStartup.class, "ACSD_SocketPortNum"));
092:
093: // work-around for jspinner incorrect fonts
094: Font font = jTextField1.getFont();
095: jSpinner1TextField.setFont(font);
096:
097: /*
098: * mnemonics generated in the guarded block do not work
099: * because of change of the model after mnemonic setting
100: * remove the workaround after completion of issue 111094
101: */
102: org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1,
103: org.openide.util.NbBundle.getMessage(
104: CustomizerStartup.class, "TXT_CustomScript")); // NOI18N
105: org.openide.awt.Mnemonics.setLocalizedText(jCheckBox4,
106: org.openide.util.NbBundle.getMessage(
107: CustomizerStartup.class, "TXT_ForceShutdown")); // NOI18N
108: org.openide.awt.Mnemonics.setLocalizedText(jRadioButton1,
109: org.openide.util.NbBundle.getMessage(
110: CustomizerStartup.class, "TXT_SharedMemName")); // NOI18N
111: org.openide.awt.Mnemonics.setLocalizedText(jRadioButton2,
112: org.openide.util.NbBundle.getMessage(
113: CustomizerStartup.class, "TXT_SocketPort")); // NOI18N
114: }
115:
116: /** This method is called from within the constructor to
117: * initialize the form.
118: * WARNING: Do NOT modify this code. The content of this method is
119: * always regenerated by the Form Editor.
120: */
121: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
122: private void initComponents() {
123: java.awt.GridBagConstraints gridBagConstraints;
124:
125: buttonGroup1 = new javax.swing.ButtonGroup();
126: jLabel1 = new javax.swing.JLabel();
127: jTextField1 = new javax.swing.JTextField();
128: jCheckBox1 = new javax.swing.JCheckBox();
129: jLabel4 = new javax.swing.JLabel();
130: jCheckBox4 = new javax.swing.JCheckBox();
131: jRadioButton1 = new javax.swing.JRadioButton();
132: jRadioButton2 = new javax.swing.JRadioButton();
133: jTextField4 = new javax.swing.JTextField();
134: browseButton = new javax.swing.JButton();
135: jLabel2 = new javax.swing.JLabel();
136: jSpinner1 = new javax.swing.JSpinner();
137:
138: setLayout(new java.awt.GridBagLayout());
139:
140: jLabel1.setLabelFor(jTextField1);
141: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
142: org.openide.util.NbBundle.getMessage(
143: CustomizerStartup.class, "TXT_StartupScript")); // NOI18N
144: gridBagConstraints = new java.awt.GridBagConstraints();
145: gridBagConstraints.gridx = 0;
146: gridBagConstraints.gridy = 1;
147: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
148: gridBagConstraints.insets = new java.awt.Insets(5, 17, 0, 0);
149: add(jLabel1, gridBagConstraints);
150: jLabel1.getAccessibleContext()
151: .setAccessibleName(
152: org.openide.util.NbBundle.getMessage(
153: CustomizerStartup.class,
154: "ASCN_CatalinaScript")); // NOI18N
155: jLabel1.getAccessibleContext()
156: .setAccessibleDescription(
157: org.openide.util.NbBundle.getMessage(
158: CustomizerStartup.class,
159: "ASCD_CatalinaScript")); // NOI18N
160:
161: jTextField1.setColumns(20);
162: jTextField1.setDocument(custData.getScriptPathModel());
163: gridBagConstraints = new java.awt.GridBagConstraints();
164: gridBagConstraints.gridx = 1;
165: gridBagConstraints.gridy = 1;
166: gridBagConstraints.gridwidth = 2;
167: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
168: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
169: gridBagConstraints.weightx = 1.0;
170: gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0);
171: add(jTextField1, gridBagConstraints);
172: jTextField1.getAccessibleContext().setAccessibleName(
173: org.openide.util.NbBundle.getMessage(
174: CustomizerStartup.class, "ASCN_Script")); // NOI18N
175: jTextField1.getAccessibleContext().setAccessibleDescription(
176: org.openide.util.NbBundle.getMessage(
177: CustomizerStartup.class, "ASCD_Script")); // NOI18N
178:
179: org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1,
180: org.openide.util.NbBundle.getMessage(
181: CustomizerStartup.class, "TXT_CustomScript")); // NOI18N
182: jCheckBox1.setModel(custData.getCustomScriptModel());
183: jCheckBox1
184: .addChangeListener(new javax.swing.event.ChangeListener() {
185: public void stateChanged(
186: javax.swing.event.ChangeEvent evt) {
187: jCheckBox1StateChanged(evt);
188: }
189: });
190: gridBagConstraints = new java.awt.GridBagConstraints();
191: gridBagConstraints.gridx = 0;
192: gridBagConstraints.gridy = 0;
193: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
194: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
195: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
196: add(jCheckBox1, gridBagConstraints);
197: jCheckBox1.getAccessibleContext().setAccessibleName(
198: org.openide.util.NbBundle.getMessage(
199: CustomizerStartup.class, "ASCN_CustomScript")); // NOI18N
200: jCheckBox1.getAccessibleContext().setAccessibleDescription(
201: org.openide.util.NbBundle.getMessage(
202: CustomizerStartup.class, "ASCD_CustomScript")); // NOI18N
203:
204: org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
205: org.openide.util.NbBundle.getMessage(
206: CustomizerStartup.class, "TXT_DebugTransport")); // NOI18N
207: gridBagConstraints = new java.awt.GridBagConstraints();
208: gridBagConstraints.gridx = 0;
209: gridBagConstraints.gridy = 3;
210: gridBagConstraints.gridwidth = 2;
211: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
212: gridBagConstraints.insets = new java.awt.Insets(11, 12, 0, 0);
213: add(jLabel4, gridBagConstraints);
214: jLabel4.getAccessibleContext().setAccessibleName(
215: org.openide.util.NbBundle.getMessage(
216: CustomizerStartup.class, "ACSN_DebugTrans")); // NOI18N
217: jLabel4.getAccessibleContext().setAccessibleDescription(
218: org.openide.util.NbBundle.getMessage(
219: CustomizerStartup.class, "ACSN_DebugTrans")); // NOI18N
220:
221: org.openide.awt.Mnemonics.setLocalizedText(jCheckBox4,
222: org.openide.util.NbBundle.getMessage(
223: CustomizerStartup.class, "TXT_ForceShutdown")); // NOI18N
224: jCheckBox4.setModel(custData.getForceStopModel());
225: gridBagConstraints = new java.awt.GridBagConstraints();
226: gridBagConstraints.gridx = 0;
227: gridBagConstraints.gridy = 2;
228: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
229: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
230: gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
231: add(jCheckBox4, gridBagConstraints);
232: jCheckBox4.getAccessibleContext().setAccessibleName(
233: org.openide.util.NbBundle.getMessage(
234: CustomizerStartup.class, "ASCN_ForceStop")); // NOI18N
235: jCheckBox4.getAccessibleContext().setAccessibleDescription(
236: org.openide.util.NbBundle.getMessage(
237: CustomizerStartup.class, "ASCD_ForceStop")); // NOI18N
238:
239: buttonGroup1.add(jRadioButton1);
240: org.openide.awt.Mnemonics.setLocalizedText(jRadioButton1,
241: org.openide.util.NbBundle.getMessage(
242: CustomizerStartup.class, "TXT_SharedMemName")); // NOI18N
243: jRadioButton1.setModel(custData.getSharedMemModel());
244: gridBagConstraints = new java.awt.GridBagConstraints();
245: gridBagConstraints.gridx = 0;
246: gridBagConstraints.gridy = 4;
247: gridBagConstraints.gridwidth = 2;
248: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
249: gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
250: add(jRadioButton1, gridBagConstraints);
251: jRadioButton1.getAccessibleContext().setAccessibleName(
252: org.openide.util.NbBundle.getMessage(
253: CustomizerStartup.class, "ACSN_SharedMem")); // NOI18N
254: jRadioButton1.getAccessibleContext().setAccessibleDescription(
255: org.openide.util.NbBundle.getMessage(
256: CustomizerStartup.class, "ACSD_SharedMem")); // NOI18N
257:
258: buttonGroup1.add(jRadioButton2);
259: org.openide.awt.Mnemonics.setLocalizedText(jRadioButton2,
260: org.openide.util.NbBundle.getMessage(
261: CustomizerStartup.class, "TXT_SocketPort")); // NOI18N
262: jRadioButton2.setModel(custData.getSocketModel());
263: gridBagConstraints = new java.awt.GridBagConstraints();
264: gridBagConstraints.gridx = 0;
265: gridBagConstraints.gridy = 5;
266: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
267: gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 0);
268: add(jRadioButton2, gridBagConstraints);
269: jRadioButton2.getAccessibleContext().setAccessibleName(
270: org.openide.util.NbBundle.getMessage(
271: CustomizerStartup.class, "ACSN_SocketPort")); // NOI18N
272: jRadioButton2.getAccessibleContext().setAccessibleDescription(
273: org.openide.util.NbBundle.getMessage(
274: CustomizerStartup.class, "ACSD_SocektPort")); // NOI18N
275:
276: jTextField4.setColumns(15);
277: jTextField4.setDocument(custData.getSharedMemNameModel());
278: gridBagConstraints = new java.awt.GridBagConstraints();
279: gridBagConstraints.gridx = 2;
280: gridBagConstraints.gridy = 4;
281: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
282: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
283: gridBagConstraints.weightx = 1.0;
284: gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0);
285: add(jTextField4, gridBagConstraints);
286: jTextField4.getAccessibleContext().setAccessibleName(
287: org.openide.util.NbBundle.getMessage(
288: CustomizerStartup.class, "ACSD_SharedMemName")); // NOI18N
289:
290: org.openide.awt.Mnemonics.setLocalizedText(browseButton,
291: org.openide.util.NbBundle.getMessage(
292: CustomizerStartup.class,
293: "TXT_BrowseCatalinaScript")); // NOI18N
294: browseButton.setEnabled(false);
295: browseButton
296: .addActionListener(new java.awt.event.ActionListener() {
297: public void actionPerformed(
298: java.awt.event.ActionEvent evt) {
299: browseButtonActionPerformed(evt);
300: }
301: });
302: gridBagConstraints = new java.awt.GridBagConstraints();
303: gridBagConstraints.gridx = 3;
304: gridBagConstraints.gridy = 1;
305: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
306: gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 12);
307: add(browseButton, gridBagConstraints);
308: browseButton.getAccessibleContext().setAccessibleName(
309: org.openide.util.NbBundle.getMessage(
310: CustomizerStartup.class, "ASCN_Browse")); // NOI18N
311: browseButton.getAccessibleContext().setAccessibleDescription(
312: org.openide.util.NbBundle.getMessage(
313: CustomizerStartup.class, "ASCD_Browse")); // NOI18N
314:
315: org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
316: org.openide.util.NbBundle.getMessage(
317: CustomizerStartup.class,
318: "TXT_NoteChangesTakeAffect")); // NOI18N
319: gridBagConstraints = new java.awt.GridBagConstraints();
320: gridBagConstraints.gridx = 0;
321: gridBagConstraints.gridy = 6;
322: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
323: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
324: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
325: gridBagConstraints.weighty = 1.0;
326: gridBagConstraints.insets = new java.awt.Insets(5, 12, 12, 0);
327: add(jLabel2, gridBagConstraints);
328: jLabel2.getAccessibleContext().setAccessibleName(
329: org.openide.util.NbBundle.getMessage(
330: CustomizerStartup.class, "ASCN_Note")); // NOI18N
331: jLabel2.getAccessibleContext().setAccessibleDescription(
332: org.openide.util.NbBundle.getMessage(
333: CustomizerStartup.class, "ASCD_Note")); // NOI18N
334:
335: jSpinner1.setFont(new java.awt.Font("Dialog", 0, 12));
336: jSpinner1.setModel(custData.getDebugPortModel());
337: jSpinner1.setEditor(new JSpinner.NumberEditor(jSpinner1, "#"));
338: gridBagConstraints = new java.awt.GridBagConstraints();
339: gridBagConstraints.gridx = 2;
340: gridBagConstraints.gridy = 5;
341: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
342: gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0);
343: add(jSpinner1, gridBagConstraints);
344: }// </editor-fold>//GEN-END:initComponents
345:
346: private void browseButtonActionPerformed(
347: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
348: JFileChooser chooser;
349: File script = new File(jTextField1.getText().trim());
350: File currentFolder = script.isDirectory() ? script : script
351: .getParentFile();
352:
353: if (currentFolder != null && currentFolder.exists()) {
354: chooser = new JFileChooser(currentFolder);
355: } else if (catalinaHome != null && catalinaHome.exists()) {
356: chooser = new JFileChooser(catalinaHome);
357: } else {
358: chooser = new JFileChooser();
359: }
360:
361: int returnVal = chooser.showOpenDialog(SwingUtilities
362: .getWindowAncestor(this ));
363: if (returnVal == JFileChooser.APPROVE_OPTION) {
364: jTextField1.setText(chooser.getSelectedFile()
365: .getAbsolutePath());
366: }
367: }//GEN-LAST:event_browseButtonActionPerformed
368:
369: private void jCheckBox1StateChanged(
370: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jCheckBox1StateChanged
371: updateCustomScriptComponents();
372: }//GEN-LAST:event_jCheckBox1StateChanged
373:
374: private void updateCustomScriptComponents() {
375: boolean enabled = jCheckBox1.isSelected();
376: jLabel1.setEnabled(enabled);
377: jTextField1.setEnabled(enabled);
378: browseButton.setEnabled(enabled);
379: }
380:
381: // Variables declaration - do not modify//GEN-BEGIN:variables
382: private javax.swing.JButton browseButton;
383: private javax.swing.ButtonGroup buttonGroup1;
384: private javax.swing.JCheckBox jCheckBox1;
385: private javax.swing.JCheckBox jCheckBox4;
386: private javax.swing.JLabel jLabel1;
387: private javax.swing.JLabel jLabel2;
388: private javax.swing.JLabel jLabel4;
389: private javax.swing.JRadioButton jRadioButton1;
390: private javax.swing.JRadioButton jRadioButton2;
391: private javax.swing.JSpinner jSpinner1;
392: private javax.swing.JTextField jTextField1;
393: private javax.swing.JTextField jTextField4;
394: // End of variables declaration//GEN-END:variables
395:
396: }
|