Cleanup code whitespace
[nbgit.git] / src / org / nbgit / options / GitPanel.java
blobc4267c343ba8d9d98ba91c030f9b8f95ae357ca8
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.nbgit.options;
44 import javax.swing.UIManager;
45 import javax.swing.event.DocumentEvent;
46 import javax.swing.event.DocumentListener;
47 import org.nbgit.GitModuleConfig;
48 import org.nbgit.util.GitUtils;
49 import org.nbgit.util.HtmlFormatter;
51 final class GitPanel extends javax.swing.JPanel {
53 private final GitOptionsPanelController controller;
54 private final DocumentListener listener;
56 GitPanel(GitOptionsPanelController controller)
58 this.controller = controller;
59 this.listener = new DocumentListener() {
61 public void insertUpdate(DocumentEvent e)
63 nameChange();
66 public void removeUpdate(DocumentEvent e)
68 nameChange();
71 public void changedUpdate(DocumentEvent e)
73 nameChange();
77 initComponents();
80 @Override
81 public void addNotify()
83 super.addNotify();
84 emailTextField.getDocument().addDocumentListener(listener);
87 @Override
88 public void removeNotify()
90 emailTextField.getDocument().removeDocumentListener(listener);
91 super.removeNotify();
94 /** This method is called from within the constructor to
95 * initialize the form.
96 * WARNING: Do NOT modify this code. The content of this method is
97 * always regenerated by the Form Editor.
99 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
100 private void initComponents() {
102 jTabbedPane1 = new javax.swing.JTabbedPane();
103 generalOptionsPanel = new javax.swing.JPanel();
104 userInformation = new javax.swing.JPanel();
105 emailLabel = new javax.swing.JLabel();
106 userNameLabel = new javax.swing.JLabel();
107 userNameTextField = new javax.swing.JTextField();
108 statusLabels = new javax.swing.JPanel();
109 jLabel3 = new javax.swing.JLabel();
110 fileOptionsPanel = new javax.swing.JPanel();
111 exportFilename = new javax.swing.JLabel();
112 backupOnRevertModifications = new javax.swing.JCheckBox();
113 logoLabel = new javax.swing.JLabel();
115 generalOptionsPanel.setOpaque(false);
117 userInformation.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(GitPanel.class, "UserInformation"))); // NOI18N
118 userInformation.setName(org.openide.util.NbBundle.getMessage(GitPanel.class, "UserInformationPanel.Title")); // NOI18N
119 userInformation.setOpaque(false);
121 emailLabel.setLabelFor(emailTextField);
122 org.openide.awt.Mnemonics.setLocalizedText(emailLabel, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel1.text")); // NOI18N
124 emailTextField.setToolTipText(org.openide.util.NbBundle.getMessage(GitPanel.class, "emailTextField.TOOLTIP")); // NOI18N
126 userNameLabel.setLabelFor(userNameTextField);
127 org.openide.awt.Mnemonics.setLocalizedText(userNameLabel, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel5.text")); // NOI18N
129 userNameTextField.setToolTipText(org.openide.util.NbBundle.getMessage(GitPanel.class, "userNameTextField.TOOLTIP")); // NOI18N
131 org.jdesktop.layout.GroupLayout userInformationLayout = new org.jdesktop.layout.GroupLayout(userInformation);
132 userInformation.setLayout(userInformationLayout);
133 userInformationLayout.setHorizontalGroup(
134 userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
135 .add(userInformationLayout.createSequentialGroup()
136 .addContainerGap()
137 .add(userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
138 .add(org.jdesktop.layout.GroupLayout.TRAILING, userInformationLayout.createSequentialGroup()
139 .add(userNameLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 85, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
140 .add(26, 26, 26))
141 .add(userInformationLayout.createSequentialGroup()
142 .add(emailLabel)
143 .add(18, 18, 18)))
144 .add(userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
145 .add(emailTextField)
146 .add(userNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 304, Short.MAX_VALUE))
147 .addContainerGap())
149 userInformationLayout.setVerticalGroup(
150 userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
151 .add(userInformationLayout.createSequentialGroup()
152 .add(userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
153 .add(emailLabel)
154 .add(emailTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
155 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
156 .add(userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
157 .add(userNameLabel)
158 .add(userNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
159 .add(36, 36, 36))
162 emailTextField.getAccessibleContext().setAccessibleName("Email:");
163 emailTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_userNameTextField")); // NOI18N
165 statusLabels.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(GitPanel.class, "StatusLabel"))); // NOI18N
166 statusLabels.setOpaque(false);
168 jLabel3.setLabelFor(annotationTextField);
169 org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel3.text")); // NOI18N
171 annotationTextField.setText(org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.annotationTextField.text")); // NOI18N
172 annotationTextField.addActionListener(new java.awt.event.ActionListener() {
173 public void actionPerformed(java.awt.event.ActionEvent evt) {
174 annotationTextFieldActionPerformed(evt);
178 org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.addButton.text")); // NOI18N
180 org.jdesktop.layout.GroupLayout statusLabelsLayout = new org.jdesktop.layout.GroupLayout(statusLabels);
181 statusLabels.setLayout(statusLabelsLayout);
182 statusLabelsLayout.setHorizontalGroup(
183 statusLabelsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
184 .add(org.jdesktop.layout.GroupLayout.TRAILING, statusLabelsLayout.createSequentialGroup()
185 .addContainerGap()
186 .add(jLabel3)
187 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
188 .add(annotationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 265, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
189 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
190 .add(addButton)
191 .add(88, 88, 88))
193 statusLabelsLayout.setVerticalGroup(
194 statusLabelsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
195 .add(statusLabelsLayout.createSequentialGroup()
196 .addContainerGap()
197 .add(statusLabelsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
198 .add(annotationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
199 .add(addButton)
200 .add(jLabel3))
201 .addContainerGap(20, Short.MAX_VALUE))
204 addButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_addButton")); // NOI18N
206 org.jdesktop.layout.GroupLayout generalOptionsPanelLayout = new org.jdesktop.layout.GroupLayout(generalOptionsPanel);
207 generalOptionsPanel.setLayout(generalOptionsPanelLayout);
208 generalOptionsPanelLayout.setHorizontalGroup(
209 generalOptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
210 .add(generalOptionsPanelLayout.createSequentialGroup()
211 .addContainerGap()
212 .add(generalOptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
213 .add(userInformation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
214 .add(statusLabels, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 500, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
215 .addContainerGap(150, Short.MAX_VALUE))
217 generalOptionsPanelLayout.setVerticalGroup(
218 generalOptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
219 .add(generalOptionsPanelLayout.createSequentialGroup()
220 .addContainerGap()
221 .add(userInformation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
222 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
223 .add(statusLabels, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
224 .addContainerGap(139, Short.MAX_VALUE))
227 jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(GitPanel.class, "BasicSettingsTab.Title"), generalOptionsPanel); // NOI18N
229 fileOptionsPanel.setOpaque(false);
231 exportFilename.setLabelFor(exportFilenameTextField);
232 org.openide.awt.Mnemonics.setLocalizedText(exportFilename, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.ExportFilename.text")); // NOI18N
234 backupOnRevertModifications.setSelected(true);
235 org.openide.awt.Mnemonics.setLocalizedText(backupOnRevertModifications, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jCheckBox1.text")); // NOI18N
237 org.openide.awt.Mnemonics.setLocalizedText(exportFilenameBrowseButton, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.browseButton2.text")); // NOI18N
239 org.jdesktop.layout.GroupLayout fileOptionsPanelLayout = new org.jdesktop.layout.GroupLayout(fileOptionsPanel);
240 fileOptionsPanel.setLayout(fileOptionsPanelLayout);
241 fileOptionsPanelLayout.setHorizontalGroup(
242 fileOptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
243 .add(fileOptionsPanelLayout.createSequentialGroup()
244 .add(fileOptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
245 .add(fileOptionsPanelLayout.createSequentialGroup()
246 .addContainerGap()
247 .add(backupOnRevertModifications))
248 .add(fileOptionsPanelLayout.createSequentialGroup()
249 .add(24, 24, 24)
250 .add(exportFilename)
251 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
252 .add(exportFilenameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 145, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
253 .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
254 .add(exportFilenameBrowseButton)))
255 .addContainerGap(218, Short.MAX_VALUE))
257 fileOptionsPanelLayout.setVerticalGroup(
258 fileOptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
259 .add(org.jdesktop.layout.GroupLayout.TRAILING, fileOptionsPanelLayout.createSequentialGroup()
260 .addContainerGap(140, Short.MAX_VALUE)
261 .add(fileOptionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
262 .add(exportFilenameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
263 .add(exportFilenameBrowseButton)
264 .add(exportFilename))
265 .add(124, 124, 124)
266 .add(backupOnRevertModifications)
267 .add(54, 54, 54))
270 backupOnRevertModifications.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_backupOnRevertModifications")); // NOI18N
271 exportFilenameTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_exportFileNameTextField")); // NOI18N
272 exportFilenameBrowseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_exportFilenameBrowseButton")); // NOI18N
274 jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(GitPanel.class, "fileOptionsPanel.title"), fileOptionsPanel); // NOI18N
276 logoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/nbgit/resources/icons/gitoptions-logo.png"))); // NOI18N
278 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
279 this.setLayout(layout);
280 layout.setHorizontalGroup(
281 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
282 .add(layout.createSequentialGroup()
283 .addContainerGap()
284 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
285 .add(org.jdesktop.layout.GroupLayout.TRAILING, logoLabel)
286 .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 691, Short.MAX_VALUE))
287 .addContainerGap())
289 layout.setVerticalGroup(
290 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
291 .add(layout.createSequentialGroup()
292 .add(logoLabel)
293 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
294 .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE)
295 .addContainerGap())
297 }// </editor-fold>//GEN-END:initComponents
299 private void annotationTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_annotationTextFieldActionPerformed
300 // TODO add your handling code here:
301 }//GEN-LAST:event_annotationTextFieldActionPerformed
303 private void nameChange()
305 controller.changed();
308 void load()
310 // TODO read settings and initialize GUI
311 // Example:
312 // someCheckBox.setSelected(Preferences.userNodeForPackage(GitPanel.class).getBoolean("someFlag", false)); // NOI18N
313 // or for org.openide.util with API spec. version >= 7.4:
314 // someCheckBox.setSelected(NbPreferences.forModule(GitPanel.class).getBoolean("someFlag", false)); // NOI18N
315 // or:
316 // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty());
317 emailTextField.setText(GitModuleConfig.getDefault().getEmail());
318 userNameTextField.setText(GitModuleConfig.getDefault().getUserName());
319 exportFilenameTextField.setText(GitModuleConfig.getDefault().getExportFilename());
320 annotationTextField.setText(GitModuleConfig.getDefault().getAnnotationFormat());
321 backupOnRevertModifications.setSelected(GitModuleConfig.getDefault().getBackupOnRevertModifications());
324 void store()
326 // TODO store modified settings
327 // Example:
328 // Preferences.userNodeForPackage(GitPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N
329 // or for org.openide.util with API spec. version >= 7.4:
330 // NbPreferences.forModule(GitPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N
331 // or:
332 // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
333 GitModuleConfig.getDefault().setEmail(emailTextField.getText());
334 GitModuleConfig.getDefault().setUserName(userNameTextField.getText());
335 GitModuleConfig.getDefault().setExportFilename(exportFilenameTextField.getText());
336 GitModuleConfig.getDefault().setAnnotationFormat(annotationTextField.getText());
337 GitModuleConfig.getDefault().setBackupOnRevertModifications(backupOnRevertModifications.isSelected());
338 if (HtmlFormatter.isRevisionInAnnotationFormat(annotationTextField.getText()))
339 GitUtils.warningDialog(GitPanel.class,
340 "MSG_STATUS_LABEL_WITH_REVSION_TITLE", "MSG_STATUS_LABEL_WITH_REVSION_MSG");
343 boolean valid()
345 // TODO check whether form is consistent and complete
346 //return true;
347 String name = userNameTextField.getText();
348 String email = emailTextField.getText();
349 Boolean valid;
351 valid = GitModuleConfig.getDefault().isUserNameValid(name);
352 if (!valid)
353 return false;
354 valid = GitModuleConfig.getDefault().isEmailValid(email);
355 return valid;
358 // Variables declaration - do not modify//GEN-BEGIN:variables
359 final javax.swing.JButton addButton = new javax.swing.JButton();
360 final javax.swing.JTextField annotationTextField = new javax.swing.JTextField();
361 private javax.swing.JCheckBox backupOnRevertModifications;
362 private javax.swing.JLabel emailLabel;
363 final javax.swing.JTextField emailTextField = new javax.swing.JTextField();
364 private javax.swing.JLabel exportFilename;
365 final javax.swing.JButton exportFilenameBrowseButton = new javax.swing.JButton();
366 final javax.swing.JTextField exportFilenameTextField = new javax.swing.JTextField();
367 private javax.swing.JPanel fileOptionsPanel;
368 private javax.swing.JPanel generalOptionsPanel;
369 private javax.swing.JLabel jLabel3;
370 private javax.swing.JTabbedPane jTabbedPane1;
371 private javax.swing.JLabel logoLabel;
372 private javax.swing.JPanel statusLabels;
373 private javax.swing.JPanel userInformation;
374 private javax.swing.JLabel userNameLabel;
375 private javax.swing.JTextField userNameTextField;
376 // End of variables declaration//GEN-END:variables