KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > catalog > impl > XCatalogCustomizer


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;
20
21 import java.beans.*;
22 import java.io.File JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24
25 /**
26  * XML catalog customizer. It allows to customize catalog location.
27  *
28  * @author Petr Kuzel
29  * @version
30  */

31 public class XCatalogCustomizer extends javax.swing.JPanel JavaDoc implements Customizer {
32
33     /** Serial Version UID */
34     private static final long serialVersionUID =-1437233290256708363L;
35
36     XCatalog model = null;
37
38     /** Creates new customizer XCatalogCustomizer */
39     public XCatalogCustomizer() {
40         initComponents ();
41
42         this.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_XCatalogCustomizer"));
43         locationLabel.setDisplayedMnemonic((Util.THIS.getString("XCatalogCustomizer.locationLabel.mne")).charAt(0));
44         locationTextField.getAccessibleContext().setAccessibleDescription(Util.THIS.getString("ACSD_locationTextField"));
45     }
46
47     /** This method is called from within the constructor to
48      * initialize the form.
49      * WARNING: Do NOT modify this code. The content of this method is
50      * always regenerated by the FormEditor.
51      */

52     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
53
private void initComponents() {
54         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
55
56         locationLabel = new javax.swing.JLabel JavaDoc();
57         locationTextField = new javax.swing.JTextField JavaDoc();
58         descTextArea = new javax.swing.JTextArea JavaDoc();
59         selectButton = new javax.swing.JButton JavaDoc();
60
61         setLayout(new java.awt.GridBagLayout JavaDoc());
62
63         locationLabel.setLabelFor(locationTextField);
64         locationLabel.setText(Util.THIS.getString ("XCatalogCustomizer.locationLabel.text"));
65         add(locationLabel, new java.awt.GridBagConstraints JavaDoc());
66
67         locationTextField.setColumns(20);
68         locationTextField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
69             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
70                 locationTextFieldActionPerformed(evt);
71             }
72         });
73         locationTextField.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
74             public void focusLost(java.awt.event.FocusEvent JavaDoc evt) {
75                 locationTextFieldFocusLost(evt);
76             }
77         });
78
79         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
80         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
81         gridBagConstraints.weightx = 1.0;
82         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
83         add(locationTextField, gridBagConstraints);
84
85         descTextArea.setEditable(false);
86         descTextArea.setFont(javax.swing.UIManager.getFont ("Label.font"));
87         descTextArea.setForeground(new java.awt.Color JavaDoc(102, 102, 153));
88         descTextArea.setLineWrap(true);
89         descTextArea.setText(Util.THIS.getString("DESC_xcatalog_fmts"));
90         descTextArea.setWrapStyleWord(true);
91         descTextArea.setDisabledTextColor(javax.swing.UIManager.getColor ("Label.foreground"));
92         descTextArea.setEnabled(false);
93         descTextArea.setOpaque(false);
94         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
95         gridBagConstraints.gridx = 0;
96         gridBagConstraints.gridy = 1;
97         gridBagConstraints.gridwidth = 3;
98         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
99         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
100         gridBagConstraints.weightx = 1.0;
101         gridBagConstraints.weighty = 1.0;
102         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 0, 0);
103         add(descTextArea, gridBagConstraints);
104
105         selectButton.setText(java.util.ResourceBundle.getBundle("org/netbeans/modules/xml/catalog/impl/Bundle").getString("PROP_choose_file"));
106         selectButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
107             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
108                 selectButtonActionPerformed(evt);
109             }
110         });
111
112         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
113         gridBagConstraints.gridx = 2;
114         gridBagConstraints.gridy = 0;
115         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
116         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
117         add(selectButton, gridBagConstraints);
118
119     }// </editor-fold>//GEN-END:initComponents
120

121     private void selectButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_selectButtonActionPerformed
122
File JavaDoc f = org.netbeans.modules.xml.catalog.lib.Util.selectCatalogFile("txt xml cat catalog"); // NOI18N
123
if (f == null) return;
124         try {
125             String JavaDoc location = f.toURL().toExternalForm();
126             locationTextField.setText(location);
127             model.setLocation(location);
128         } catch (MalformedURLException JavaDoc ex) {
129             // ignore
130
}
131     }//GEN-LAST:event_selectButtonActionPerformed
132

133     //!!! find out whether action performed is not enought
134

135     private void locationTextFieldFocusLost(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_locationTextFieldFocusLost
136
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("FocusLost-setting location: " + locationTextField.getText()); // NOI18N
137
model.setSource(locationTextField.getText());
138     }//GEN-LAST:event_locationTextFieldFocusLost
139

140     private void locationTextFieldActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_locationTextFieldActionPerformed
141
if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("ActionPerformed-setting location: " + locationTextField.getText()); // NOI18N
142
model.setSource(locationTextField.getText());
143     }//GEN-LAST:event_locationTextFieldActionPerformed
144

145     /**
146      * Set model for this customizer.
147      */

148     public void setObject(java.lang.Object JavaDoc peer) {
149         if ((peer instanceof XCatalog) == false) {
150             throw new IllegalArgumentException JavaDoc("XCatalog instance expected (" + peer.getClass() + ")."); // NOI18N
151
}
152         
153         model = (XCatalog) peer;
154         locationTextField.setText(model.getSource());
155     }
156
157     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc p1) {
158     }
159     
160     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc p1) {
161     }
162     
163     // Variables declaration - do not modify//GEN-BEGIN:variables
164
private javax.swing.JTextArea JavaDoc descTextArea;
165     private javax.swing.JLabel JavaDoc locationLabel;
166     private javax.swing.JTextField JavaDoc locationTextField;
167     private javax.swing.JButton JavaDoc selectButton;
168     // End of variables declaration//GEN-END:variables
169

170 }
171
Popular Tags