Source Code Cross Referenced for Rectangle.java in  » Apache-Harmony-Java-SE » java-package » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Denis M. Kishenko
019:         * @version $Revision$
020:         */package java.awt;
021:
022:        import java.awt.geom.Rectangle2D;
023:        import java.io.Serializable;
024:
025:        public class Rectangle extends Rectangle2D implements  Shape,
026:                Serializable {
027:
028:            private static final long serialVersionUID = -4345857070255674764L;
029:
030:            public int x;
031:            public int y;
032:            public int width;
033:            public int height;
034:
035:            public Rectangle() {
036:                setBounds(0, 0, 0, 0);
037:            }
038:
039:            public Rectangle(Point p) {
040:                setBounds(p.x, p.y, 0, 0);
041:            }
042:
043:            public Rectangle(Point p, Dimension d) {
044:                setBounds(p.x, p.y, d.width, d.height);
045:            }
046:
047:            public Rectangle(int x, int y, int width, int height) {
048:                setBounds(x, y, width, height);
049:            }
050:
051:            public Rectangle(int width, int height) {
052:                setBounds(0, 0, width, height);
053:            }
054:
055:            public Rectangle(Rectangle r) {
056:                setBounds(r.x, r.y, r.width, r.height);
057:            }
058:
059:            public Rectangle(Dimension d) {
060:                setBounds(0, 0, d.width, d.height);
061:            }
062:
063:            @Override
064:            public double getX() {
065:                return x;
066:            }
067:
068:            @Override
069:            public double getY() {
070:                return y;
071:            }
072:
073:            @Override
074:            public double getHeight() {
075:                return height;
076:            }
077:
078:            @Override
079:            public double getWidth() {
080:                return width;
081:            }
082:
083:            @Override
084:            public boolean isEmpty() {
085:                return width <= 0 || height <= 0;
086:            }
087:
088:            public Dimension getSize() {
089:                return new Dimension(width, height);
090:            }
091:
092:            public void setSize(int width, int height) {
093:                this .width = width;
094:                this .height = height;
095:            }
096:
097:            public void setSize(Dimension d) {
098:                setSize(d.width, d.height);
099:            }
100:
101:            public Point getLocation() {
102:                return new Point(x, y);
103:            }
104:
105:            public void setLocation(int x, int y) {
106:                this .x = x;
107:                this .y = y;
108:            }
109:
110:            public void setLocation(Point p) {
111:                setLocation(p.x, p.y);
112:            }
113:
114:            /**
115:             * @deprecated
116:             */
117:            @Deprecated
118:            public void move(int x, int y) {
119:                setLocation(x, y);
120:            }
121:
122:            @Override
123:            public void setRect(double x, double y, double width, double height) {
124:                int x1 = (int) Math.floor(x);
125:                int y1 = (int) Math.floor(y);
126:                int x2 = (int) Math.ceil(x + width);
127:                int y2 = (int) Math.ceil(y + height);
128:                setBounds(x1, y1, x2 - x1, y2 - y1);
129:            }
130:
131:            /**
132:             * @deprecated
133:             */
134:            @Deprecated
135:            public void resize(int width, int height) {
136:                setBounds(x, y, width, height);
137:            }
138:
139:            /**
140:             * @deprecated
141:             */
142:            @Deprecated
143:            public void reshape(int x, int y, int width, int height) {
144:                setBounds(x, y, width, height);
145:            }
146:
147:            @Override
148:            public Rectangle getBounds() {
149:                return new Rectangle(x, y, width, height);
150:            }
151:
152:            @Override
153:            public Rectangle2D getBounds2D() {
154:                return getBounds();
155:            }
156:
157:            public void setBounds(int x, int y, int width, int height) {
158:                this .x = x;
159:                this .y = y;
160:                this .height = height;
161:                this .width = width;
162:            }
163:
164:            public void setBounds(Rectangle r) {
165:                setBounds(r.x, r.y, r.width, r.height);
166:            }
167:
168:            public void grow(int dx, int dy) {
169:                x -= dx;
170:                y -= dy;
171:                width += dx + dx;
172:                height += dy + dy;
173:            }
174:
175:            public void translate(int mx, int my) {
176:                x += mx;
177:                y += my;
178:            }
179:
180:            public void add(int px, int py) {
181:                int x1 = Math.min(x, px);
182:                int x2 = Math.max(x + width, px);
183:                int y1 = Math.min(y, py);
184:                int y2 = Math.max(y + height, py);
185:                setBounds(x1, y1, x2 - x1, y2 - y1);
186:            }
187:
188:            public void add(Point p) {
189:                add(p.x, p.y);
190:            }
191:
192:            public void add(Rectangle r) {
193:                int x1 = Math.min(x, r.x);
194:                int x2 = Math.max(x + width, r.x + r.width);
195:                int y1 = Math.min(y, r.y);
196:                int y2 = Math.max(y + height, r.y + r.height);
197:                setBounds(x1, y1, x2 - x1, y2 - y1);
198:            }
199:
200:            public boolean contains(int px, int py) {
201:                if (isEmpty()) {
202:                    return false;
203:                }
204:                if (px < x || py < y) {
205:                    return false;
206:                }
207:                px -= x;
208:                py -= y;
209:                return px < width && py < height;
210:            }
211:
212:            public boolean contains(Point p) {
213:                return contains(p.x, p.y);
214:            }
215:
216:            public boolean contains(int rx, int ry, int rw, int rh) {
217:                return contains(rx, ry) && contains(rx + rw - 1, ry + rh - 1);
218:            }
219:
220:            public boolean contains(Rectangle r) {
221:                return contains(r.x, r.y, r.width, r.height);
222:            }
223:
224:            /**
225:             * @deprecated
226:             */
227:            @Deprecated
228:            public boolean inside(int px, int py) {
229:                return contains(px, py);
230:            }
231:
232:            @Override
233:            public Rectangle2D createIntersection(Rectangle2D r) {
234:                if (r instanceof  Rectangle) {
235:                    return intersection((Rectangle) r);
236:                }
237:                Rectangle2D dst = new Rectangle2D.Double();
238:                Rectangle2D.intersect(this , r, dst);
239:                return dst;
240:            }
241:
242:            public Rectangle intersection(Rectangle r) {
243:                int x1 = Math.max(x, r.x);
244:                int y1 = Math.max(y, r.y);
245:                int x2 = Math.min(x + width, r.x + r.width);
246:                int y2 = Math.min(y + height, r.y + r.height);
247:                return new Rectangle(x1, y1, x2 - x1, y2 - y1);
248:            }
249:
250:            public boolean intersects(Rectangle r) {
251:                return !intersection(r).isEmpty();
252:            }
253:
254:            @Override
255:            public int outcode(double px, double py) {
256:                int code = 0;
257:
258:                if (width <= 0) {
259:                    code |= OUT_LEFT | OUT_RIGHT;
260:                } else if (px < x) {
261:                    code |= OUT_LEFT;
262:                } else if (px > x + width) {
263:                    code |= OUT_RIGHT;
264:                }
265:
266:                if (height <= 0) {
267:                    code |= OUT_TOP | OUT_BOTTOM;
268:                } else if (py < y) {
269:                    code |= OUT_TOP;
270:                } else if (py > y + height) {
271:                    code |= OUT_BOTTOM;
272:                }
273:
274:                return code;
275:            }
276:
277:            @Override
278:            public Rectangle2D createUnion(Rectangle2D r) {
279:                if (r instanceof  Rectangle) {
280:                    return union((Rectangle) r);
281:                }
282:                Rectangle2D dst = new Rectangle2D.Double();
283:                Rectangle2D.union(this , r, dst);
284:                return dst;
285:            }
286:
287:            public Rectangle union(Rectangle r) {
288:                Rectangle dst = new Rectangle(this );
289:                dst.add(r);
290:                return dst;
291:            }
292:
293:            @Override
294:            public boolean equals(Object obj) {
295:                if (obj == this ) {
296:                    return true;
297:                }
298:                if (obj instanceof  Rectangle) {
299:                    Rectangle r = (Rectangle) obj;
300:                    return r.x == x && r.y == y && r.width == width
301:                            && r.height == height;
302:                }
303:                return false;
304:            }
305:
306:            @Override
307:            public String toString() {
308:                // The output format based on 1.5 release behaviour. It could be obtained in the following way
309:                // System.out.println(new Rectangle().toString())
310:                return getClass().getName() + "[x=" + x + ",y=" + y + //$NON-NLS-1$ //$NON-NLS-2$
311:                        ",width=" + width + ",height=" + height + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
312:            }
313:
314:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.