Cleanup code whitespace
[nbgit.git] / src / org / nbgit / ui / commit / CommitPanel.java
blob3bad5d21f26bd227c3121e1e83f3aefba9e2ba16
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.ui.commit;
44 import java.awt.Cursor;
45 import java.awt.event.MouseAdapter;
46 import java.awt.event.MouseEvent;
47 import java.util.List;
48 import java.util.prefs.PreferenceChangeEvent;
49 import java.util.prefs.PreferenceChangeListener;
50 import javax.swing.event.TableModelEvent;
51 import javax.swing.event.TableModelListener;
52 import org.nbgit.GitModuleConfig;
53 import org.netbeans.modules.versioning.util.ListenersSupport;
54 import org.netbeans.modules.versioning.util.StringSelector;
55 import org.netbeans.modules.versioning.util.Utils;
56 import org.netbeans.modules.versioning.util.VersioningListener;
57 import org.openide.util.NbBundle;
59 /**
61 * @author pk97937
63 public class CommitPanel extends javax.swing.JPanel implements PreferenceChangeListener, TableModelListener {
65 static final Object EVENT_SETTINGS_CHANGED = new Object();
67 private CommitTable commitTable;
69 /** Creates new form CommitPanel */
70 public CommitPanel() {
71 initComponents();
74 void setCommitTable(CommitTable commitTable) {
75 this.commitTable = commitTable;
78 void setErrorLabel(String htmlErrorLabel) {
79 jLabel2.setText(htmlErrorLabel);
82 @Override
83 public void addNotify() {
84 super.addNotify();
85 GitModuleConfig.getDefault().getPreferences().addPreferenceChangeListener(this);
86 commitTable.getTableModel().addTableModelListener(this);
87 listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED);
89 recentLink.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
90 recentLink.addMouseListener(new MouseAdapter() {
91 @Override
92 public void mouseClicked(MouseEvent e) {
93 onBrowseRecentMessages();
95 });
97 List<String> messages = Utils.getStringList(GitModuleConfig.getDefault().getPreferences(), CommitAction.RECENT_COMMIT_MESSAGES);
98 if (messages.size() > 0) {
99 messageTextArea.setText(messages.get(0));
101 messageTextArea.selectAll();
104 @Override
105 public void removeNotify() {
106 commitTable.getTableModel().removeTableModelListener(this);
107 GitModuleConfig.getDefault().getPreferences().removePreferenceChangeListener(this);
108 super.removeNotify();
111 private void onBrowseRecentMessages() {
112 String message = StringSelector.select(NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_RecentTitle"), // NOI18N
113 NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_RecentPrompt"), // NOI18N
114 Utils.getStringList(GitModuleConfig.getDefault().getPreferences(), CommitAction.RECENT_COMMIT_MESSAGES));
115 if (message != null) {
116 messageTextArea.replaceSelection(message);
120 public void preferenceChange(PreferenceChangeEvent evt) {
121 if (evt.getKey().startsWith(GitModuleConfig.PROP_COMMIT_EXCLUSIONS)) {
122 commitTable.dataChanged();
123 listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED);
127 public void tableChanged(TableModelEvent e) {
128 listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED);
131 /** This method is called from within the constructor to
132 * initialize the form.
133 * WARNING: Do NOT modify this code. The content of this method is
134 * always regenerated by the Form Editor.
136 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
137 private void initComponents() {
139 setMinimumSize(new java.awt.Dimension(400, 300));
140 setPreferredSize(new java.awt.Dimension(650, 400));
142 jLabel1.setLabelFor(messageTextArea);
143 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_Message")); // NOI18N
145 messageTextArea.setColumns(30);
146 messageTextArea.setLineWrap(true);
147 messageTextArea.setRows(6);
148 messageTextArea.setTabSize(4);
149 messageTextArea.setWrapStyleWord(true);
150 messageTextArea.setMinimumSize(new java.awt.Dimension(100, 18));
151 jScrollPane1.setViewportView(messageTextArea);
152 messageTextArea.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CommitPanel.class, "ACSN_CommitForm_Message")); // NOI18N
153 messageTextArea.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CommitPanel.class, "ACSD_CommitForm_Message")); // NOI18N
155 org.openide.awt.Mnemonics.setLocalizedText(filesLabel, org.openide.util.NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_FilesToCommit")); // NOI18N
157 filesPanel.setPreferredSize(new java.awt.Dimension(240, 108));
159 org.jdesktop.layout.GroupLayout filesPanelLayout = new org.jdesktop.layout.GroupLayout(filesPanel);
160 filesPanel.setLayout(filesPanelLayout);
161 filesPanelLayout.setHorizontalGroup(
162 filesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
163 .add(0, 610, Short.MAX_VALUE)
165 filesPanelLayout.setVerticalGroup(
166 filesPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
167 .add(0, 173, Short.MAX_VALUE)
170 recentLink.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/nbgit/resources/icons/recent_messages.png"))); // NOI18N
171 recentLink.setToolTipText(org.openide.util.NbBundle.getMessage(CommitPanel.class, "CTL_CommitForm_RecentMessages")); // NOI18N
173 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
174 this.setLayout(layout);
175 layout.setHorizontalGroup(
176 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
177 .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
178 .addContainerGap()
179 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
180 .add(org.jdesktop.layout.GroupLayout.LEADING, filesPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 610, Short.MAX_VALUE)
181 .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 610, Short.MAX_VALUE)
182 .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
183 .add(jLabel1)
184 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 482, Short.MAX_VALUE)
185 .add(recentLink))
186 .add(org.jdesktop.layout.GroupLayout.LEADING, filesLabel)
187 .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel2))
188 .addContainerGap())
190 layout.setVerticalGroup(
191 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
192 .add(layout.createSequentialGroup()
193 .addContainerGap()
194 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
195 .add(jLabel1)
196 .add(recentLink))
197 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
198 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
199 .add(15, 15, 15)
200 .add(filesLabel)
201 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
202 .add(filesPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
203 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
204 .add(jLabel2)
205 .addContainerGap())
208 getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CommitPanel.class, "ACSN_CommitDialog")); // NOI18N
209 getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CommitPanel.class, "ACSD_CommitDialog")); // NOI18N
210 }// </editor-fold>//GEN-END:initComponents
212 ListenersSupport listenerSupport = new ListenersSupport(this);
213 public void addVersioningListener(VersioningListener listener) {
214 listenerSupport.addListener(listener);
217 public void removeVersioningListener(VersioningListener listener) {
218 listenerSupport.removeListener(listener);
221 // Variables declaration - do not modify//GEN-BEGIN:variables
222 final javax.swing.JLabel filesLabel = new javax.swing.JLabel();
223 final javax.swing.JPanel filesPanel = new javax.swing.JPanel();
224 final javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
225 final javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
226 final javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
227 final javax.swing.JTextArea messageTextArea = new javax.swing.JTextArea();
228 final javax.swing.JLabel recentLink = new javax.swing.JLabel();
229 // End of variables declaration//GEN-END:variables