KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.netbeans.core.UIExceptions;
24 import org.openide.explorer.propertysheet.ExPropertyEditor;
25 import org.openide.util.NbBundle;
26
27 /** A property editor for Dimension class.
28 * @author Petr Hamernik
29 * @version 0.10, 21 Jul, 1998
30 */

31 public class DimensionEditor extends ArrayOfIntSupport {
32     public DimensionEditor() {
33         super("java.awt.Dimension", 2); // NOI18N
34
}
35
36     /** Abstract method for translating the value from getValue() method to array of int. */
37     int[] getValues() {
38         Dimension JavaDoc d = (Dimension JavaDoc) getValue();
39         return new int[] { d.width, d.height };
40     }
41
42     static String JavaDoc toArr (int[] ints) {
43         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
44         if ((ints != null) && (ints.length > 0)) {
45             for (int i=0; i < ints.length; i++) {
46                 sb.append (ints[i]);
47                 if (i != ints.length-1) {
48                     sb.append (','); //NOI18N
49
}
50             }
51         } else {
52             return NbBundle.getMessage (DimensionEditor.class,
53                 "MSG_NULL_OR_EMPTY"); //NOI18N
54
}
55         return sb.toString();
56     }
57     
58     /** Abstract method for translating the array of int to value
59     * which is set to method setValue(XXX)
60     */

61     void setValues(int[] val) {
62         if ((val[0] < 0) || (val[1] < 0)) {
63             String JavaDoc msg = NbBundle.getMessage(DimensionEditor.class,
64                 "CTL_NegativeSize"); //NOI18N
65
IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc (
66                 "Negative value"); //NOI18N
67
UIExceptions.annotateUser(iae, iae.getMessage(), msg, null,
68                                      new java.util.Date JavaDoc());
69             throw iae;
70         }
71         else
72             setValue(new Dimension JavaDoc(val[0], val[1]));
73     }
74
75     public boolean supportsCustomEditor () {
76         return true;
77     }
78
79     public java.awt.Component JavaDoc getCustomEditor () {
80         return new PointCustomEditor (this, env);
81     }
82
83
84     /** @return the format of value set in property editor. */
85     String JavaDoc getHintFormat() {
86         return NbBundle.getMessage(DimensionEditor.class, "CTL_HintFormat"); //NOI18N
87
}
88
89     /** Provides name of XML tag to use for XML persistence of the property value */
90     protected String JavaDoc getXMLValueTag () {
91         return "Dimension"; // NOI18N
92
}
93
94 }
95
Popular Tags