KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > actions > tag > TagSettings


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss.ui.actions.tag;
21
22 import org.netbeans.lib.cvsclient.command.tag.TagCommand;
23 import org.netbeans.lib.cvsclient.CVSRoot;
24 import org.netbeans.modules.versioning.system.cvss.util.Utils;
25 import org.netbeans.modules.versioning.system.cvss.ui.selectors.BranchSelector;
26
27 import javax.swing.event.DocumentListener JavaDoc;
28 import javax.swing.event.DocumentEvent JavaDoc;
29 import javax.swing.*;
30 import java.io.IOException JavaDoc;
31 import java.io.File JavaDoc;
32
33 /**
34  * Settings panel for the Tag command.
35  *
36  * @author Maros Sandor
37  */

38 public class TagSettings extends javax.swing.JPanel JavaDoc implements DocumentListener JavaDoc {
39     
40     private final File JavaDoc[] roots;
41
42     public TagSettings(File JavaDoc [] roots) {
43         this.roots = roots;
44         initComponents();
45         tfName.getDocument().addDocumentListener(this);
46     }
47     
48     void refreshComponents() {
49         cbMoveTag.setEnabled(!cbDeleteTag.isSelected());
50         cbDeleteTag.setEnabled(!cbMoveTag.isSelected());
51         cbCheckModified.setEnabled(!cbDeleteTag.isSelected());
52         JButton okButton = (JButton) getClientProperty("OKButton"); // NOI18N
53
if (okButton != null) {
54             okButton.setEnabled(Utils.isTagValid(tfName.getText()));
55         }
56     }
57
58     public void insertUpdate(DocumentEvent JavaDoc e) {
59         refreshComponents();
60     }
61
62     public void removeUpdate(DocumentEvent JavaDoc e) {
63         refreshComponents();
64     }
65
66     public void changedUpdate(DocumentEvent JavaDoc e) {
67         refreshComponents();
68     }
69
70     public void setCommand(TagCommand cmd) {
71         cbMoveTag.setSelected(cmd.isOverrideExistingTag());
72         cbCheckModified.setSelected(cmd.isCheckThatUnmodified());
73         cbDeleteTag.setSelected(cmd.isDeleteTag());
74         tfName.setText(cmd.getTag());
75     }
76
77     public void updateCommand(TagCommand cmd) {
78         cmd.setOverrideExistingTag(cbMoveTag.isSelected());
79         cmd.setCheckThatUnmodified(cbCheckModified.isSelected());
80         cmd.setDeleteTag(cbDeleteTag.isSelected());
81         cmd.setTag(tfName.getText());
82     }
83     
84     /** This method is called from within the constructor to
85      * initialize the form.
86      * WARNING: Do NOT modify this code. The content of this method is
87      * always regenerated by the Form Editor.
88      */

89     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
90
private void initComponents() {
91
92         cbCheckModified = new javax.swing.JCheckBox JavaDoc();
93         cbMoveTag = new javax.swing.JCheckBox JavaDoc();
94         nameLabel = new javax.swing.JLabel JavaDoc();
95         tfName = new javax.swing.JTextField JavaDoc();
96         jButton1 = new javax.swing.JButton JavaDoc();
97         cbDeleteTag = new javax.swing.JCheckBox JavaDoc();
98
99         setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
100
101         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle"); // NOI18N
102
org.openide.awt.Mnemonics.setLocalizedText(cbCheckModified, bundle.getString("CTL_TagForm_EnsureUptodate")); // NOI18N
103
cbCheckModified.setToolTipText(bundle.getString("TT_TagForm_EnsureUptodate")); // NOI18N
104
cbCheckModified.addActionListener(new java.awt.event.ActionListener JavaDoc() {
105             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
106                 cbCheckModifiedActionPerformed(evt);
107             }
108         });
109
110         org.openide.awt.Mnemonics.setLocalizedText(cbMoveTag, bundle.getString("CTL_TagForm_MoveExisting")); // NOI18N
111
cbMoveTag.setToolTipText(bundle.getString("TT_TagForm_MoveExisting")); // NOI18N
112
cbMoveTag.addActionListener(new java.awt.event.ActionListener JavaDoc() {
113             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
114                 cbMoveTagActionPerformed(evt);
115             }
116         });
117
118         nameLabel.setLabelFor(tfName);
119         org.openide.awt.Mnemonics.setLocalizedText(nameLabel, bundle.getString("CTL_TagForm_TagName")); // NOI18N
120

121         tfName.setColumns(20);
122
123         org.openide.awt.Mnemonics.setLocalizedText(jButton1, bundle.getString("CTL_BrowseTag")); // NOI18N
124
jButton1.setToolTipText(bundle.getString("TT_BrowseTag")); // NOI18N
125
jButton1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
126             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
127                 onBrowseTag(evt);
128             }
129         });
130
131         org.openide.awt.Mnemonics.setLocalizedText(cbDeleteTag, bundle.getString("CTL_TagForm_DeleteExisting")); // NOI18N
132
cbDeleteTag.setToolTipText(bundle.getString("TT_TagForm_DeleteExisting")); // NOI18N
133
cbDeleteTag.addActionListener(new java.awt.event.ActionListener JavaDoc() {
134             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
135                 cbDeleteTagActionPerformed(evt);
136             }
137         });
138
139         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
140         this.setLayout(layout);
141         layout.setHorizontalGroup(
142             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
143             .add(layout.createSequentialGroup()
144                 .add(cbMoveTag, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
145                 .add(159, 159, 159))
146             .add(layout.createSequentialGroup()
147                 .add(nameLabel)
148                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
149                 .add(tfName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
150                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
151                 .add(jButton1))
152             .add(layout.createSequentialGroup()
153                 .add(cbCheckModified, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
154                 .add(159, 159, 159))
155             .add(layout.createSequentialGroup()
156                 .add(cbDeleteTag, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
157                 .add(159, 159, 159))
158         );
159         layout.setVerticalGroup(
160             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
161             .add(layout.createSequentialGroup()
162                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
163                     .add(nameLabel)
164                     .add(jButton1)
165                     .add(tfName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
166                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
167                 .add(cbCheckModified, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 23, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
168                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
169                 .add(cbMoveTag)
170                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
171                 .add(cbDeleteTag))
172         );
173     }// </editor-fold>//GEN-END:initComponents
174

175     private void cbDeleteTagActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbDeleteTagActionPerformed
176
refreshComponents();
177     }//GEN-LAST:event_cbDeleteTagActionPerformed
178

179     private void cbMoveTagActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbMoveTagActionPerformed
180
refreshComponents();
181     }//GEN-LAST:event_cbMoveTagActionPerformed
182

183     private void onBrowseTag(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_onBrowseTag
184
for (int i = 0; i < roots.length; i++) {
185             try {
186                 CVSRoot.parse(Utils.getCVSRootFor(roots[i])); // raises exception
187
BranchSelector selector = new BranchSelector();
188                 String JavaDoc tag = selector.selectTag(roots[i]);
189                 if (tag != null) {
190                     tfName.setText(tag);
191                 }
192                 return;
193             } catch (IOException JavaDoc e) {
194                 // no root for this file, try next
195
}
196         }
197     }//GEN-LAST:event_onBrowseTag
198

199     private void cbCheckModifiedActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_cbCheckModifiedActionPerformed
200
// TODO add your handling code here:
201
}//GEN-LAST:event_cbCheckModifiedActionPerformed
202

203     
204     // Variables declaration - do not modify//GEN-BEGIN:variables
205
private javax.swing.JCheckBox JavaDoc cbCheckModified;
206     private javax.swing.JCheckBox JavaDoc cbDeleteTag;
207     private javax.swing.JCheckBox JavaDoc cbMoveTag;
208     private javax.swing.JButton JavaDoc jButton1;
209     private javax.swing.JLabel JavaDoc nameLabel;
210     private javax.swing.JTextField JavaDoc tfName;
211     // End of variables declaration//GEN-END:variables
212
}
213
Popular Tags