/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License. When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* Contributor(s):
*
* The Original Software is NetBeans. The Initial Developer of the Original
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
* Microsystems, Inc. All Rights Reserved.
* Portions Copyright 2008 Alexander Coles (Ikonoklastik Productions).
*
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*/
package org.nbgit.options;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.nbgit.GitModuleConfig;
import org.nbgit.util.GitUtils;
import org.nbgit.util.HtmlFormatter;
final class GitPanel extends javax.swing.JPanel {
private final GitOptionsPanelController controller;
private final DocumentListener listener;
GitPanel(GitOptionsPanelController controller) {
this.controller = controller;
this.listener = new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
nameChange();
}
public void removeUpdate(DocumentEvent e) {
nameChange();
}
public void changedUpdate(DocumentEvent e) {
nameChange();
}
};
initComponents();
}
@Override
public void addNotify() {
super.addNotify();
emailTextField.getDocument().addDocumentListener(listener);
}
@Override
public void removeNotify() {
emailTextField.getDocument().removeDocumentListener(listener);
super.removeNotify();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
userInformation = new javax.swing.JPanel();
emailLabel = new javax.swing.JLabel();
userNameLabel = new javax.swing.JLabel();
userNameTextField = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
statusLabels = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
signOffCommits = new javax.swing.JCheckBox();
stripSpaceBox = new javax.swing.JCheckBox();
jPanel2 = new javax.swing.JPanel();
backupOnRevertModifications = new javax.swing.JCheckBox();
userInformation.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(GitPanel.class, "UserInformation"))); // NOI18N
userInformation.setName(org.openide.util.NbBundle.getMessage(GitPanel.class, "UserInformationPanel.Title")); // NOI18N
userInformation.setOpaque(false);
emailLabel.setLabelFor(emailTextField);
org.openide.awt.Mnemonics.setLocalizedText(emailLabel, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel1.text")); // NOI18N
emailTextField.setToolTipText(org.openide.util.NbBundle.getMessage(GitPanel.class, "emailTextField.TOOLTIP")); // NOI18N
userNameLabel.setLabelFor(userNameTextField);
org.openide.awt.Mnemonics.setLocalizedText(userNameLabel, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel5.text")); // NOI18N
userNameTextField.setToolTipText(org.openide.util.NbBundle.getMessage(GitPanel.class, "userNameTextField.TOOLTIP")); // NOI18N
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, "user@example.org");
org.jdesktop.layout.GroupLayout userInformationLayout = new org.jdesktop.layout.GroupLayout(userInformation);
userInformation.setLayout(userInformationLayout);
userInformationLayout.setHorizontalGroup(
userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(userInformationLayout.createSequentialGroup()
.addContainerGap()
.add(userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(userNameLabel)
.add(emailLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 95, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(16, 16, 16)
.add(userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(emailTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
.add(userNameTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE))
.addContainerGap())
);
userInformationLayout.setVerticalGroup(
userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(userInformationLayout.createSequentialGroup()
.add(userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
.add(userNameTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(userNameLabel))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(userInformationLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
.add(emailLabel)
.add(emailTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel1)
.addContainerGap())
);
emailTextField.getAccessibleContext().setAccessibleName("Email:");
emailTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_userNameTextField")); // NOI18N
statusLabels.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(GitPanel.class, "StatusLabel"))); // NOI18N
statusLabels.setOpaque(false);
jLabel3.setLabelFor(annotationTextField);
org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jLabel3.text")); // NOI18N
annotationTextField.setText(org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.annotationTextField.text")); // NOI18N
annotationTextField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
annotationTextFieldActionPerformed(evt);
}
});
org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.addButton.text")); // NOI18N
org.jdesktop.layout.GroupLayout statusLabelsLayout = new org.jdesktop.layout.GroupLayout(statusLabels);
statusLabels.setLayout(statusLabelsLayout);
statusLabelsLayout.setHorizontalGroup(
statusLabelsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusLabelsLayout.createSequentialGroup()
.addContainerGap()
.add(jLabel3)
.add(59, 59, 59)
.add(annotationTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 403, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(addButton)
.addContainerGap())
);
statusLabelsLayout.setVerticalGroup(
statusLabelsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusLabelsLayout.createSequentialGroup()
.add(statusLabelsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(statusLabelsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE, false)
.add(jLabel3)
.add(addButton))
.add(statusLabelsLayout.createSequentialGroup()
.add(2, 2, 2)
.add(annotationTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
addButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_addButton")); // NOI18N
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Commit Options"));
org.openide.awt.Mnemonics.setLocalizedText(signOffCommits, "Insert Signed-off-by line in commit messages");
org.openide.awt.Mnemonics.setLocalizedText(stripSpaceBox, "Strip space from commit message");
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(signOffCommits)
.add(stripSpaceBox))
.addContainerGap(326, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel1Layout.createSequentialGroup()
.add(signOffCommits)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(stripSpaceBox)
.addContainerGap(13, Short.MAX_VALUE))
);
jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Revert Options"));
backupOnRevertModifications.setSelected(true);
org.openide.awt.Mnemonics.setLocalizedText(backupOnRevertModifications, org.openide.util.NbBundle.getMessage(GitPanel.class, "GitPanel.jCheckBox1.text")); // NOI18N
org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.add(backupOnRevertModifications)
.addContainerGap(209, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPanel2Layout.createSequentialGroup()
.add(backupOnRevertModifications)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
backupOnRevertModifications.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(GitPanel.class, "ACSD_backupOnRevertModifications")); // NOI18N
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, userInformation, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.LEADING, statusLabels, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(userInformation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(statusLabels, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void annotationTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_annotationTextFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_annotationTextFieldActionPerformed
private void nameChange()
{
controller.changed();
}
void load()
{
// TODO read settings and initialize GUI
// Example:
// someCheckBox.setSelected(Preferences.userNodeForPackage(GitPanel.class).getBoolean("someFlag", false)); // NOI18N
// or for org.openide.util with API spec. version >= 7.4:
// someCheckBox.setSelected(NbPreferences.forModule(GitPanel.class).getBoolean("someFlag", false)); // NOI18N
// or:
// someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty());
emailTextField.setText(GitModuleConfig.getDefault().getEmail());
userNameTextField.setText(GitModuleConfig.getDefault().getUserName());
annotationTextField.setText(GitModuleConfig.getDefault().getAnnotationFormat());
signOffCommits.setSelected(GitModuleConfig.getDefault().getSignOffCommits());
stripSpaceBox.setSelected(GitModuleConfig.getDefault().getStripSpace());
backupOnRevertModifications.setSelected(GitModuleConfig.getDefault().getBackupOnRevertModifications());
}
void store()
{
// TODO store modified settings
// Example:
// Preferences.userNodeForPackage(GitPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N
// or for org.openide.util with API spec. version >= 7.4:
// NbPreferences.forModule(GitPanel.class).putBoolean("someFlag", someCheckBox.isSelected()); // NOI18N
// or:
// SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
GitModuleConfig.getDefault().setEmail(emailTextField.getText());
GitModuleConfig.getDefault().setUserName(userNameTextField.getText());
GitModuleConfig.getDefault().setAnnotationFormat(annotationTextField.getText());
GitModuleConfig.getDefault().setSignOffCommits(signOffCommits.isSelected());
GitModuleConfig.getDefault().setStripSpace(stripSpaceBox.isSelected());
GitModuleConfig.getDefault().setBackupOnRevertModifications(backupOnRevertModifications.isSelected());
if (HtmlFormatter.isRevisionInAnnotationFormat(annotationTextField.getText()))
GitUtils.warningDialog(GitPanel.class,
"MSG_STATUS_LABEL_WITH_REVSION_TITLE", "MSG_STATUS_LABEL_WITH_REVSION_MSG");
}
boolean valid()
{
// TODO check whether form is consistent and complete
//return true;
String name = userNameTextField.getText();
String email = emailTextField.getText();
Boolean valid;
valid = GitModuleConfig.getDefault().isUserNameValid(name);
if (!valid)
return false;
valid = GitModuleConfig.getDefault().isEmailValid(email);
return valid;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
final javax.swing.JButton addButton = new javax.swing.JButton();
final javax.swing.JTextField annotationTextField = new javax.swing.JTextField();
private javax.swing.JCheckBox backupOnRevertModifications;
private javax.swing.JLabel emailLabel;
final javax.swing.JTextField emailTextField = new javax.swing.JTextField();
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JCheckBox signOffCommits;
private javax.swing.JPanel statusLabels;
private javax.swing.JCheckBox stripSpaceBox;
private javax.swing.JPanel userInformation;
private javax.swing.JLabel userNameLabel;
private javax.swing.JTextField userNameTextField;
// End of variables declaration//GEN-END:variables
}