1 19 20 package org.netbeans.modules.html.palette.items; 21 import java.awt.Dialog ; 22 import java.awt.event.ActionEvent ; 23 import java.awt.event.ActionListener ; 24 import java.text.SimpleDateFormat ; 25 import java.util.Calendar ; 26 import java.util.Date ; 27 import java.util.GregorianCalendar ; 28 import javax.swing.DefaultComboBoxModel ; 29 import org.openide.DialogDescriptor; 30 import org.openide.DialogDisplayer; 31 import org.openide.util.NbBundle; 32 33 34 35 39 public class METACustomizer extends javax.swing.JPanel { 40 41 private Dialog dialog = null; 42 private DialogDescriptor descriptor = null; 43 private boolean dialogOK = false; 44 45 private DefaultComboBoxModel headerModel = new DefaultComboBoxModel (META.headers); 46 private DefaultComboBoxModel engineModel = new DefaultComboBoxModel (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 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 displayName = ""; 67 try { 68 displayName = NbBundle.getBundle("org.netbeans.modules.html.palette.items.resources.Bundle").getString("NAME_html-META"); } 70 catch (Exception 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 () { 76 public void actionPerformed(ActionEvent 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; case 1: jTextField1.setText("en-US"); break; case 2: jTextField1.setText("3;URL=http://"); break; case 3: jTextField1.setText("no-cache"); break; case 4: jTextField1.setText(createRFC1123Date()); } 116 } 117 else if (jRadioButton2.isSelected()) { 118 ENGINE_SELECTED = nameIndex; 119 switch (nameIndex) { 120 case 0: jTextField1.setText("ALL"); break; case 1: jTextField1.setText(""); break; case 2: jTextField1.setText("keyword [, keyword]*"); } 124 } 125 } 126 127 private String createRFC1123Date() { 128 129 Calendar cal = new GregorianCalendar (); 130 cal.set(Calendar.YEAR, cal.get(Calendar.YEAR) + 1); 131 Date currentDatetimePlusOneYear = cal.getTime(); 132 SimpleDateFormat formatter = new SimpleDateFormat ("EEE, dd MMM yyyy k:mm:ss z"); String 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) meta.setName(jComboBox1.getSelectedItem().toString()); 149 150 String content = jTextField1.getText(); 151 meta.setContent(content); 152 153 } 154 155 160 private void initComponents() { 162 java.awt.GridBagConstraints gridBagConstraints; 163 164 buttonGroup1 = new javax.swing.ButtonGroup (); 165 jLabel1 = new javax.swing.JLabel (); 166 jRadioButton1 = new javax.swing.JRadioButton (); 167 jRadioButton2 = new javax.swing.JRadioButton (); 168 jLabel2 = new javax.swing.JLabel (); 169 jTextField1 = new javax.swing.JTextField (); 170 jLabel3 = new javax.swing.JLabel (); 171 jComboBox1 = new javax.swing.JComboBox (); 172 173 setLayout(new java.awt.GridBagLayout ()); 174 175 org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(METACustomizer.class, "LBL_META_Type")); 176 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (new java.awt.Insets (0, 0, 0, 0))); 189 jRadioButton1.setMargin(new java.awt.Insets (0, 0, 0, 0)); 190 jRadioButton1.addItemListener(new java.awt.event.ItemListener () { 191 public void itemStateChanged(java.awt.event.ItemEvent evt) { 192 jRadioButton1ItemStateChanged(evt); 193 } 194 }); 195 196 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (new java.awt.Insets (0, 0, 0, 0))); 209 jRadioButton2.setMargin(new java.awt.Insets (0, 0, 0, 0)); 210 jRadioButton2.addItemListener(new java.awt.event.ItemListener () { 211 public void itemStateChanged(java.awt.event.ItemEvent evt) { 212 jRadioButton2ItemStateChanged(evt); 213 } 214 }); 215 216 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (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 (); 229 gridBagConstraints.gridx = 0; 230 gridBagConstraints.gridy = 2; 231 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 232 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (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 (); 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 (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 () { 261 public void actionPerformed(java.awt.event.ActionEvent evt) { 262 jComboBox1ActionPerformed(evt); 263 } 264 }); 265 266 gridBagConstraints = new java.awt.GridBagConstraints (); 267 gridBagConstraints.gridx = 1; 268 gridBagConstraints.gridy = 2; 269 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 270 gridBagConstraints.insets = new java.awt.Insets (12, 12, 0, 12); 271 add(jComboBox1, gridBagConstraints); 272 273 } 274 276 private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) { setContent(); 278 } 280 private void jRadioButton2ItemStateChanged(java.awt.event.ItemEvent evt) { setNamesModel(); 282 } 284 private void jRadioButton1ItemStateChanged(java.awt.event.ItemEvent evt) { setNamesModel(); 286 } 288 289 private javax.swing.ButtonGroup buttonGroup1; 291 private javax.swing.JComboBox jComboBox1; 292 private javax.swing.JLabel jLabel1; 293 private javax.swing.JLabel jLabel2; 294 private javax.swing.JLabel jLabel3; 295 private javax.swing.JRadioButton jRadioButton1; 296 private javax.swing.JRadioButton jRadioButton2; 297 private javax.swing.JTextField jTextField1; 298 300 } 301 | Popular Tags |