KickJava   Java API By Example, From Geeks To Geeks.

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


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.Rectangle JavaDoc;
23 import org.netbeans.core.UIExceptions;
24 import org.openide.explorer.propertysheet.ExPropertyEditor;
25 import org.openide.explorer.propertysheet.PropertyEnv;
26 import org.openide.util.NbBundle;
27
28 /** A property editor for Rectangle class.
29 * @author Petr Hamernik
30 */

31 public class RectangleEditor extends ArrayOfIntSupport {
32
33     public RectangleEditor() {
34         super("java.awt.Rectangle", 4); // NOI18N
35
}
36
37     /** Abstract method for translating the value from getValue() method to array of int. */
38     int[] getValues() {
39         Rectangle JavaDoc rect = (Rectangle JavaDoc) getValue();
40         return new int[] { rect.x, rect.y, rect.width, rect.height };
41     }
42
43     /** Abstract method for translating the array of int to value
44     * which is set to method setValue(XXX)
45     */

46     void setValues(int[] val) {
47         if ((val[0] < 0) || (val[1] < 0) || (val[2] < 0) || (val[3] < 0)) {
48             String JavaDoc msg = NbBundle.getMessage(DimensionEditor.class,
49                 "CTL_NegativeSize"); //NOI18N
50
IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc (
51                 "Negative value"); //NOI18N
52
UIExceptions.annotateUser(iae, iae.getMessage(), msg, null,
53                                      new java.util.Date JavaDoc());
54             throw iae;
55
56         }
57         else
58             setValue(new Rectangle JavaDoc(val[0], val[1], val[2], val[3]));
59     }
60
61     public boolean supportsCustomEditor () {
62         return true;
63     }
64
65     public java.awt.Component JavaDoc getCustomEditor () {
66         return new RectangleCustomEditor (this, env);
67     }
68
69     /** @return the format of value set in property editor. */
70     String JavaDoc getHintFormat() {
71         return NbBundle.getMessage(RectangleEditor.class, "CTL_HintFormatRE");
72     }
73
74     /** Provides name of XML tag to use for XML persistence of the property value */
75     protected String JavaDoc getXMLValueTag () {
76         return "Rectangle"; // NOI18N
77
}
78
79     private PropertyEnv env;
80     public void attachEnv(PropertyEnv env) {
81         //cache for custom editor
82
this.env = env;
83     }
84     
85 }
86
Popular Tags