1 19 20 package org.netbeans.modules.junit.wizards; 21 22 import java.awt.GridBagConstraints ; 23 import java.awt.GridBagLayout ; 24 import java.awt.Insets ; 25 import java.util.ResourceBundle ; 26 import javax.accessibility.AccessibleContext ; 27 import javax.swing.BorderFactory ; 28 import javax.swing.ComboBoxModel ; 29 import javax.swing.JComboBox ; 30 import javax.swing.JComponent ; 31 import javax.swing.JLabel ; 32 import javax.swing.JPanel ; 33 import javax.swing.UIManager ; 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 47 public class SettingsPanel extends JPanel { 48 49 50 private JLabel lblProjectName; 51 52 private JLabel lblTestFileName; 53 54 private JComboBox cboTemplate; 55 56 66 public SettingsPanel(String projectName, 67 String testFileName, 68 String defaultTemplate, 69 JComponent optionsPanel) { 70 71 72 ResourceBundle bundle = NbBundle.getBundle(SettingsPanel.class); 73 74 JLabel lblProject = new JLabel (); 75 JLabel lblFileName = new JLabel (); 76 JLabel lblTemplate = new JLabel (); 77 78 Mnemonics.setLocalizedText(lblProject, 79 bundle.getString("LBL_Project")); Mnemonics.setLocalizedText(lblFileName, 81 bundle.getString("LBL_Filename")); Mnemonics.setLocalizedText(lblTemplate, 83 bundle.getString("LBL_Template")); 85 lblProjectName = new JLabel (projectName); 86 lblTestFileName = new JLabel (testFileName); 87 cboTemplate = GuiUtils.createTemplateChooser(defaultTemplate); 88 89 lblProject.setLabelFor(lblProjectName); 90 lblFileName.setLabelFor(lblTestFileName); 91 lblTemplate.setLabelFor(cboTemplate); 92 93 AccessibleContext accessCtx; 94 accessCtx = lblProjectName.getAccessibleContext(); 95 accessCtx.setAccessibleName( 96 bundle.getString("AD_Name_Project_name")); accessCtx.setAccessibleDescription( 98 bundle.getString("AD_Descr_Project_name")); 100 accessCtx = lblTestFileName.getAccessibleContext(); 101 accessCtx.setAccessibleName( 102 bundle.getString("AD_Name_Test_class_file_name")); accessCtx.setAccessibleDescription( 104 bundle.getString("AD_Descr_Test_class_file_name")); 106 accessCtx = cboTemplate.getAccessibleContext(); 107 accessCtx.setAccessibleName( 108 bundle.getString("AD_Name_Test_class_template")); accessCtx.setAccessibleDescription( 110 bundle.getString("AD_Descr_Test_class_template")); 112 bundle = null; 113 114 115 setLayout(new GridBagLayout ()); 116 117 GridBagConstraints gbc = new GridBagConstraints (); 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 (0, 0, 6, 12); 125 add(lblProject, gbc); 126 127 gbc.gridwidth = GridBagConstraints.REMAINDER; 128 gbc.weightx = 1.0f; 129 gbc.insets = new Insets (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 (0, 0, 0, 12); 137 add(lblFileName, gbc); 138 139 gbc.gridwidth = GridBagConstraints.REMAINDER; 140 gbc.weightx = 1.0f; 141 gbc.insets = new Insets (0, 0, 0, 0); 142 add(lblTestFileName, gbc); 143 144 gbc.gridy++; 145 146 gbc.fill = GridBagConstraints.HORIZONTAL; 147 gbc.insets = new Insets (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 (0, 0, 11, 12); 156 add(lblTemplate, gbc); 157 158 gbc.gridwidth = GridBagConstraints.REMAINDER; 159 gbc.weightx = 1.0f; 160 gbc.insets = new Insets (0, 0, 11, 0); 161 add(cboTemplate, gbc); 162 163 gbc.gridy++; 164 165 gbc.insets = new Insets (0, 0, 0, 0); 166 add(optionsPanel, gbc); 167 168 169 170 gbc.gridy++; 171 172 gbc.weighty = 1.0f; 173 add(new JPanel (), gbc); 174 } 175 176 178 void setProjectName(String projectName) { 179 lblProjectName.setText(projectName); 180 } 181 182 184 void setTestFileName(String testFileName) { 185 lblTestFileName.setText(testFileName); 186 } 187 188 195 FileObject getTemplate() { 196 Object selectedObject = cboTemplate.getSelectedItem(); 197 if (selectedObject == null) { 198 return null; 199 } 200 return (FileObject) ((NamedObject) selectedObject).object; 201 } 202 203 209 void selectTemplate(String templatePath) { 210 if (templatePath == null) { 211 return; 212 } 213 214 ComboBoxModel 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 236 private JComponent createSeparator() { 237 JPanel panel = new SizeRestrictedPanel(false, true); 238 panel.setPreferredSize(new java.awt.Dimension (1, 1)); 239 panel.setBorder(BorderFactory.createMatteBorder( 240 1, 0, 0, 0, 241 UIManager.getDefaults().getColor("Label.foreground"))); return panel; 243 } 244 245 } 246 | Popular Tags |