KickJava   Java API By Example, From Geeks To Geeks.

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


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.modules.versioning.system.cvss.CvsModuleConfig;
23 import org.netbeans.modules.versioning.system.cvss.ui.selectors.BranchSelector;
24 import org.netbeans.modules.versioning.system.cvss.util.Utils;
25 import org.netbeans.lib.cvsclient.CVSRoot;
26
27 import java.io.File JavaDoc;
28 import java.io.IOException JavaDoc;
29 import org.openide.util.*;
30
31 /**
32  * Settings panel for the Switch To Branch action.
33  *
34  * @author Maros Sandor
35  */

36 class SwitchBranchPanel extends javax.swing.JPanel JavaDoc {
37     
38     private final File JavaDoc[] roots;
39
40     /** Creates new form SwitchBranchPanel */
41     public SwitchBranchPanel(File JavaDoc [] roots) {
42         this.roots = roots;
43         initComponents();
44         rbSwitchToTrunk.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean("SwitchBranchSettings.switchToTrunk", true)); // NOI18N
45
rbSwitchToBranch.setSelected(CvsModuleConfig.getDefault().getPreferences().getBoolean("SwitchBranchSettings.switchToBranch", false)); // NOI18N
46
tfBranchName.setText(CvsModuleConfig.getDefault().getPreferences().get("SwitchBranchSettings.branchName", NbBundle.getMessage(SwitchBranchPanel.class, "BK2001"))); // NOI18N
47
refreshComponents();
48     }
49
50     public void saveSettings() {
51         CvsModuleConfig.getDefault().getPreferences().putBoolean("SwitchBranchSettings.switchToTrunk", rbSwitchToTrunk.isSelected()); // NOI18N
52
CvsModuleConfig.getDefault().getPreferences().putBoolean("SwitchBranchSettings.switchToBranch", rbSwitchToBranch.isSelected()); // NOI18N
53
CvsModuleConfig.getDefault().getPreferences().put("SwitchBranchSettings.branchName", tfBranchName.getText()); // NOI18N
54
}
55
56     private void refreshComponents() {
57         if (rbSwitchToTrunk.isSelected()) {
58             tfBranchName.setEnabled(false);
59             bBrowse.setEnabled(false);
60         } else {
61             tfBranchName.setEnabled(true);
62             bBrowse.setEnabled(true);
63         }
64     }
65     
66     public String JavaDoc getBranchName() {
67         return tfBranchName.getText();
68     }
69
70     public boolean isSwitchToTrunk() {
71         return rbSwitchToTrunk.isSelected();
72     }
73
74     /** This method is called from within the constructor to
75      * initialize the form.
76      * WARNING: Do NOT modify this code. The content of this method is
77      * always regenerated by the Form Editor.
78      */

79     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
80
private void initComponents() {
81         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
82
83         bgSwitchRadio = new javax.swing.ButtonGroup JavaDoc();
84         rbSwitchToTrunk = new javax.swing.JRadioButton JavaDoc();
85         rbSwitchToBranch = new javax.swing.JRadioButton JavaDoc();
86         tfBranchName = new javax.swing.JTextField JavaDoc();
87         bBrowse = new javax.swing.JButton JavaDoc();
88
89         setLayout(new java.awt.GridBagLayout JavaDoc());
90
91         setBorder(javax.swing.BorderFactory.createEmptyBorder(12, 12, 0, 11));
92         bgSwitchRadio.add(rbSwitchToTrunk);
93         org.openide.awt.Mnemonics.setLocalizedText(rbSwitchToTrunk, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle").getString("CTL_SwitchBranchForm_ToTrunk"));
94         rbSwitchToTrunk.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle").getString("TT_SwitchBranchForm_ToTrunk"));
95         rbSwitchToTrunk.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 2, 0));
96         rbSwitchToTrunk.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
97         rbSwitchToTrunk.addActionListener(new java.awt.event.ActionListener JavaDoc() {
98             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
99                 radioSwitch(evt);
100             }
101         });
102
103         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
104         gridBagConstraints.gridx = 0;
105         gridBagConstraints.gridy = 0;
106         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
107         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
108         add(rbSwitchToTrunk, gridBagConstraints);
109
110         bgSwitchRadio.add(rbSwitchToBranch);
111         org.openide.awt.Mnemonics.setLocalizedText(rbSwitchToBranch, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle").getString("CTL_SwitchBranchForm_ToBranch"));
112         rbSwitchToBranch.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle").getString("TT_SwitchBranchForm_ToBranch"));
113         rbSwitchToBranch.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
114         rbSwitchToBranch.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
115         rbSwitchToBranch.addActionListener(new java.awt.event.ActionListener JavaDoc() {
116             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
117                 radioSwitch(evt);
118             }
119         });
120
121         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
122         gridBagConstraints.gridx = 0;
123         gridBagConstraints.gridy = 1;
124         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 6);
125         add(rbSwitchToBranch, gridBagConstraints);
126
127         tfBranchName.setColumns(20);
128         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
129         gridBagConstraints.gridx = 1;
130         gridBagConstraints.gridy = 1;
131         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
132         gridBagConstraints.weightx = 1.0;
133         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 6);
134         add(tfBranchName, gridBagConstraints);
135         tfBranchName.getAccessibleContext().setAccessibleName(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle").getString("ACSN_SwitchBranchForm_BranchName"));
136         tfBranchName.getAccessibleContext().setAccessibleDescription(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle").getString("ACSD_SwitchBranchForm_BranchName"));
137
138         org.openide.awt.Mnemonics.setLocalizedText(bBrowse, java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle").getString("CTL_SwitchBranchForm_BrowseBranch"));
139         bBrowse.setToolTipText(java.util.ResourceBundle.getBundle("org/netbeans/modules/versioning/system/cvss/ui/actions/tag/Bundle").getString("TT_SwitchBranchForm_BrowseBranch"));
140         bBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
141             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
142                 browseBranches(evt);
143             }
144         });
145
146         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
147         gridBagConstraints.gridx = 2;
148         gridBagConstraints.gridy = 1;
149         add(bBrowse, gridBagConstraints);
150
151     }
152     // </editor-fold>//GEN-END:initComponents
153

154     private void browseBranches(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseBranches
155
for (int i = 0; i < roots.length; i++) {
156             try {
157                 CVSRoot.parse(Utils.getCVSRootFor(roots[i])); // raises exception
158
BranchSelector selector = new BranchSelector();
159                 String JavaDoc tag = selector.selectTag(roots[i]);
160                 if (tag != null) {
161                     tfBranchName.setText(tag);
162                 }
163                 return;
164             } catch (IOException JavaDoc e) {
165                 // no root for this file, try next
166
}
167         }
168     }//GEN-LAST:event_browseBranches
169

170     private void radioSwitch(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_radioSwitch
171
refreshComponents();
172     }//GEN-LAST:event_radioSwitch
173

174     
175     // Variables declaration - do not modify//GEN-BEGIN:variables
176
private javax.swing.JButton JavaDoc bBrowse;
177     private javax.swing.ButtonGroup JavaDoc bgSwitchRadio;
178     private javax.swing.JRadioButton JavaDoc rbSwitchToBranch;
179     private javax.swing.JRadioButton JavaDoc rbSwitchToTrunk;
180     private javax.swing.JTextField JavaDoc tfBranchName;
181     // End of variables declaration//GEN-END:variables
182

183 }
184
Popular Tags