KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > beaninfo > editors > DimensionCustomEditor


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.beaninfo.editors;
21
22 import java.awt.Dimension JavaDoc;
23 import java.beans.PropertyChangeEvent JavaDoc;
24 import java.beans.PropertyChangeListener JavaDoc;
25 import java.util.ResourceBundle JavaDoc;
26 import org.netbeans.core.UIExceptions;
27 import org.openide.awt.Mnemonics;
28
29 import org.openide.explorer.propertysheet.PropertyEnv;
30 import org.openide.util.NbBundle;
31
32 /**
33  *
34  * @author IanFormanek, Vladimir Zboril
35  */

36 public class DimensionCustomEditor extends javax.swing.JPanel JavaDoc implements PropertyChangeListener JavaDoc {
37
38     static final long serialVersionUID =3718340148720193844L;
39
40     /** Creates new form DimensionCustomEditor */
41     public DimensionCustomEditor(DimensionEditor editor) {
42         initComponents();
43         this.editor = editor;
44         this.editor.env.setState(PropertyEnv.STATE_NEEDS_VALIDATION);
45         this.editor.env.addPropertyChangeListener(this);
46
47         Dimension JavaDoc dimension = (Dimension JavaDoc)editor.getValue ();
48         
49         if (dimension == null) dimension = new Dimension JavaDoc (0, 0);
50         jLabel1.setText(NbBundle.getMessage(DimensionCustomEditor.class, "CTL_Dimension"));
51         Mnemonics.setLocalizedText(widthLabel, NbBundle.getMessage(DimensionCustomEditor.class, "CTL_Width"));
52         widthLabel.setLabelFor(widthField);
53         Mnemonics.setLocalizedText(heightLabel, NbBundle.getMessage(DimensionCustomEditor.class, "CTL_Height"));
54         heightLabel.setLabelFor(heightField);
55
56         widthField.setText (String.valueOf(dimension.width));
57         heightField.setText (String.valueOf(dimension.height));
58 // HelpCtx.setHelpIDString (this, DimensionCustomEditor.class.getName ());
59

60         widthField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DimensionCustomEditor.class, "ACSD_CTL_Width"));
61         heightField.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DimensionCustomEditor.class, "ACSD_CTL_Height"));
62         getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(DimensionCustomEditor.class, "ACSD_DimensionCustomEditor"));
63     }
64
65     public java.awt.Dimension JavaDoc getPreferredSize () {
66         return new java.awt.Dimension JavaDoc (280, 160);
67     }
68
69     private Object JavaDoc getPropertyValue () throws IllegalStateException JavaDoc {
70         try {
71             int width = Integer.parseInt (widthField.getText ());
72             int height = Integer.parseInt (heightField.getText ());
73             if ((width < 0) || (height < 0)) {
74                 IllegalStateException JavaDoc ise = new IllegalStateException JavaDoc();
75                 UIExceptions.annotateUser(ise, null,
76                     NbBundle.getMessage(DimensionCustomEditor.class, "CTL_NegativeSize"), null, null);
77                 throw ise;
78             }
79             return new Dimension JavaDoc (width, height);
80         } catch (NumberFormatException JavaDoc e) {
81             IllegalStateException JavaDoc ise = new IllegalStateException JavaDoc();
82             UIExceptions.annotateUser(ise, null,
83                 NbBundle.getMessage(DimensionCustomEditor.class, "CTL_NegativeSize"), null, null);
84             throw ise;
85         }
86     }
87
88     public void propertyChange(PropertyChangeEvent JavaDoc evt) {
89         if (PropertyEnv.PROP_STATE.equals(evt.getPropertyName()) && evt.getNewValue() == PropertyEnv.STATE_VALID) {
90             editor.setValue(getPropertyValue());
91         }
92     }
93     
94     /** This method is called from within the constructor to
95      * initialize the form.
96      * WARNING: Do NOT modify this code. The content of this method is
97      * always regenerated by the Form Editor.
98      */

99     private void initComponents() {//GEN-BEGIN:initComponents
100
insidePanel = new javax.swing.JPanel JavaDoc();
101         jLabel1 = new javax.swing.JLabel JavaDoc();
102         widthLabel = new javax.swing.JLabel JavaDoc();
103         widthField = new javax.swing.JTextField JavaDoc();
104         heightLabel = new javax.swing.JLabel JavaDoc();
105         heightField = new javax.swing.JTextField JavaDoc();
106         
107         setLayout(new java.awt.GridBagLayout JavaDoc());
108         java.awt.GridBagConstraints JavaDoc gridBagConstraints1;
109         
110         insidePanel.setLayout(new java.awt.GridBagLayout JavaDoc());
111         java.awt.GridBagConstraints JavaDoc gridBagConstraints2;
112         
113         jLabel1.setText("jLabel1");
114         jLabel1.setLabelFor(insidePanel);
115         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
116         gridBagConstraints2.gridx = 0;
117         gridBagConstraints2.gridy = 0;
118         gridBagConstraints2.gridwidth = java.awt.GridBagConstraints.REMAINDER;
119         gridBagConstraints2.insets = new java.awt.Insets JavaDoc(12, 12, 0, 0);
120         gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
121         gridBagConstraints2.weightx = 1.0;
122         insidePanel.add(jLabel1, gridBagConstraints2);
123         
124         widthLabel.setText("jLabel2");
125         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
126         gridBagConstraints2.gridx = 0;
127         gridBagConstraints2.gridy = 1;
128         gridBagConstraints2.insets = new java.awt.Insets JavaDoc(12, 17, 0, 0);
129         gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
130         insidePanel.add(widthLabel, gridBagConstraints2);
131         
132         widthField.setColumns(5);
133         widthField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
134             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
135                 updateInsets(evt);
136             }
137         });
138         
139         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
140         gridBagConstraints2.gridx = 1;
141         gridBagConstraints2.gridy = 1;
142         gridBagConstraints2.insets = new java.awt.Insets JavaDoc(12, 5, 0, 12);
143         gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
144         insidePanel.add(widthField, gridBagConstraints2);
145         
146         heightLabel.setText("jLabel3");
147         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints2.gridx = 0;
149         gridBagConstraints2.gridy = 2;
150         gridBagConstraints2.insets = new java.awt.Insets JavaDoc(5, 17, 0, 0);
151         gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
152         gridBagConstraints2.weighty = 1.0;
153         insidePanel.add(heightLabel, gridBagConstraints2);
154         
155         heightField.setColumns(5);
156         heightField.addActionListener(new java.awt.event.ActionListener JavaDoc() {
157             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
158                 updateInsets(evt);
159             }
160         });
161         
162         gridBagConstraints2 = new java.awt.GridBagConstraints JavaDoc();
163         gridBagConstraints2.gridx = 1;
164         gridBagConstraints2.gridy = 2;
165         gridBagConstraints2.insets = new java.awt.Insets JavaDoc(5, 5, 0, 12);
166         gridBagConstraints2.anchor = java.awt.GridBagConstraints.NORTHWEST;
167         insidePanel.add(heightField, gridBagConstraints2);
168         
169         gridBagConstraints1 = new java.awt.GridBagConstraints JavaDoc();
170         gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
171         gridBagConstraints1.weightx = 1.0;
172         gridBagConstraints1.weighty = 1.0;
173         add(insidePanel, gridBagConstraints1);
174         
175     }//GEN-END:initComponents
176

177     private void updateInsets(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_updateInsets
178
// Add your handling code here:
179
try {
180             int width = Integer.parseInt (widthField.getText ());
181             int height = Integer.parseInt (heightField.getText ());
182             editor.setValue (new Dimension JavaDoc (width, height));
183         } catch (NumberFormatException JavaDoc e) {
184             // [PENDING beep]
185
}
186     }//GEN-LAST:event_updateInsets
187

188     // Variables declaration - do not modify//GEN-BEGIN:variables
189
private javax.swing.JPanel JavaDoc insidePanel;
190     private javax.swing.JLabel JavaDoc jLabel1;
191     private javax.swing.JLabel JavaDoc widthLabel;
192     private javax.swing.JTextField JavaDoc widthField;
193     private javax.swing.JLabel JavaDoc heightLabel;
194     private javax.swing.JTextField JavaDoc heightField;
195     // End of variables declaration//GEN-END:variables
196

197     private DimensionEditor editor;
198 }
199
200
Popular Tags