2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.html.palette.items;
43
import java.awt.Dialog;
44
import java.awt.event.ActionEvent;
45
import java.awt.event.ActionListener;
46
import java.text.SimpleDateFormat;
47
import java.util.Calendar;
48
import java.util.Date;
49
import java.util.GregorianCalendar;
50
import javax.swing.DefaultComboBoxModel;
51
import org.openide.DialogDescriptor;
52
import org.openide.DialogDisplayer;
53
import org.openide.util.NbBundle;
59
* @author Libor Kotouc
61
public class METACustomizer extends javax.swing.JPanel {
63
private Dialog dialog = null;
64
private DialogDescriptor descriptor = null;
65
private boolean dialogOK = false;
67
private DefaultComboBoxModel headerModel = new DefaultComboBoxModel(META.headers);
68
private DefaultComboBoxModel engineModel = new DefaultComboBoxModel(META.engines);
72
private int HEADER_SELECTED = META.HEADER_DEFAULT;
73
private int ENGINE_SELECTED = META.ENGINE_DEFAULT;
75
/** Creates new form OLCustomizerPanel */
76
public METACustomizer(META meta) {
81
jRadioButton1.setSelected(true);
84
public boolean showDialog() {
88
String displayName = "";
90
displayName = NbBundle.getBundle("org.netbeans.modules.html.palette.items.resources.Bundle").getString("NAME_html-META"); // NOI18N
92
catch (Exception e) {}
94
descriptor = new DialogDescriptor
95
(this, NbBundle.getMessage(METACustomizer.class, "LBL_Customizer_InsertPrefix") + " " + displayName, true,
96
DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.OK_OPTION,
97
new ActionListener() {
98
public void actionPerformed(ActionEvent e) {
99
if (descriptor.getValue().equals(DialogDescriptor.OK_OPTION)) {
108
dialog = DialogDisplayer.getDefault().createDialog(descriptor);
109
dialog.setVisible(true);
114
private void setNamesModel() {
116
if (jRadioButton1.isSelected()) {
117
jComboBox1.setModel(headerModel);
118
jComboBox1.setSelectedIndex(HEADER_SELECTED);
120
else if (jRadioButton2.isSelected()) {
121
jComboBox1.setModel(engineModel);
122
jComboBox1.setSelectedIndex(ENGINE_SELECTED);
126
private void setContent() {
128
int nameIndex = jComboBox1.getSelectedIndex();
129
if (jRadioButton1.isSelected()) {
130
HEADER_SELECTED = nameIndex;
132
case 0: jTextField1.setText("text/html; charset=UTF-8"); break; // NOI18N
133
case 1: jTextField1.setText("en-US"); break; // NOI18N
134
case 2: jTextField1.setText("3;URL=http://"); break; // NOI18N
135
case 3: jTextField1.setText("no-cache"); break; // NOI18N
136
case 4: jTextField1.setText(createRFC1123Date()); // NOI18N
139
else if (jRadioButton2.isSelected()) {
140
ENGINE_SELECTED = nameIndex;
142
case 0: jTextField1.setText("ALL"); break; // NOI18N
143
case 1: jTextField1.setText(""); break; // NOI18N
144
case 2: jTextField1.setText("keyword [, keyword]*"); // NOI18N
149
private String createRFC1123Date() {
151
Calendar cal = new GregorianCalendar();
152
cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1);
153
Date currentDatetimePlusOneYear = cal.getTime();
154
SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy k:mm:ss z"); // NOI18N
155
String dateString = formatter.format(currentDatetimePlusOneYear);
160
private void evaluateInput() {
162
if (jRadioButton1.isSelected())
163
meta.setType(META.TYPE_HEADERS);
164
else if (jRadioButton2.isSelected())
165
meta.setType(META.TYPE_ENGINES);
167
int nameIndex = jComboBox1.getSelectedIndex();
168
meta.setNameIndex(nameIndex);
169
if (nameIndex == -1) // new or no value selected
170
meta.setName(jComboBox1.getSelectedItem().toString());
172
String content = jTextField1.getText();
173
meta.setContent(content);
177
/** This method is called from within the constructor to
178
* initialize the form.
179
* WARNING: Do NOT modify this code. The content of this method is
180
* always regenerated by the Form Editor.
182
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
183
private void initComponents() {
184
java.awt.GridBagConstraints gridBagConstraints;
186
buttonGroup1 = new javax.swing.ButtonGroup();
187
jLabel1 = new javax.swing.JLabel();
188
jRadioButton1 = new javax.swing.JRadioButton();
189
jRadioButton2 = new javax.swing.JRadioButton();
190
jLabel2 = new javax.swing.JLabel();
191
jTextField1 = new javax.swing.JTextField();
192
jLabel3 = new javax.swing.JLabel();
193
jComboBox1 = new javax.swing.JComboBox();
195
setLayout(new java.awt.GridBagLayout());
197
org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_Type"));
198
gridBagConstraints = new java.awt.GridBagConstraints();
199
gridBagConstraints.gridx = 0;
200
gridBagConstraints.gridy = 0;
201
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
202
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
203
gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
204
add(jLabel1, gridBagConstraints);
205
jLabel1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_Type"));
206
jLabel1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_Type"));
208
buttonGroup1.add(jRadioButton1);
209
org.openide.awt.Mnemonics.setLocalizedText(jRadioButton1, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_header"));
210
jRadioButton1.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(0, 0, 0, 0)));
211
jRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
212
jRadioButton1.addItemListener(new java.awt.event.ItemListener() {
213
public void itemStateChanged(java.awt.event.ItemEvent evt) {
214
jRadioButton1ItemStateChanged(evt);
218
gridBagConstraints = new java.awt.GridBagConstraints();
219
gridBagConstraints.gridx = 1;
220
gridBagConstraints.gridy = 0;
221
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
222
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
223
gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
224
add(jRadioButton1, gridBagConstraints);
225
jRadioButton1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_header"));
226
jRadioButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_header"));
228
buttonGroup1.add(jRadioButton2);
229
org.openide.awt.Mnemonics.setLocalizedText(jRadioButton2, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_engines"));
230
jRadioButton2.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(0, 0, 0, 0)));
231
jRadioButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
232
jRadioButton2.addItemListener(new java.awt.event.ItemListener() {
233
public void itemStateChanged(java.awt.event.ItemEvent evt) {
234
jRadioButton2ItemStateChanged(evt);
238
gridBagConstraints = new java.awt.GridBagConstraints();
239
gridBagConstraints.gridx = 1;
240
gridBagConstraints.gridy = 1;
241
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
242
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
243
gridBagConstraints.insets = new java.awt.Insets(5, 12, 0, 12);
244
add(jRadioButton2, gridBagConstraints);
245
jRadioButton2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_engines"));
246
jRadioButton2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_engines"));
248
jLabel2.setLabelFor(jComboBox1);
249
org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_Name"));
250
gridBagConstraints = new java.awt.GridBagConstraints();
251
gridBagConstraints.gridx = 0;
252
gridBagConstraints.gridy = 2;
253
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
254
gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
255
add(jLabel2, gridBagConstraints);
256
jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_Name"));
257
jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_Name"));
259
jTextField1.setColumns(30);
260
gridBagConstraints = new java.awt.GridBagConstraints();
261
gridBagConstraints.gridx = 1;
262
gridBagConstraints.gridy = 3;
263
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
264
gridBagConstraints.weightx = 1.0;
265
gridBagConstraints.weighty = 1.0;
266
gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 12);
267
add(jTextField1, gridBagConstraints);
269
jLabel3.setLabelFor(jTextField1);
270
org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_Content"));
271
gridBagConstraints = new java.awt.GridBagConstraints();
272
gridBagConstraints.gridx = 0;
273
gridBagConstraints.gridy = 3;
274
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
275
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
276
gridBagConstraints.insets = new java.awt.Insets(12, 12, 12, 0);
277
add(jLabel3, gridBagConstraints);
278
jLabel3.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSN_META_Content"));
279
jLabel3.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(METACustomizer.class, "ACSD_META_Content"));
281
jComboBox1.setEditable(true);
282
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
283
public void actionPerformed(java.awt.event.ActionEvent evt) {
284
jComboBox1ActionPerformed(evt);
288
gridBagConstraints = new java.awt.GridBagConstraints();
289
gridBagConstraints.gridx = 1;
290
gridBagConstraints.gridy = 2;
291
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
292
gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 12);
293
add(jComboBox1, gridBagConstraints);
296
// </editor-fold>//GEN-END:initComponents
298
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
300
}//GEN-LAST:event_jComboBox1ActionPerformed
302
private void jRadioButton2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton2ItemStateChanged
304
}//GEN-LAST:event_jRadioButton2ItemStateChanged
306
private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRadioButton1ItemStateChanged
308
}//GEN-LAST:event_jRadioButton1ItemStateChanged
311
// Variables declaration - do not modify//GEN-BEGIN:variables
312
private javax.swing.ButtonGroup buttonGroup1;
313
private javax.swing.JComboBox jComboBox1;
314
private javax.swing.JLabel jLabel1;
315
private javax.swing.JLabel jLabel2;
316
private javax.swing.JLabel jLabel3;
317
private javax.swing.JRadioButton jRadioButton1;
318
private javax.swing.JRadioButton jRadioButton2;
319
private javax.swing.JTextField jTextField1;
320
// End of variables declaration//GEN-END:variables