KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > catalog > impl > sun > CatalogCustomizer


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 package org.netbeans.modules.xml.catalog.impl.sun;
20
21 import java.beans.*;
22 import java.io.File JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24
25 /**
26  * Catalog customizer. It allows to customize catalog location and
27  * preferences.
28  *
29  * @author Petr Kuzel
30  * @version
31  */

32 public class CatalogCustomizer extends javax.swing.JPanel JavaDoc implements Customizer {
33
34     /** Serial Version UID */
35     private static final long serialVersionUID =-1437233290256708364L;
36
37     Catalog model = null;
38
39     /** Creates new customizer XCatalogCustomizer */
40     public CatalogCustomizer() {
41         initComponents ();
42         
43         // A11Y
44
this.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_CatalogCustomizer"));
45         
46         locationLabel.setDisplayedMnemonic((Util.THIS.getString("CatalogCustomizer.locationLabel.mne")).charAt(0));
47         locationTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_locationTextField"));
48
49         preferCheckBox.setMnemonic(Util.THIS.getString("MNE_preference").charAt(0));
50         preferCheckBox.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_preference"));
51         
52         selectButton.setMnemonic(Util.THIS.getString("MNE_file").charAt(0));
53         selectButton.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_file"));
54     }
55
56     /** This method is called from within the constructor to
57      * initialize the form.
58      * WARNING: Do NOT modify this code. The content of this method is
59      * always regenerated by the FormEditor.
60      */

61     private void initComponents() {//GEN-BEGIN:initComponents
62
java.awt.GridBagConstraints JavaDoc gridBagConstraints;
63
64         locationLabel = new javax.swing.JLabel JavaDoc();
65         locationTextField = new javax.swing.JTextField JavaDoc();
66         selectButton = new javax.swing.JButton JavaDoc();
67         preferCheckBox = new javax.swing.JCheckBox JavaDoc();
68         descTextArea = new javax.swing.JTextArea JavaDoc();
69
70         FormListener formListener = new FormListener();
71
72         setLayout(new java.awt.GridBagLayout JavaDoc());
73
74         locationLabel.setLabelFor(locationTextField);
75         locationLabel.setText(Util.THIS.getString ("CatalogCustomizer.locationLabel.text"));
76         add(locationLabel, new java.awt.GridBagConstraints JavaDoc());
77
78         locationTextField.setColumns(40);
79         locationTextField.addActionListener(formListener);
80         locationTextField.addFocusListener(formListener);
81
82         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
83         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
84         gridBagConstraints.weightx = 1.0;
85         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
86         add(locationTextField, gridBagConstraints);
87
88         selectButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/catalog/impl/sun/Bundle").getString("PROP_choose_file"));
89         selectButton.addActionListener(formListener);
90
91         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
92         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
93         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
94         add(selectButton, gridBagConstraints);
95
96         preferCheckBox.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/catalog/impl/sun/Bundle").getString("LBL_preference"));
97         preferCheckBox.setToolTipText(Util.THIS.getString("HINT_pp"));
98         preferCheckBox.addChangeListener(formListener);
99
100         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
101         gridBagConstraints.gridx = 1;
102         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
103         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
104         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
105         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 12, 0, 11);
106         add(preferCheckBox, gridBagConstraints);
107
108         descTextArea.setColumns(40);
109         descTextArea.setEditable(false);
110         descTextArea.setFont(javax.swing.UIManager.getFont ("Label.font"));
111         descTextArea.setForeground(new java.awt.Color JavaDoc(102, 102, 153));
112         descTextArea.setLineWrap(true);
113         descTextArea.setRows(4);
114         descTextArea.setText(Util.THIS.getString("DESC_catalog_fmts"));
115         descTextArea.setWrapStyleWord(true);
116         descTextArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground"));
117         descTextArea.setEnabled(false);
118         descTextArea.setOpaque(false);
119         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
120         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
121         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
122         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
123         gridBagConstraints.weightx = 1.0;
124         gridBagConstraints.weighty = 1.0;
125         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
126         add(descTextArea, gridBagConstraints);
127
128     }
129
130     // Code for dispatching events from components to event handlers.
131

132     private class FormListener implements java.awt.event.ActionListener JavaDoc, java.awt.event.FocusListener JavaDoc, javax.swing.event.ChangeListener JavaDoc {
133         public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
134             if (evt.getSource() == locationTextField) {
135                 CatalogCustomizer.this.locationTextFieldActionPerformed(evt);
136             }
137             else if (evt.getSource() == selectButton) {
138                 CatalogCustomizer.this.selectButtonActionPerformed(evt);
139             }
140         }
141
142         public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
143         }
144
145         public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
146             if (evt.getSource() == locationTextField) {
147                 CatalogCustomizer.this.locationTextFieldFocusLost(evt);
148             }
149         }
150
151         public void stateChanged(javax.swing.event.ChangeEvent JavaDoc evt) {
152             if (evt.getSource() == preferCheckBox) {
153                 CatalogCustomizer.this.preferCheckBoxStateChanged(evt);
154             }
155         }
156     }//GEN-END:initComponents
157

158     private void selectButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_selectButtonActionPerformed
159
File JavaDoc f = org.netbeans.modules.xml.catalog.lib.Util.selectCatalogFile("txt xml cat catalog"); // NOI18N
160
if (f == null) return;
161         try {
162             String JavaDoc location = f.toURL().toExternalForm();
163             locationTextField.setText(location);
164             model.setLocation(location);
165         } catch (MalformedURLException JavaDoc ex) {
166             // ignore
167
}
168     }//GEN-LAST:event_selectButtonActionPerformed
169

170     private void preferCheckBoxStateChanged(javax.swing.event.ChangeEvent JavaDoc evt) {//GEN-FIRST:event_preferCheckBoxStateChanged
171
if (model != null) model.setPreferPublic(preferCheckBox.isSelected());
172     }//GEN-LAST:event_preferCheckBoxStateChanged
173

174     //!!! find out whether action performed is not enough
175

176     private void locationTextFieldFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_locationTextFieldFocusLost
177
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("FocusLost-setting location: " + locationTextField.getText()); // NOI18N
178
model.setLocation(locationTextField.getText());
179     }//GEN-LAST:event_locationTextFieldFocusLost
180

181     private void locationTextFieldActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_locationTextFieldActionPerformed
182
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("ActionPerformed-setting location: " + locationTextField.getText()); // NOI18N
183
model.setLocation(locationTextField.getText());
184     }//GEN-LAST:event_locationTextFieldActionPerformed
185

186     /**
187      * Set model for this customizer.
188      */

189     public void setObject(java.lang.Object JavaDoc peer) {
190         if ((peer instanceof Catalog) == false) {
191             throw new IllegalArgumentException JavaDoc("Catalog instance expected (" + peer.getClass() + ")."); // NOI18N
192
}
193         
194         model = (Catalog) peer;
195         locationTextField.setText(model.getLocation());
196         preferCheckBox.setSelected(model.isPreferPublic());
197     }
198
199     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc p1) {
200     }
201     
202     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc p1) {
203     }
204     
205     // Variables declaration - do not modify//GEN-BEGIN:variables
206
private javax.swing.JTextArea JavaDoc descTextArea;
207     private javax.swing.JLabel JavaDoc locationLabel;
208     private javax.swing.JTextField JavaDoc locationTextField;
209     private javax.swing.JCheckBox JavaDoc preferCheckBox;
210     private javax.swing.JButton JavaDoc selectButton;
211     // End of variables declaration//GEN-END:variables
212

213 }
214
Popular Tags