KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > html > palette > items > METACustomizer


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.html.palette.items;
21 import java.awt.Dialog JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.awt.event.ActionListener JavaDoc;
24 import java.text.SimpleDateFormat JavaDoc;
25 import java.util.Calendar JavaDoc;
26 import java.util.Date JavaDoc;
27 import java.util.GregorianCalendar JavaDoc;
28 import javax.swing.DefaultComboBoxModel JavaDoc;
29 import org.openide.DialogDescriptor;
30 import org.openide.DialogDisplayer;
31 import org.openide.util.NbBundle;
32
33
34
35 /**
36  *
37  * @author Libor Kotouc
38  */

39 public class METACustomizer extends javax.swing.JPanel JavaDoc {
40     
41     private Dialog JavaDoc dialog = null;
42     private DialogDescriptor descriptor = null;
43     private boolean dialogOK = false;
44
45     private DefaultComboBoxModel JavaDoc headerModel = new DefaultComboBoxModel JavaDoc(META.headers);
46     private DefaultComboBoxModel JavaDoc engineModel = new DefaultComboBoxModel JavaDoc(META.engines);
47     
48     META meta;
49     
50     private int HEADER_SELECTED = META.HEADER_DEFAULT;
51     private int ENGINE_SELECTED = META.ENGINE_DEFAULT;
52             
53     /** Creates new form OLCustomizerPanel */
54     public METACustomizer(META meta) {
55         this.meta = meta;
56         
57         initComponents();
58         
59         jRadioButton1.setSelected(true);
60     }
61     
62     public boolean showDialog() {
63         
64         dialogOK = false;
65         
66         String JavaDoc displayName = "";
67         try {
68             displayName = NbBundle.getBundle("org.netbeans.modules.html.palette.items.resources.Bundle").getString("NAME_html-META"); // NOI18N
69
}
70         catch (Exception JavaDoc e) {}
71         
72         descriptor = new DialogDescriptor
73                 (this, NbBundle.getMessage(METACustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true,
74                  DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
75                  new ActionListener JavaDoc() {
76                      public void actionPerformed(ActionEvent JavaDoc e) {
77                         if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
78                             evaluateInput();
79                             dialogOK = true;
80                         }
81                         dialog.dispose();
82              }
83          }
84                 );
85         
86         dialog = DialogDisplayer.getDefault().createDialog(descriptor);
87         dialog.setVisible(true);
88         
89         return dialogOK;
90     }
91
92     private void setNamesModel() {
93
94         if (jRadioButton1.isSelected()) {
95             jComboBox1.setModel(headerModel);
96             jComboBox1.setSelectedIndex(HEADER_SELECTED);
97         }
98         else if (jRadioButton2.isSelected()) {
99             jComboBox1.setModel(engineModel);
100             jComboBox1.setSelectedIndex(ENGINE_SELECTED);
101         }
102     }
103     
104     private void setContent() {
105         
106         int nameIndex = jComboBox1.getSelectedIndex();
107         if (jRadioButton1.isSelected()) {
108             HEADER_SELECTED = nameIndex;
109             switch (nameIndex) {
110                 case 0: jTextField1.setText("text/html; charset=UTF-8"); break; // NOI18N
111
case 1: jTextField1.setText("en-US"); break; // NOI18N
112
case 2: jTextField1.setText("3;URL=http://"); break; // NOI18N
113
case 3: jTextField1.setText("no-cache"); break; // NOI18N
114
case 4: jTextField1.setText(createRFC1123Date()); // NOI18N
115
}
116         }
117         else if (jRadioButton2.isSelected()) {
118             ENGINE_SELECTED = nameIndex;
119             switch (nameIndex) {
120                 case 0: jTextField1.setText("ALL"); break; // NOI18N
121
case 1: jTextField1.setText(""); break; // NOI18N
122
case 2: jTextField1.setText("keyword [, keyword]*"); // NOI18N
123
}
124         }
125     }
126     
127     private String JavaDoc createRFC1123Date() {
128         
129         Calendar JavaDoc cal = new GregorianCalendar JavaDoc();
130         cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1);
131         Date JavaDoc currentDatetimePlusOneYear = cal.getTime();
132         SimpleDateFormat JavaDoc formatter = new SimpleDateFormat JavaDoc("EEE, dd MMM yyyy k:mm:ss z"); // NOI18N
133
String JavaDoc dateString = formatter.format(currentDatetimePlusOneYear);
134         
135         return dateString;
136     }
137     
138     private void evaluateInput() {
139
140         if (jRadioButton1.isSelected())
141             meta.setType(META.TYPE_HEADERS);
142         else if (jRadioButton2.isSelected())
143             meta.setType(META.TYPE_ENGINES);
144
145         int nameIndex = jComboBox1.getSelectedIndex();
146         meta.setNameIndex(nameIndex);
147         if (nameIndex == -1) // new or no value selected
148
meta.setName(jComboBox1.getSelectedItem().toString());
149         
150         String JavaDoc content = jTextField1.getText();
151         meta.setContent(content);
152
153     }
154     
155     /** This method is called from within the constructor to
156      * initialize the form.
157      * WARNING: Do NOT modify this code. The content of this method is
158      * always regenerated by the Form Editor.
159      */

160     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
161
private void initComponents() {
162         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
163
164         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
165         jLabel1 = new javax.swing.JLabel JavaDoc();
166         jRadioButton1 = new javax.swing.JRadioButton JavaDoc();
167         jRadioButton2 = new javax.swing.JRadioButton JavaDoc();
168         jLabel2 = new javax.swing.JLabel JavaDoc();
169         jTextField1 = new javax.swing.JTextField JavaDoc();
170         jLabel3 = new javax.swing.JLabel JavaDoc();
171         jComboBox1 = new javax.swing.JComboBox JavaDoc();
172
173         setLayout(new java.awt.GridBagLayout JavaDoc());
174
175         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_Type"));
176         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
177         gridBagConstraints.gridx = 0;
178         gridBagConstraints.gridy = 0;
179         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
180         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
182         add(jLabel1, gridBagConstraints);
183         jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_Type"));
184         jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_Type"));
185
186         buttonGroup1.add(jRadioButton1);
187         org.openide.awt.Mnemonics.setLocalizedText(jRadioButton1, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_header"));
188         jRadioButton1.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(0, 0, 0, 0)));
189         jRadioButton1.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
190         jRadioButton1.addItemListener(new java.awt.event.ItemListener JavaDoc() {
191             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
192                 jRadioButton1ItemStateChanged(evt);
193             }
194         });
195
196         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
197         gridBagConstraints.gridx = 1;
198         gridBagConstraints.gridy = 0;
199         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
200         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
201         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
202         add(jRadioButton1, gridBagConstraints);
203         jRadioButton1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_header"));
204         jRadioButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_header"));
205
206         buttonGroup1.add(jRadioButton2);
207         org.openide.awt.Mnemonics.setLocalizedText(jRadioButton2, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_engines"));
208         jRadioButton2.setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(0, 0, 0, 0)));
209         jRadioButton2.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
210         jRadioButton2.addItemListener(new java.awt.event.ItemListener JavaDoc() {
211             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
212                 jRadioButton2ItemStateChanged(evt);
213             }
214         });
215
216         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
217         gridBagConstraints.gridx = 1;
218         gridBagConstraints.gridy = 1;
219         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
220         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
221         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 12, 0, 12);
222         add(jRadioButton2, gridBagConstraints);
223         jRadioButton2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_engines"));
224         jRadioButton2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_engines"));
225
226         jLabel2.setLabelFor(jComboBox1);
227         org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_Name"));
228         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
229         gridBagConstraints.gridx = 0;
230         gridBagConstraints.gridy = 2;
231         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
232         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
233         add(jLabel2, gridBagConstraints);
234         jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_Name"));
235         jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_Name"));
236
237         jTextField1.setColumns(30);
238         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
239         gridBagConstraints.gridx = 1;
240         gridBagConstraints.gridy = 3;
241         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
242         gridBagConstraints.weightx = 1.0;
243         gridBagConstraints.weighty = 1.0;
244         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 12);
245         add(jTextField1, gridBagConstraints);
246
247         jLabel3.setLabelFor(jTextField1);
248         org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_Content"));
249         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
250         gridBagConstraints.gridx = 0;
251         gridBagConstraints.gridy = 3;
252         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
253         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
254         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 12, 0);
255         add(jLabel3, gridBagConstraints);
256         jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_Content"));
257         jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_Content"));
258
259         jComboBox1.setEditable(true);
260         jComboBox1.addActionListener(new java.awt.event.ActionListener JavaDoc() {
261             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
262                 jComboBox1ActionPerformed(evt);
263             }
264         });
265
266         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
267         gridBagConstraints.gridx = 1;
268         gridBagConstraints.gridy = 2;
269         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
270         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 12);
271         add(jComboBox1, gridBagConstraints);
272
273     }
274     // </editor-fold>//GEN-END:initComponents
275

276     private void jComboBox1ActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
277
setContent();
278     }//GEN-LAST:event_jComboBox1ActionPerformed
279

280     private void jRadioButton2ItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButton2ItemStateChanged
281
setNamesModel();
282     }//GEN-LAST:event_jRadioButton2ItemStateChanged
283

284     private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged
285
setNamesModel();
286     }//GEN-LAST:event_jRadioButton1ItemStateChanged
287

288     
289     // Variables declaration - do not modify//GEN-BEGIN:variables
290
private javax.swing.ButtonGroup JavaDoc buttonGroup1;
291     private javax.swing.JComboBox JavaDoc jComboBox1;
292     private javax.swing.JLabel JavaDoc jLabel1;
293     private javax.swing.JLabel JavaDoc jLabel2;
294     private javax.swing.JLabel JavaDoc jLabel3;
295     private javax.swing.JRadioButton JavaDoc jRadioButton1;
296     private javax.swing.JRadioButton JavaDoc jRadioButton2;
297     private javax.swing.JTextField JavaDoc jTextField1;
298     // End of variables declaration//GEN-END:variables
299

300 }
301
Popular Tags