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.subversion.ui.commit;
043:
044: import org.netbeans.modules.subversion.SvnModuleConfig;
045: import org.netbeans.modules.versioning.util.ListenersSupport;
046: import org.netbeans.modules.versioning.util.VersioningListener;
047: import org.netbeans.modules.versioning.util.Utils;
048: import org.netbeans.modules.versioning.util.StringSelector;
049: import org.openide.util.NbBundle;
050:
051: import javax.swing.event.TableModelListener;
052: import javax.swing.event.TableModelEvent;
053: import java.util.prefs.PreferenceChangeEvent;
054: import java.util.prefs.PreferenceChangeListener;
055: import java.util.*;
056: import java.awt.event.MouseAdapter;
057: import java.awt.event.MouseEvent;
058: import java.awt.Cursor;
059:
060: /**
061: *
062: * @author pk97937
063: */
064: public class CommitPanel extends javax.swing.JPanel implements
065: PreferenceChangeListener, TableModelListener {
066:
067: static final Object EVENT_SETTINGS_CHANGED = new Object();
068:
069: private CommitTable commitTable;
070:
071: /** Creates new form CommitPanel */
072: public CommitPanel() {
073: initComponents();
074: }
075:
076: void setCommitTable(CommitTable commitTable) {
077: this .commitTable = commitTable;
078: }
079:
080: void setErrorLabel(String htmlErrorLabel) {
081: jLabel2.setText(htmlErrorLabel);
082: }
083:
084: public void addNotify() {
085: super .addNotify();
086: SvnModuleConfig.getDefault().getPreferences()
087: .addPreferenceChangeListener(this );
088: commitTable.getTableModel().addTableModelListener(this );
089: listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED);
090:
091: recentLink.setCursor(Cursor
092: .getPredefinedCursor(Cursor.HAND_CURSOR));
093: recentLink.addMouseListener(new MouseAdapter() {
094: public void mouseClicked(MouseEvent e) {
095: onBrowseRecentMessages();
096: }
097: });
098:
099: List<String> messages = Utils.getStringList(SvnModuleConfig
100: .getDefault().getPreferences(),
101: CommitAction.RECENT_COMMIT_MESSAGES);
102: if (messages.size() > 0) {
103: messageTextArea.setText(messages.get(0));
104: }
105: messageTextArea.selectAll();
106: }
107:
108: public void removeNotify() {
109: commitTable.getTableModel().removeTableModelListener(this );
110: SvnModuleConfig.getDefault().getPreferences()
111: .removePreferenceChangeListener(this );
112: super .removeNotify();
113: }
114:
115: private void onBrowseRecentMessages() {
116: String message = StringSelector.select(NbBundle.getMessage(
117: CommitPanel.class, "CTL_CommitForm_RecentTitle"),
118: NbBundle.getMessage(CommitPanel.class,
119: "CTL_CommitForm_RecentPrompt"), Utils
120: .getStringList(SvnModuleConfig.getDefault()
121: .getPreferences(),
122: CommitAction.RECENT_COMMIT_MESSAGES));
123: if (message != null) {
124: messageTextArea.replaceSelection(message);
125: }
126: }
127:
128: public void preferenceChange(PreferenceChangeEvent evt) {
129: if (evt.getKey().startsWith(
130: SvnModuleConfig.PROP_COMMIT_EXCLUSIONS)) {
131: commitTable.dataChanged();
132: listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED);
133: }
134: }
135:
136: public void tableChanged(TableModelEvent e) {
137: listenerSupport.fireVersioningEvent(EVENT_SETTINGS_CHANGED);
138: }
139:
140: /** This method is called from within the constructor to
141: * initialize the form.
142: * WARNING: Do NOT modify this code. The content of this method is
143: * always regenerated by the Form Editor.
144: */
145: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
146: private void initComponents() {
147:
148: setMinimumSize(new java.awt.Dimension(400, 300));
149: setPreferredSize(new java.awt.Dimension(650, 400));
150:
151: jLabel1.setLabelFor(messageTextArea);
152: org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
153: org.openide.util.NbBundle.getMessage(CommitPanel.class,
154: "CTL_CommitForm_Message")); // NOI18N
155:
156: messageTextArea.setColumns(30);
157: messageTextArea.setLineWrap(true);
158: messageTextArea.setRows(6);
159: messageTextArea.setTabSize(4);
160: messageTextArea.setWrapStyleWord(true);
161: messageTextArea.setMinimumSize(new java.awt.Dimension(100, 18));
162: jScrollPane1.setViewportView(messageTextArea);
163: messageTextArea.getAccessibleContext().setAccessibleName(
164: org.openide.util.NbBundle.getMessage(CommitPanel.class,
165: "ACSN_CommitForm_Message")); // NOI18N
166: messageTextArea.getAccessibleContext()
167: .setAccessibleDescription(
168: org.openide.util.NbBundle.getMessage(
169: CommitPanel.class,
170: "ACSD_CommitForm_Message")); // NOI18N
171:
172: org.openide.awt.Mnemonics.setLocalizedText(filesLabel,
173: org.openide.util.NbBundle.getMessage(CommitPanel.class,
174: "CTL_CommitForm_FilesToCommit")); // NOI18N
175:
176: filesPanel.setPreferredSize(new java.awt.Dimension(240, 108));
177:
178: org.jdesktop.layout.GroupLayout filesPanelLayout = new org.jdesktop.layout.GroupLayout(
179: filesPanel);
180: filesPanel.setLayout(filesPanelLayout);
181: filesPanelLayout.setHorizontalGroup(filesPanelLayout
182: .createParallelGroup(
183: org.jdesktop.layout.GroupLayout.LEADING).add(0,
184: 626, Short.MAX_VALUE));
185: filesPanelLayout.setVerticalGroup(filesPanelLayout
186: .createParallelGroup(
187: org.jdesktop.layout.GroupLayout.LEADING).add(0,
188: 204, Short.MAX_VALUE));
189:
190: recentLink
191: .setIcon(new javax.swing.ImageIcon(
192: getClass()
193: .getResource(
194: "/org/netbeans/modules/subversion/resources/icons/recent_messages.png"))); // NOI18N
195: recentLink.setToolTipText(org.openide.util.NbBundle.getMessage(
196: CommitPanel.class, "CTL_CommitForm_RecentMessages")); // NOI18N
197:
198: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
199: this );
200: this .setLayout(layout);
201: layout
202: .setHorizontalGroup(layout
203: .createParallelGroup(
204: org.jdesktop.layout.GroupLayout.LEADING)
205: .add(
206: org.jdesktop.layout.GroupLayout.TRAILING,
207: layout
208: .createSequentialGroup()
209: .addContainerGap()
210: .add(
211: layout
212: .createParallelGroup(
213: org.jdesktop.layout.GroupLayout.TRAILING)
214: .add(
215: org.jdesktop.layout.GroupLayout.LEADING,
216: filesPanel,
217: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
218: 626,
219: Short.MAX_VALUE)
220: .add(
221: org.jdesktop.layout.GroupLayout.LEADING,
222: jScrollPane1,
223: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
224: 626,
225: Short.MAX_VALUE)
226: .add(
227: org.jdesktop.layout.GroupLayout.LEADING,
228: layout
229: .createSequentialGroup()
230: .add(
231: jLabel1)
232: .addPreferredGap(
233: org.jdesktop.layout.LayoutStyle.RELATED,
234: 499,
235: Short.MAX_VALUE)
236: .add(
237: recentLink))
238: .add(
239: org.jdesktop.layout.GroupLayout.LEADING,
240: filesLabel)
241: .add(
242: org.jdesktop.layout.GroupLayout.LEADING,
243: jLabel2))
244: .addContainerGap()));
245: layout
246: .setVerticalGroup(layout
247: .createParallelGroup(
248: org.jdesktop.layout.GroupLayout.LEADING)
249: .add(
250: layout
251: .createSequentialGroup()
252: .addContainerGap()
253: .add(
254: layout
255: .createParallelGroup(
256: org.jdesktop.layout.GroupLayout.BASELINE)
257: .add(jLabel1)
258: .add(recentLink))
259: .addPreferredGap(
260: org.jdesktop.layout.LayoutStyle.RELATED)
261: .add(
262: jScrollPane1,
263: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
264: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
265: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
266: .add(15, 15, 15)
267: .add(filesLabel)
268: .addPreferredGap(
269: org.jdesktop.layout.LayoutStyle.RELATED)
270: .add(
271: filesPanel,
272: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
273: 204, Short.MAX_VALUE)
274: .addPreferredGap(
275: org.jdesktop.layout.LayoutStyle.RELATED)
276: .add(jLabel2).addContainerGap()));
277:
278: getAccessibleContext().setAccessibleName(
279: org.openide.util.NbBundle.getMessage(CommitPanel.class,
280: "ACSN_CommitDialog")); // NOI18N
281: getAccessibleContext().setAccessibleDescription(
282: org.openide.util.NbBundle.getMessage(CommitPanel.class,
283: "ACSD_CommitDialog")); // NOI18N
284: }// </editor-fold>//GEN-END:initComponents
285:
286: ListenersSupport listenerSupport = new ListenersSupport(this );
287:
288: public void addVersioningListener(VersioningListener listener) {
289: listenerSupport.addListener(listener);
290: }
291:
292: public void removeVersioningListener(VersioningListener listener) {
293: listenerSupport.removeListener(listener);
294: }
295:
296: // Variables declaration - do not modify//GEN-BEGIN:variables
297: final javax.swing.JLabel filesLabel = new javax.swing.JLabel();
298: final javax.swing.JPanel filesPanel = new javax.swing.JPanel();
299: final javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
300: final javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
301: final javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
302: final javax.swing.JTextArea messageTextArea = new javax.swing.JTextArea();
303: final javax.swing.JLabel recentLink = new javax.swing.JLabel();
304: // End of variables declaration//GEN-END:variables
305:
306: }
|