KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > html > RewritePanel


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

19
20 package org.netbeans.modules.tasklist.html;
21
22 import java.awt.*;
23 import javax.swing.*;
24 import javax.swing.text.*;
25 import javax.swing.event.*;
26 import java.awt.event.*;
27 import org.openide.loaders.DataObject;
28
29 import org.openide.util.NbBundle;
30
31 /**
32  * Confirmation panel before launching an HTML rewrite;
33  * provide the user the capability to set some of jtidy's
34  * options
35  * <p>
36  * @todo Add option to show the new file in a merge dialog?
37  *
38  * @author Tor Norbye
39  */

40 public class RewritePanel extends javax.swing.JPanel JavaDoc
41      implements ActionListener {
42
43     private static final long serialVersionUID = 1;
44
45     private RewriteAction action;
46     private Document doc;
47     private DataObject dobj;
48
49     /** Creates new form RewritePanel */
50     public RewritePanel(RewriteAction action, Document doc, DataObject dobj) {
51         this.action = action;
52         this.doc = doc;
53         this.dobj = dobj;
54         initComponents();
55         xhtmlCB.addActionListener(this);
56         previewButton.addActionListener(this);
57     }
58
59     public void actionPerformed(ActionEvent evt) {
60         if (evt.getSource() == xhtmlCB) {
61             // Cannot choose uppercase tags or strip-end-tags
62
// on XML mode
63
boolean xml = xhtmlCB.isSelected();
64             if (upperRB.isSelected()) {
65                 upperRB.setSelected(false);
66                 lowerRB.setSelected(true);
67             }
68             upperRB.setEnabled(!xml);
69             if (omitCB.isSelected()) {
70                 omitCB.setSelected(false);
71             }
72             omitCB.setEnabled(!xml);
73         } else if (evt.getSource() == previewButton) {
74             action.preview(this, doc, dobj);
75         }
76     }
77     
78     /** This method is called from within the constructor to
79      * initialize the form.
80      * WARNING: Do NOT modify this code. The content of this method is
81      * always regenerated by the Form Editor.
82      */

83     private void initComponents() {//GEN-BEGIN:initComponents
84
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
85
86         caseButtonGroup = new javax.swing.ButtonGroup JavaDoc();
87         jLabel1 = new javax.swing.JLabel JavaDoc();
88         xhtmlCB = new javax.swing.JCheckBox JavaDoc();
89         replaceCB = new javax.swing.JCheckBox JavaDoc();
90         lowerRB = new javax.swing.JRadioButton JavaDoc();
91         upperRB = new javax.swing.JRadioButton JavaDoc();
92         omitCB = new javax.swing.JCheckBox JavaDoc();
93         indentCB = new javax.swing.JCheckBox JavaDoc();
94         wrapCB = new javax.swing.JCheckBox JavaDoc();
95         wrapText = new javax.swing.JTextField JavaDoc();
96         previewButton = new javax.swing.JButton JavaDoc();
97
98         setLayout(new java.awt.GridBagLayout JavaDoc());
99
100         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(12, 12, 11, 11)));
101         jLabel1.setText(NbBundle.getMessage(RewritePanel.class, "RewriteSettings")); // NOI18N();
102
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
103         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
104         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
105         add(jLabel1, gridBagConstraints);
106
107         xhtmlCB.setText(NbBundle.getMessage(RewritePanel.class, "ConvertXHTML")); // NOI18N();
108
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
109         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
110         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
111         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
112         add(xhtmlCB, gridBagConstraints);
113
114         replaceCB.setText(NbBundle.getMessage(RewritePanel.class, "ReplaceFont")); // NOI18N();
115
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
116         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
117         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
118         add(replaceCB, gridBagConstraints);
119
120         lowerRB.setSelected(true);
121         lowerRB.setText(NbBundle.getMessage(RewritePanel.class, "Lowercase")); // NOI18N();
122
caseButtonGroup.add(lowerRB);
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
125         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
126         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
127         add(lowerRB, gridBagConstraints);
128
129         upperRB.setText(NbBundle.getMessage(RewritePanel.class, "Uppercase")); // NOI18N();
130
caseButtonGroup.add(upperRB);
131         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
132         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
133         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
134         add(upperRB, gridBagConstraints);
135
136         omitCB.setText(NbBundle.getMessage(RewritePanel.class, "OmitOptional")); // NOI18N();
137
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
139         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
140         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
141         add(omitCB, gridBagConstraints);
142
143         indentCB.setText(NbBundle.getMessage(RewritePanel.class, "Indent")); // NOI18N();
144
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
146         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
147         add(indentCB, gridBagConstraints);
148
149         wrapCB.setText(NbBundle.getMessage(RewritePanel.class, "WrapCol")); // NOI18N();
150
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
151         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
152         add(wrapCB, gridBagConstraints);
153
154         wrapText.setColumns(3);
155         wrapText.setText("68");
156         wrapText.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
157         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
159         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
160         add(wrapText, gridBagConstraints);
161
162         previewButton.setText(NbBundle.getMessage(RewritePanel.class, "Preview")); // NOI18N();
163
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
164         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
166         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
167         add(previewButton, gridBagConstraints);
168
169     }//GEN-END:initComponents
170

171     
172     // Variables declaration - do not modify//GEN-BEGIN:variables
173
private javax.swing.JCheckBox JavaDoc indentCB;
174     private javax.swing.JCheckBox JavaDoc replaceCB;
175     private javax.swing.JRadioButton JavaDoc upperRB;
176     private javax.swing.JTextField JavaDoc wrapText;
177     private javax.swing.JButton JavaDoc previewButton;
178     private javax.swing.JCheckBox JavaDoc omitCB;
179     private javax.swing.JCheckBox JavaDoc wrapCB;
180     private javax.swing.JLabel JavaDoc jLabel1;
181     private javax.swing.JCheckBox JavaDoc xhtmlCB;
182     private javax.swing.ButtonGroup JavaDoc caseButtonGroup;
183     private javax.swing.JRadioButton JavaDoc lowerRB;
184     // End of variables declaration//GEN-END:variables
185

186    boolean getXHTML() {
187         return xhtmlCB.isSelected();
188    }
189
190    boolean getIndent() {
191         return indentCB.isSelected();
192    }
193
194    boolean getReplace() {
195         return replaceCB.isSelected();
196    }
197
198    boolean getOmit() {
199         return omitCB.isSelected();
200    }
201
202    boolean getUpper() {
203         return upperRB.isSelected();
204    }
205
206    int getWrapCol() {
207        if (!wrapCB.isSelected()) {
208            return 0;
209        }
210        String JavaDoc str = wrapText.getText().trim();
211        int col = 68;
212        try {
213            col = Integer.parseInt(str);
214        } catch (Exception JavaDoc e) {
215        }
216        return col;
217    }
218
219     void setXHTML(boolean on) {
220         xhtmlCB.setSelected(on);
221    }
222
223    void setIndent(boolean on) {
224         indentCB.setSelected(on);
225    }
226
227    void setReplace(boolean on) {
228         replaceCB.setSelected(on);
229    }
230
231    void setOmit(boolean on) {
232         omitCB.setSelected(on);
233    }
234
235    void setUpper(boolean on) {
236         upperRB.setSelected(on);
237         lowerRB.setSelected(!on);
238    }
239
240    void setWrapCol(int col) {
241        if (col == 0) {
242            wrapCB.setSelected(false);
243        } else {
244            wrapText.setText(Integer.toString(col));
245            wrapCB.setSelected(true);
246        }
247    }
248
249    void setXML(boolean on) {
250        // Document is XML - cannot "convert to" XML
251
xhtmlCB.setEnabled(!on);
252        if (on) {
253            upperRB.setSelected(false);
254            lowerRB.setSelected(true);
255            omitCB.setSelected(false);
256            omitCB.setEnabled(false);
257            replaceCB.setSelected(false);
258            replaceCB.setEnabled(false);
259        }
260    }
261 }
262
Popular Tags