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.mercurial.options;
043:
044: import org.netbeans.modules.mercurial.HgModuleConfig;
045:
046: import javax.swing.event.DocumentListener;
047: import javax.swing.event.DocumentEvent;
048: import org.netbeans.modules.mercurial.MercurialAnnotator;
049: import org.netbeans.modules.mercurial.util.HgUtils;
050:
051: final class MercurialPanel extends javax.swing.JPanel {
052:
053: private final MercurialOptionsPanelController controller;
054: private final DocumentListener listener;
055:
056: MercurialPanel(MercurialOptionsPanelController controller) {
057: this .controller = controller;
058: this .listener = new DocumentListener() {
059: public void insertUpdate(DocumentEvent e) {
060: nameChange();
061: }
062:
063: public void removeUpdate(DocumentEvent e) {
064: nameChange();
065: }
066:
067: public void changedUpdate(DocumentEvent e) {
068: nameChange();
069: }
070: };
071: initComponents();
072: }
073:
074: @Override
075: public void addNotify() {
076: super .addNotify();
077: userNameTextField.getDocument().addDocumentListener(listener);
078: }
079:
080: @Override
081: public void removeNotify() {
082: userNameTextField.getDocument()
083: .removeDocumentListener(listener);
084: super .removeNotify();
085: }
086:
087: /** This method is called from within the constructor to
088: * initialize the form.
089: * WARNING: Do NOT modify this code. The content of this method is
090: * always regenerated by the Form Editor.
091: */
092: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
093: private void initComponents() {
094:
095: jLabel1 = new javax.swing.JLabel();
096: jLabel2 = new javax.swing.JLabel();
097: jPanel1 = new javax.swing.JPanel();
098: jLabel3 = new javax.swing.JLabel();
099: jPanel2 = new javax.swing.JPanel();
100: jLabel4 = new javax.swing.JLabel();
101: exportFilename = new javax.swing.JLabel();
102: backupOnRevertModifications = new javax.swing.JCheckBox();
103:
104: jLabel1.setLabelFor(userNameTextField);
105: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
106: org.openide.util.NbBundle.getMessage(
107: MercurialPanel.class,
108: "MercurialPanel.jLabel1.text")); // NOI18N
109:
110: jLabel2.setLabelFor(executablePathTextField);
111: org.openide.awt.Mnemonics.setLocalizedText(jLabel2,
112: org.openide.util.NbBundle.getMessage(
113: MercurialPanel.class,
114: "MercurialPanel.jLabel2.text")); // NOI18N
115:
116: org.openide.awt.Mnemonics.setLocalizedText(
117: execPathBrowseButton, org.openide.util.NbBundle
118: .getMessage(MercurialPanel.class,
119: "MercurialPanel.browseButton.text")); // NOI18N
120:
121: jPanel1
122: .setBorder(javax.swing.BorderFactory
123: .createTitledBorder(org.openide.util.NbBundle
124: .getMessage(MercurialPanel.class,
125: "MercurialPanel.jPanel1.border.title"))); // NOI18N
126:
127: jLabel3.setLabelFor(annotationTextField);
128: org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
129: org.openide.util.NbBundle.getMessage(
130: MercurialPanel.class,
131: "MercurialPanel.jLabel3.text")); // NOI18N
132:
133: annotationTextField.setText(org.openide.util.NbBundle
134: .getMessage(MercurialPanel.class,
135: "MercurialPanel.annotationTextField.text")); // NOI18N
136:
137: org.openide.awt.Mnemonics.setLocalizedText(addButton,
138: org.openide.util.NbBundle.getMessage(
139: MercurialPanel.class,
140: "MercurialPanel.addButton.text")); // NOI18N
141:
142: org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(
143: jPanel1);
144: jPanel1.setLayout(jPanel1Layout);
145: jPanel1Layout
146: .setHorizontalGroup(jPanel1Layout
147: .createParallelGroup(
148: org.jdesktop.layout.GroupLayout.LEADING)
149: .add(
150: jPanel1Layout
151: .createSequentialGroup()
152: .addContainerGap()
153: .add(jLabel3)
154: .addPreferredGap(
155: org.jdesktop.layout.LayoutStyle.UNRELATED)
156: .add(
157: annotationTextField,
158: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
159: 405,
160: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
161: .addPreferredGap(
162: org.jdesktop.layout.LayoutStyle.RELATED,
163: 115, Short.MAX_VALUE)
164: .add(addButton)
165: .addContainerGap()));
166: jPanel1Layout
167: .setVerticalGroup(jPanel1Layout
168: .createParallelGroup(
169: org.jdesktop.layout.GroupLayout.LEADING)
170: .add(
171: jPanel1Layout
172: .createSequentialGroup()
173: .addContainerGap()
174: .add(
175: jPanel1Layout
176: .createParallelGroup(
177: org.jdesktop.layout.GroupLayout.BASELINE)
178: .add(jLabel3)
179: .add(addButton)
180: .add(
181: annotationTextField,
182: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
183: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
184: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
185: .addContainerGap(20,
186: Short.MAX_VALUE)));
187:
188: addButton.getAccessibleContext().setAccessibleDescription(
189: org.openide.util.NbBundle.getMessage(
190: MercurialPanel.class, "ACSD_addButton")); // NOI18N
191:
192: jPanel2.setBorder(javax.swing.BorderFactory
193: .createTitledBorder(org.openide.util.NbBundle
194: .getMessage(MercurialPanel.class,
195: "MecurialPanel.jPanel2.border.title"))); // NOI18N
196:
197: org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
198: org.openide.util.NbBundle.getMessage(
199: MercurialPanel.class,
200: "MercurialPanel.jLabel4.text")); // NOI18N
201:
202: org.openide.awt.Mnemonics.setLocalizedText(manageButton,
203: org.openide.util.NbBundle.getMessage(
204: MercurialPanel.class,
205: "MercurialPanel.manageButton.text")); // NOI18N
206:
207: org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(
208: jPanel2);
209: jPanel2.setLayout(jPanel2Layout);
210: jPanel2Layout
211: .setHorizontalGroup(jPanel2Layout
212: .createParallelGroup(
213: org.jdesktop.layout.GroupLayout.LEADING)
214: .add(
215: jPanel2Layout
216: .createSequentialGroup()
217: .addContainerGap()
218: .add(jLabel4)
219: .addPreferredGap(
220: org.jdesktop.layout.LayoutStyle.RELATED,
221: 175, Short.MAX_VALUE)
222: .add(manageButton)
223: .addContainerGap()));
224: jPanel2Layout
225: .setVerticalGroup(jPanel2Layout
226: .createParallelGroup(
227: org.jdesktop.layout.GroupLayout.LEADING)
228: .add(
229: jPanel2Layout
230: .createSequentialGroup()
231: .addContainerGap()
232: .add(
233: jPanel2Layout
234: .createParallelGroup(
235: org.jdesktop.layout.GroupLayout.BASELINE)
236: .add(jLabel4)
237: .add(
238: manageButton))
239: .addContainerGap(24,
240: Short.MAX_VALUE)));
241:
242: manageButton.getAccessibleContext().setAccessibleDescription(
243: org.openide.util.NbBundle.getMessage(
244: MercurialPanel.class, "ACSD_manageButton")); // NOI18N
245:
246: exportFilename.setLabelFor(exportFilenameTextField);
247: org.openide.awt.Mnemonics.setLocalizedText(exportFilename,
248: org.openide.util.NbBundle.getMessage(
249: MercurialPanel.class,
250: "MercurialPanel.ExportFilename.text")); // NOI18N
251:
252: org.openide.awt.Mnemonics.setLocalizedText(
253: exportFilenameBrowseButton, org.openide.util.NbBundle
254: .getMessage(MercurialPanel.class,
255: "MercurialPanel.browseButton2.text")); // NOI18N
256:
257: backupOnRevertModifications.setSelected(true);
258: org.openide.awt.Mnemonics.setLocalizedText(
259: backupOnRevertModifications, org.openide.util.NbBundle
260: .getMessage(MercurialPanel.class,
261: "MercurialPanel.jCheckBox1.text")); // NOI18N
262:
263: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
264: this );
265: this .setLayout(layout);
266: layout
267: .setHorizontalGroup(layout
268: .createParallelGroup(
269: org.jdesktop.layout.GroupLayout.LEADING)
270: .add(
271: layout
272: .createSequentialGroup()
273: .addContainerGap()
274: .add(
275: layout
276: .createParallelGroup(
277: org.jdesktop.layout.GroupLayout.LEADING)
278: .add(
279: backupOnRevertModifications)
280: .add(
281: jPanel2,
282: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
283: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
284: Short.MAX_VALUE)
285: .add(
286: jPanel1,
287: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
288: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
289: Short.MAX_VALUE)
290: .add(
291: layout
292: .createSequentialGroup()
293: .add(
294: layout
295: .createParallelGroup(
296: org.jdesktop.layout.GroupLayout.LEADING,
297: false)
298: .add(
299: jLabel1,
300: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
301: 160,
302: Short.MAX_VALUE)
303: .add(
304: jLabel2,
305: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
306: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
307: Short.MAX_VALUE)
308: .add(
309: exportFilename,
310: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
311: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
312: Short.MAX_VALUE))
313: .addPreferredGap(
314: org.jdesktop.layout.LayoutStyle.RELATED)
315: .add(
316: layout
317: .createParallelGroup(
318: org.jdesktop.layout.GroupLayout.LEADING)
319: .add(
320: userNameTextField,
321: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
322: 558,
323: Short.MAX_VALUE)
324: .add(
325: org.jdesktop.layout.GroupLayout.TRAILING,
326: layout
327: .createSequentialGroup()
328: .add(
329: layout
330: .createParallelGroup(
331: org.jdesktop.layout.GroupLayout.LEADING)
332: .add(
333: exportFilenameTextField,
334: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
335: 427,
336: Short.MAX_VALUE)
337: .add(
338: org.jdesktop.layout.GroupLayout.TRAILING,
339: executablePathTextField,
340: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
341: 427,
342: Short.MAX_VALUE))
343: .addPreferredGap(
344: org.jdesktop.layout.LayoutStyle.RELATED)
345: .add(
346: layout
347: .createParallelGroup(
348: org.jdesktop.layout.GroupLayout.TRAILING)
349: .add(
350: execPathBrowseButton)
351: .add(
352: exportFilenameBrowseButton,
353: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
354: 125,
355: Short.MAX_VALUE))))))
356: .addContainerGap()));
357: layout
358: .setVerticalGroup(layout
359: .createParallelGroup(
360: org.jdesktop.layout.GroupLayout.LEADING)
361: .add(
362: layout
363: .createSequentialGroup()
364: .addContainerGap()
365: .add(
366: layout
367: .createParallelGroup(
368: org.jdesktop.layout.GroupLayout.BASELINE)
369: .add(
370: userNameTextField,
371: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
372: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
373: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
374: .add(jLabel1))
375: .add(18, 18, 18)
376: .add(
377: layout
378: .createParallelGroup(
379: org.jdesktop.layout.GroupLayout.BASELINE)
380: .add(
381: execPathBrowseButton)
382: .add(jLabel2)
383: .add(
384: executablePathTextField,
385: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
386: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
387: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
388: .add(18, 18, 18)
389: .add(
390: layout
391: .createParallelGroup(
392: org.jdesktop.layout.GroupLayout.BASELINE)
393: .add(
394: exportFilename)
395: .add(
396: exportFilenameTextField,
397: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
398: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
399: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
400: .add(
401: exportFilenameBrowseButton))
402: .add(10, 10, 10)
403: .add(
404: jPanel1,
405: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
406: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
407: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
408: .add(18, 18, 18)
409: .add(
410: jPanel2,
411: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
412: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
413: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
414: .add(18, 18, 18)
415: .add(
416: backupOnRevertModifications)
417: .addContainerGap(25,
418: Short.MAX_VALUE)));
419:
420: userNameTextField.getAccessibleContext()
421: .setAccessibleDescription(
422: org.openide.util.NbBundle.getMessage(
423: MercurialPanel.class,
424: "ACSD_userNameTextField")); // NOI18N
425: executablePathTextField.getAccessibleContext()
426: .setAccessibleDescription(
427: org.openide.util.NbBundle.getMessage(
428: MercurialPanel.class,
429: "ACSD_executablePathTextField")); // NOI18N
430: execPathBrowseButton.getAccessibleContext()
431: .setAccessibleDescription(
432: org.openide.util.NbBundle.getMessage(
433: MercurialPanel.class,
434: "ACSD_execPathBrowseButton")); // NOI18N
435: exportFilenameTextField.getAccessibleContext()
436: .setAccessibleDescription(
437: org.openide.util.NbBundle.getMessage(
438: MercurialPanel.class,
439: "ACSD_exportFileNameTextField")); // NOI18N
440: exportFilenameBrowseButton.getAccessibleContext()
441: .setAccessibleDescription(
442: org.openide.util.NbBundle.getMessage(
443: MercurialPanel.class,
444: "ACSD_exportFilenameBrowseButton")); // NOI18N
445: backupOnRevertModifications.getAccessibleContext()
446: .setAccessibleDescription(
447: org.openide.util.NbBundle.getMessage(
448: MercurialPanel.class,
449: "ACSD_backupOnRevertModifications")); // NOI18N
450: }// </editor-fold>//GEN-END:initComponents
451:
452: private void nameChange() {
453: controller.changed();
454: }
455:
456: void load() {
457: // TODO read settings and initialize GUI
458: // Example:
459: // someCheckBox.setSelected(Preferences.userNodeForPackage(MercurialPanel.class).getBoolean("someFlag", false)); // NOI18N
460: // or for org.openide.util with API spec. version >= 7.4:
461: // someCheckBox.setSelected(NbPreferences.forModule(MercurialPanel.class).getBoolean("someFlag", false)); // NOI18N
462: // or:
463: // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty());
464: userNameTextField.setText(HgModuleConfig.getDefault()
465: .getUserName());
466: executablePathTextField.setText(HgModuleConfig.getDefault()
467: .getExecutableBinaryPath());
468: exportFilenameTextField.setText(HgModuleConfig.getDefault()
469: .getExportFilename());
470: annotationTextField.setText(HgModuleConfig.getDefault()
471: .getAnnotationFormat());
472: backupOnRevertModifications.setSelected(HgModuleConfig
473: .getDefault().getBackupOnRevertModifications());
474: }
475:
476: void store() {
477: // TODO store modified settings
478: // Example:
479: // Preferences.userNodeForPackage(MercurialPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N
480: // or for org.openide.util with API spec. version >= 7.4:
481: // NbPreferences.forModule(MercurialPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N
482: // or:
483: // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
484: HgModuleConfig.getDefault().setUserName(
485: userNameTextField.getText());
486: HgModuleConfig.getDefault().setExecutableBinaryPath(
487: executablePathTextField.getText());
488: HgModuleConfig.getDefault().setExportFilename(
489: exportFilenameTextField.getText());
490: HgModuleConfig.getDefault().setAnnotationFormat(
491: annotationTextField.getText());
492: HgModuleConfig.getDefault().setBackupOnRevertModifications(
493: backupOnRevertModifications.isSelected());
494: if (MercurialAnnotator
495: .isRevisionInAnnotationFormat(annotationTextField
496: .getText())) {
497: HgUtils.warningDialog(MercurialPanel.class,
498: "MSG_STATUS_LABEL_WITH_REVSION_TITLE",
499: "MSG_STATUS_LABEL_WITH_REVSION_MSG");// NOI18N
500: }
501: }
502:
503: boolean valid() {
504: // TODO check whether form is consistent and complete
505: //return true;
506: String username = userNameTextField.getText();
507: Boolean valid;
508: valid = HgModuleConfig.getDefault().isUserNameValid(username);
509: if (!valid)
510: return false;
511: String execpath = executablePathTextField.getText();
512: valid = HgModuleConfig.getDefault().isExecPathValid(execpath);
513: return valid;
514: }
515:
516: // Variables declaration - do not modify//GEN-BEGIN:variables
517: final javax.swing.JButton addButton = new javax.swing.JButton();
518: final javax.swing.JTextField annotationTextField = new javax.swing.JTextField();
519: private javax.swing.JCheckBox backupOnRevertModifications;
520: final javax.swing.JButton execPathBrowseButton = new javax.swing.JButton();
521: final javax.swing.JTextField executablePathTextField = new javax.swing.JTextField();
522: private javax.swing.JLabel exportFilename;
523: final javax.swing.JButton exportFilenameBrowseButton = new javax.swing.JButton();
524: final javax.swing.JTextField exportFilenameTextField = new javax.swing.JTextField();
525: private javax.swing.JLabel jLabel1;
526: private javax.swing.JLabel jLabel2;
527: private javax.swing.JLabel jLabel3;
528: private javax.swing.JLabel jLabel4;
529: private javax.swing.JPanel jPanel1;
530: private javax.swing.JPanel jPanel2;
531: final javax.swing.JButton manageButton = new javax.swing.JButton();
532: final javax.swing.JTextField userNameTextField = new javax.swing.JTextField();
533: // End of variables declaration//GEN-END:variables
534:
535: }
|