KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > actions > CssRuleCreateActionDialog


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
20 /*
21  * CssRuleCreateActionDialog.java
22  *
23  * Created on February 3, 2005, 9:16 AM
24  */

25
26 package org.netbeans.modules.css.actions;
27
28 import org.netbeans.modules.css.visual.model.HtmlTags;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31 import java.util.ArrayList JavaDoc;
32 import javax.swing.DefaultComboBoxModel JavaDoc;
33 import javax.swing.DefaultListModel JavaDoc;
34 import javax.swing.JButton JavaDoc;
35 import javax.swing.JDialog JavaDoc;
36 import javax.swing.SwingUtilities JavaDoc;
37 import org.openide.DialogDescriptor;
38 import org.openide.DialogDisplayer;
39 import org.openide.util.HelpCtx;
40 import org.openide.util.NbBundle;
41
42 /**
43  * Dialog for creating the Style Rule
44  * @author Winston Prakash
45  * @version 1.0
46  */

47 public class CssRuleCreateActionDialog extends javax.swing.JPanel JavaDoc {
48
49     private JDialog JavaDoc dialog;
50     private DialogDescriptor dlg = null;
51
52     private String JavaDoc okString = NbBundle.getMessage(CssRuleCreateActionDialog.class, "OK");
53     private String JavaDoc cancelString = NbBundle.getMessage(CssRuleCreateActionDialog.class, "CANCEL");
54
55 // DesignerService designerService = DesignerService.getDefault();
56

57     private JButton JavaDoc okButton = new JButton JavaDoc(okString);
58     private JButton JavaDoc cancelButton = new JButton JavaDoc(cancelString);
59
60     private static final String JavaDoc ELEMENT_TYPE = "elelment"; //NOI18N
61
private static final String JavaDoc CLASS_TYPE = "class"; //NOI18N
62
private static final String JavaDoc ELEMENT_ID_TYPE = "element_id"; //NOI18N
63

64     private static final String JavaDoc NONE = "<None>"; //NOI18N
65

66     DefaultListModel JavaDoc selectedRules = new DefaultListModel JavaDoc();
67
68     private String JavaDoc styleRuleName = "";
69
70     /** Creates new form CssRuleCreateActionDialog */
71     public CssRuleCreateActionDialog() {
72         initComponents();
73         String JavaDoc[] htmlTags = HtmlTags.getTags();
74
75         // Optional prefix
76
DefaultComboBoxModel JavaDoc htmlTagsModel1 = new DefaultComboBoxModel JavaDoc();
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 JavaDoc htmlTagsModel = new DefaultComboBoxModel JavaDoc();
87         //htmlTagsModel.addElement(NONE);
88
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         // Add a listener to the dialog's buttons
99
ActionListener JavaDoc listener = new ActionListener JavaDoc() {
100             public void actionPerformed(ActionEvent JavaDoc evt) {
101                 Object JavaDoc o = evt.getSource();
102                 Object JavaDoc[] option = dlg.getOptions();
103
104                 if (o == option[0]) {
105                     styleRuleName = previewTextField.getText().trim();
106                     // As Jeff pointed out even if user has not added
107
// any value to the right hand side the values selected
108
// in the left hand side should be used
109
if(styleRuleName.equals("")){
110                         String JavaDoc 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 JavaDoc[] { okButton, cancelButton });
119         dlg.setClosingOptions(new Object JavaDoc[] {cancelButton});
120         dlg.setHelpCtx(new HelpCtx("projrave_ui_elements_css_create_style_rule")); // NOI18N
121

122         dialog = (JDialog JavaDoc) DialogDisplayer.getDefault().createDialog(dlg);
123         dialog.setResizable(false);
124         dialog.pack();
125         dialog.setVisible(true);
126     }
127     
128     public String JavaDoc getStyleRuleName(){
129         return styleRuleName;
130     }
131     
132     /** This method is called from within the constructor to
133      * initialize the form.
134      * WARNING: Do NOT modify this code. The content of this method is
135      * always regenerated by the Form Editor.
136      */

137     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
138
private void initComponents() {
139         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
140
141         selectRuleButtonGroup = new javax.swing.ButtonGroup JavaDoc();
142         previewPanel = new javax.swing.JPanel JavaDoc();
143         previewLable = new javax.swing.JLabel JavaDoc();
144         previewTextField = new javax.swing.JTextField JavaDoc();
145         rulePanel = new javax.swing.JPanel JavaDoc();
146         addRemoveRulePanel = new javax.swing.JPanel JavaDoc();
147         addRuleButton = new javax.swing.JButton JavaDoc();
148         removeRuleButton = new javax.swing.JButton JavaDoc();
149         selectRulePanel = new javax.swing.JPanel JavaDoc();
150         selectElementRadioButton = new javax.swing.JRadioButton JavaDoc();
151         selectElementComboBox = new javax.swing.JComboBox JavaDoc();
152         selectClassRadioButton = new javax.swing.JRadioButton JavaDoc();
153         selectClassTextField = new javax.swing.JTextField JavaDoc();
154         selectElelmentIdRadioButton = new javax.swing.JRadioButton JavaDoc();
155         selectElementIdTextField = new javax.swing.JTextField JavaDoc();
156         classPrefixComboBox = new javax.swing.JComboBox JavaDoc();
157         classPrefixSeparator = new javax.swing.JLabel JavaDoc();
158         ruleHierarchyPanel = new javax.swing.JPanel JavaDoc();
159         moveRulePanel = new javax.swing.JPanel JavaDoc();
160         moveRuleUpButton = new javax.swing.JButton JavaDoc();
161         moveRuleDownButton = new javax.swing.JButton JavaDoc();
162         hierarchyContainer = new javax.swing.JPanel JavaDoc();
163         ruleHierarchyScroll = new javax.swing.JScrollPane JavaDoc();
164         ruleHierarchyList = new javax.swing.JList JavaDoc();
165
166         setLayout(new java.awt.BorderLayout JavaDoc());
167
168         previewPanel.setLayout(new java.awt.BorderLayout JavaDoc(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 JavaDoc(3, 3));
182
183         rulePanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
184         addRemoveRulePanel.setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc() {
191             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
192                 addRuleButtonActionPerformed(evt);
193             }
194         });
195
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc() {
204             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
205                 removeRuleButtonActionPerformed(evt);
206             }
207         });
208
209         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
210         gridBagConstraints.gridx = 0;
211         gridBagConstraints.gridy = 1;
212         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
213         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc());
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 JavaDoc() {
226             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
227                 selectRuleActionPerformed(evt);
228             }
229         });
230
231         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc(new String JavaDoc[] { "a", "abbr" }));
242         selectElementComboBox.setEnabled(false);
243         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc() {
259             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
260                 selectRuleActionPerformed(evt);
261             }
262         });
263
264         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc() {
276             public void keyTyped(java.awt.event.KeyEvent JavaDoc evt) {
277                 selectClassTextFieldKeyTyped(evt);
278             }
279         });
280
281         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
282         gridBagConstraints.gridx = 2;
283         gridBagConstraints.gridy = 1;
284         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
285         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc() {
295             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
296                 selectRuleActionPerformed(evt);
297             }
298         });
299
300         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
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 JavaDoc(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 JavaDoc(new String JavaDoc[] { "abbr" }));
322         classPrefixComboBox.setToolTipText(org.openide.util.NbBundle.getMessage(CssRuleCreateActionDialog.class, "OPTIONAL_ELEMENT_TOOLTIP"));
323         classPrefixComboBox.setEnabled(false);
324         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc("Dialog", 1, 18));
334         classPrefixSeparator.setText(".");
335         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc());
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 JavaDoc() {
353             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
354                 moveRuleUpActionPerformed(evt);
355             }
356         });
357
358         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc() {
366             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
367                 moveRuleDownActionPerformed(evt);
368             }
369         });
370
371         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
372         gridBagConstraints.gridx = 0;
373         gridBagConstraints.gridy = 1;
374         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
375         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc());
381
382         hierarchyContainer.setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
383         ruleHierarchyScroll.setPreferredSize(new java.awt.Dimension JavaDoc(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     }// </editor-fold>//GEN-END:initComponents
397

398     private void selectClassTextFieldKeyTyped(java.awt.event.KeyEvent JavaDoc evt) {//GEN-FIRST:event_selectClassTextFieldKeyTyped
399
SwingUtilities.invokeLater(new Runnable JavaDoc(){
400             public void run(){
401                 if (!selectClassTextField.getText().equals("")){
402                     classPrefixComboBox.setEnabled(true);
403                 }else{
404                     classPrefixComboBox.setEnabled(false);
405                 }
406             }
407         });
408     }//GEN-LAST:event_selectClassTextFieldKeyTyped
409

410     private void moveRuleDownActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_moveRuleDownActionPerformed
411
int index = ruleHierarchyList.getSelectedIndex();
412         if(index < selectedRules.getSize()){
413             Object JavaDoc currentObject = selectedRules.get(index);
414             Object JavaDoc 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     }//GEN-LAST:event_moveRuleDownActionPerformed
421

422     private void moveRuleUpActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_moveRuleUpActionPerformed
423
int index = ruleHierarchyList.getSelectedIndex();
424         if(index > 0){
425             Object JavaDoc currentObject = selectedRules.get(index);
426             Object JavaDoc 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     }//GEN-LAST:event_moveRuleUpActionPerformed
433

434     private void removeRuleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removeRuleButtonActionPerformed
435
Object JavaDoc[] 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     }//GEN-LAST:event_removeRuleButtonActionPerformed
448

449     private void selectRuleActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_selectRuleActionPerformed
450
String JavaDoc 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     }//GEN-LAST:event_selectRuleActionPerformed
469

470     private void addRuleButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addRuleButtonActionPerformed
471
String JavaDoc ruleType = selectRuleButtonGroup.getSelection().getActionCommand();
472         String JavaDoc rule = null;
473         if(ruleType.equals(ELEMENT_TYPE)){
474             rule = (String JavaDoc) selectElementComboBox.getSelectedItem();
475             if(rule.equals(NONE)) rule = null;
476         }else if(ruleType.equals(CLASS_TYPE)){
477             if(!selectClassTextField.getText().trim().equals("")){
478                 String JavaDoc rulePrefix = (String JavaDoc) 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     }//GEN-LAST:event_addRuleButtonActionPerformed
496

497     private String JavaDoc getRule(String JavaDoc ruleType){
498         String JavaDoc rule = null;
499         if(ruleType.equals(ELEMENT_TYPE)){
500             rule = (String JavaDoc) selectElementComboBox.getSelectedItem();
501             if(rule.equals(NONE)) rule = null;
502         }else if(ruleType.equals(CLASS_TYPE)){
503             if(!selectClassTextField.getText().trim().equals("")){
504                 String JavaDoc rulePrefix = (String JavaDoc) 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 JavaDoc ruleSetBuf = new StringBuffer JavaDoc();
520         for(int i = 0; i < selectedRules.size(); i++){
521             String JavaDoc ruleName = ((String JavaDoc) 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     // Variables declaration - do not modify//GEN-BEGIN:variables
529
private javax.swing.JPanel JavaDoc addRemoveRulePanel;
530     private javax.swing.JButton JavaDoc addRuleButton;
531     private javax.swing.JComboBox JavaDoc classPrefixComboBox;
532     private javax.swing.JLabel JavaDoc classPrefixSeparator;
533     private javax.swing.JPanel JavaDoc hierarchyContainer;
534     private javax.swing.JButton JavaDoc moveRuleDownButton;
535     private javax.swing.JPanel JavaDoc moveRulePanel;
536     private javax.swing.JButton JavaDoc moveRuleUpButton;
537     private javax.swing.JLabel JavaDoc previewLable;
538     private javax.swing.JPanel JavaDoc previewPanel;
539     private javax.swing.JTextField JavaDoc previewTextField;
540     private javax.swing.JButton JavaDoc removeRuleButton;
541     private javax.swing.JList JavaDoc ruleHierarchyList;
542     private javax.swing.JPanel JavaDoc ruleHierarchyPanel;
543     private javax.swing.JScrollPane JavaDoc ruleHierarchyScroll;
544     private javax.swing.JPanel JavaDoc rulePanel;
545     private javax.swing.JRadioButton JavaDoc selectClassRadioButton;
546     private javax.swing.JTextField JavaDoc selectClassTextField;
547     private javax.swing.JRadioButton JavaDoc selectElelmentIdRadioButton;
548     private javax.swing.JComboBox JavaDoc selectElementComboBox;
549     private javax.swing.JTextField JavaDoc selectElementIdTextField;
550     private javax.swing.JRadioButton JavaDoc selectElementRadioButton;
551     private javax.swing.ButtonGroup JavaDoc selectRuleButtonGroup;
552     private javax.swing.JPanel JavaDoc selectRulePanel;
553     // End of variables declaration//GEN-END:variables
554
}
555
Popular Tags