001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: /*
043: * CssRuleCreateActionDialog.java
044: *
045: * Created on February 3, 2005, 9:16 AM
046: */
047:
048: package org.netbeans.modules.css.actions;
049:
050: import org.netbeans.modules.css.visual.model.HtmlTags;
051: import java.awt.event.ActionEvent;
052: import java.awt.event.ActionListener;
053: import javax.swing.DefaultComboBoxModel;
054: import javax.swing.DefaultListModel;
055: import javax.swing.JDialog;
056: import javax.swing.SwingUtilities;
057: import org.openide.DialogDescriptor;
058: import org.openide.DialogDisplayer;
059: import org.openide.util.HelpCtx;
060: import org.openide.util.NbBundle;
061:
062: /**
063: * Dialog for creating the Style Rule
064: * @author Winston Prakash
065: * @version 1.0
066: */
067: public class CssRuleCreateActionDialog extends javax.swing.JPanel {
068:
069: private JDialog dialog;
070: private DialogDescriptor dlg = null;
071:
072: private static final String ELEMENT_TYPE = "elelment"; //NOI18N
073: private static final String CLASS_TYPE = "class"; //NOI18N
074: private static final String ELEMENT_ID_TYPE = "element_id"; //NOI18N
075:
076: private static final String NONE = "<None>"; //NOI18N
077:
078: DefaultListModel selectedRules = new DefaultListModel();
079:
080: private String styleRuleName = "";
081:
082: /** Creates new form CssRuleCreateActionDialog */
083: public CssRuleCreateActionDialog() {
084: initComponents();
085: String[] htmlTags = HtmlTags.getTags();
086:
087: // Optional prefix
088: DefaultComboBoxModel htmlTagsModel1 = new DefaultComboBoxModel();
089: htmlTagsModel1.addElement(NONE);
090: htmlTagsModel1.addElement("a:link");
091: htmlTagsModel1.addElement("a:visited");
092: htmlTagsModel1.addElement("a:hover");
093: htmlTagsModel1.addElement("a:active");
094: for (int i = 0; i < htmlTags.length; i++) {
095: htmlTagsModel1.addElement(htmlTags[i]);
096: }
097:
098: DefaultComboBoxModel htmlTagsModel = new DefaultComboBoxModel();
099: //htmlTagsModel.addElement(NONE);
100: for (int i = 0; i < htmlTags.length; i++) {
101: htmlTagsModel.addElement(htmlTags[i]);
102: }
103: selectElementComboBox.setModel(htmlTagsModel);
104: classPrefixComboBox.setModel(htmlTagsModel1);
105: ruleHierarchyList.setModel(selectedRules);
106: removeRuleButton.setEnabled(false);
107: }
108:
109: public void showDialog() {
110: // Add a listener to the dialog's buttons
111: ActionListener listener = new ActionListener() {
112: public void actionPerformed(ActionEvent evt) {
113: if (evt.getSource() == DialogDescriptor.OK_OPTION) {
114: styleRuleName = previewTextField.getText().trim();
115: // As Jeff pointed out even if user has not added
116: // any value to the right hand side the values selected
117: // in the left hand side should be used
118: if (styleRuleName.equals("")) {
119: String selectionType = selectRuleButtonGroup
120: .getSelection().getActionCommand();
121: styleRuleName = getRule(selectionType);
122: }
123: dialog.setVisible(false);
124: }
125: }
126: };
127: dlg = new DialogDescriptor(this , NbBundle.getMessage(
128: CssRuleCreateActionDialog.class,
129: "STYLE_RULE_EDITOR_TITLE"), true, listener);
130: dlg.setHelpCtx(new HelpCtx(
131: "projrave_ui_elements_css_create_style_rule")); // NOI18N
132:
133: dialog = (JDialog) DialogDisplayer.getDefault().createDialog(
134: dlg);
135: dialog.setResizable(false);
136: dialog.pack();
137: dialog.setVisible(true);
138: }
139:
140: public String getStyleRuleName() {
141: return styleRuleName;
142: }
143:
144: /** This method is called from within the constructor to
145: * initialize the form.
146: * WARNING: Do NOT modify this code. The content of this method is
147: * always regenerated by the Form Editor.
148: */
149: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
150: private void initComponents() {
151: java.awt.GridBagConstraints gridBagConstraints;
152:
153: selectRuleButtonGroup = new javax.swing.ButtonGroup();
154: previewPanel = new javax.swing.JPanel();
155: previewLable = new javax.swing.JLabel();
156: previewTextField = new javax.swing.JTextField();
157: rulePanel = new javax.swing.JPanel();
158: addRemoveRulePanel = new javax.swing.JPanel();
159: addRuleButton = new javax.swing.JButton();
160: removeRuleButton = new javax.swing.JButton();
161: selectRulePanel = new javax.swing.JPanel();
162: selectElementRadioButton = new javax.swing.JRadioButton();
163: selectElementComboBox = new javax.swing.JComboBox();
164: selectClassRadioButton = new javax.swing.JRadioButton();
165: selectClassTextField = new javax.swing.JTextField();
166: selectElelmentIdRadioButton = new javax.swing.JRadioButton();
167: selectElementIdTextField = new javax.swing.JTextField();
168: classPrefixComboBox = new javax.swing.JComboBox();
169: classPrefixSeparator = new javax.swing.JLabel();
170: ruleHierarchyPanel = new javax.swing.JPanel();
171: moveRulePanel = new javax.swing.JPanel();
172: moveRuleUpButton = new javax.swing.JButton();
173: moveRuleDownButton = new javax.swing.JButton();
174: hierarchyContainer = new javax.swing.JPanel();
175: ruleHierarchyScroll = new javax.swing.JScrollPane();
176: ruleHierarchyList = new javax.swing.JList();
177:
178: setLayout(new java.awt.BorderLayout());
179:
180: previewPanel.setBorder(javax.swing.BorderFactory
181: .createEmptyBorder(5, 8, 5, 8));
182: previewPanel.setLayout(new java.awt.BorderLayout(5, 5));
183:
184: previewLable.setLabelFor(previewTextField);
185: org.openide.awt.Mnemonics.setLocalizedText(previewLable,
186: org.openide.util.NbBundle.getMessage(
187: CssRuleCreateActionDialog.class,
188: "RULE_PREVIEW_LABEL")); // NOI18N
189: previewPanel.add(previewLable, java.awt.BorderLayout.WEST);
190:
191: previewTextField.setEditable(false);
192: previewPanel
193: .add(previewTextField, java.awt.BorderLayout.CENTER);
194: previewTextField.getAccessibleContext()
195: .setAccessibleDescription(
196: org.openide.util.NbBundle.getMessage(
197: CssRuleCreateActionDialog.class,
198: "PREVIEW_LABEL_ACCESSIBLE_DESC")); // NOI18N
199:
200: add(previewPanel, java.awt.BorderLayout.SOUTH);
201:
202: rulePanel.setBorder(javax.swing.BorderFactory
203: .createEmptyBorder(5, 5, 5, 5));
204: rulePanel.setLayout(new java.awt.BorderLayout(3, 3));
205:
206: addRemoveRulePanel.setBorder(javax.swing.BorderFactory
207: .createEmptyBorder(0, 5, 0, 5));
208: addRemoveRulePanel.setLayout(new java.awt.GridBagLayout());
209:
210: addRuleButton.setMnemonic(org.openide.util.NbBundle.getMessage(
211: CssRuleCreateActionDialog.class,
212: "ADD_RULE_BUTTON_MNEMONIC").charAt(0));
213: addRuleButton.setText(org.openide.util.NbBundle.getMessage(
214: CssRuleCreateActionDialog.class, "ADD_RULE_LBL")); // NOI18N
215: addRuleButton.setToolTipText(org.openide.util.NbBundle
216: .getMessage(CssRuleCreateActionDialog.class,
217: "ADD_RULE_TOOL_TIP")); // NOI18N
218: addRuleButton
219: .addActionListener(new java.awt.event.ActionListener() {
220: public void actionPerformed(
221: java.awt.event.ActionEvent evt) {
222: addRuleButtonActionPerformed(evt);
223: }
224: });
225: gridBagConstraints = new java.awt.GridBagConstraints();
226: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
227: addRemoveRulePanel.add(addRuleButton, gridBagConstraints);
228:
229: removeRuleButton.setMnemonic(org.openide.util.NbBundle
230: .getMessage(CssRuleCreateActionDialog.class,
231: "REMOVE_RULE_BUTTON_MNEMONIC").charAt(0));
232: removeRuleButton.setText(org.openide.util.NbBundle.getMessage(
233: CssRuleCreateActionDialog.class, "REMOVE_RULE_LBL")); // NOI18N
234: removeRuleButton.setToolTipText(org.openide.util.NbBundle
235: .getMessage(CssRuleCreateActionDialog.class,
236: "REMOVE_RULE_TOOL_TIP")); // NOI18N
237: removeRuleButton
238: .addActionListener(new java.awt.event.ActionListener() {
239: public void actionPerformed(
240: java.awt.event.ActionEvent evt) {
241: removeRuleButtonActionPerformed(evt);
242: }
243: });
244: gridBagConstraints = new java.awt.GridBagConstraints();
245: gridBagConstraints.gridx = 0;
246: gridBagConstraints.gridy = 1;
247: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
248: gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
249: addRemoveRulePanel.add(removeRuleButton, gridBagConstraints);
250:
251: rulePanel.add(addRemoveRulePanel, java.awt.BorderLayout.CENTER);
252:
253: selectRulePanel.setBorder(javax.swing.BorderFactory
254: .createTitledBorder(org.openide.util.NbBundle
255: .getMessage(CssRuleCreateActionDialog.class,
256: "RULE_TYPE_PANEL_TITLE"))); // NOI18N
257: selectRulePanel.setLayout(new java.awt.GridBagLayout());
258:
259: selectRuleButtonGroup.add(selectElementRadioButton);
260: selectElementRadioButton.setMnemonic(org.openide.util.NbBundle
261: .getMessage(CssRuleCreateActionDialog.class,
262: "ELEMENT_RULE_TYPE_MNEMONIC").charAt(0));
263: selectElementRadioButton.setText(org.openide.util.NbBundle
264: .getMessage(CssRuleCreateActionDialog.class,
265: "HTML_ELELEMT")); // NOI18N
266: selectElementRadioButton.setActionCommand(ELEMENT_TYPE);
267: selectElementRadioButton
268: .addActionListener(new java.awt.event.ActionListener() {
269: public void actionPerformed(
270: java.awt.event.ActionEvent evt) {
271: selectRuleActionPerformed(evt);
272: }
273: });
274: gridBagConstraints = new java.awt.GridBagConstraints();
275: gridBagConstraints.gridx = 0;
276: gridBagConstraints.gridy = 2;
277: gridBagConstraints.gridwidth = 3;
278: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
279: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
280: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 5);
281: selectRulePanel.add(selectElementRadioButton,
282: gridBagConstraints);
283: selectElementRadioButton
284: .getAccessibleContext()
285: .setAccessibleDescription(
286: org.openide.util.NbBundle
287: .getMessage(
288: CssRuleCreateActionDialog.class,
289: "HTML_ELEMENT_RULE_TYPE_ACCESSIBLE_DESCRIPTION")); // NOI18N
290:
291: selectElementComboBox
292: .setModel(new javax.swing.DefaultComboBoxModel(
293: new String[] { "a", "abbr" }));
294: selectElementComboBox.setEnabled(false);
295: gridBagConstraints = new java.awt.GridBagConstraints();
296: gridBagConstraints.gridx = 0;
297: gridBagConstraints.gridy = 3;
298: gridBagConstraints.gridwidth = 3;
299: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
300: gridBagConstraints.insets = new java.awt.Insets(0, 20, 5, 5);
301: selectRulePanel.add(selectElementComboBox, gridBagConstraints);
302: selectElementComboBox.getAccessibleContext().setAccessibleName(
303: org.openide.util.NbBundle.getMessage(
304: CssRuleCreateActionDialog.class,
305: "HTML_ELEMENT_ACCESSIBLE_NAME")); // NOI18N
306: selectElementComboBox.getAccessibleContext()
307: .setAccessibleDescription(
308: org.openide.util.NbBundle.getMessage(
309: CssRuleCreateActionDialog.class,
310: "HTML_ELEMENT_ACCESSIBLE_DESC")); // NOI18N
311:
312: selectRuleButtonGroup.add(selectClassRadioButton);
313: selectClassRadioButton.setMnemonic(org.openide.util.NbBundle
314: .getMessage(CssRuleCreateActionDialog.class,
315: "CLASS_RULE_TYPE_MNEMONIC").charAt(0));
316: selectClassRadioButton.setSelected(true);
317: selectClassRadioButton.setText(org.openide.util.NbBundle
318: .getMessage(CssRuleCreateActionDialog.class,
319: "CLASS_NAME_LBL")); // NOI18N
320: selectClassRadioButton.setActionCommand(CLASS_TYPE);
321: selectClassRadioButton
322: .addActionListener(new java.awt.event.ActionListener() {
323: public void actionPerformed(
324: java.awt.event.ActionEvent evt) {
325: selectRuleActionPerformed(evt);
326: }
327: });
328: gridBagConstraints = new java.awt.GridBagConstraints();
329: gridBagConstraints.gridx = 0;
330: gridBagConstraints.gridy = 0;
331: gridBagConstraints.gridwidth = 3;
332: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
333: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
334: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 5);
335: selectRulePanel.add(selectClassRadioButton, gridBagConstraints);
336: selectClassRadioButton
337: .getAccessibleContext()
338: .setAccessibleDescription(
339: org.openide.util.NbBundle
340: .getMessage(
341: CssRuleCreateActionDialog.class,
342: "CLASS_RULE_TYPE_ACCESSIBLE_DESCRIPTION")); // NOI18N
343:
344: selectClassTextField.setColumns(15);
345: selectClassTextField
346: .addKeyListener(new java.awt.event.KeyAdapter() {
347: public void keyTyped(java.awt.event.KeyEvent evt) {
348: selectClassTextFieldKeyTyped(evt);
349: }
350: });
351: gridBagConstraints = new java.awt.GridBagConstraints();
352: gridBagConstraints.gridx = 2;
353: gridBagConstraints.gridy = 1;
354: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
355: gridBagConstraints.insets = new java.awt.Insets(0, 2, 5, 5);
356: selectRulePanel.add(selectClassTextField, gridBagConstraints);
357: selectClassTextField.getAccessibleContext().setAccessibleName(
358: org.openide.util.NbBundle.getMessage(
359: CssRuleCreateActionDialog.class,
360: "CLASS_TEXT_FIELD_ACCESSIBLE_NAME")); // NOI18N
361: selectClassTextField.getAccessibleContext()
362: .setAccessibleDescription(
363: org.openide.util.NbBundle.getMessage(
364: CssRuleCreateActionDialog.class,
365: "CLASS_TEXT_FIELD_ACCESSIBLE_DESC")); // NOI18N
366:
367: selectRuleButtonGroup.add(selectElelmentIdRadioButton);
368: selectElelmentIdRadioButton
369: .setMnemonic(org.openide.util.NbBundle.getMessage(
370: CssRuleCreateActionDialog.class,
371: "ELEMENT_ID_RULE_TYPE_MNEMONIC").charAt(0));
372: selectElelmentIdRadioButton.setText(org.openide.util.NbBundle
373: .getMessage(CssRuleCreateActionDialog.class,
374: "ELEMENT_ID_LBL")); // NOI18N
375: selectElelmentIdRadioButton.setActionCommand(ELEMENT_ID_TYPE);
376: selectElelmentIdRadioButton
377: .addActionListener(new java.awt.event.ActionListener() {
378: public void actionPerformed(
379: java.awt.event.ActionEvent evt) {
380: selectRuleActionPerformed(evt);
381: }
382: });
383: gridBagConstraints = new java.awt.GridBagConstraints();
384: gridBagConstraints.gridx = 0;
385: gridBagConstraints.gridy = 4;
386: gridBagConstraints.gridwidth = 3;
387: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
388: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
389: gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 5);
390: selectRulePanel.add(selectElelmentIdRadioButton,
391: gridBagConstraints);
392: selectElelmentIdRadioButton
393: .getAccessibleContext()
394: .setAccessibleDescription(
395: org.openide.util.NbBundle
396: .getMessage(
397: CssRuleCreateActionDialog.class,
398: "ELEMENT_ID_RULE_TYPE_ACCESSIBLE_DESCRIPTION")); // NOI18N
399:
400: selectElementIdTextField.setEnabled(false);
401: gridBagConstraints = new java.awt.GridBagConstraints();
402: gridBagConstraints.gridx = 0;
403: gridBagConstraints.gridy = 5;
404: gridBagConstraints.gridwidth = 3;
405: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
406: gridBagConstraints.insets = new java.awt.Insets(0, 20, 5, 5);
407: selectRulePanel.add(selectElementIdTextField,
408: gridBagConstraints);
409: selectElementIdTextField
410: .getAccessibleContext()
411: .setAccessibleName(
412: org.openide.util.NbBundle.getMessage(
413: CssRuleCreateActionDialog.class,
414: "ELEMENT_ID_TEXTFIELD_ACCESSIBLE_NAME")); // NOI18N
415: selectElementIdTextField
416: .getAccessibleContext()
417: .setAccessibleDescription(
418: org.openide.util.NbBundle.getMessage(
419: CssRuleCreateActionDialog.class,
420: "ELEMENT_ID_TEXTFIELD_ACCESSIBLE_DESC")); // NOI18N
421:
422: classPrefixComboBox
423: .setModel(new javax.swing.DefaultComboBoxModel(
424: new String[] { "abbr" }));
425: classPrefixComboBox.setToolTipText(org.openide.util.NbBundle
426: .getMessage(CssRuleCreateActionDialog.class,
427: "OPTIONAL_ELEMENT_TOOLTIP")); // NOI18N
428: classPrefixComboBox.setEnabled(false);
429: gridBagConstraints = new java.awt.GridBagConstraints();
430: gridBagConstraints.gridx = 0;
431: gridBagConstraints.gridy = 1;
432: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
433: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
434: gridBagConstraints.insets = new java.awt.Insets(0, 20, 5, 2);
435: selectRulePanel.add(classPrefixComboBox, gridBagConstraints);
436: classPrefixComboBox.getAccessibleContext()
437: .setAccessibleDescription(
438: org.openide.util.NbBundle.getMessage(
439: CssRuleCreateActionDialog.class,
440: "OPTIONAL_ELEMENT_ACCESSIBLE_DESC")); // NOI18N
441:
442: classPrefixSeparator
443: .setFont(new java.awt.Font("Dialog", 1, 18));
444: classPrefixSeparator.setText(".");
445: gridBagConstraints = new java.awt.GridBagConstraints();
446: gridBagConstraints.gridx = 1;
447: gridBagConstraints.gridy = 1;
448: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
449: selectRulePanel.add(classPrefixSeparator, gridBagConstraints);
450:
451: rulePanel.add(selectRulePanel, java.awt.BorderLayout.WEST);
452:
453: ruleHierarchyPanel.setBorder(javax.swing.BorderFactory
454: .createTitledBorder(org.openide.util.NbBundle
455: .getMessage(CssRuleCreateActionDialog.class,
456: "RULE_HIERARCHY_TITLE"))); // NOI18N
457: ruleHierarchyPanel.setLayout(new java.awt.BorderLayout(2, 2));
458:
459: moveRulePanel.setBorder(javax.swing.BorderFactory
460: .createEmptyBorder(1, 1, 1, 5));
461: moveRulePanel.setLayout(new java.awt.GridBagLayout());
462:
463: moveRuleUpButton.setMnemonic(org.openide.util.NbBundle
464: .getMessage(CssRuleCreateActionDialog.class,
465: "UP_RULE_BUTTON_MNEMONIC").charAt(0));
466: moveRuleUpButton.setText(org.openide.util.NbBundle.getMessage(
467: CssRuleCreateActionDialog.class, "MOVE_RULE_UP_LBL")); // NOI18N
468: moveRuleUpButton.setToolTipText(org.openide.util.NbBundle
469: .getMessage(CssRuleCreateActionDialog.class,
470: "UP_RULE_BUTTON_TOOLTIP")); // NOI18N
471: moveRuleUpButton
472: .addActionListener(new java.awt.event.ActionListener() {
473: public void actionPerformed(
474: java.awt.event.ActionEvent evt) {
475: moveRuleUpActionPerformed(evt);
476: }
477: });
478: gridBagConstraints = new java.awt.GridBagConstraints();
479: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
480: moveRulePanel.add(moveRuleUpButton, gridBagConstraints);
481:
482: moveRuleDownButton.setMnemonic(org.openide.util.NbBundle
483: .getMessage(CssRuleCreateActionDialog.class,
484: "DOWN_RULE_BUTTON_MNEMONIC").charAt(0));
485: moveRuleDownButton.setText(org.openide.util.NbBundle
486: .getMessage(CssRuleCreateActionDialog.class,
487: "MOVE_RULE_DOWN_LBL")); // NOI18N
488: moveRuleDownButton.setToolTipText(org.openide.util.NbBundle
489: .getMessage(CssRuleCreateActionDialog.class,
490: "DOWN_RULE_BUTTON_TOOLTIP")); // NOI18N
491: moveRuleDownButton
492: .addActionListener(new java.awt.event.ActionListener() {
493: public void actionPerformed(
494: java.awt.event.ActionEvent evt) {
495: moveRuleDownActionPerformed(evt);
496: }
497: });
498: gridBagConstraints = new java.awt.GridBagConstraints();
499: gridBagConstraints.gridx = 0;
500: gridBagConstraints.gridy = 1;
501: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
502: gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
503: moveRulePanel.add(moveRuleDownButton, gridBagConstraints);
504:
505: ruleHierarchyPanel.add(moveRulePanel,
506: java.awt.BorderLayout.EAST);
507:
508: hierarchyContainer.setBorder(javax.swing.BorderFactory
509: .createEmptyBorder(5, 5, 5, 5));
510: hierarchyContainer.setLayout(new java.awt.BorderLayout());
511:
512: ruleHierarchyScroll.setPreferredSize(new java.awt.Dimension(
513: 150, 200));
514: ruleHierarchyScroll.setViewportView(ruleHierarchyList);
515: ruleHierarchyList.getAccessibleContext().setAccessibleName(
516: org.openide.util.NbBundle.getMessage(
517: CssRuleCreateActionDialog.class,
518: "STYLE_RULE_LIST_ACCESSIBLE_NAME")); // NOI18N
519: ruleHierarchyList.getAccessibleContext()
520: .setAccessibleDescription(
521: org.openide.util.NbBundle.getMessage(
522: CssRuleCreateActionDialog.class,
523: "STYLE_RULE_LIST_ACCESSIBLE_DESC")); // NOI18N
524:
525: hierarchyContainer.add(ruleHierarchyScroll,
526: java.awt.BorderLayout.CENTER);
527:
528: ruleHierarchyPanel.add(hierarchyContainer,
529: java.awt.BorderLayout.CENTER);
530:
531: rulePanel.add(ruleHierarchyPanel, java.awt.BorderLayout.EAST);
532:
533: add(rulePanel, java.awt.BorderLayout.CENTER);
534: }// </editor-fold>//GEN-END:initComponents
535:
536: private void selectClassTextFieldKeyTyped(
537: java.awt.event.KeyEvent evt) {//GEN-FIRST:event_selectClassTextFieldKeyTyped
538: SwingUtilities.invokeLater(new Runnable() {
539: public void run() {
540: if (!selectClassTextField.getText().equals("")) {
541: classPrefixComboBox.setEnabled(true);
542: } else {
543: classPrefixComboBox.setEnabled(false);
544: }
545: }
546: });
547: }//GEN-LAST:event_selectClassTextFieldKeyTyped
548:
549: private void moveRuleDownActionPerformed(
550: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveRuleDownActionPerformed
551: int index = ruleHierarchyList.getSelectedIndex();
552: if (index < selectedRules.getSize()) {
553: Object currentObject = selectedRules.get(index);
554: Object prevObject = selectedRules.get(index + 1);
555: selectedRules.setElementAt(currentObject, index + 1);
556: selectedRules.setElementAt(prevObject, index);
557: ruleHierarchyList.setSelectedIndex(index + 1);
558: resetRuleHierarchy();
559: }
560: }//GEN-LAST:event_moveRuleDownActionPerformed
561:
562: private void moveRuleUpActionPerformed(
563: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveRuleUpActionPerformed
564: int index = ruleHierarchyList.getSelectedIndex();
565: if (index > 0) {
566: Object currentObject = selectedRules.get(index);
567: Object prevObject = selectedRules.get(index - 1);
568: selectedRules.setElementAt(currentObject, index - 1);
569: selectedRules.setElementAt(prevObject, index);
570: ruleHierarchyList.setSelectedIndex(index - 1);
571: resetRuleHierarchy();
572: }
573: }//GEN-LAST:event_moveRuleUpActionPerformed
574:
575: private void removeRuleButtonActionPerformed(
576: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeRuleButtonActionPerformed
577: Object[] selections = ruleHierarchyList.getSelectedValues();
578: for (int i = 0; i < selections.length; i++) {
579: if (selectedRules.contains(selections[i])) {
580: selectedRules.removeElement(selections[i]);
581: }
582: }
583: if (!selectedRules.isEmpty()) {
584: ruleHierarchyList.setSelectedIndex(0);
585: } else {
586: removeRuleButton.setEnabled(false);
587: }
588: resetRuleHierarchy();
589: }//GEN-LAST:event_removeRuleButtonActionPerformed
590:
591: private void selectRuleActionPerformed(
592: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectRuleActionPerformed
593: String ruleType = evt.getActionCommand();
594: if (ruleType.equals(ELEMENT_TYPE)) {
595: selectElementComboBox.setEnabled(true);
596: classPrefixComboBox.setEnabled(false);
597: selectClassTextField.setEnabled(false);
598: selectElementIdTextField.setEnabled(false);
599: } else if (ruleType.equals(CLASS_TYPE)) {
600: selectElementComboBox.setEnabled(false);
601: classPrefixComboBox.setEnabled(true);
602: selectClassTextField.setEnabled(true);
603: selectElementIdTextField.setEnabled(false);
604: } else if (ruleType.equals(ELEMENT_ID_TYPE)) {
605: selectElementComboBox.setEnabled(false);
606: classPrefixComboBox.setEnabled(false);
607: selectClassTextField.setEnabled(false);
608: selectElementIdTextField.setEnabled(true);
609: }
610: resetRuleHierarchy();
611: }//GEN-LAST:event_selectRuleActionPerformed
612:
613: private void addRuleButtonActionPerformed(
614: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addRuleButtonActionPerformed
615: String ruleType = selectRuleButtonGroup.getSelection()
616: .getActionCommand();
617: String rule = null;
618: if (ruleType.equals(ELEMENT_TYPE)) {
619: rule = (String) selectElementComboBox.getSelectedItem();
620: if (rule.equals(NONE))
621: rule = null;
622: } else if (ruleType.equals(CLASS_TYPE)) {
623: if (!selectClassTextField.getText().trim().equals("")) {
624: String rulePrefix = (String) classPrefixComboBox
625: .getSelectedItem();
626: rule = "." + selectClassTextField.getText().trim();
627: if (!rulePrefix.equals(NONE)) {
628: rule = rulePrefix + rule;
629: }
630: }
631: } else if (ruleType.equals(ELEMENT_ID_TYPE)) {
632: if (!selectElementIdTextField.getText().trim().equals("")) {
633: rule = "#" + selectElementIdTextField.getText().trim();
634: ;
635: }
636: }
637: if ((rule != null) && (!selectedRules.contains(rule))) {
638: selectedRules.addElement(rule);
639: ruleHierarchyList.setSelectedValue(rule, true);
640: removeRuleButton.setEnabled(true);
641: }
642: resetRuleHierarchy();
643: }//GEN-LAST:event_addRuleButtonActionPerformed
644:
645: private String getRule(String ruleType) {
646: String rule = null;
647: if (ruleType.equals(ELEMENT_TYPE)) {
648: rule = (String) selectElementComboBox.getSelectedItem();
649: if (rule.equals(NONE))
650: rule = null;
651: } else if (ruleType.equals(CLASS_TYPE)) {
652: if (!selectClassTextField.getText().trim().equals("")) {
653: String rulePrefix = (String) classPrefixComboBox
654: .getSelectedItem();
655: rule = "." + selectClassTextField.getText().trim();
656: if (!rulePrefix.equals(NONE)) {
657: rule = rulePrefix + rule;
658: }
659: }
660: } else if (ruleType.equals(ELEMENT_ID_TYPE)) {
661: if (!selectElementIdTextField.getText().trim().equals("")) {
662: rule = "#" + selectElementIdTextField.getText().trim();
663: ;
664: }
665: }
666: return rule;
667: }
668:
669: private void resetRuleHierarchy() {
670: StringBuffer ruleSetBuf = new StringBuffer();
671: for (int i = 0; i < selectedRules.size(); i++) {
672: String ruleName = ((String) selectedRules.get(i)).trim();
673: ruleSetBuf.append(ruleName);
674: if (i < selectedRules.size() - 1)
675: ruleSetBuf.append(" ");
676: }
677: previewTextField.setText(ruleSetBuf.toString());
678: }
679:
680: // Variables declaration - do not modify//GEN-BEGIN:variables
681: private javax.swing.JPanel addRemoveRulePanel;
682: private javax.swing.JButton addRuleButton;
683: private javax.swing.JComboBox classPrefixComboBox;
684: private javax.swing.JLabel classPrefixSeparator;
685: private javax.swing.JPanel hierarchyContainer;
686: private javax.swing.JButton moveRuleDownButton;
687: private javax.swing.JPanel moveRulePanel;
688: private javax.swing.JButton moveRuleUpButton;
689: private javax.swing.JLabel previewLable;
690: private javax.swing.JPanel previewPanel;
691: private javax.swing.JTextField previewTextField;
692: private javax.swing.JButton removeRuleButton;
693: private javax.swing.JList ruleHierarchyList;
694: private javax.swing.JPanel ruleHierarchyPanel;
695: private javax.swing.JScrollPane ruleHierarchyScroll;
696: private javax.swing.JPanel rulePanel;
697: private javax.swing.JRadioButton selectClassRadioButton;
698: private javax.swing.JTextField selectClassTextField;
699: private javax.swing.JRadioButton selectElelmentIdRadioButton;
700: private javax.swing.JComboBox selectElementComboBox;
701: private javax.swing.JTextField selectElementIdTextField;
702: private javax.swing.JRadioButton selectElementRadioButton;
703: private javax.swing.ButtonGroup selectRuleButtonGroup;
704: private javax.swing.JPanel selectRulePanel;
705: // End of variables declaration//GEN-END:variables
706: }
|