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.apisupport.project.ui.wizard.options;
043:
044: import java.io.File;
045: import javax.swing.JFileChooser;
046: import javax.swing.event.DocumentEvent;
047: import javax.swing.event.DocumentListener;
048: import org.netbeans.modules.apisupport.project.ui.UIUtil;
049: import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardIterator;
050: import org.openide.WizardDescriptor;
051: import org.openide.util.HelpCtx;
052: import org.openide.util.NbBundle;
053:
054: /**
055: * @author Radek Matous
056: */
057: final class OptionsPanel0 extends BasicWizardIterator.Panel {
058: private NewOptionsIterator.DataModel data;
059: private DocumentListener fieldsDL;
060:
061: public OptionsPanel0(final WizardDescriptor setting,
062: final NewOptionsIterator.DataModel data) {
063: super (setting);
064: this .data = data;
065: initComponents();
066: initAccessibility();
067: putClientProperty("NewFileWizard_Title",// NOI18N
068: NbBundle.getMessage(OptionsPanel0.class,
069: "LBL_OptionsWizardTitle")); // NOI18N
070:
071: }
072:
073: private void addListeners() {
074: if (fieldsDL == null) {
075: fieldsDL = new UIUtil.DocumentAdapter() {
076: public void insertUpdate(DocumentEvent e) {
077: updateData();
078: }
079: };
080:
081: categoryNameField.getDocument().addDocumentListener(
082: fieldsDL);
083: displayNameField1.getDocument().addDocumentListener(
084: fieldsDL);
085: iconField.getDocument().addDocumentListener(fieldsDL);
086: titleField.getDocument().addDocumentListener(fieldsDL);
087: tooltipField1.getDocument().addDocumentListener(fieldsDL);
088: }
089: }
090:
091: private void removeListeners() {
092: if (fieldsDL != null) {
093: categoryNameField.getDocument().removeDocumentListener(
094: fieldsDL);
095: displayNameField1.getDocument().removeDocumentListener(
096: fieldsDL);
097: iconField.getDocument().removeDocumentListener(fieldsDL);
098: titleField.getDocument().removeDocumentListener(fieldsDL);
099: tooltipField1.getDocument()
100: .removeDocumentListener(fieldsDL);
101: fieldsDL = null;
102: }
103: }
104:
105: protected void storeToDataModel() {
106: removeListeners();
107: updateData();
108: }
109:
110: protected void readFromDataModel() {
111: addListeners();
112: }
113:
114: private void updateData() {
115: int retCode = 0;
116: if (advancedButton.isSelected()) {
117: assert !optionsCategoryButton.isSelected();
118: retCode = data.setDataForAdvanced(displayNameField1
119: .getText(), tooltipField1.getText());
120: } else {
121: assert optionsCategoryButton.isSelected();
122: retCode = data.setDataForOptionCategory(titleField
123: .getText(), categoryNameField.getText(), iconField
124: .getText());
125: }
126: if (data.isSuccessCode(retCode)) {
127: markValid();
128: } else if (data.isErrorCode(retCode)) {
129: setError(data.getErrorMessage(retCode));
130: } else if (data.isWarningCode(retCode)) {
131: setWarning(data.getWarningMessage(retCode));
132: } else {
133: assert false : retCode;
134: }
135: }
136:
137: protected String getPanelName() {
138: return NbBundle.getMessage(OptionsPanel0.class,
139: "LBL_OptionsPanel0_Title"); // NOI18N
140: }
141:
142: protected HelpCtx getHelp() {
143: return new HelpCtx(OptionsPanel0.class);
144: }
145:
146: private static String getMessage(String key) {
147: return NbBundle.getMessage(OptionsPanel0.class, key);
148: }
149:
150: private void initAccessibility() {
151: this .getAccessibleContext().setAccessibleDescription(
152: getMessage("ACS_OptionsPanel0"));
153: advancedButton.getAccessibleContext().setAccessibleDescription(
154: getMessage("ACS_LBL_Advanced"));
155: optionsCategoryButton.getAccessibleContext()
156: .setAccessibleDescription(
157: getMessage("ACS_LBL_OptionsCategory"));
158: titleField.getAccessibleContext().setAccessibleDescription(
159: getMessage("ACS_CTL_Title"));
160: tooltipField1.getAccessibleContext().setAccessibleDescription(
161: getMessage("ACS_CTL_Tooltip"));
162: displayNameField1.getAccessibleContext()
163: .setAccessibleDescription(
164: getMessage("ACS_CTL_DisplayName"));
165: categoryNameField.getAccessibleContext()
166: .setAccessibleDescription(
167: getMessage("ACS_CTL_CategoryName"));
168: iconField.getAccessibleContext().setAccessibleDescription(
169: getMessage("ACS_CTL_IconPath"));
170: iconButton.getAccessibleContext().setAccessibleDescription(
171: getMessage("ACS_CTL_IconButton"));
172: }
173:
174: public void addNotify() {
175: super .addNotify();
176: addListeners();
177: updateData();
178: }
179:
180: public void removeNotify() {
181: super .removeNotify();
182: removeListeners();
183: }
184:
185: private void enableDisable() {
186: boolean advancedEnabled = advancedButton.isSelected();
187: assert advancedEnabled != optionsCategoryButton.isSelected();
188:
189: categoryNameField.setEnabled(!advancedEnabled);
190: categoryNameLbl.setEnabled(!advancedEnabled);
191: iconButton.setEnabled(!advancedEnabled);
192: iconField.setEnabled(!advancedEnabled);
193: iconLbl.setEnabled(!advancedEnabled);
194: titleField.setEnabled(!advancedEnabled);
195: titleLbl.setEnabled(!advancedEnabled);
196:
197: displayNameField1.setEnabled(advancedEnabled);
198: displayNameLbl1.setEnabled(advancedEnabled);
199: tooltipField1.setEnabled(advancedEnabled);
200: tooltipLbl1.setEnabled(advancedEnabled);
201: }
202:
203: /** This method is called from within the constructor to
204: * initialize the form.
205: * WARNING: Do NOT modify this code. The content of this method is
206: * always regenerated by the Form Editor.
207: */
208: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
209: private void initComponents() {
210: java.awt.GridBagConstraints gridBagConstraints;
211:
212: buttonGroup1 = new javax.swing.ButtonGroup();
213: advancedButton = new javax.swing.JRadioButton();
214: optionsCategoryButton = new javax.swing.JRadioButton();
215: dummyPanel = new javax.swing.JPanel();
216: categoryNameLbl = new javax.swing.JLabel();
217: categoryNameField = new javax.swing.JTextField();
218: displayNameLbl1 = new javax.swing.JLabel();
219: displayNameField1 = new javax.swing.JTextField();
220: tooltipLbl1 = new javax.swing.JLabel();
221: tooltipField1 = new javax.swing.JTextField();
222: titleLbl = new javax.swing.JLabel();
223: titleField = new javax.swing.JTextField();
224: iconLbl = new javax.swing.JLabel();
225: iconField = new javax.swing.JTextField();
226: iconButton = new javax.swing.JButton();
227:
228: setLayout(new java.awt.GridBagLayout());
229:
230: buttonGroup1.add(advancedButton);
231: advancedButton.setSelected(true);
232: org.openide.awt.Mnemonics
233: .setLocalizedText(
234: advancedButton,
235: java.util.ResourceBundle
236: .getBundle(
237: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
238: .getString("LBL_Advanced"));
239: advancedButton.setBorder(javax.swing.BorderFactory
240: .createEmptyBorder(0, 0, 0, 0));
241: advancedButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
242: advancedButton
243: .addActionListener(new java.awt.event.ActionListener() {
244: public void actionPerformed(
245: java.awt.event.ActionEvent evt) {
246: advancedButtonActionPerformed(evt);
247: }
248: });
249:
250: gridBagConstraints = new java.awt.GridBagConstraints();
251: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
252: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
253: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
254: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
255: add(advancedButton, gridBagConstraints);
256:
257: buttonGroup1.add(optionsCategoryButton);
258: org.openide.awt.Mnemonics
259: .setLocalizedText(
260: optionsCategoryButton,
261: java.util.ResourceBundle
262: .getBundle(
263: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
264: .getString("LBL_OptionsCategory"));
265: optionsCategoryButton.setBorder(javax.swing.BorderFactory
266: .createEmptyBorder(0, 0, 0, 0));
267: optionsCategoryButton
268: .setMargin(new java.awt.Insets(0, 0, 0, 0));
269: optionsCategoryButton
270: .addActionListener(new java.awt.event.ActionListener() {
271: public void actionPerformed(
272: java.awt.event.ActionEvent evt) {
273: optionsCategoryButtonActionPerformed(evt);
274: }
275: });
276:
277: gridBagConstraints = new java.awt.GridBagConstraints();
278: gridBagConstraints.gridx = 0;
279: gridBagConstraints.gridy = 3;
280: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
281: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
282: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
283: gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
284: add(optionsCategoryButton, gridBagConstraints);
285:
286: gridBagConstraints = new java.awt.GridBagConstraints();
287: gridBagConstraints.gridx = 0;
288: gridBagConstraints.gridy = 7;
289: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
290: gridBagConstraints.weightx = 1.0;
291: gridBagConstraints.weighty = 1.0;
292: add(dummyPanel, gridBagConstraints);
293:
294: categoryNameLbl.setLabelFor(categoryNameField);
295: org.openide.awt.Mnemonics
296: .setLocalizedText(
297: categoryNameLbl,
298: java.util.ResourceBundle
299: .getBundle(
300: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
301: .getString("LBL_CategoryName"));
302: categoryNameLbl.setEnabled(false);
303: gridBagConstraints = new java.awt.GridBagConstraints();
304: gridBagConstraints.gridx = 0;
305: gridBagConstraints.gridy = 5;
306: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
307: gridBagConstraints.insets = new java.awt.Insets(0, 18, 6, 12);
308: add(categoryNameLbl, gridBagConstraints);
309:
310: categoryNameField.setEnabled(false);
311: gridBagConstraints = new java.awt.GridBagConstraints();
312: gridBagConstraints.gridx = 1;
313: gridBagConstraints.gridy = 5;
314: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
315: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
316: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
317: gridBagConstraints.weightx = 1.0;
318: gridBagConstraints.insets = new java.awt.Insets(0, 0, 6, 0);
319: add(categoryNameField, gridBagConstraints);
320:
321: displayNameLbl1.setLabelFor(displayNameField1);
322: org.openide.awt.Mnemonics
323: .setLocalizedText(
324: displayNameLbl1,
325: java.util.ResourceBundle
326: .getBundle(
327: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
328: .getString("LBL_DisplaName"));
329: gridBagConstraints = new java.awt.GridBagConstraints();
330: gridBagConstraints.gridx = 0;
331: gridBagConstraints.gridy = 1;
332: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
333: gridBagConstraints.insets = new java.awt.Insets(0, 18, 6, 12);
334: add(displayNameLbl1, gridBagConstraints);
335:
336: gridBagConstraints = new java.awt.GridBagConstraints();
337: gridBagConstraints.gridx = 1;
338: gridBagConstraints.gridy = 1;
339: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
340: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
341: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
342: gridBagConstraints.weightx = 1.0;
343: add(displayNameField1, gridBagConstraints);
344:
345: tooltipLbl1.setLabelFor(tooltipField1);
346: org.openide.awt.Mnemonics
347: .setLocalizedText(
348: tooltipLbl1,
349: java.util.ResourceBundle
350: .getBundle(
351: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
352: .getString("LBL_Tooltip"));
353: gridBagConstraints = new java.awt.GridBagConstraints();
354: gridBagConstraints.gridx = 0;
355: gridBagConstraints.gridy = 2;
356: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
357: gridBagConstraints.insets = new java.awt.Insets(6, 18, 6, 12);
358: add(tooltipLbl1, gridBagConstraints);
359:
360: gridBagConstraints = new java.awt.GridBagConstraints();
361: gridBagConstraints.gridx = 1;
362: gridBagConstraints.gridy = 2;
363: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
364: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
365: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
366: gridBagConstraints.weightx = 1.0;
367: add(tooltipField1, gridBagConstraints);
368:
369: titleLbl.setLabelFor(titleField);
370: org.openide.awt.Mnemonics
371: .setLocalizedText(
372: titleLbl,
373: java.util.ResourceBundle
374: .getBundle(
375: "org/netbeans/modules/apisupport/project/ui/wizard/options/Bundle")
376: .getString("LBL_Title"));
377: titleLbl.setEnabled(false);
378: gridBagConstraints = new java.awt.GridBagConstraints();
379: gridBagConstraints.gridx = 0;
380: gridBagConstraints.gridy = 4;
381: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
382: gridBagConstraints.insets = new java.awt.Insets(6, 18, 6, 12);
383: add(titleLbl, gridBagConstraints);
384:
385: titleField.setEnabled(false);
386: gridBagConstraints = new java.awt.GridBagConstraints();
387: gridBagConstraints.gridx = 1;
388: gridBagConstraints.gridy = 4;
389: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
390: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
391: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
392: gridBagConstraints.weightx = 1.0;
393: add(titleField, gridBagConstraints);
394:
395: iconLbl.setLabelFor(iconField);
396: org.openide.awt.Mnemonics.setLocalizedText(iconLbl,
397: org.openide.util.NbBundle.getMessage(
398: OptionsPanel0.class, "LBL_Icon"));
399: iconLbl.setEnabled(false);
400: gridBagConstraints = new java.awt.GridBagConstraints();
401: gridBagConstraints.gridx = 0;
402: gridBagConstraints.gridy = 6;
403: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
404: gridBagConstraints.insets = new java.awt.Insets(0, 18, 0, 0);
405: add(iconLbl, gridBagConstraints);
406:
407: iconField.setEditable(false);
408: iconField.setText(org.openide.util.NbBundle.getMessage(
409: OptionsPanel0.class, "CTL_None"));
410: iconField.setEnabled(false);
411: gridBagConstraints = new java.awt.GridBagConstraints();
412: gridBagConstraints.gridx = 1;
413: gridBagConstraints.gridy = 6;
414: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
415: gridBagConstraints.weightx = 1.0;
416: gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 12);
417: add(iconField, gridBagConstraints);
418:
419: org.openide.awt.Mnemonics.setLocalizedText(iconButton,
420: org.openide.util.NbBundle.getMessage(
421: OptionsPanel0.class, "LBL_Icon_Browse"));
422: iconButton.setEnabled(false);
423: iconButton
424: .addActionListener(new java.awt.event.ActionListener() {
425: public void actionPerformed(
426: java.awt.event.ActionEvent evt) {
427: iconButtonActionPerformed(evt);
428: }
429: });
430:
431: gridBagConstraints = new java.awt.GridBagConstraints();
432: gridBagConstraints.gridx = 2;
433: gridBagConstraints.gridy = 6;
434: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
435: gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
436: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
437: add(iconButton, gridBagConstraints);
438:
439: }// </editor-fold>//GEN-END:initComponents
440:
441: private void optionsCategoryButtonActionPerformed(
442: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_optionsCategoryButtonActionPerformed
443: enableDisable();
444: updateData();
445: }//GEN-LAST:event_optionsCategoryButtonActionPerformed
446:
447: private void advancedButtonActionPerformed(
448: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedButtonActionPerformed
449: enableDisable();
450: updateData();
451: }//GEN-LAST:event_advancedButtonActionPerformed
452:
453: private void iconButtonActionPerformed(
454: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iconButtonActionPerformed
455: JFileChooser chooser = UIUtil.getIconFileChooser(iconField
456: .getText());
457: int ret = chooser.showDialog(this , getMessage("LBL_Select")); // NOI18N
458: if (ret == JFileChooser.APPROVE_OPTION) {
459: File iconFile = chooser.getSelectedFile();
460: iconField.setText(iconFile.getAbsolutePath());
461: //updateData();
462: }
463: }//GEN-LAST:event_iconButtonActionPerformed
464:
465: // Variables declaration - do not modify//GEN-BEGIN:variables
466: private javax.swing.JRadioButton advancedButton;
467: private javax.swing.ButtonGroup buttonGroup1;
468: private javax.swing.JTextField categoryNameField;
469: private javax.swing.JLabel categoryNameLbl;
470: private javax.swing.JTextField displayNameField1;
471: private javax.swing.JLabel displayNameLbl1;
472: private javax.swing.JPanel dummyPanel;
473: private javax.swing.JButton iconButton;
474: private javax.swing.JTextField iconField;
475: private javax.swing.JLabel iconLbl;
476: private javax.swing.JRadioButton optionsCategoryButton;
477: private javax.swing.JTextField titleField;
478: private javax.swing.JLabel titleLbl;
479: private javax.swing.JTextField tooltipField1;
480: private javax.swing.JLabel tooltipLbl1;
481: // End of variables declaration//GEN-END:variables
482:
483: }
|