KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > ui > history > ViewRevisionPanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.versioning.system.cvss.ui.history;
20
21 import org.openide.util.NbBundle;
22 import org.netbeans.modules.versioning.spi.VCSContext;
23 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig;
24 import org.netbeans.modules.versioning.system.cvss.ui.selectors.BranchSelector;
25 import org.netbeans.modules.versioning.system.cvss.util.Utils;
26 import org.netbeans.lib.cvsclient.CVSRoot;
27
28 import java.io.IOException JavaDoc;
29 import java.io.File JavaDoc;
30 import java.util.*;
31
32 /**
33  * View Revision customization panel.
34  *
35  * @author Maros Sandor
36  */

37 class ViewRevisionPanel extends javax.swing.JPanel JavaDoc {
38     
39     private final String JavaDoc VIEW_TRUNK_HEAD = "ViewRevisionPanel.ViewTrunkHEAD"; // NOI18N
40
private final String JavaDoc VIEW_BRANCH = "ViewRevisionPanel.ViewBranch"; // NOI18N
41
private final String JavaDoc VIEW_BRANCH_NAME = "ViewRevisionPanel.ViewBranchName"; // NOI18N
42

43     private final VCSContext ctx;
44
45     public ViewRevisionPanel(VCSContext ctx) {
46         this.ctx = ctx;
47         initComponents();
48         rbBranch.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean(VIEW_BRANCH, true));
49         rbTrunk.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean(VIEW_TRUNK_HEAD, false));
50         tfTagName.setText(CvsModuleConfig.getDefault().getPreferences().get(VIEW_BRANCH_NAME, ""));
51         refreshComponents();
52     }
53
54     String JavaDoc getRevision() {
55         return rbTrunk.isSelected() ? "HEAD" : tfTagName.getText(); // NOI18N
56
}
57     
58     void saveSettings() {
59         CvsModuleConfig.getDefault().getPreferences().putBoolean(VIEW_TRUNK_HEAD, rbTrunk.isSelected());
60         CvsModuleConfig.getDefault().getPreferences().putBoolean(VIEW_BRANCH, rbBranch.isSelected());
61         CvsModuleConfig.getDefault().getPreferences().put(VIEW_BRANCH_NAME, tfTagName.getText());
62     }
63     
64     void refreshComponents() {
65         tfTagName.setEnabled(rbBranch.isSelected());
66         bBrowse.setEnabled(rbBranch.isSelected());
67     }
68     
69     private String JavaDoc browseBranches() {
70         Set<File JavaDoc> roots = ctx.getRootFiles();
71         for (File JavaDoc root : roots) {
72             try {
73                 CVSRoot.parse(Utils.getCVSRootFor(root)); // raises exception
74
BranchSelector selector = new BranchSelector();
75                 return selector.selectTag(root);
76             } catch (IOException JavaDoc e) {
77                 // no root for this file, try next
78
}
79         }
80         return null;
81     }
82     
83     /** This method is called from within the constructor to
84      * initialize the form.
85      * WARNING: Do NOT modify this code. The content of this method is
86      * always regenerated by the Form Editor.
87      */

88     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
89
private void initComponents() {
90
91         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
92         rbTrunk = new javax.swing.JRadioButton JavaDoc();
93         rbBranch = new javax.swing.JRadioButton JavaDoc();
94         tfTagName = new javax.swing.JTextField JavaDoc();
95         bBrowse = new javax.swing.JButton JavaDoc();
96
97         buttonGroup1.add(rbTrunk);
98         org.openide.awt.Mnemonics.setLocalizedText(rbTrunk, NbBundle.getMessage(ViewRevisionPanel.class, "ViewRevisionPanel.rbTrunk.text")); // NOI18N
99
rbTrunk.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
100         rbTrunk.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
101         rbTrunk.addActionListener(new java.awt.event.ActionListener JavaDoc() {
102             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
103                 rbTrunkActionPerformed(evt);
104             }
105         });
106
107         buttonGroup1.add(rbBranch);
108         org.openide.awt.Mnemonics.setLocalizedText(rbBranch, NbBundle.getMessage(ViewRevisionPanel.class, "ViewRevisionPanel.rbBranch.text")); // NOI18N
109
rbBranch.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
110         rbBranch.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
111         rbBranch.addActionListener(new java.awt.event.ActionListener JavaDoc() {
112             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
113                 rbBranchActionPerformed(evt);
114             }
115         });
116
117         tfTagName.setText(NbBundle.getMessage(ViewRevisionPanel.class, "ViewRevisionPanel.tfTagName.text")); // NOI18N
118

119         org.openide.awt.Mnemonics.setLocalizedText(bBrowse, NbBundle.getMessage(ViewRevisionPanel.class, "ViewRevisionPanel.bBrowse.text")); // NOI18N
120
bBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
121             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
122                 bBrowseActionPerformed(evt);
123             }
124         });
125
126         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
127         this.setLayout(layout);
128         layout.setHorizontalGroup(
129             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
130             .add(layout.createSequentialGroup()
131                 .addContainerGap()
132                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
133                     .add(layout.createSequentialGroup()
134                         .add(rbBranch)
135                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
136                         .add(tfTagName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 183, Short.MAX_VALUE)
137                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
138                         .add(bBrowse))
139                     .add(rbTrunk))
140                 .addContainerGap())
141         );
142         layout.setVerticalGroup(
143             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
144             .add(layout.createSequentialGroup()
145                 .addContainerGap()
146                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
147                     .add(rbBranch)
148                     .add(bBrowse)
149                     .add(tfTagName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
150                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
151                 .add(rbTrunk)
152                 .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
153         );
154     }// </editor-fold>//GEN-END:initComponents
155

156     private void rbBranchActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_rbBranchActionPerformed
157
refreshComponents();
158     }//GEN-LAST:event_rbBranchActionPerformed
159

160     private void rbTrunkActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_rbTrunkActionPerformed
161
refreshComponents();
162     }//GEN-LAST:event_rbTrunkActionPerformed
163

164     private void bBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_bBrowseActionPerformed
165
String JavaDoc tag = browseBranches();
166         if (tag != null) {
167             tfTagName.setText(tag);
168         }
169     }//GEN-LAST:event_bBrowseActionPerformed
170

171     
172     // Variables declaration - do not modify//GEN-BEGIN:variables
173
private javax.swing.JButton JavaDoc bBrowse;
174     private javax.swing.ButtonGroup JavaDoc buttonGroup1;
175     private javax.swing.JRadioButton JavaDoc rbBranch;
176     private javax.swing.JRadioButton JavaDoc rbTrunk;
177     private javax.swing.JTextField JavaDoc tfTagName;
178     // End of variables declaration//GEN-END:variables
179

180 }
181
Popular Tags