1 19 20 package org.netbeans.modules.xml.catalog; 21 22 import org.openide.util.NbBundle; 23 import org.openide.DialogDescriptor; 24 25 26 31 public class CatalogEntryPanel extends javax.swing.JPanel { 32 33 private org.openide.DialogDescriptor enclosingDesc; 34 35 public CatalogEntryPanel() { 36 initComponents(); 37 DocListener docListener = new DocListener(this); 38 publicTF.getDocument().addDocumentListener(docListener); 39 systemTF.getDocument().addDocumentListener(docListener); 40 uriTF.getDocument().addDocumentListener(docListener); 41 getAccessibleContext().setAccessibleName(titleLabel.getText()); 42 getAccessibleContext().setAccessibleDescription(descLabel.getText()); 43 } 44 45 void setEnclosingDesc(DialogDescriptor enclosingDesc) { 46 this.enclosingDesc=enclosingDesc; 47 } 48 49 public String getPublicId() { 50 return publicTF.getText(); 51 } 52 53 public boolean isPublic() { 54 return publicRB.isSelected(); 55 } 56 57 public String getSystemId() { 58 return systemTF.getText(); 59 } 60 61 public String getUri() { 62 return uriTF.getText(); 63 } 64 65 66 private void checkValues() { 67 if (enclosingDesc==null) return; 68 if (getUri().length()==0) enclosingDesc.setValid(false); 69 else if (isPublic() && getPublicId().length()==0) enclosingDesc.setValid(false); 70 else if (!isPublic() && getSystemId().length()==0) enclosingDesc.setValid(false); 71 else enclosingDesc.setValid(true); 72 } 73 74 79 private void initComponents() { 81 java.awt.GridBagConstraints gridBagConstraints; 82 83 buttonGroup1 = new javax.swing.ButtonGroup (); 84 publicRB = new javax.swing.JRadioButton (); 85 systemRB = new javax.swing.JRadioButton (); 86 publicTF = new javax.swing.JTextField (); 87 systemTF = new javax.swing.JTextField (); 88 jLabel1 = new javax.swing.JLabel (); 89 jLabel2 = new javax.swing.JLabel (); 90 uriLabel = new javax.swing.JLabel (); 91 uriTF = new javax.swing.JTextField (); 92 browseButton = new javax.swing.JButton (); 93 titleLabel = new javax.swing.JLabel (); 94 descLabel = new javax.swing.JLabel (); 95 96 setLayout(new java.awt.GridBagLayout ()); 97 98 buttonGroup1.add(publicRB); 99 publicRB.setMnemonic(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "RADIO_publicId_mnem").charAt(0)); 100 publicRB.setSelected(true); 101 publicRB.setText(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "RADIO_publicId")); 102 publicRB.addItemListener(new java.awt.event.ItemListener () { 103 public void itemStateChanged(java.awt.event.ItemEvent evt) { 104 publicRBItemStateChanged(evt); 105 } 106 }); 107 108 gridBagConstraints = new java.awt.GridBagConstraints (); 109 gridBagConstraints.gridx = 0; 110 gridBagConstraints.gridy = 1; 111 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 112 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 0); 113 add(publicRB, gridBagConstraints); 114 115 buttonGroup1.add(systemRB); 116 systemRB.setMnemonic(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "RADIO_systemId_mnem").charAt(0)); 117 systemRB.setText(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "RADIO_systemId")); 118 gridBagConstraints = new java.awt.GridBagConstraints (); 119 gridBagConstraints.gridx = 0; 120 gridBagConstraints.gridy = 3; 121 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 122 gridBagConstraints.insets = new java.awt.Insets (10, 5, 0, 0); 123 add(systemRB, gridBagConstraints); 124 125 publicTF.setColumns(40); 126 gridBagConstraints = new java.awt.GridBagConstraints (); 127 gridBagConstraints.gridx = 1; 128 gridBagConstraints.gridy = 1; 129 gridBagConstraints.gridwidth = 2; 130 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 131 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 132 gridBagConstraints.weightx = 1.0; 133 gridBagConstraints.insets = new java.awt.Insets (5, 5, 0, 5); 134 add(publicTF, gridBagConstraints); 135 136 systemTF.setColumns(25); 137 systemTF.setEditable(false); 138 gridBagConstraints = new java.awt.GridBagConstraints (); 139 gridBagConstraints.gridx = 1; 140 gridBagConstraints.gridy = 3; 141 gridBagConstraints.gridwidth = 2; 142 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 143 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 144 gridBagConstraints.weightx = 1.0; 145 gridBagConstraints.insets = new java.awt.Insets (10, 5, 0, 5); 146 add(systemTF, gridBagConstraints); 147 148 jLabel1.setText(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "HINT_publicId")); 149 gridBagConstraints = new java.awt.GridBagConstraints (); 150 gridBagConstraints.gridx = 1; 151 gridBagConstraints.gridy = 2; 152 gridBagConstraints.gridwidth = 2; 153 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 154 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 5); 155 add(jLabel1, gridBagConstraints); 156 157 jLabel2.setText(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "HINT_systemId")); 158 gridBagConstraints = new java.awt.GridBagConstraints (); 159 gridBagConstraints.gridx = 1; 160 gridBagConstraints.gridy = 4; 161 gridBagConstraints.gridwidth = 2; 162 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 163 gridBagConstraints.insets = new java.awt.Insets (0, 5, 0, 5); 164 add(jLabel2, gridBagConstraints); 165 166 uriLabel.setDisplayedMnemonic(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "LBL_uri_mnem").charAt(0)); 167 uriLabel.setLabelFor(uriTF); 168 uriLabel.setText(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "LBL_uri")); 169 gridBagConstraints = new java.awt.GridBagConstraints (); 170 gridBagConstraints.gridx = 0; 171 gridBagConstraints.gridy = 5; 172 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 173 gridBagConstraints.insets = new java.awt.Insets (20, 5, 5, 0); 174 add(uriLabel, gridBagConstraints); 175 176 uriTF.setColumns(35); 177 uriTF.setEditable(false); 178 gridBagConstraints = new java.awt.GridBagConstraints (); 179 gridBagConstraints.gridx = 1; 180 gridBagConstraints.gridy = 5; 181 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 182 gridBagConstraints.weightx = 1.0; 183 gridBagConstraints.insets = new java.awt.Insets (20, 5, 5, 0); 184 add(uriTF, gridBagConstraints); 185 186 browseButton.setMnemonic(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "LBL_browse_mnem").charAt(0)); 187 browseButton.setText(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "LBL_browse")); 188 browseButton.addActionListener(new java.awt.event.ActionListener () { 189 public void actionPerformed(java.awt.event.ActionEvent evt) { 190 browseButtonActionPerformed(evt); 191 } 192 }); 193 194 gridBagConstraints = new java.awt.GridBagConstraints (); 195 gridBagConstraints.gridx = 2; 196 gridBagConstraints.gridy = 5; 197 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 198 gridBagConstraints.insets = new java.awt.Insets (20, 5, 5, 5); 199 add(browseButton, gridBagConstraints); 200 201 titleLabel.setText(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "HINT_panel")); 202 gridBagConstraints = new java.awt.GridBagConstraints (); 203 gridBagConstraints.gridwidth = 3; 204 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 205 gridBagConstraints.insets = new java.awt.Insets (5, 5, 10, 5); 206 add(titleLabel, gridBagConstraints); 207 208 descLabel.setText(org.openide.util.NbBundle.getMessage(CatalogEntryPanel.class, "LBL_catalogEntryDesc")); 209 gridBagConstraints = new java.awt.GridBagConstraints (); 210 gridBagConstraints.gridx = 0; 211 gridBagConstraints.gridy = 6; 212 gridBagConstraints.gridwidth = 3; 213 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 214 gridBagConstraints.insets = new java.awt.Insets (20, 5, 5, 5); 215 add(descLabel, gridBagConstraints); 216 217 } 218 220 private void publicRBItemStateChanged(java.awt.event.ItemEvent evt) { if (publicRB.isSelected()) { 223 publicTF.setEditable(true); 224 systemTF.setEditable(false); 225 } else { 226 publicTF.setEditable(false); 227 systemTF.setEditable(true); 228 } 229 checkValues(); 230 } 232 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) { String dialogTitle = NbBundle.getMessage(CatalogEntryPanel.class,"TITLE_SelectDTDorSchema"); 235 String maskTitle = NbBundle.getMessage(CatalogEntryPanel.class,"TXT_DTDorSchema"); 236 java.io.File f = org.netbeans.modules.xml.catalog.lib.Util.selectFile("dtd xsd DTD XSD", dialogTitle, maskTitle); if (f == null) return; 238 try { 239 String location = f.toURL().toExternalForm(); 240 uriTF.setText(location); 241 } catch (java.net.MalformedURLException ex) { 242 } 244 } 246 247 private javax.swing.JButton browseButton; 249 private javax.swing.ButtonGroup buttonGroup1; 250 private javax.swing.JLabel descLabel; 251 private javax.swing.JLabel jLabel1; 252 private javax.swing.JLabel jLabel2; 253 private javax.swing.JRadioButton publicRB; 254 private javax.swing.JTextField publicTF; 255 private javax.swing.JRadioButton systemRB; 256 private javax.swing.JTextField systemTF; 257 private javax.swing.JLabel titleLabel; 258 private javax.swing.JLabel uriLabel; 259 private javax.swing.JTextField uriTF; 260 262 263 private class DocListener implements javax.swing.event.DocumentListener { 264 CatalogEntryPanel panel; 265 266 public DocListener(CatalogEntryPanel panel) { 267 this.panel=panel; 268 } 269 272 public void changedUpdate(javax.swing.event.DocumentEvent evt) { 273 panel.checkValues(); 274 } 275 276 279 public void insertUpdate(javax.swing.event.DocumentEvent evt) { 280 panel.checkValues(); 281 } 282 283 286 public void removeUpdate(javax.swing.event.DocumentEvent evt) { 287 panel.checkValues(); 288 } 289 } 290 } 291 | Popular Tags |