KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > catalog > CatalogEntryPanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.catalog;
21
22 import org.openide.util.NbBundle;
23 import org.openide.DialogDescriptor;
24
25
26 /** Panel for Add Catalog Entry action
27  *
28  * Created on May 31, 2005
29  * @author mkuchtiak
30  */

31 public class CatalogEntryPanel extends javax.swing.JPanel JavaDoc {
32
33     private org.openide.DialogDescriptor enclosingDesc;
34     /** Creates new form CatalogEntryPanel */
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 JavaDoc getPublicId() {
50         return publicTF.getText();
51     }
52     
53     public boolean isPublic() {
54         return publicRB.isSelected();
55     }
56     
57     public String JavaDoc getSystemId() {
58         return systemTF.getText();
59     }
60     
61     public String JavaDoc 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     /** This method is called from within the constructor to
75      * initialize the form.
76      * WARNING: Do NOT modify this code. The content of this method is
77      * always regenerated by the Form Editor.
78      */

79     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
80
private void initComponents() {
81         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
82
83         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
84         publicRB = new javax.swing.JRadioButton JavaDoc();
85         systemRB = new javax.swing.JRadioButton JavaDoc();
86         publicTF = new javax.swing.JTextField JavaDoc();
87         systemTF = new javax.swing.JTextField JavaDoc();
88         jLabel1 = new javax.swing.JLabel JavaDoc();
89         jLabel2 = new javax.swing.JLabel JavaDoc();
90         uriLabel = new javax.swing.JLabel JavaDoc();
91         uriTF = new javax.swing.JTextField JavaDoc();
92         browseButton = new javax.swing.JButton JavaDoc();
93         titleLabel = new javax.swing.JLabel JavaDoc();
94         descLabel = new javax.swing.JLabel JavaDoc();
95
96         setLayout(new java.awt.GridBagLayout JavaDoc());
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 JavaDoc() {
103             public void itemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {
104                 publicRBItemStateChanged(evt);
105             }
106         });
107
108         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
109         gridBagConstraints.gridx = 0;
110         gridBagConstraints.gridy = 1;
111         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
112         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
119         gridBagConstraints.gridx = 0;
120         gridBagConstraints.gridy = 3;
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
122         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 5, 0, 0);
123         add(systemRB, gridBagConstraints);
124
125         publicTF.setColumns(40);
126         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(5, 5, 0, 5);
134         add(publicTF, gridBagConstraints);
135
136         systemTF.setColumns(25);
137         systemTF.setEditable(false);
138         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc();
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 JavaDoc(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 JavaDoc();
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 JavaDoc(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 JavaDoc();
170         gridBagConstraints.gridx = 0;
171         gridBagConstraints.gridy = 5;
172         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
173         gridBagConstraints.insets = new java.awt.Insets JavaDoc(20, 5, 5, 0);
174         add(uriLabel, gridBagConstraints);
175
176         uriTF.setColumns(35);
177         uriTF.setEditable(false);
178         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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 JavaDoc() {
189             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
190                 browseButtonActionPerformed(evt);
191             }
192         });
193
194         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
195         gridBagConstraints.gridx = 2;
196         gridBagConstraints.gridy = 5;
197         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
198         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
203         gridBagConstraints.gridwidth = 3;
204         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
205         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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 JavaDoc();
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 JavaDoc(20, 5, 5, 5);
215         add(descLabel, gridBagConstraints);
216
217     }
218     // </editor-fold>//GEN-END:initComponents
219

220     private void publicRBItemStateChanged(java.awt.event.ItemEvent JavaDoc evt) {//GEN-FIRST:event_publicRBItemStateChanged
221
// TODO add your handling code here:
222
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     }//GEN-LAST:event_publicRBItemStateChanged
231

232     private void browseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseButtonActionPerformed
233
// TODO add your handling code here:
234
String JavaDoc dialogTitle = NbBundle.getMessage(CatalogEntryPanel.class,"TITLE_SelectDTDorSchema");
235         String JavaDoc maskTitle = NbBundle.getMessage(CatalogEntryPanel.class,"TXT_DTDorSchema");
236         java.io.File JavaDoc f = org.netbeans.modules.xml.catalog.lib.Util.selectFile("dtd xsd DTD XSD", dialogTitle, maskTitle); // NOI18N
237
if (f == null) return;
238         try {
239             String JavaDoc location = f.toURL().toExternalForm();
240             uriTF.setText(location);
241         } catch (java.net.MalformedURLException JavaDoc ex) {
242             // ignore
243
}
244     }//GEN-LAST:event_browseButtonActionPerformed
245

246     
247     // Variables declaration - do not modify//GEN-BEGIN:variables
248
private javax.swing.JButton JavaDoc browseButton;
249     private javax.swing.ButtonGroup JavaDoc buttonGroup1;
250     private javax.swing.JLabel JavaDoc descLabel;
251     private javax.swing.JLabel JavaDoc jLabel1;
252     private javax.swing.JLabel JavaDoc jLabel2;
253     private javax.swing.JRadioButton JavaDoc publicRB;
254     private javax.swing.JTextField JavaDoc publicTF;
255     private javax.swing.JRadioButton JavaDoc systemRB;
256     private javax.swing.JTextField JavaDoc systemTF;
257     private javax.swing.JLabel JavaDoc titleLabel;
258     private javax.swing.JLabel JavaDoc uriLabel;
259     private javax.swing.JTextField JavaDoc uriTF;
260     // End of variables declaration//GEN-END:variables
261

262     /** Useful DocumentListener class that can be added to the panel's text compoents */
263     private class DocListener implements javax.swing.event.DocumentListener JavaDoc {
264         CatalogEntryPanel panel;
265         
266         public DocListener(CatalogEntryPanel panel) {
267             this.panel=panel;
268         }
269         /**
270          * Method from DocumentListener
271          */

272         public void changedUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
273             panel.checkValues();
274         }
275
276         /**
277          * Method from DocumentListener
278          */

279         public void insertUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
280             panel.checkValues();
281         }
282
283         /**
284          * Method from DocumentListener
285          */

286         public void removeUpdate(javax.swing.event.DocumentEvent JavaDoc evt) {
287             panel.checkValues();
288         }
289     }
290 }
291
Popular Tags