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.lib.awtextra;
043:
044: import java.awt.Dimension;
045: import java.awt.Point;
046:
047: /** An object that encapsulates position and (optionally) size for
048: * Absolute positioning of components.
049: *
050: * @see AbsoluteLayout
051: * @version 1.01, Aug 19, 1998
052: */
053: public class AbsoluteConstraints implements java.io.Serializable {
054: /** generated Serialized Version UID */
055: static final long serialVersionUID = 5261460716622152494L;
056:
057: /** The X position of the component */
058: public int x;
059: /** The Y position of the component */
060: public int y;
061: /** The width of the component or -1 if the component's preferred width should be used */
062: public int width = -1;
063: /** The height of the component or -1 if the component's preferred height should be used */
064: public int height = -1;
065:
066: /** Creates a new AbsoluteConstraints for specified position.
067: * @param pos The position to be represented by this AbsoluteConstraints
068: */
069: public AbsoluteConstraints(Point pos) {
070: this (pos.x, pos.y);
071: }
072:
073: /** Creates a new AbsoluteConstraints for specified position.
074: * @param x The X position to be represented by this AbsoluteConstraints
075: * @param y The Y position to be represented by this AbsoluteConstraints
076: */
077: public AbsoluteConstraints(int x, int y) {
078: this .x = x;
079: this .y = y;
080: }
081:
082: /** Creates a new AbsoluteConstraints for specified position and size.
083: * @param pos The position to be represented by this AbsoluteConstraints
084: * @param size The size to be represented by this AbsoluteConstraints or null
085: * if the component's preferred size should be used
086: */
087: public AbsoluteConstraints(Point pos, Dimension size) {
088: this .x = pos.x;
089: this .y = pos.y;
090: if (size != null) {
091: this .width = size.width;
092: this .height = size.height;
093: }
094: }
095:
096: /** Creates a new AbsoluteConstraints for specified position and size.
097: * @param x The X position to be represented by this AbsoluteConstraints
098: * @param y The Y position to be represented by this AbsoluteConstraints
099: * @param width The width to be represented by this AbsoluteConstraints or -1 if the
100: * component's preferred width should be used
101: * @param height The height to be represented by this AbsoluteConstraints or -1 if the
102: * component's preferred height should be used
103: */
104: public AbsoluteConstraints(int x, int y, int width, int height) {
105: this .x = x;
106: this .y = y;
107: this .width = width;
108: this .height = height;
109: }
110:
111: /** @return The X position represented by this AbsoluteConstraints */
112: public int getX() {
113: return x;
114: }
115:
116: /** @return The Y position represented by this AbsoluteConstraints */
117: public int getY() {
118: return y;
119: }
120:
121: /** @return The width represented by this AbsoluteConstraints or -1 if the
122: * component's preferred width should be used
123: */
124: public int getWidth() {
125: return width;
126: }
127:
128: /** @return The height represented by this AbsoluteConstraints or -1 if the
129: * component's preferred height should be used
130: */
131: public int getHeight() {
132: return height;
133: }
134:
135: public String toString() {
136: return super .toString() + " [x=" + x + ", y=" + y + ", width="
137: + width + ", height=" + height + "]";
138: }
139:
140: }
|