001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.xml.catalog.impl.sun;
042:
043: import java.beans.*;
044: import java.io.File;
045: import java.net.MalformedURLException;
046: import org.openide.util.NbBundle;
047:
048: /**
049: * Catalog customizer. It allows to customize catalog location and
050: * preferences.
051: *
052: * @author Petr Kuzel
053: * @version
054: */
055: public class CatalogCustomizer extends javax.swing.JPanel implements
056: Customizer {
057:
058: /** Serial Version UID */
059: private static final long serialVersionUID = -1437233290256708364L;
060:
061: Catalog model = null;
062:
063: /** Creates new customizer XCatalogCustomizer */
064: public CatalogCustomizer() {
065: initComponents();
066:
067: // A11Y
068: this .getAccessibleContext().setAccessibleDescription(
069: NbBundle.getMessage(CatalogCustomizer.class,
070: "ACSD_CatalogCustomizer"));
071:
072: locationLabel.setDisplayedMnemonic((NbBundle.getMessage(
073: CatalogCustomizer.class,
074: "CatalogCustomizer.locationLabel.mne")).charAt(0));
075: locationTextField.getAccessibleContext()
076: .setAccessibleDescription(
077: NbBundle.getMessage(CatalogCustomizer.class,
078: "ACSD_locationTextField"));
079:
080: preferCheckBox.setMnemonic(NbBundle.getMessage(
081: CatalogCustomizer.class, "MNE_preference").charAt(0));
082: preferCheckBox.getAccessibleContext().setAccessibleDescription(
083: NbBundle.getMessage(CatalogCustomizer.class,
084: "ACSD_preference"));
085:
086: selectButton.setMnemonic(NbBundle.getMessage(
087: CatalogCustomizer.class, "MNE_file").charAt(0));
088: selectButton.getAccessibleContext().setAccessibleDescription(
089: NbBundle.getMessage(CatalogCustomizer.class,
090: "ACSD_file"));
091: }
092:
093: /** This method is called from within the constructor to
094: * initialize the form.
095: * WARNING: Do NOT modify this code. The content of this method is
096: * always regenerated by the FormEditor.
097: */
098: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
099: private void initComponents() {
100: java.awt.GridBagConstraints gridBagConstraints;
101:
102: locationLabel = new javax.swing.JLabel();
103: locationTextField = new javax.swing.JTextField();
104: selectButton = new javax.swing.JButton();
105: preferCheckBox = new javax.swing.JCheckBox();
106: descTextArea = new javax.swing.JTextArea();
107:
108: setLayout(new java.awt.GridBagLayout());
109:
110: locationLabel.setLabelFor(locationTextField);
111: locationLabel.setText(NbBundle.getMessage(
112: CatalogCustomizer.class,
113: "CatalogCustomizer.locationLabel.text")); // NOI18N
114: add(locationLabel, new java.awt.GridBagConstraints());
115:
116: locationTextField.setColumns(40);
117: locationTextField
118: .addActionListener(new java.awt.event.ActionListener() {
119: public void actionPerformed(
120: java.awt.event.ActionEvent evt) {
121: locationTextFieldActionPerformed(evt);
122: }
123: });
124: locationTextField
125: .addFocusListener(new java.awt.event.FocusAdapter() {
126: public void focusLost(java.awt.event.FocusEvent evt) {
127: locationTextFieldFocusLost(evt);
128: }
129: });
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
132: gridBagConstraints.weightx = 1.0;
133: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
134: add(locationTextField, gridBagConstraints);
135:
136: java.util.ResourceBundle bundle = java.util.ResourceBundle
137: .getBundle("org/netbeans/modules/xml/catalog/impl/sun/Bundle"); // NOI18N
138: selectButton.setText(bundle.getString("PROP_choose_file")); // NOI18N
139: selectButton
140: .addActionListener(new java.awt.event.ActionListener() {
141: public void actionPerformed(
142: java.awt.event.ActionEvent evt) {
143: selectButtonActionPerformed(evt);
144: }
145: });
146: gridBagConstraints = new java.awt.GridBagConstraints();
147: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
148: gridBagConstraints.insets = new java.awt.Insets(0, 12, 0, 0);
149: add(selectButton, gridBagConstraints);
150:
151: preferCheckBox.setText(bundle.getString("LBL_preference")); // NOI18N
152: preferCheckBox.setToolTipText(NbBundle.getMessage(
153: CatalogCustomizer.class, "HINT_pp")); // NOI18N
154: preferCheckBox
155: .addChangeListener(new javax.swing.event.ChangeListener() {
156: public void stateChanged(
157: javax.swing.event.ChangeEvent evt) {
158: preferCheckBoxStateChanged(evt);
159: }
160: });
161: gridBagConstraints = new java.awt.GridBagConstraints();
162: gridBagConstraints.gridx = 1;
163: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
164: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
165: gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
166: gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 11);
167: add(preferCheckBox, gridBagConstraints);
168:
169: descTextArea.setColumns(40);
170: descTextArea.setEditable(false);
171: descTextArea.setFont(javax.swing.UIManager
172: .getFont("Label.font"));
173: descTextArea.setForeground(new java.awt.Color(102, 102, 153));
174: descTextArea.setLineWrap(true);
175: descTextArea.setRows(4);
176: descTextArea.setText(NbBundle.getMessage(
177: CatalogCustomizer.class, "DESC_catalog_fmts")); // NOI18N
178: descTextArea.setWrapStyleWord(true);
179: descTextArea.setDisabledTextColor(javax.swing.UIManager
180: .getColor("Label.foreground"));
181: descTextArea.setEnabled(false);
182: descTextArea.setOpaque(false);
183: gridBagConstraints = new java.awt.GridBagConstraints();
184: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
185: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
186: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
187: gridBagConstraints.weightx = 1.0;
188: gridBagConstraints.weighty = 1.0;
189: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
190: add(descTextArea, gridBagConstraints);
191: }// </editor-fold>//GEN-END:initComponents
192:
193: private void selectButtonActionPerformed(
194: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
195: File f = org.netbeans.modules.xml.catalog.lib.Util
196: .selectCatalogFile("txt xml cat catalog"); // NOI18N
197: if (f == null)
198: return;
199: try {
200: String location = f.toURL().toExternalForm();
201: locationTextField.setText(location);
202: model.setLocation(location);
203: } catch (MalformedURLException ex) {
204: // ignore
205: }
206: }//GEN-LAST:event_selectButtonActionPerformed
207:
208: private void preferCheckBoxStateChanged(
209: javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_preferCheckBoxStateChanged
210: if (model != null)
211: model.setPreferPublic(preferCheckBox.isSelected());
212: }//GEN-LAST:event_preferCheckBoxStateChanged
213:
214: //!!! find out whether action performed is not enough
215:
216: private void locationTextFieldFocusLost(
217: java.awt.event.FocusEvent evt) {//GEN-FIRST:event_locationTextFieldFocusLost
218: //if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("FocusLost-setting location: " + locationTextField.getText()); // NOI18N
219: model.setLocation(locationTextField.getText());
220: }//GEN-LAST:event_locationTextFieldFocusLost
221:
222: private void locationTextFieldActionPerformed(
223: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_locationTextFieldActionPerformed
224: //if ( Util.THIS.isLoggable() ) /* then */ Util.THIS.debug("ActionPerformed-setting location: " + locationTextField.getText()); // NOI18N
225: model.setLocation(locationTextField.getText());
226: }//GEN-LAST:event_locationTextFieldActionPerformed
227:
228: /**
229: * Set model for this customizer.
230: */
231: public void setObject(java.lang.Object peer) {
232: if ((peer instanceof Catalog) == false) {
233: throw new IllegalArgumentException(
234: "Catalog instance expected (" + peer.getClass()
235: + ")."); // NOI18N
236: }
237:
238: model = (Catalog) peer;
239: locationTextField.setText(model.getLocation());
240: preferCheckBox.setSelected(model.isPreferPublic());
241: }
242:
243: public void addPropertyChangeListener(
244: java.beans.PropertyChangeListener p1) {
245: }
246:
247: public void removePropertyChangeListener(
248: java.beans.PropertyChangeListener p1) {
249: }
250:
251: // Variables declaration - do not modify//GEN-BEGIN:variables
252: private javax.swing.JTextArea descTextArea;
253: private javax.swing.JLabel locationLabel;
254: private javax.swing.JTextField locationTextField;
255: private javax.swing.JCheckBox preferCheckBox;
256: private javax.swing.JButton selectButton;
257: // End of variables declaration//GEN-END:variables
258:
259: }
|