1 19 20 package org.netbeans.modules.xml.core.wizard; 21 22 import java.awt.*; 23 import java.awt.event.*; 24 import java.net.MalformedURLException ; 25 import java.net.URL ; 26 27 import java.util.Enumeration ; 28 import java.util.Iterator ; 29 import java.util.Set ; 30 import java.util.Vector ; 31 32 import javax.swing.ComboBoxModel ; 33 import javax.swing.DefaultComboBoxModel ; 34 import javax.swing.FocusManager ; 35 import javax.swing.text.JTextComponent ; 36 37 import org.openide.nodes.Children; 38 import org.openide.nodes.FilterNode; 39 import org.openide.nodes.Node; 40 import org.openide.nodes.NodeOperation; 41 42 import org.xml.sax.*; 43 44 50 public class DTDPanel extends AbstractPanel { 51 52 private static final long serialVersionUID = 5310047495162425192L; 53 54 55 56 public DTDPanel() { 57 initComponents(); 58 initAccessibility(); 59 60 Component editor = pidComboBox.getEditor().getEditorComponent(); 62 editor.addFocusListener(new FocusAdapter() { 63 public void focusLost(FocusEvent e) { 64 if (existsPID()) updatePossibilities(); 65 } 66 }); 67 68 } 69 70 75 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 77 78 descTextArea = new javax.swing.JTextArea (); 79 pidLabel = new javax.swing.JLabel (); 80 pidComboBox = new javax.swing.JComboBox (); 81 catalogButton = new javax.swing.JButton (); 82 sidLabel = new javax.swing.JLabel (); 83 sidComboBox = new javax.swing.JComboBox (); 84 rootLabel = new javax.swing.JLabel (); 85 rootComboBox = new javax.swing.JComboBox (); 86 fillPanel = new javax.swing.JPanel (); 87 88 setLayout(new java.awt.GridBagLayout ()); 89 90 setName(Util.THIS.getString("PROP_dtd_panel_name")); 91 descTextArea.setEditable(false); 92 descTextArea.setLineWrap(true); 93 descTextArea.setText(Util.THIS.getString("MSG_dtd_panel_desc")); 94 descTextArea.setWrapStyleWord(true); 95 descTextArea.setDisabledTextColor(descTextArea.getForeground()); 96 descTextArea.setEnabled(false); 97 descTextArea.setOpaque(false); 98 gridBagConstraints = new java.awt.GridBagConstraints (); 99 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 100 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 101 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 102 add(descTextArea, gridBagConstraints); 103 104 pidLabel.setLabelFor(pidComboBox); 105 pidLabel.setText(Util.THIS.getString("PROP_dtd_pid_name")); 106 pidLabel.setToolTipText(Util.THIS.getString("PROP_dtd_pidLable_desc")); 107 gridBagConstraints = new java.awt.GridBagConstraints (); 108 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 109 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 110 add(pidLabel, gridBagConstraints); 111 112 pidComboBox.setEditable(true); 113 pidComboBox.setToolTipText(Util.THIS.getString("PROP_dtd_pidComboBox_desc")); 114 pidComboBox.addActionListener(new java.awt.event.ActionListener () { 115 public void actionPerformed(java.awt.event.ActionEvent evt) { 116 pidComboBoxActionPerformed(evt); 117 } 118 }); 119 120 pidComboBox.addFocusListener(new java.awt.event.FocusAdapter () { 121 public void focusLost(java.awt.event.FocusEvent evt) { 122 pidComboBoxFocusLost(evt); 123 } 124 }); 125 126 gridBagConstraints = new java.awt.GridBagConstraints (); 127 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 128 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 129 gridBagConstraints.weightx = 1.0; 130 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 131 add(pidComboBox, gridBagConstraints); 132 133 catalogButton.setText(Util.THIS.getString("PROP_dtd_catalog_name")); 134 catalogButton.setToolTipText(Util.THIS.getString("PROP_dtd_catalog_desc")); 135 catalogButton.addActionListener(new java.awt.event.ActionListener () { 136 public void actionPerformed(java.awt.event.ActionEvent evt) { 137 catalogButtonActionPerformed(evt); 138 } 139 }); 140 141 gridBagConstraints = new java.awt.GridBagConstraints (); 142 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 143 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 144 add(catalogButton, gridBagConstraints); 145 146 sidLabel.setLabelFor(sidComboBox); 147 sidLabel.setText(Util.THIS.getString("PROP_dtd_sid_name")); 148 sidLabel.setToolTipText(Util.THIS.getString("PROP_dtd_sidLabel_desc")); 149 gridBagConstraints = new java.awt.GridBagConstraints (); 150 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 151 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 152 add(sidLabel, gridBagConstraints); 153 154 sidComboBox.setEditable(true); 155 sidComboBox.setToolTipText(Util.THIS.getString("PROP_dtd_sidComboBox_desc")); 156 sidComboBox.addActionListener(new java.awt.event.ActionListener () { 157 public void actionPerformed(java.awt.event.ActionEvent evt) { 158 sidComboBoxActionPerformed(evt); 159 } 160 }); 161 162 sidComboBox.addFocusListener(new java.awt.event.FocusAdapter () { 163 public void focusLost(java.awt.event.FocusEvent evt) { 164 sidComboBoxFocusLost(evt); 165 } 166 }); 167 168 gridBagConstraints = new java.awt.GridBagConstraints (); 169 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 170 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 171 gridBagConstraints.weightx = 1.0; 172 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 173 add(sidComboBox, gridBagConstraints); 174 175 rootLabel.setLabelFor(rootComboBox); 176 rootLabel.setText(Util.THIS.getString("PROP_dtd_root_name")); 177 rootLabel.setToolTipText(Util.THIS.getString("PROP_dtd_rootLabel_desc")); 178 gridBagConstraints = new java.awt.GridBagConstraints (); 179 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 180 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 181 add(rootLabel, gridBagConstraints); 182 183 rootComboBox.setEditable(true); 184 rootComboBox.setToolTipText(Util.THIS.getString("PROP_dtd_rootComboBox_desc")); 185 gridBagConstraints = new java.awt.GridBagConstraints (); 186 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 187 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 188 gridBagConstraints.weightx = 1.0; 189 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 190 add(rootComboBox, gridBagConstraints); 191 192 fillPanel.setLayout(null); 193 194 gridBagConstraints = new java.awt.GridBagConstraints (); 195 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 196 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 197 gridBagConstraints.weightx = 1.0; 198 gridBagConstraints.weighty = 1.0; 199 add(fillPanel, gridBagConstraints); 200 201 } 203 private void catalogButtonActionPerformed(java.awt.event.ActionEvent evt) { Node catalog = getCatalogNode(); 205 if (catalog == null) return; 206 NodeOperation.getDefault().explore(catalog); 207 } 209 private void initAccessibility() { 210 211 Util util = Util.THIS; 212 rootLabel.setDisplayedMnemonic(util.getChar("PROP_dtd_rootLabel_mne")); 213 pidLabel.setDisplayedMnemonic(util.getChar("PROP_dtd_pidLabel_mne")); 214 sidLabel.setDisplayedMnemonic(util.getChar("PROP_dtd_sidLabel_mne")); 215 catalogButton.setMnemonic(util.getChar("PROP_dtd_catalog_mne")); 216 getAccessibleContext().setAccessibleDescription(descTextArea.getText()); 217 } 218 219 private void sidComboBoxActionPerformed(java.awt.event.ActionEvent evt) { if (sidComboBox.isPopupVisible()) return; 222 if (existsPID() == false) updatePossibilities(); 223 } 225 private void pidComboBoxActionPerformed(java.awt.event.ActionEvent evt) { if (pidComboBox.isPopupVisible()) return; 228 229 if (existsPID()) updatePossibilities(); 230 } 232 private void pidComboBoxFocusLost(java.awt.event.FocusEvent evt) { if (existsPID()) updatePossibilities(); 234 } 236 private void sidComboBoxFocusLost(java.awt.event.FocusEvent evt) { if (existsPID() == false) updatePossibilities(); 238 } 240 243 private Node getCatalogNode() { 244 245 258 return null; 259 } 260 261 private boolean existsPID() { 263 Object pid = pidModel.getSelectedItem(); 264 return (pid != null) && (pid instanceof String ) 265 && (((String )pid).trim().equals("") == false); 266 } 267 268 private void updatePossibilities() { 269 271 Util.THIS.debug("Updating possible roots (DTD)..."); 272 273 InputSource in = new InputSource(); 274 275 Object sid = sidModel.getSelectedItem(); 276 String systemId = null; 277 try { 278 if (sid != null) { 279 systemId = sid.toString(); 280 URL context = model.getTargetFolderURL(); 281 if (context != null) { 282 systemId = new URL (context, systemId).toExternalForm(); 283 } 284 } 285 } catch (MalformedURLException ex) { 286 } 288 in.setSystemId(systemId); 289 290 Object pid = pidModel.getSelectedItem(); 291 in.setPublicId( pid == null ? null : pid.toString() ); 292 293 Util.THIS.debug("PID: " + pid + ", SID:" + sid); 294 Set roots = new DTDParser().parse(in); 295 296 if (roots.size() > 0) { 297 rootModel.removeAllElements(); 298 Iterator it = roots.iterator(); 299 while (it.hasNext()) { 300 String next = (String ) it.next(); 301 rootModel.addElement(next); 302 } 303 } 304 305 Component editor = rootComboBox.getEditor().getEditorComponent(); 307 if (editor instanceof JTextComponent ) { 308 ((JTextComponent )editor).selectAll(); 309 } 310 } 311 312 314 protected void initView() { 315 316 String [] pids = Util.getKnownDTDPublicIDs(); 318 pidModel = new DefaultComboBoxModel (pids); 319 sidModel = new DefaultComboBoxModel (recentSIDs); 320 rootModel = new DefaultComboBoxModel (); 321 322 pidComboBox.setModel(pidModel); 323 pidComboBox.getEditor().selectAll(); 324 325 if (true || getCatalogNode() == null) { 326 catalogButton.setVisible(false); 327 } 329 330 rootComboBox.setModel(rootModel); 332 333 sidComboBox.setModel(sidModel); 334 335 } 336 337 339 protected void updateModel() { 340 Object pid = pidModel.getSelectedItem(); 341 model.setPublicID( pid == null ? null : pid.toString() ); 342 343 Object sid = sidModel.getSelectedItem(); 344 model.setSystemID(sid == null ? null : sid.toString()); 345 346 Object root = rootModel.getSelectedItem(); 347 model.setRoot(root == null ? null : root.toString()); 348 349 Util.THIS.debug("Model updated PID: " + pid + " SID: " + sid + " root: " + root); 350 351 353 if (recentSIDs.contains(sid) == false) { 354 recentSIDs.add(sid); 355 } 356 } 357 358 360 protected void updateView() { 361 } 362 363 private DefaultComboBoxModel rootModel; 364 private DefaultComboBoxModel pidModel; 365 private DefaultComboBoxModel sidModel; 366 367 private static Vector recentSIDs = new Vector (); 368 369 private javax.swing.JLabel rootLabel; 371 private javax.swing.JButton catalogButton; 372 private javax.swing.JLabel pidLabel; 373 private javax.swing.JComboBox rootComboBox; 374 private javax.swing.JComboBox sidComboBox; 375 private javax.swing.JTextArea descTextArea; 376 private javax.swing.JComboBox pidComboBox; 377 private javax.swing.JLabel sidLabel; 378 private javax.swing.JPanel fillPanel; 379 381 } 382 | Popular Tags |