56
57 /**
58 * If isClient is true, the bounds represent the client window area.
59 * Otherwise, they represent the entire window area, with the insets included
60 */
61 public WindowDimensions(Point loc, Dimension size, Insets in, boolean isClient) {
62 this(new Rectangle(loc, size), in, isClient);
63 }
64
65 /**
66 * If isClient is true, the bounds represent the client window area.
67 * Otherwise, they represent the entire window area, with the insets included
68 */
69 public WindowDimensions(Rectangle bounds, boolean isClient) {
70 this(bounds, null, isClient);
71 }
72
73 public WindowDimensions(final WindowDimensions dims) {
74 this.loc = new Point(dims.loc);
75 this.size = new Dimension(dims.size);
76 this.insets = (dims.insets != null)?((Insets)dims.insets.clone()):new Insets(0, 0, 0, 0);
77 this.isClientSizeSet = dims.isClientSizeSet;
78 }
79
80 public Rectangle getClientRect() {
81 if (isClientSizeSet) {
82 return new Rectangle(loc, size);
83 } else {
84 // Calculate client bounds
85 if (insets != null) {
86 return new Rectangle(loc.x, loc.y,
87 size.width-(insets.left+insets.right),
88 size.height-(insets.top+insets.bottom));
89 } else {
90 return new Rectangle(loc, size);
91 }
92 }
93 }
94
95 public void setClientSize(Dimension size) {
96 this.size = new Dimension(size);
99
100 public void setClientSize(int width, int height) {
101 size = new Dimension(width, height);
102 isClientSizeSet = true;
103 }
104
105 public Dimension getClientSize() {
106 return getClientRect().getSize();
107 }
108
109 public void setSize(int width, int height) {
110 size = new Dimension(width, height);
111 isClientSizeSet = false;
112 }
113
114 public Dimension getSize() {
115 return getBounds().getSize();
116 }
117
118 public Insets getInsets() {
119 return (Insets)insets.clone();
120 }
121 public Rectangle getBounds() {
122 if (isClientSizeSet) {
123 Rectangle res = new Rectangle(loc, size);
124 res.width += (insets.left + insets.right);
125 res.height += (insets.top + insets.bottom);
126 return res;
127 } else {
128 return new Rectangle(loc, size);
129 }
130 }
131
132 public Point getLocation() {
133 return new Point(loc);
134 }
135 public void setLocation(int x, int y) {
136 loc = new Point(x, y);
137 }
138
139 public Rectangle getScreenBounds() {
160 return isClientSizeSet;
161 }
162
163 public String toString() {
164 return "[" + loc + ", " + size + "(" +(isClientSizeSet?"client":"bounds") + ")+" + insets + "]";
165 }
166
167 public boolean equals(Object o) {
168 if (!(o instanceof WindowDimensions)) {
169 return false;
170 }
171 WindowDimensions dims = (WindowDimensions)o;
172 return ((dims.insets.equals(insets)))
173 && (getClientRect().equals(dims.getClientRect()))
174 && (getBounds().equals(dims.getBounds()));
175 }
176
177 public int hashCode() {
178 return ((insets == null)? (0):(insets.hashCode())) ^ getClientRect().hashCode() ^ getBounds().hashCode();
179 }
180 }
|
56
57 /**
58 * If isClient is true, the bounds represent the client window area.
59 * Otherwise, they represent the entire window area, with the insets included
60 */
61 public WindowDimensions(Point loc, Dimension size, Insets in, boolean isClient) {
62 this(new Rectangle(loc, size), in, isClient);
63 }
64
65 /**
66 * If isClient is true, the bounds represent the client window area.
67 * Otherwise, they represent the entire window area, with the insets included
68 */
69 public WindowDimensions(Rectangle bounds, boolean isClient) {
70 this(bounds, null, isClient);
71 }
72
73 public WindowDimensions(final WindowDimensions dims) {
74 this.loc = new Point(dims.loc);
75 this.size = new Dimension(dims.size);
76 this.insets = cloneOrZero(dims.insets);
77 this.isClientSizeSet = dims.isClientSizeSet;
78 }
79
80 public Rectangle getClientRect() {
81 if (isClientSizeSet) {
82 return new Rectangle(loc, size);
83 } else {
84 // Calculate client bounds
85 if (insets != null) {
86 return new Rectangle(loc.x, loc.y,
87 size.width-(insets.left+insets.right),
88 size.height-(insets.top+insets.bottom));
89 } else {
90 return new Rectangle(loc, size);
91 }
92 }
93 }
94
95 public void setClientSize(Dimension size) {
96 this.size = new Dimension(size);
99
100 public void setClientSize(int width, int height) {
101 size = new Dimension(width, height);
102 isClientSizeSet = true;
103 }
104
105 public Dimension getClientSize() {
106 return getClientRect().getSize();
107 }
108
109 public void setSize(int width, int height) {
110 size = new Dimension(width, height);
111 isClientSizeSet = false;
112 }
113
114 public Dimension getSize() {
115 return getBounds().getSize();
116 }
117
118 public Insets getInsets() {
119 return cloneOrZero(insets);
120 }
121 public Rectangle getBounds() {
122 if (isClientSizeSet) {
123 Rectangle res = new Rectangle(loc, size);
124 res.width += (insets.left + insets.right);
125 res.height += (insets.top + insets.bottom);
126 return res;
127 } else {
128 return new Rectangle(loc, size);
129 }
130 }
131
132 public Point getLocation() {
133 return new Point(loc);
134 }
135 public void setLocation(int x, int y) {
136 loc = new Point(x, y);
137 }
138
139 public Rectangle getScreenBounds() {
160 return isClientSizeSet;
161 }
162
163 public String toString() {
164 return "[" + loc + ", " + size + "(" +(isClientSizeSet?"client":"bounds") + ")+" + insets + "]";
165 }
166
167 public boolean equals(Object o) {
168 if (!(o instanceof WindowDimensions)) {
169 return false;
170 }
171 WindowDimensions dims = (WindowDimensions)o;
172 return ((dims.insets.equals(insets)))
173 && (getClientRect().equals(dims.getClientRect()))
174 && (getBounds().equals(dims.getBounds()));
175 }
176
177 public int hashCode() {
178 return ((insets == null)? (0):(insets.hashCode())) ^ getClientRect().hashCode() ^ getBounds().hashCode();
179 }
180
181 private static Insets cloneOrZero(Insets insets) {
182 return insets == null ? new Insets(0, 0, 0, 0) :
183 (Insets)insets.clone();
184 }
185 }
|