KickJava   Java API By Example, From Geeks To Geeks.

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


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.Insets 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 Insets class.
29 * @author Petr Hamernik
30 */

31 public class InsetsEditor extends ArrayOfIntSupport {
32     public InsetsEditor() {
33         super("java.awt.Insets", 4); // NOI18N
34
}
35
36     /** Abstract method for translating the value from getValue() method to array of int. */
37     int[] getValues() {
38         Insets JavaDoc insets = (Insets JavaDoc) getValue();
39         if (insets != null) {
40             return new int[] { insets.top, insets.left, insets.bottom, insets.right };
41         } else {
42             return new int[4];
43         }
44     }
45
46     /** Abstract method for translating the array of int to value
47     * which is set to method setValue(XXX)
48     */

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