1 19 20 25 26 package org.netbeans.modules.css.actions; 27 28 import org.netbeans.modules.css.visual.model.HtmlTags; 29 import java.awt.event.ActionEvent ; 30 import java.awt.event.ActionListener ; 31 import java.util.ArrayList ; 32 import javax.swing.DefaultComboBoxModel ; 33 import javax.swing.DefaultListModel ; 34 import javax.swing.JButton ; 35 import javax.swing.JDialog ; 36 import javax.swing.SwingUtilities ; 37 import org.openide.DialogDescriptor; 38 import org.openide.DialogDisplayer; 39 import org.openide.util.HelpCtx; 40 import org.openide.util.NbBundle; 41 42 47 public class CssRuleCreateActionDialog extends javax.swing.JPanel { 48 49 private JDialog dialog; 50 private DialogDescriptor dlg = null; 51 52 private String okString = NbBundle.getMessage(CssRuleCreateActionDialog.class, "OK"); 53 private String cancelString = NbBundle.getMessage(CssRuleCreateActionDialog.class, "CANCEL"); 54 55 57 private JButton okButton = new JButton (okString); 58 private JButton cancelButton = new JButton (cancelString); 59 60 private static final String ELEMENT_TYPE = "elelment"; private static final String CLASS_TYPE = "class"; private static final String ELEMENT_ID_TYPE = "element_id"; 64 private static final String NONE = "<None>"; 66 DefaultListModel selectedRules = new DefaultListModel (); 67 68 private String styleRuleName = ""; 69 70 71 public CssRuleCreateActionDialog() { 72 initComponents(); 73 String [] htmlTags = HtmlTags.getTags(); 74 75 DefaultComboBoxModel htmlTagsModel1 = new DefaultComboBoxModel (); 77 htmlTagsModel1.addElement(NONE); 78 htmlTagsModel1.addElement("a:link"); 79 htmlTagsModel1.addElement("a:visited"); 80 htmlTagsModel1.addElement("a:hover"); 81 htmlTagsModel1.addElement("a:active"); 82 for( int i=0; i< htmlTags.length; i++){ 83 htmlTagsModel1.addElement(htmlTags[i]); 84 } 85 86 DefaultComboBoxModel htmlTagsModel = new DefaultComboBoxModel (); 87 for( int i=0; i< htmlTags.length; i++){ 89 htmlTagsModel.addElement(htmlTags[i]); 90 } 91 selectElementComboBox.setModel(htmlTagsModel); 92 classPrefixComboBox.setModel(htmlTagsModel1); 93 ruleHierarchyList.setModel(selectedRules); 94 removeRuleButton.setEnabled(false); 95 } 96 97 public void showDialog(){ 98 ActionListener listener = new ActionListener () { 100 public void actionPerformed(ActionEvent evt) { 101 Object o = evt.getSource(); 102 Object [] option = dlg.getOptions(); 103 104 if (o == option[0]) { 105 styleRuleName = previewTextField.getText().trim(); 106 if(styleRuleName.equals("")){ 110 String selectionType = selectRuleButtonGroup.getSelection().getActionCommand(); 111 styleRuleName = getRule(selectionType); 112 } 113 dialog.setVisible(false); 114 } 115 } 116 }; 117 dlg = new DialogDescriptor(this, NbBundle.getMessage(CssRuleCreateActionDialog.class, "STYLE_RULE_EDITOR_TITLE"), true, listener); 118 dlg.setOptions(new Object [] { okButton, cancelButton }); 119 dlg.setClosingOptions(new Object [] {cancelButton}); 120 dlg.setHelpCtx(new HelpCtx("projrave_ui_elements_css_create_style_rule")); 122 dialog = (JDialog ) DialogDisplayer.getDefault().createDialog(dlg); 123 dialog.setResizable(false); 124 dialog.pack(); 125 dialog.setVisible(true); 126 } 127 128 public String getStyleRuleName(){ 129 return styleRuleName; 130 } 131 132 137 private void initComponents() { 139 java.awt.GridBagConstraints gridBagConstraints; 140 141 selectRuleButtonGroup = new javax.swing.ButtonGroup (); 142 previewPanel = new javax.swing.JPanel (); 143 previewLable = new javax.swing.JLabel (); 144 previewTextField = new javax.swing.JTextField (); 145 rulePanel = new javax.swing.JPanel (); 146 addRemoveRulePanel = new javax.swing.JPanel (); 147 addRuleButton = new javax.swing.JButton (); 148 removeRuleButton = new javax.swing.JButton (); 149 selectRulePanel = new javax.swing.JPanel (); 150 selectElementRadioButton = new javax.swing.JRadioButton (); 151 selectElementComboBox = new javax.swing.JComboBox (); 152 selectClassRadioButton = new javax.swing.JRadioButton (); 153 selectClassTextField = new javax.swing.JTextField (); 154 selectElelmentIdRadioButton = new javax.swing.JRadioButton (); 155 selectElementIdTextField = new javax.swing.JTextField (); 156 classPrefixComboBox = new javax.swing.JComboBox (); 157 classPrefixSeparator = new javax.swing.JLabel (); 158 ruleHierarchyPanel = new javax.swing.JPanel (); 159 moveRulePanel = new javax.swing.JPanel (); 160 moveRuleUpButton = new javax.swing.JButton (); 161 moveRuleDownButton = new javax.swing.JButton (); 162 hierarchyContainer = new javax.swing.JPanel (); 163 ruleHierarchyScroll = new javax.swing.JScrollPane (); 164 ruleHierarchyList = new javax.swing.JList (); 165 166 setLayout(new java.awt.BorderLayout ()); 167 168 previewPanel.setLayout(new java.awt.BorderLayout (5, 5)); 169 170 previewPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 8, 5, 8)); 171 previewLable.setLabelFor(previewTextField); 172 previewLable.setText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "RULE_PREVIEW_LABEL")); 173 previewPanel.add(previewLable, java.awt.BorderLayout.WEST); 174 175 previewTextField.setEditable(false); 176 previewPanel.add(previewTextField, java.awt.BorderLayout.CENTER); 177 previewTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "PREVIEW_LABEL_ACCESSIBLE_DESC")); 178 179 add(previewPanel, java.awt.BorderLayout.SOUTH); 180 181 rulePanel.setLayout(new java.awt.BorderLayout (3, 3)); 182 183 rulePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); 184 addRemoveRulePanel.setLayout(new java.awt.GridBagLayout ()); 185 186 addRemoveRulePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 5)); 187 addRuleButton.setMnemonic(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ADD_RULE_BUTTON_MNEMONIC").charAt(0)); 188 addRuleButton.setText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ADD_RULE_LBL")); 189 addRuleButton.setToolTipText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ADD_RULE_TOOL_TIP")); 190 addRuleButton.addActionListener(new java.awt.event.ActionListener () { 191 public void actionPerformed(java.awt.event.ActionEvent evt) { 192 addRuleButtonActionPerformed(evt); 193 } 194 }); 195 196 gridBagConstraints = new java.awt.GridBagConstraints (); 197 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 198 addRemoveRulePanel.add(addRuleButton, gridBagConstraints); 199 200 removeRuleButton.setMnemonic(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "REMOVE_RULE_BUTTON_MNEMONIC").charAt(0)); 201 removeRuleButton.setText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "REMOVE_RULE_LBL")); 202 removeRuleButton.setToolTipText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "REMOVE_RULE_TOOL_TIP")); 203 removeRuleButton.addActionListener(new java.awt.event.ActionListener () { 204 public void actionPerformed(java.awt.event.ActionEvent evt) { 205 removeRuleButtonActionPerformed(evt); 206 } 207 }); 208 209 gridBagConstraints = new java.awt.GridBagConstraints (); 210 gridBagConstraints.gridx = 0; 211 gridBagConstraints.gridy = 1; 212 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 213 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 214 addRemoveRulePanel.add(removeRuleButton, gridBagConstraints); 215 216 rulePanel.add(addRemoveRulePanel, java.awt.BorderLayout.CENTER); 217 218 selectRulePanel.setLayout(new java.awt.GridBagLayout ()); 219 220 selectRulePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "RULE_TYPE_PANEL_TITLE"))); 221 selectRuleButtonGroup.add(selectElementRadioButton); 222 selectElementRadioButton.setMnemonic(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ELEMENT_RULE_TYPE_MNEMONIC").charAt(0)); 223 selectElementRadioButton.setText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "HTML_ELELEMT")); 224 selectElementRadioButton.setActionCommand(ELEMENT_TYPE); 225 selectElementRadioButton.addActionListener(new java.awt.event.ActionListener () { 226 public void actionPerformed(java.awt.event.ActionEvent evt) { 227 selectRuleActionPerformed(evt); 228 } 229 }); 230 231 gridBagConstraints = new java.awt.GridBagConstraints (); 232 gridBagConstraints.gridx = 0; 233 gridBagConstraints.gridy = 2; 234 gridBagConstraints.gridwidth = 3; 235 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 236 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 237 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 5); 238 selectRulePanel.add(selectElementRadioButton, gridBagConstraints); 239 selectElementRadioButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "HTML_ELEMENT_RULE_TYPE_ACCESSIBLE_DESCRIPTION")); 240 241 selectElementComboBox.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "a", "abbr" })); 242 selectElementComboBox.setEnabled(false); 243 gridBagConstraints = new java.awt.GridBagConstraints (); 244 gridBagConstraints.gridx = 0; 245 gridBagConstraints.gridy = 3; 246 gridBagConstraints.gridwidth = 3; 247 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 248 gridBagConstraints.insets = new java.awt.Insets (0, 20, 5, 5); 249 selectRulePanel.add(selectElementComboBox, gridBagConstraints); 250 selectElementComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "HTML_ELEMENT_ACCESSIBLE_NAME")); 251 selectElementComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "HTML_ELEMENT_ACCESSIBLE_DESC")); 252 253 selectRuleButtonGroup.add(selectClassRadioButton); 254 selectClassRadioButton.setMnemonic(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "CLASS_RULE_TYPE_MNEMONIC").charAt(0)); 255 selectClassRadioButton.setSelected(true); 256 selectClassRadioButton.setText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "CLASS_NAME_LBL")); 257 selectClassRadioButton.setActionCommand(CLASS_TYPE); 258 selectClassRadioButton.addActionListener(new java.awt.event.ActionListener () { 259 public void actionPerformed(java.awt.event.ActionEvent evt) { 260 selectRuleActionPerformed(evt); 261 } 262 }); 263 264 gridBagConstraints = new java.awt.GridBagConstraints (); 265 gridBagConstraints.gridx = 0; 266 gridBagConstraints.gridy = 0; 267 gridBagConstraints.gridwidth = 3; 268 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 269 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 270 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 5); 271 selectRulePanel.add(selectClassRadioButton, gridBagConstraints); 272 selectClassRadioButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "CLASS_RULE_TYPE_ACCESSIBLE_DESCRIPTION")); 273 274 selectClassTextField.setColumns(15); 275 selectClassTextField.addKeyListener(new java.awt.event.KeyAdapter () { 276 public void keyTyped(java.awt.event.KeyEvent evt) { 277 selectClassTextFieldKeyTyped(evt); 278 } 279 }); 280 281 gridBagConstraints = new java.awt.GridBagConstraints (); 282 gridBagConstraints.gridx = 2; 283 gridBagConstraints.gridy = 1; 284 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 285 gridBagConstraints.insets = new java.awt.Insets (0, 2, 5, 5); 286 selectRulePanel.add(selectClassTextField, gridBagConstraints); 287 selectClassTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "CLASS_TEXT_FIELD_ACCESSIBLE_NAME")); 288 selectClassTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "CLASS_TEXT_FIELD_ACCESSIBLE_DESC")); 289 290 selectRuleButtonGroup.add(selectElelmentIdRadioButton); 291 selectElelmentIdRadioButton.setMnemonic(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ELEMENT_ID_RULE_TYPE_MNEMONIC").charAt(0)); 292 selectElelmentIdRadioButton.setText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ELEMENT_ID_LBL")); 293 selectElelmentIdRadioButton.setActionCommand(ELEMENT_ID_TYPE); 294 selectElelmentIdRadioButton.addActionListener(new java.awt.event.ActionListener () { 295 public void actionPerformed(java.awt.event.ActionEvent evt) { 296 selectRuleActionPerformed(evt); 297 } 298 }); 299 300 gridBagConstraints = new java.awt.GridBagConstraints (); 301 gridBagConstraints.gridx = 0; 302 gridBagConstraints.gridy = 4; 303 gridBagConstraints.gridwidth = 3; 304 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 305 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 306 gridBagConstraints.insets = new java.awt.Insets (0, 0, 2, 5); 307 selectRulePanel.add(selectElelmentIdRadioButton, gridBagConstraints); 308 selectElelmentIdRadioButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ELEMENT_ID_RULE_TYPE_ACCESSIBLE_DESCRIPTION")); 309 310 selectElementIdTextField.setEnabled(false); 311 gridBagConstraints = new java.awt.GridBagConstraints (); 312 gridBagConstraints.gridx = 0; 313 gridBagConstraints.gridy = 5; 314 gridBagConstraints.gridwidth = 3; 315 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 316 gridBagConstraints.insets = new java.awt.Insets (0, 20, 5, 5); 317 selectRulePanel.add(selectElementIdTextField, gridBagConstraints); 318 selectElementIdTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ELEMENT_ID_TEXTFIELD_ACCESSIBLE_NAME")); 319 selectElementIdTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "ELEMENT_ID_TEXTFIELD_ACCESSIBLE_DESC")); 320 321 classPrefixComboBox.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "abbr" })); 322 classPrefixComboBox.setToolTipText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "OPTIONAL_ELEMENT_TOOLTIP")); 323 classPrefixComboBox.setEnabled(false); 324 gridBagConstraints = new java.awt.GridBagConstraints (); 325 gridBagConstraints.gridx = 0; 326 gridBagConstraints.gridy = 1; 327 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 328 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 329 gridBagConstraints.insets = new java.awt.Insets (0, 20, 5, 2); 330 selectRulePanel.add(classPrefixComboBox, gridBagConstraints); 331 classPrefixComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "OPTIONAL_ELEMENT_ACCESSIBLE_DESC")); 332 333 classPrefixSeparator.setFont(new java.awt.Font ("Dialog", 1, 18)); 334 classPrefixSeparator.setText("."); 335 gridBagConstraints = new java.awt.GridBagConstraints (); 336 gridBagConstraints.gridx = 1; 337 gridBagConstraints.gridy = 1; 338 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 339 selectRulePanel.add(classPrefixSeparator, gridBagConstraints); 340 341 rulePanel.add(selectRulePanel, java.awt.BorderLayout.WEST); 342 343 ruleHierarchyPanel.setLayout(new java.awt.BorderLayout (2, 2)); 344 345 ruleHierarchyPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "RULE_HIERARCHY_TITLE"))); 346 moveRulePanel.setLayout(new java.awt.GridBagLayout ()); 347 348 moveRulePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 5)); 349 moveRuleUpButton.setMnemonic(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "UP_RULE_BUTTON_MNEMONIC").charAt(0)); 350 moveRuleUpButton.setText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "MOVE_RULE_UP_LBL")); 351 moveRuleUpButton.setToolTipText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "UP_RULE_BUTTON_TOOLTIP")); 352 moveRuleUpButton.addActionListener(new java.awt.event.ActionListener () { 353 public void actionPerformed(java.awt.event.ActionEvent evt) { 354 moveRuleUpActionPerformed(evt); 355 } 356 }); 357 358 gridBagConstraints = new java.awt.GridBagConstraints (); 359 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 360 moveRulePanel.add(moveRuleUpButton, gridBagConstraints); 361 362 moveRuleDownButton.setMnemonic(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "DOWN_RULE_BUTTON_MNEMONIC").charAt(0)); 363 moveRuleDownButton.setText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "MOVE_RULE_DOWN_LBL")); 364 moveRuleDownButton.setToolTipText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "DOWN_RULE_BUTTON_TOOLTIP")); 365 moveRuleDownButton.addActionListener(new java.awt.event.ActionListener () { 366 public void actionPerformed(java.awt.event.ActionEvent evt) { 367 moveRuleDownActionPerformed(evt); 368 } 369 }); 370 371 gridBagConstraints = new java.awt.GridBagConstraints (); 372 gridBagConstraints.gridx = 0; 373 gridBagConstraints.gridy = 1; 374 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 375 gridBagConstraints.insets = new java.awt.Insets (5, 0, 0, 0); 376 moveRulePanel.add(moveRuleDownButton, gridBagConstraints); 377 378 ruleHierarchyPanel.add(moveRulePanel, java.awt.BorderLayout.EAST); 379 380 hierarchyContainer.setLayout(new java.awt.BorderLayout ()); 381 382 hierarchyContainer.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5)); 383 ruleHierarchyScroll.setPreferredSize(new java.awt.Dimension (150, 200)); 384 ruleHierarchyScroll.setViewportView(ruleHierarchyList); 385 ruleHierarchyList.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "STYLE_RULE_LIST_ACCESSIBLE_NAME")); 386 ruleHierarchyList.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "STYLE_RULE_LIST_ACCESSIBLE_DESC")); 387 388 hierarchyContainer.add(ruleHierarchyScroll, java.awt.BorderLayout.CENTER); 389 390 ruleHierarchyPanel.add(hierarchyContainer, java.awt.BorderLayout.CENTER); 391 392 rulePanel.add(ruleHierarchyPanel, java.awt.BorderLayout.EAST); 393 394 add(rulePanel, java.awt.BorderLayout.CENTER); 395 396 } 398 private void selectClassTextFieldKeyTyped(java.awt.event.KeyEvent evt) { SwingUtilities.invokeLater(new Runnable (){ 400 public void run(){ 401 if (!selectClassTextField.getText().equals("")){ 402 classPrefixComboBox.setEnabled(true); 403 }else{ 404 classPrefixComboBox.setEnabled(false); 405 } 406 } 407 }); 408 } 410 private void moveRuleDownActionPerformed(java.awt.event.ActionEvent evt) { int index = ruleHierarchyList.getSelectedIndex(); 412 if(index < selectedRules.getSize()){ 413 Object currentObject = selectedRules.get(index); 414 Object prevObject = selectedRules.get(index+1); 415 selectedRules.setElementAt(currentObject, index+1); 416 selectedRules.setElementAt(prevObject, index); 417 ruleHierarchyList.setSelectedIndex(index+1); 418 resetRuleHierarchy(); 419 } 420 } 422 private void moveRuleUpActionPerformed(java.awt.event.ActionEvent evt) { int index = ruleHierarchyList.getSelectedIndex(); 424 if(index > 0){ 425 Object currentObject = selectedRules.get(index); 426 Object prevObject = selectedRules.get(index-1); 427 selectedRules.setElementAt(currentObject, index-1); 428 selectedRules.setElementAt(prevObject, index); 429 ruleHierarchyList.setSelectedIndex(index-1); 430 resetRuleHierarchy(); 431 } 432 } 434 private void removeRuleButtonActionPerformed(java.awt.event.ActionEvent evt) { Object [] selections = ruleHierarchyList.getSelectedValues(); 436 for(int i=0; i< selections.length ;i++){ 437 if (selectedRules.contains(selections[i])){ 438 selectedRules.removeElement(selections[i]); 439 } 440 } 441 if(!selectedRules.isEmpty()) { 442 ruleHierarchyList.setSelectedIndex(0); 443 }else{ 444 removeRuleButton.setEnabled(false); 445 } 446 resetRuleHierarchy(); 447 } 449 private void selectRuleActionPerformed(java.awt.event.ActionEvent evt) { String ruleType = evt.getActionCommand(); 451 if(ruleType.equals(ELEMENT_TYPE)){ 452 selectElementComboBox.setEnabled(true); 453 classPrefixComboBox.setEnabled(false); 454 selectClassTextField.setEnabled(false); 455 selectElementIdTextField.setEnabled(false); 456 }else if(ruleType.equals(CLASS_TYPE)){ 457 selectElementComboBox.setEnabled(false); 458 classPrefixComboBox.setEnabled(true); 459 selectClassTextField.setEnabled(true); 460 selectElementIdTextField.setEnabled(false); 461 }else if(ruleType.equals(ELEMENT_ID_TYPE)){ 462 selectElementComboBox.setEnabled(false); 463 classPrefixComboBox.setEnabled(false); 464 selectClassTextField.setEnabled(false); 465 selectElementIdTextField.setEnabled(true); 466 } 467 resetRuleHierarchy(); 468 } 470 private void addRuleButtonActionPerformed(java.awt.event.ActionEvent evt) { String ruleType = selectRuleButtonGroup.getSelection().getActionCommand(); 472 String rule = null; 473 if(ruleType.equals(ELEMENT_TYPE)){ 474 rule = (String ) selectElementComboBox.getSelectedItem(); 475 if(rule.equals(NONE)) rule = null; 476 }else if(ruleType.equals(CLASS_TYPE)){ 477 if(!selectClassTextField.getText().trim().equals("")){ 478 String rulePrefix = (String ) classPrefixComboBox.getSelectedItem(); 479 rule = "." + selectClassTextField.getText().trim(); 480 if(!rulePrefix.equals(NONE)){ 481 rule = rulePrefix + rule; 482 } 483 } 484 }else if(ruleType.equals(ELEMENT_ID_TYPE)){ 485 if(!selectElementIdTextField.getText().trim().equals("")){ 486 rule = "#" + selectElementIdTextField.getText().trim();; 487 } 488 } 489 if((rule != null) && (!selectedRules.contains(rule))){ 490 selectedRules.addElement(rule); 491 ruleHierarchyList.setSelectedValue(rule,true); 492 removeRuleButton.setEnabled(true); 493 } 494 resetRuleHierarchy(); 495 } 497 private String getRule(String ruleType){ 498 String rule = null; 499 if(ruleType.equals(ELEMENT_TYPE)){ 500 rule = (String ) selectElementComboBox.getSelectedItem(); 501 if(rule.equals(NONE)) rule = null; 502 }else if(ruleType.equals(CLASS_TYPE)){ 503 if(!selectClassTextField.getText().trim().equals("")){ 504 String rulePrefix = (String ) classPrefixComboBox.getSelectedItem(); 505 rule = "." + selectClassTextField.getText().trim(); 506 if(!rulePrefix.equals(NONE)){ 507 rule = rulePrefix + rule; 508 } 509 } 510 }else if(ruleType.equals(ELEMENT_ID_TYPE)){ 511 if(!selectElementIdTextField.getText().trim().equals("")){ 512 rule = "#" + selectElementIdTextField.getText().trim();; 513 } 514 } 515 return rule; 516 } 517 518 private void resetRuleHierarchy(){ 519 StringBuffer ruleSetBuf = new StringBuffer (); 520 for(int i = 0; i < selectedRules.size(); i++){ 521 String ruleName = ((String ) selectedRules.get(i)).trim(); 522 ruleSetBuf.append(ruleName); 523 if(i < selectedRules.size()-1 )ruleSetBuf.append(" "); 524 } 525 previewTextField.setText(ruleSetBuf.toString()); 526 } 527 528 private javax.swing.JPanel addRemoveRulePanel; 530 private javax.swing.JButton addRuleButton; 531 private javax.swing.JComboBox classPrefixComboBox; 532 private javax.swing.JLabel classPrefixSeparator; 533 private javax.swing.JPanel hierarchyContainer; 534 private javax.swing.JButton moveRuleDownButton; 535 private javax.swing.JPanel moveRulePanel; 536 private javax.swing.JButton moveRuleUpButton; 537 private javax.swing.JLabel previewLable; 538 private javax.swing.JPanel previewPanel; 539 private javax.swing.JTextField previewTextField; 540 private javax.swing.JButton removeRuleButton; 541 private javax.swing.JList ruleHierarchyList; 542 private javax.swing.JPanel ruleHierarchyPanel; 543 private javax.swing.JScrollPane ruleHierarchyScroll; 544 private javax.swing.JPanel rulePanel; 545 private javax.swing.JRadioButton selectClassRadioButton; 546 private javax.swing.JTextField selectClassTextField; 547 private javax.swing.JRadioButton selectElelmentIdRadioButton; 548 private javax.swing.JComboBox selectElementComboBox; 549 private javax.swing.JTextField selectElementIdTextField; 550 private javax.swing.JRadioButton selectElementRadioButton; 551 private javax.swing.ButtonGroup selectRuleButtonGroup; 552 private javax.swing.JPanel selectRulePanel; 553 } 555 | Popular Tags |