1 19 package org.netbeans.modules.xml.core.wizard; 20 21 import java.awt.Component ; 22 import java.net.*; 23 import java.io.*; 24 import java.util.Iterator ; 25 import javax.swing.DefaultComboBoxModel ; 26 import javax.swing.text.JTextComponent ; 27 28 37 public class SchemaPanel extends AbstractPanel { 38 39 private static final long serialVersionUID = -7568909683682244030L; 40 41 42 43 public SchemaPanel() { 44 initComponents(); 45 initAccessibility(); 46 } 47 48 53 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 55 56 descTextArea = new javax.swing.JTextArea (); 57 locationLabel = new javax.swing.JLabel (); 58 locationTextField = new javax.swing.JTextField (); 59 locationButton = new javax.swing.JButton (); 60 nsLabel = new javax.swing.JLabel (); 61 nsComboBox = new javax.swing.JComboBox (); 62 rootLabel = new javax.swing.JLabel (); 63 rootComboBox = new javax.swing.JComboBox (); 64 fillPanel = new javax.swing.JPanel (); 65 66 setLayout(new java.awt.GridBagLayout ()); 67 68 setName(Util.THIS.getString("PROP_schema_panel_name")); 69 descTextArea.setColumns(20); 70 descTextArea.setEditable(false); 71 descTextArea.setLineWrap(true); 72 descTextArea.setText(Util.THIS.getString("MSG_schema_wizard_desc")); 73 descTextArea.setWrapStyleWord(true); 74 descTextArea.setDisabledTextColor(descTextArea.getForeground()); 75 descTextArea.setEnabled(false); 76 descTextArea.setOpaque(false); 77 gridBagConstraints = new java.awt.GridBagConstraints (); 78 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 79 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 80 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 81 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 82 add(descTextArea, gridBagConstraints); 83 84 locationLabel.setLabelFor(locationTextField); 85 locationLabel.setText(Util.THIS.getString("LBL_schema_location")); 86 locationLabel.setToolTipText(Util.THIS.getString("PROP_schema_locationLabel_desc")); 87 gridBagConstraints = new java.awt.GridBagConstraints (); 88 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 89 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 90 add(locationLabel, gridBagConstraints); 91 92 locationTextField.setToolTipText(Util.THIS.getString("PROP_schema_locationTextField_desc")); 93 locationTextField.addFocusListener(new java.awt.event.FocusAdapter () { 94 public void focusLost(java.awt.event.FocusEvent evt) { 95 locationTextFieldFocusLost(evt); 96 } 97 }); 98 99 gridBagConstraints = new java.awt.GridBagConstraints (); 100 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 101 gridBagConstraints.weightx = 1.0; 102 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 103 add(locationTextField, gridBagConstraints); 104 105 locationButton.setText(Util.THIS.getString("LBL_browse")); 106 locationButton.setToolTipText(Util.THIS.getString("PROP_schema_locationButton_desc")); 107 locationButton.addActionListener(new java.awt.event.ActionListener () { 108 public void actionPerformed(java.awt.event.ActionEvent evt) { 109 locationButtonActionPerformed(evt); 110 } 111 }); 112 113 gridBagConstraints = new java.awt.GridBagConstraints (); 114 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 115 gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; 116 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 117 add(locationButton, gridBagConstraints); 118 119 nsLabel.setLabelFor(nsComboBox); 120 nsLabel.setText(Util.THIS.getString("LBL_root_namespace")); 121 nsLabel.setToolTipText(Util.THIS.getString("PROP_schema_nsLabel_desc")); 122 gridBagConstraints = new java.awt.GridBagConstraints (); 123 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 124 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 12); 125 add(nsLabel, gridBagConstraints); 126 127 nsComboBox.setEditable(true); 128 nsComboBox.setToolTipText(Util.THIS.getString("PROP_schema_nsComboBox_desc")); 129 gridBagConstraints = new java.awt.GridBagConstraints (); 130 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 131 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 132 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH; 133 gridBagConstraints.weightx = 1.0; 134 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 135 add(nsComboBox, gridBagConstraints); 136 137 rootLabel.setLabelFor(rootComboBox); 138 rootLabel.setText(Util.THIS.getString("PROP_schema_root_name")); 139 rootLabel.setToolTipText(Util.THIS.getString("PROP_schema_rootLabel_desc")); 140 gridBagConstraints = new java.awt.GridBagConstraints (); 141 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 142 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 12); 143 add(rootLabel, gridBagConstraints); 144 145 rootComboBox.setEditable(true); 146 rootComboBox.setToolTipText(Util.THIS.getString("PROP_schema_rootComboBox_desc")); 147 gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 149 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 150 gridBagConstraints.weightx = 1.0; 151 add(rootComboBox, gridBagConstraints); 152 153 fillPanel.setLayout(null); 154 155 gridBagConstraints = new java.awt.GridBagConstraints (); 156 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 157 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 158 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 159 gridBagConstraints.weightx = 1.0; 160 gridBagConstraints.weighty = 1.0; 161 add(fillPanel, gridBagConstraints); 162 163 } 165 private void initAccessibility() { 166 167 Util util = Util.THIS; 169 locationLabel.setDisplayedMnemonic(util.getChar("PROP_schema_locationLabel_mne")); 170 rootLabel.setDisplayedMnemonic(util.getChar("PROP_schema_rootLabel_mne")); 171 nsLabel.setDisplayedMnemonic(util.getChar("PROP_schema_nsLabel_mne")); 172 locationButton.setMnemonic(util.getChar("PROP_schema_locationButton_mne")); 173 getAccessibleContext().setAccessibleDescription(descTextArea.getText()); 174 } 175 176 private void locationTextFieldFocusLost(java.awt.event.FocusEvent evt) { updatePossibilities(); 178 } 180 private void locationButtonActionPerformed(java.awt.event.ActionEvent evt) { File file = Util.selectSchemaFile("xsd xml xsdl"); 182 if (file == null) return; 183 try { 184 URL url = file.toURL(); 185 locationTextField.setText(url.toExternalForm()); 186 updatePossibilities(); 187 } catch (MalformedURLException ex) { 188 } 190 } 192 195 private void updatePossibilities() { 196 197 199 SchemaParser parser = new SchemaParser(); 200 201 String systemId = locationTextField.getText(); 202 try { 203 URL context = model.getTargetFolderURL(); 204 if (context != null) { 205 systemId = new URL(context, systemId).toExternalForm(); 206 } 207 } catch (MalformedURLException ex) { 208 } 210 SchemaParser.SchemaInfo info = parser.parse(systemId); 211 212 if (info == null) return; 213 214 nsModel.removeAllElements(); 215 if (info.namespace != null) { 216 nsModel.addElement(info.namespace); 217 } 218 219 if (info.roots.size() > 0) { 220 rootModel.removeAllElements(); 221 Iterator it = info.roots.iterator(); 222 while (it.hasNext()) { 223 String next = (String ) it.next(); 224 rootModel.addElement(next); 225 } 226 } 227 228 Component editor = rootComboBox.getEditor().getEditorComponent(); 230 if (editor instanceof JTextComponent ) { 231 ((JTextComponent )editor).selectAll(); 232 } 233 } 234 235 237 protected void initView() { 238 239 241 nsModel = new DefaultComboBoxModel (); 242 rootModel = new DefaultComboBoxModel (); 243 244 nsComboBox.setModel(nsModel); 245 rootComboBox.setModel(rootModel); 246 } 247 248 250 protected void updateModel() { 251 String uri = locationTextField.getText(); 252 if (uri != null) { 253 uri = uri.replaceAll(" ", "%20"); try { 256 uri = new URI(uri).toASCIIString(); 258 } catch (URISyntaxException e) { 259 } 261 } 262 model.setSystemID(uri == null || uri.length() == 0 ? null : uri); 263 264 Object ns = nsComboBox.getSelectedItem(); 265 model.setNamespace(ns == null ? null : ns.toString()); 266 267 Object root = rootComboBox.getSelectedItem(); 268 model.setRoot(root == null ? null : root.toString()); 269 270 } 271 272 274 protected void updateView() { 275 } 276 277 private DefaultComboBoxModel nsModel; 278 private DefaultComboBoxModel rootModel; 279 280 private javax.swing.JLabel locationLabel; 282 private javax.swing.JLabel rootLabel; 283 private javax.swing.JLabel nsLabel; 284 private javax.swing.JComboBox rootComboBox; 285 private javax.swing.JTextField locationTextField; 286 private javax.swing.JTextArea descTextArea; 287 private javax.swing.JButton locationButton; 288 private javax.swing.JComboBox nsComboBox; 289 private javax.swing.JPanel fillPanel; 290 292 } 293 | Popular Tags |