KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > ui > basic > editors > NamespacePanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * NamespacePanel.java
22  *
23  * Created on December 20, 2005, 5:49 PM
24  */

25
26 package org.netbeans.modules.xml.schema.ui.basic.editors;
27
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import java.util.Collection JavaDoc;
31 import javax.swing.event.DocumentEvent JavaDoc;
32 import javax.swing.event.DocumentListener JavaDoc;
33 import javax.swing.event.ListSelectionEvent JavaDoc;
34 import javax.swing.event.ListSelectionListener JavaDoc;
35
36 /**
37  *
38  * @author Todd Fast, todd.fast@sun.com
39  */

40 public class NamespacePanel extends javax.swing.JPanel JavaDoc
41         implements ActionListener JavaDoc, ListSelectionListener JavaDoc, DocumentListener JavaDoc {
42
43     static final long serialVersionUID = 1L;
44     public static final String JavaDoc PROP_VALID_SELECTION="validSelection";
45     private boolean isValid=true;
46     /** Creates new form NotationSystemForm */
47     public NamespacePanel(String JavaDoc currentTns, Collection JavaDoc<String JavaDoc> uris, Collection JavaDoc<NamespaceEditor.Option> options) {
48         initComponents();
49         initialize(currentTns,uris,options);
50     }
51
52     /** This method is called from within the constructor to
53      * initialize the form.
54      * WARNING: Do NOT modify this code. The content of this method is
55      * always regenerated by the Form Editor.
56      */

57     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
58
private void initComponents() {
59         buttonGroup1 = new javax.swing.ButtonGroup JavaDoc();
60         noNamespaceRadioButton = new javax.swing.JRadioButton JavaDoc();
61         schemaNamespaceRadioButton = new javax.swing.JRadioButton JavaDoc();
62         otherNamespaceRadioButton = new javax.swing.JRadioButton JavaDoc();
63         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
64         uriList = new javax.swing.JList JavaDoc();
65         otherNamespaceTextField = new javax.swing.JTextField JavaDoc();
66         dummyLabel1 = new javax.swing.JLabel JavaDoc();
67         dummyLabel2 = new javax.swing.JLabel JavaDoc();
68
69         org.openide.awt.Mnemonics.setLocalizedText(noNamespaceRadioButton, org.openide.util.NbBundle.getMessage(NamespacePanel.class, "LBL_NoNamespace"));
70         noNamespaceRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(NamespacePanel.class, "HINT_NoNamespace"));
71         noNamespaceRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
72         noNamespaceRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
73         buttonGroup1.add(noNamespaceRadioButton);
74         noNamespaceRadioButton.addActionListener(this);
75
76         org.openide.awt.Mnemonics.setLocalizedText(schemaNamespaceRadioButton, org.openide.util.NbBundle.getMessage(NamespacePanel.class, "LBL_SchemaNamespace"));
77         schemaNamespaceRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(NamespacePanel.class, "HINT_SchemaNamespace"));
78         schemaNamespaceRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
79         schemaNamespaceRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
80         buttonGroup1.add(schemaNamespaceRadioButton);
81         schemaNamespaceRadioButton.addActionListener(this);
82
83         org.openide.awt.Mnemonics.setLocalizedText(otherNamespaceRadioButton, org.openide.util.NbBundle.getMessage(NamespacePanel.class, "LBL_OtherNamespace"));
84         otherNamespaceRadioButton.setToolTipText(org.openide.util.NbBundle.getMessage(NamespacePanel.class, "HINT_OtherNamespace"));
85         otherNamespaceRadioButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
86         otherNamespaceRadioButton.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
87         buttonGroup1.add(otherNamespaceRadioButton);
88         otherNamespaceRadioButton.addActionListener(this);
89
90         uriList.addListSelectionListener(this);
91         jScrollPane1.setViewportView(uriList);
92
93         otherNamespaceTextField.setText(org.openide.util.NbBundle.getMessage(NamespacePanel.class, "TXT_defaultTNS"));
94         otherNamespaceTextField.getDocument().addDocumentListener(this);
95         otherNamespaceTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(NamespacePanel.class, "HINT_OtherNamespace"));
96         otherNamespaceTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(NamespacePanel.class, "HINT_OtherNamespace"));
97
98         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
99         this.setLayout(layout);
100         layout.setHorizontalGroup(
101             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
102             .add(layout.createSequentialGroup()
103                 .addContainerGap()
104                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
105                     .add(layout.createSequentialGroup()
106                         .add(17, 17, 17)
107                         .add(otherNamespaceTextField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE))
108                     .add(layout.createSequentialGroup()
109                         .add(17, 17, 17)
110                         .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 363, Short.MAX_VALUE))
111                     .add(layout.createSequentialGroup()
112                         .add(schemaNamespaceRadioButton)
113                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
114                         .add(dummyLabel2))
115                     .add(otherNamespaceRadioButton)
116                     .add(layout.createSequentialGroup()
117                         .add(noNamespaceRadioButton)
118                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
119                         .add(dummyLabel1)))
120                 .addContainerGap())
121         );
122         layout.setVerticalGroup(
123             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
124             .add(layout.createSequentialGroup()
125                 .add(11, 11, 11)
126                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
127                     .add(noNamespaceRadioButton)
128                     .add(dummyLabel1))
129                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
130                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
131                     .add(schemaNamespaceRadioButton)
132                     .add(dummyLabel2))
133                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
134                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 124, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
135                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
136                 .add(otherNamespaceRadioButton)
137                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
138                 .add(otherNamespaceTextField, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
139                 .addContainerGap(94, Short.MAX_VALUE))
140         );
141     }// </editor-fold>//GEN-END:initComponents
142

143
144     private void initialize(String JavaDoc currentTns, final Collection JavaDoc<String JavaDoc> uris, Collection JavaDoc<NamespaceEditor.Option> options) {
145         // hide radio button for uri list and uri list
146
if (uris==null || uris.isEmpty()) {
147             schemaNamespaceRadioButton.setVisible(false);
148             uriList.setVisible(false);
149             jScrollPane1.setVisible(false);
150         } else {
151             uriList.setListData(uris.toArray(new String JavaDoc[uris.size()]));
152         }
153         // hide other radio buttons if needed
154
if(!options.contains(NamespaceEditor.Option.None)) {
155             noNamespaceRadioButton.setSelected(false);
156             noNamespaceRadioButton.setVisible(false);
157         }
158         if(currentTns==null || currentTns.trim().length()==0) {
159             uriList.setEnabled(false);
160             if(noNamespaceRadioButton.isVisible()) {
161                 noNamespaceRadioButton.setSelected(true);
162                 otherNamespaceTextField.setEnabled(false);
163             } else if (otherNamespaceRadioButton.isVisible()) {
164                 otherNamespaceRadioButton.setSelected(true);
165                 otherNamespaceTextField.setEnabled(true);
166             }
167         } else if(uris!=null && uris.contains(currentTns)) {
168             schemaNamespaceRadioButton.setSelected(true);
169             uriList.setSelectedValue(currentTns,true);
170             uriList.setEnabled(true);
171             otherNamespaceTextField.setEnabled(false);
172         } else {
173             uriList.setEnabled(false);
174             if(otherNamespaceRadioButton.isVisible()) {
175                 otherNamespaceRadioButton.setSelected(true);
176                 otherNamespaceTextField.setText(currentTns);
177                 otherNamespaceTextField.setEnabled(true);
178             }
179         }
180     }
181     
182     public void checkValidity() {
183         boolean newValue = false;
184         if(noNamespaceRadioButton.isSelected()) {
185             newValue = true;
186         } else if(schemaNamespaceRadioButton.isSelected()) {
187             newValue = uriList.getSelectedValue()!=null;
188         } else if(otherNamespaceRadioButton.isSelected()) {
189             newValue = !otherNamespaceTextField.getText().equals("");
190         }
191         firePropertyChange(PROP_VALID_SELECTION,isValid,newValue);
192         isValid = newValue;
193     }
194
195     public String JavaDoc getCurrentSelection() {
196         if(schemaNamespaceRadioButton.isSelected()) {
197             return (String JavaDoc) uriList.getSelectedValue();
198         } else if (otherNamespaceRadioButton.isSelected()){
199             String JavaDoc otherUri = otherNamespaceTextField.getText().trim();
200             if (otherUri.length()>0) return otherUri;
201         }
202         return null;
203     }
204
205     public void actionPerformed(ActionEvent JavaDoc evt) {
206         Object JavaDoc source = evt.getSource();
207         if(source.equals(noNamespaceRadioButton)) {
208             uriList.setEnabled(false);
209             otherNamespaceTextField.setEnabled(false);
210         } else if(source.equals(otherNamespaceRadioButton)){
211             uriList.setEnabled(false);
212             otherNamespaceTextField.setEnabled(true);
213         } else if(source.equals(schemaNamespaceRadioButton)) {
214             otherNamespaceTextField.setEnabled(false);
215             uriList.setEnabled(true);
216         }
217         checkValidity();
218     }
219
220     public void valueChanged(ListSelectionEvent JavaDoc e) {
221         checkValidity();
222     }
223
224     public void insertUpdate(DocumentEvent JavaDoc e) {
225         checkValidity();
226     }
227
228     public void removeUpdate(DocumentEvent JavaDoc e) {
229         checkValidity();
230     }
231
232     public void changedUpdate(DocumentEvent JavaDoc e) {
233     }
234
235     // Variables declaration - do not modify//GEN-BEGIN:variables
236
public javax.swing.ButtonGroup JavaDoc buttonGroup1;
237     public javax.swing.JLabel JavaDoc dummyLabel1;
238     public javax.swing.JLabel JavaDoc dummyLabel2;
239     public javax.swing.JScrollPane JavaDoc jScrollPane1;
240     public javax.swing.JRadioButton JavaDoc noNamespaceRadioButton;
241     public javax.swing.JRadioButton JavaDoc otherNamespaceRadioButton;
242     public javax.swing.JTextField JavaDoc otherNamespaceTextField;
243     public javax.swing.JRadioButton JavaDoc schemaNamespaceRadioButton;
244     public javax.swing.JList JavaDoc uriList;
245     // End of variables declaration//GEN-END:variables
246

247 }
248
Popular Tags