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:
042: package org.netbeans.beaninfo.editors;
043:
044: import java.awt.Dimension;
045: import org.netbeans.core.UIExceptions;
046: import org.openide.explorer.propertysheet.ExPropertyEditor;
047: import org.openide.util.NbBundle;
048:
049: /** A property editor for Dimension class.
050: * @author Petr Hamernik
051: * @version 0.10, 21 Jul, 1998
052: */
053: public class DimensionEditor extends ArrayOfIntSupport {
054: public DimensionEditor() {
055: super ("java.awt.Dimension", 2); // NOI18N
056: }
057:
058: /** Abstract method for translating the value from getValue() method to array of int. */
059: int[] getValues() {
060: Dimension d = (Dimension) getValue();
061: return new int[] { d.width, d.height };
062: }
063:
064: static String toArr(int[] ints) {
065: StringBuffer sb = new StringBuffer();
066: if ((ints != null) && (ints.length > 0)) {
067: for (int i = 0; i < ints.length; i++) {
068: sb.append(ints[i]);
069: if (i != ints.length - 1) {
070: sb.append(','); //NOI18N
071: }
072: }
073: } else {
074: return NbBundle.getMessage(DimensionEditor.class,
075: "MSG_NULL_OR_EMPTY"); //NOI18N
076: }
077: return sb.toString();
078: }
079:
080: /** Abstract method for translating the array of int to value
081: * which is set to method setValue(XXX)
082: */
083: void setValues(int[] val) {
084: if ((val[0] < 0) || (val[1] < 0)) {
085: String msg = NbBundle.getMessage(DimensionEditor.class,
086: "CTL_NegativeSize"); //NOI18N
087: IllegalArgumentException iae = new IllegalArgumentException(
088: "Negative value"); //NOI18N
089: UIExceptions.annotateUser(iae, iae.getMessage(), msg, null,
090: new java.util.Date());
091: throw iae;
092: } else
093: setValue(new Dimension(val[0], val[1]));
094: }
095:
096: public boolean supportsCustomEditor() {
097: return true;
098: }
099:
100: public java.awt.Component getCustomEditor() {
101: return new PointCustomEditor(this , env);
102: }
103:
104: /** @return the format of value set in property editor. */
105: String getHintFormat() {
106: return NbBundle.getMessage(DimensionEditor.class,
107: "CTL_HintFormat"); //NOI18N
108: }
109:
110: /** Provides name of XML tag to use for XML persistence of the property value */
111: protected String getXMLValueTag() {
112: return "Dimension"; // NOI18N
113: }
114:
115: }
|