KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > junit > wizards > SettingsPanel


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

19
20 package org.netbeans.modules.junit.wizards;
21
22 import java.awt.GridBagConstraints JavaDoc;
23 import java.awt.GridBagLayout JavaDoc;
24 import java.awt.Insets JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26 import javax.accessibility.AccessibleContext JavaDoc;
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.ComboBoxModel JavaDoc;
29 import javax.swing.JComboBox JavaDoc;
30 import javax.swing.JComponent JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.UIManager JavaDoc;
34 import org.netbeans.modules.junit.GuiUtils;
35 import org.netbeans.modules.junit.NamedObject;
36 import org.netbeans.modules.junit.SizeRestrictedPanel;
37 import org.openide.awt.Mnemonics;
38 import org.openide.filesystems.FileObject;
39 import org.openide.util.NbBundle;
40
41 /**
42  * Panel which serves as a visual component for step "Settings"
43  * of the wizards.
44  *
45  * @author Marian Petras
46  */

47 public class SettingsPanel extends JPanel JavaDoc {
48     
49     /** label displaying the project name */
50     private JLabel JavaDoc lblProjectName;
51     /** label displaying the (target) folder name */
52     private JLabel JavaDoc lblTestFileName;
53     /** combo-box for choice of template */
54     private JComboBox JavaDoc cboTemplate;
55     
56     /**
57      * Creates a new instance of <code>SettingsPanel</code>.
58      *
59      * @param projectName project name to be displayed in the panel
60      * @param folderName folder name to be displayed in the panel
61      * @param defaultTemplate resource path of the default template
62      * @param optionsPanel panel containing checkboxes and other GUI
63      * elements, to be displayed in the lower part
64      * of the panel
65      */

66     public SettingsPanel(String JavaDoc projectName,
67                          String JavaDoc testFileName,
68                          String JavaDoc defaultTemplate,
69                          JComponent JavaDoc optionsPanel) {
70         
71         /* Create the components: */
72         ResourceBundle JavaDoc bundle = NbBundle.getBundle(SettingsPanel.class);
73         
74         JLabel JavaDoc lblProject = new JLabel JavaDoc();
75         JLabel JavaDoc lblFileName = new JLabel JavaDoc();
76         JLabel JavaDoc lblTemplate = new JLabel JavaDoc();
77         
78         Mnemonics.setLocalizedText(lblProject,
79                                    bundle.getString("LBL_Project")); //NOI18N
80
Mnemonics.setLocalizedText(lblFileName,
81                                    bundle.getString("LBL_Filename")); //NOI18N
82
Mnemonics.setLocalizedText(lblTemplate,
83                                    bundle.getString("LBL_Template")); //NOI18N
84

85         lblProjectName = new JLabel JavaDoc(projectName);
86         lblTestFileName = new JLabel JavaDoc(testFileName);
87         cboTemplate = GuiUtils.createTemplateChooser(defaultTemplate);
88         
89         lblProject.setLabelFor(lblProjectName);
90         lblFileName.setLabelFor(lblTestFileName);
91         lblTemplate.setLabelFor(cboTemplate);
92         
93         AccessibleContext JavaDoc accessCtx;
94         accessCtx = lblProjectName.getAccessibleContext();
95         accessCtx.setAccessibleName(
96                 bundle.getString("AD_Name_Project_name")); //NOI18N
97
accessCtx.setAccessibleDescription(
98                 bundle.getString("AD_Descr_Project_name")); //NOI18N
99

100         accessCtx = lblTestFileName.getAccessibleContext();
101         accessCtx.setAccessibleName(
102                 bundle.getString("AD_Name_Test_class_file_name")); //NOI18N
103
accessCtx.setAccessibleDescription(
104                 bundle.getString("AD_Descr_Test_class_file_name")); //NOI18N
105

106         accessCtx = cboTemplate.getAccessibleContext();
107         accessCtx.setAccessibleName(
108                 bundle.getString("AD_Name_Test_class_template")); //NOI18N
109
accessCtx.setAccessibleDescription(
110                 bundle.getString("AD_Descr_Test_class_template")); //NOI18N
111

112         bundle = null;
113         
114         /* set layout of the components: */
115         setLayout(new GridBagLayout JavaDoc());
116         
117         GridBagConstraints JavaDoc gbc = new GridBagConstraints JavaDoc();
118         gbc.anchor = GridBagConstraints.WEST;
119         
120         gbc.gridy = 0;
121         
122         gbc.gridwidth = 1;
123         gbc.weightx = 0.0f;
124         gbc.insets = new Insets JavaDoc(0, 0, 6, 12);
125         add(lblProject, gbc);
126         
127         gbc.gridwidth = GridBagConstraints.REMAINDER;
128         gbc.weightx = 1.0f;
129         gbc.insets = new Insets JavaDoc(0, 0, 6, 0);
130         add(lblProjectName, gbc);
131         
132         gbc.gridy++;
133         
134         gbc.gridwidth = 1;
135         gbc.weightx = 0.0f;
136         gbc.insets = new Insets JavaDoc(0, 0, 0, 12);
137         add(lblFileName, gbc);
138         
139         gbc.gridwidth = GridBagConstraints.REMAINDER;
140         gbc.weightx = 1.0f;
141         gbc.insets = new Insets JavaDoc(0, 0, 0, 0);
142         add(lblTestFileName, gbc);
143         
144         gbc.gridy++;
145         
146         gbc.fill = GridBagConstraints.HORIZONTAL;
147         gbc.insets = new Insets JavaDoc(12, 0, 18, 0);
148         add(createSeparator(), gbc);
149         gbc.fill = GridBagConstraints.NONE;
150         
151         gbc.gridy++;
152         
153         gbc.gridwidth = 1;
154         gbc.weightx = 0.0f;
155         gbc.insets = new Insets JavaDoc(0, 0, 11, 12);
156         add(lblTemplate, gbc);
157         
158         gbc.gridwidth = GridBagConstraints.REMAINDER;
159         gbc.weightx = 1.0f;
160         gbc.insets = new Insets JavaDoc(0, 0, 11, 0);
161         add(cboTemplate, gbc);
162         
163         gbc.gridy++;
164         
165         gbc.insets = new Insets JavaDoc(0, 0, 0, 0);
166         add(optionsPanel, gbc);
167         
168         /* Create a vertical filler at the bottom part of this panel: */
169         
170         gbc.gridy++;
171         
172         gbc.weighty = 1.0f;
173         add(new JPanel JavaDoc(), gbc);
174     }
175     
176     /**
177      */

178     void setProjectName(String JavaDoc projectName) {
179         lblProjectName.setText(projectName);
180     }
181     
182     /**
183      */

184     void setTestFileName(String JavaDoc testFileName) {
185         lblTestFileName.setText(testFileName);
186     }
187     
188     /**
189      * Returns a chosen template.
190      *
191      * @return <code>FileObject</code> representing the template chosen
192      * in the combo-box; or <code>null</code> if no template is chosen
193      * (because of the combo-box being empty)
194      */

195     FileObject getTemplate() {
196         Object JavaDoc selectedObject = cboTemplate.getSelectedItem();
197         if (selectedObject == null) {
198             return null;
199         }
200         return (FileObject) ((NamedObject) selectedObject).object;
201     }
202     
203     /**
204      * Selects a given template.
205      *
206      * @param templatePath path of the template which should be selected;
207      * may be <code>null</code> - then no item is selected
208      */

209     void selectTemplate(String JavaDoc templatePath) {
210         if (templatePath == null) {
211             return;
212         }
213         
214         ComboBoxModel JavaDoc model = cboTemplate.getModel();
215         int itemsCount = model.getSize();
216         
217         if (itemsCount == 0) {
218             return;
219         }
220         
221         for (int i = 0; i < itemsCount; i++) {
222             NamedObject namedObj = (NamedObject) model.getElementAt(i);
223             FileObject template = (FileObject) namedObj.object;
224             if (template.getPath().equals(templatePath)) {
225                 cboTemplate.setSelectedIndex(i);
226                 return;
227             }
228         }
229     }
230     
231     /**
232      * Creates a separator - horizontal line.
233      *
234      * @return created separator
235      */

236     private JComponent JavaDoc createSeparator() {
237         JPanel JavaDoc panel = new SizeRestrictedPanel(false, true);
238         panel.setPreferredSize(new java.awt.Dimension JavaDoc(1, 1));
239         panel.setBorder(BorderFactory.createMatteBorder(
240                 1, 0, 0, 0,
241                 UIManager.getDefaults().getColor("Label.foreground"))); //NOI18N
242
return panel;
243     }
244     
245 }
246
Popular Tags