Renamed methods to reflect use of Email not Name as UI in Git.
[nbgit.git] / src / org / netbeans / modules / git / options / GitPanel.java
blobc3217e99f50dea915e37928e5ebbb6fde1f311f5
1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html
12 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13 * specific language governing permissions and limitations under the
14 * License. When distributing the software, include this License Header
15 * Notice in each file and include the License file at
16 * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17 * particular file as subject to the "Classpath" exception as provided
18 * by Sun in the GPL Version 2 section of the License file that
19 * accompanied this code. If applicable, add the following below the
20 * License Header, with the fields enclosed by brackets [] replaced by
21 * your own identifying information:
22 * "Portions Copyrighted [year] [name of copyright owner]"
24 * Contributor(s):
26 * The Original Software is NetBeans. The Initial Developer of the Original
27 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28 * Microsystems, Inc. All Rights Reserved.
29 * Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
31 * If you wish your version of this file to be governed by only the CDDL
32 * or only the GPL Version 2, indicate your decision by adding
33 * "[Contributor] elects to include this software in this distribution
34 * under the [CDDL or GPL Version 2] license." If you do not indicate a
35 * single choice of license, a recipient has the option to distribute
36 * your version of this file under either the CDDL, the GPL Version 2 or
37 * to extend the choice of license to its licensees as provided above.
38 * However, if you add GPL Version 2 code and therefore, elected the GPL
39 * Version 2 license, then the option applies only if the new code is
40 * made subject to such option by the copyright holder.
42 package org.netbeans.modules.git.options;
44 import javax.swing.UIManager;
45 import javax.swing.event.DocumentEvent;
46 import javax.swing.event.DocumentListener;
47 import org.netbeans.modules.git.GitAnnotator;
48 import org.netbeans.modules.git.GitModuleConfig;
49 import org.netbeans.modules.git.util.GitUtils;
51 final class GitPanel extends javax.swing.JPanel {
53 private final GitOptionsPanelController controller;
54 private final DocumentListener listener;
56 GitPanel(GitOptionsPanelController controller) {
57 this.controller = controller;
58 this.listener = new DocumentListener() {
59 public void insertUpdate(DocumentEvent e) { nameChange(); }
60 public void removeUpdate(DocumentEvent e) { nameChange(); }
61 public void changedUpdate(DocumentEvent e) { nameChange(); }
63 initComponents();
66 @Override
67 public void addNotify() {
68 super.addNotify();
69 emailTextField.getDocument().addDocumentListener(listener);
72 @Override
73 public void removeNotify() {
74 emailTextField.getDocument().removeDocumentListener(listener);
75 super.removeNotify();
80 /** This method is called from within the constructor to
81 * initialize the form.
82 * WARNING: Do NOT modify this code. The content of this method is
83 * always regenerated by the Form Editor.
85 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
86 private void initComponents() {
88 emailLabel = new javax.swing.JLabel();
89 execPathLabel = new javax.swing.JLabel();
90 jPanel1 = new javax.swing.JPanel();
91 jLabel3 = new javax.swing.JLabel();
92 jPanel2 = new javax.swing.JPanel();
93 jLabel4 = new javax.swing.JLabel();
94 exportFilename = new javax.swing.JLabel();
95 backupOnRevertModifications = new javax.swing.JCheckBox();
96 userNameTextField = new javax.swing.JTextField();
97 userNameLabel = new javax.swing.JLabel();
99 emailLabel.setLabelFor(emailTextField);
100 org.openide.awt.Mnemonics.setLocalizedText(emailLabel, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel1.text")); // NOI18N
102 execPathLabel.setLabelFor(executablePathTextField);
103 org.openide.awt.Mnemonics.setLocalizedText(execPathLabel, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel2.text")); // NOI18N
105 org.openide.awt.Mnemonics.setLocalizedText(execPathBrowseButton, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.browseButton.text")); // NOI18N
107 jPanel1.setBorder(UIManager.getBorder("TitledBorder.aquaVariant"));
109 jLabel3.setLabelFor(annotationTextField);
110 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel3.text")); // NOI18N
112 annotationTextField.setText(org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.annotationTextField.text")); // NOI18N
114 org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.addButton.text")); // NOI18N
116 org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
117 jPanel1.setLayout(jPanel1Layout);
118 jPanel1Layout.setHorizontalGroup(
119 jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
120 .add(jPanel1Layout.createSequentialGroup()
121 .addContainerGap()
122 .add(jLabel3)
123 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
124 .add(annotationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 405, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
125 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 25, Short.MAX_VALUE)
126 .add(addButton)
127 .addContainerGap())
129 jPanel1Layout.setVerticalGroup(
130 jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
131 .add(jPanel1Layout.createSequentialGroup()
132 .addContainerGap()
133 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
134 .add(jLabel3)
135 .add(addButton)
136 .add(annotationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
137 .addContainerGap(20, Short.MAX_VALUE))
140 addButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_addButton")); // NOI18N
142 jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
144 org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel4.text")); // NOI18N
146 org.openide.awt.Mnemonics.setLocalizedText(manageButton, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.manageButton.text")); // NOI18N
148 org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
149 jPanel2.setLayout(jPanel2Layout);
150 jPanel2Layout.setHorizontalGroup(
151 jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
152 .add(jPanel2Layout.createSequentialGroup()
153 .addContainerGap()
154 .add(jLabel4)
155 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 67, Short.MAX_VALUE)
156 .add(manageButton)
157 .addContainerGap())
159 jPanel2Layout.setVerticalGroup(
160 jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
161 .add(jPanel2Layout.createSequentialGroup()
162 .addContainerGap()
163 .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
164 .add(jLabel4)
165 .add(manageButton))
166 .addContainerGap(24, Short.MAX_VALUE))
169 manageButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_manageButton")); // NOI18N
171 exportFilename.setLabelFor(exportFilenameTextField);
172 org.openide.awt.Mnemonics.setLocalizedText(exportFilename, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.ExportFilename.text")); // NOI18N
174 org.openide.awt.Mnemonics.setLocalizedText(exportFilenameBrowseButton, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.browseButton2.text")); // NOI18N
176 backupOnRevertModifications.setSelected(true);
177 org.openide.awt.Mnemonics.setLocalizedText(backupOnRevertModifications, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jCheckBox1.text")); // NOI18N
179 userNameLabel.setLabelFor(userNameTextField);
180 org.openide.awt.Mnemonics.setLocalizedText(userNameLabel, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel5.text")); // NOI18N
182 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
183 this.setLayout(layout);
184 layout.setHorizontalGroup(
185 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
186 .add(layout.createSequentialGroup()
187 .addContainerGap()
188 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
189 .add(layout.createSequentialGroup()
190 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
191 .add(backupOnRevertModifications)
192 .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
193 .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
194 .add(layout.createSequentialGroup()
195 .add(emailLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
196 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
197 .add(emailTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE))
198 .add(layout.createSequentialGroup()
199 .add(userNameLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
200 .add(70, 70, 70)
201 .add(userNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE)))
202 .addContainerGap())
203 .add(layout.createSequentialGroup()
204 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
205 .add(layout.createSequentialGroup()
206 .add(exportFilename)
207 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
208 .add(execPathLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE))
209 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
210 .add(exportFilenameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
211 .add(executablePathTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE))
212 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
213 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
214 .add(execPathBrowseButton)
215 .add(exportFilenameBrowseButton))
216 .add(20, 20, 20))))
218 layout.setVerticalGroup(
219 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
220 .add(layout.createSequentialGroup()
221 .addContainerGap()
222 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
223 .add(emailLabel)
224 .add(emailTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
225 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
226 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
227 .add(userNameLabel)
228 .add(userNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
229 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
230 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
231 .add(execPathBrowseButton)
232 .add(executablePathTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
233 .add(execPathLabel))
234 .add(18, 18, 18)
235 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
236 .add(exportFilenameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
237 .add(exportFilenameBrowseButton)
238 .add(exportFilename))
239 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 54, Short.MAX_VALUE)
240 .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
241 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
242 .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
243 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
244 .add(backupOnRevertModifications)
245 .add(27, 27, 27))
248 emailTextField.getAccessibleContext().setAccessibleName("Email:");
249 emailTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_userNameTextField")); // NOI18N
250 executablePathTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_executablePathTextField")); // NOI18N
251 execPathBrowseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_execPathBrowseButton")); // NOI18N
252 jPanel2.getAccessibleContext().setAccessibleName("<GitPanel.jPanel2.border.title>");
253 exportFilenameTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_exportFileNameTextField")); // NOI18N
254 exportFilenameBrowseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_exportFilenameBrowseButton")); // NOI18N
255 backupOnRevertModifications.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_backupOnRevertModifications")); // NOI18N
256 }// </editor-fold>//GEN-END:initComponents
258 private void nameChange() {
259 controller.changed();
262 void load() {
263 // TODO read settings and initialize GUI
264 // Example:
265 // someCheckBox.setSelected(Preferences.userNodeForPackage(GitPanel.class).getBoolean("someFlag", false)); // NOI18N
266 // or for org.openide.util with API spec. version >= 7.4:
267 // someCheckBox.setSelected(NbPreferences.forModule(GitPanel.class).getBoolean("someFlag", false)); // NOI18N
268 // or:
269 // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty());
270 emailTextField.setText(GitModuleConfig.getDefault().getEmail());
271 userNameTextField.setText(GitModuleConfig.getDefault().getUserName());
272 executablePathTextField.setText(GitModuleConfig.getDefault().getExecutableBinaryPath());
273 exportFilenameTextField.setText(GitModuleConfig.getDefault().getExportFilename());
274 annotationTextField.setText(GitModuleConfig.getDefault().getAnnotationFormat());
275 backupOnRevertModifications.setSelected(GitModuleConfig.getDefault().getBackupOnRevertModifications());
278 void store() {
279 // TODO store modified settings
280 // Example:
281 // Preferences.userNodeForPackage(GitPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N
282 // or for org.openide.util with API spec. version >= 7.4:
283 // NbPreferences.forModule(GitPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N
284 // or:
285 // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
286 GitModuleConfig.getDefault().setEmail(emailTextField.getText());
287 GitModuleConfig.getDefault().setUserName(userNameTextField.getText());
288 GitModuleConfig.getDefault().setExecutableBinaryPath(executablePathTextField.getText());
289 GitModuleConfig.getDefault().setExportFilename(exportFilenameTextField.getText());
290 GitModuleConfig.getDefault().setAnnotationFormat(annotationTextField.getText());
291 GitModuleConfig.getDefault().setBackupOnRevertModifications(backupOnRevertModifications.isSelected());
292 if (GitAnnotator.isRevisionInAnnotationFormat(annotationTextField.getText())){
293 GitUtils.warningDialog(GitPanel.class,
294 "MSG_STATUS_LABEL_WITH_REVSION_TITLE", "MSG_STATUS_LABEL_WITH_REVSION_MSG");// NOI18N
298 boolean valid() {
299 // TODO check whether form is consistent and complete
300 //return true;
301 String name = userNameTextField.getText();
302 String email = emailTextField.getText();
303 String execpath = executablePathTextField.getText();
304 Boolean valid;
306 valid = GitModuleConfig.getDefault().isUserNameValid(name);
307 if (!valid) return false;
308 valid = GitModuleConfig.getDefault().isEmailValid(email);
309 if (!valid) return false;
310 valid = GitModuleConfig.getDefault().isExecPathValid(execpath);
311 return valid;
314 // Variables declaration - do not modify//GEN-BEGIN:variables
315 final javax.swing.JButton addButton = new javax.swing.JButton();
316 final javax.swing.JTextField annotationTextField = new javax.swing.JTextField();
317 private javax.swing.JCheckBox backupOnRevertModifications;
318 private javax.swing.JLabel emailLabel;
319 final javax.swing.JTextField emailTextField = new javax.swing.JTextField();
320 final javax.swing.JButton execPathBrowseButton = new javax.swing.JButton();
321 private javax.swing.JLabel execPathLabel;
322 final javax.swing.JTextField executablePathTextField = new javax.swing.JTextField();
323 private javax.swing.JLabel exportFilename;
324 final javax.swing.JButton exportFilenameBrowseButton = new javax.swing.JButton();
325 final javax.swing.JTextField exportFilenameTextField = new javax.swing.JTextField();
326 private javax.swing.JLabel jLabel3;
327 private javax.swing.JLabel jLabel4;
328 private javax.swing.JPanel jPanel1;
329 private javax.swing.JPanel jPanel2;
330 final javax.swing.JButton manageButton = new javax.swing.JButton();
331 private javax.swing.JLabel userNameLabel;
332 private javax.swing.JTextField userNameTextField;
333 // End of variables declaration//GEN-END:variables