1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.netbeans.lib.awtextra;
15
16 import java.awt.Dimension;
17 import java.awt.Point;
18
19 /*** An object that encapsulates position and (optionally) size for
20 * Absolute positioning of components.
21 *
22 * @see AbsoluteLayout
23 * @version 1.01, Aug 19, 1998
24 */
25 public class AbsoluteConstraints implements java.io.Serializable {
26 /*** generated Serialized Version UID */
27 static final long serialVersionUID = 5261460716622152494L;
28
29 /*** The X position of the component */
30 public int x;
31 /*** The Y position of the component */
32 public int y;
33 /*** The width of the component or -1 if the component's preferred width should be used */
34 public int width = -1;
35 /*** The height of the component or -1 if the component's preferred height should be used */
36 public int height = -1;
37
38 /*** Creates a new AbsoluteConstraints for specified position.
39 * @param pos The position to be represented by this AbsoluteConstraints
40 */
41 public AbsoluteConstraints(Point pos) {
42 this (pos.x, pos.y);
43 }
44
45 /*** Creates a new AbsoluteConstraints for specified position.
46 * @param x The X position to be represented by this AbsoluteConstraints
47 * @param y The Y position to be represented by this AbsoluteConstraints
48 */
49 public AbsoluteConstraints(int x, int y) {
50 this.x = x;
51 this.y = y;
52 }
53
54 /*** Creates a new AbsoluteConstraints for specified position and size.
55 * @param pos The position to be represented by this AbsoluteConstraints
56 * @param size The size to be represented by this AbsoluteConstraints or null
57 * if the component's preferred size should be used
58 */
59 public AbsoluteConstraints(Point pos, Dimension size) {
60 this.x = pos.x;
61 this.y = pos.y;
62 if (size != null) {
63 this.width = size.width;
64 this.height = size.height;
65 }
66 }
67
68 /*** Creates a new AbsoluteConstraints for specified position and size.
69 * @param x The X position to be represented by this AbsoluteConstraints
70 * @param y The Y position to be represented by this AbsoluteConstraints
71 * @param width The width to be represented by this AbsoluteConstraints or -1 if the
72 * component's preferred width should be used
73 * @param height The height to be represented by this AbsoluteConstraints or -1 if the
74 * component's preferred height should be used
75 */
76 public AbsoluteConstraints(int x, int y, int width, int height) {
77 this.x = x;
78 this.y = y;
79 this.width = width;
80 this.height = height;
81 }
82
83 /*** @return The X position represented by this AbsoluteConstraints */
84 public int getX () {
85 return x;
86 }
87
88 /*** @return The Y position represented by this AbsoluteConstraints */
89 public int getY () {
90 return y;
91 }
92
93 /*** @return The width represented by this AbsoluteConstraints or -1 if the
94 * component's preferred width should be used
95 */
96 public int getWidth () {
97 return width;
98 }
99
100 /*** @return The height represented by this AbsoluteConstraints or -1 if the
101 * component's preferred height should be used
102 */
103 public int getHeight () {
104 return height;
105 }
106
107 public String toString () {
108 return super.toString () +" [x="+x+", y="+y+", width="+width+", height="+height+"]";
109 }
110
111 }
112