Source Code Cross Referenced for Box.java in  » 6.0-JDK-Modules » j2me » com » sun » perseus » j2d » 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 » 6.0 JDK Modules » j2me » com.sun.perseus.j2d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:        package com.sun.perseus.j2d;
027:
028:        import org.w3c.dom.svg.SVGRect;
029:
030:        /**
031:         * This class represents an "SVGRect" datatype, consisting of a minimum X, 
032:         * minimum Y, width and height values.
033:         *
034:         * @author <a href="mailto:kevin.wong@sun.com">Kevin Wong</a>
035:         * @version $Id: Box.java,v 1.4 2006/04/21 06:35:00 st125089 Exp $
036:         */
037:        public class Box implements  SVGRect {
038:            /**
039:             * The smallest x-axis value of the rectangle
040:             */
041:            public float x;
042:
043:            /**
044:             * The smallest y-axis value of the rectangle
045:             */
046:            public float y;
047:
048:            /**
049:             * The width value of the rectangle
050:             */
051:            public float width;
052:
053:            /**
054:             * The height value of the rectangle
055:             */
056:            public float height;
057:
058:            /**
059:             * @param x the rect's x-axis origin.
060:             * @param y the rect's y-axis origin.
061:             * @param w the rect's x-axis width.
062:             * @param h the rect's y-axis height.
063:             */
064:            public Box(final float x, final float y, final float w,
065:                    final float h) {
066:                this .x = x;
067:                this .y = y;
068:                this .width = w;
069:                this .height = h;
070:            }
071:
072:            /**
073:             * Copy constructor
074:             *
075:             * @param b the Box to copy. Should not be null.
076:             */
077:            public Box(Box b) {
078:                this (b.x, b.y, b.width, b.height);
079:            }
080:
081:            /**
082:             *
083:             */
084:            public void setX(final float value) {
085:                x = value;
086:            }
087:
088:            /**
089:             *
090:             */
091:            public void setY(final float value) {
092:                y = value;
093:            }
094:
095:            /**
096:             *
097:             */
098:            public void setWidth(final float value) {
099:                width = value;
100:            }
101:
102:            /**
103:             *
104:             */
105:            public void setHeight(final float value) {
106:                height = value;
107:            }
108:
109:            /**
110:             *
111:             */
112:            public float getX() {
113:                return x;
114:            }
115:
116:            /**
117:             *
118:             */
119:            public float getY() {
120:                return y;
121:            }
122:
123:            /**
124:             *
125:             */
126:            public float getWidth() {
127:                return width;
128:            }
129:
130:            /**
131:             *
132:             */
133:            public float getHeight() {
134:                return height;
135:            }
136:
137:            /**
138:             * Snaps this Box instance to the integer grid.
139:             */
140:            public void snap() {
141:                float fmaxX = x + width;
142:                float fmaxY = y + height;
143:
144:                // x and y need to snap to the left of the integer grid.
145:                // We cannot simply cast as we need pixel accurate results.
146:
147:                // Narrowing rounds towards zero
148:                int x = (int) this .x;
149:                if (this .x < 0 && (this .x - x != 0)) {
150:                    x -= 1;
151:                }
152:
153:                int y = (int) this .y; // Narrowing
154:                if (this .y < 0 && (this .y - y) != 0) {
155:                    y -= 1;
156:                }
157:
158:                // maxX and maxY need to snap to the right of the integer grid.
159:                int maxX = (int) fmaxX;
160:                if (fmaxX > 0 && (fmaxX - maxX) != 0) {
161:                    maxX += 1;
162:                }
163:
164:                int maxY = (int) fmaxY;
165:                if (fmaxY > 0 && (fmaxY - maxY) != 0) {
166:                    maxY += 1;
167:                }
168:
169:                this .x = x;
170:                this .y = y;
171:                this .width = (maxX - x);
172:                this .height = (maxY - y);
173:            }
174:
175:            /**
176:             * @return true if the input object is this Box or if x, y, width and height
177:             *         are equals.
178:             */
179:            public boolean equals(final Object cmp) {
180:                if (cmp == this ) {
181:                    return true;
182:                }
183:
184:                if (cmp == null) {
185:                    return false;
186:                }
187:
188:                if (cmp instanceof  Box) {
189:                    Box b = (Box) cmp;
190:                    return b.x == x && b.y == y && b.width == width
191:                            && b.height == height;
192:                }
193:
194:                return false;
195:            }
196:
197:            /**
198:             * Debugging helper.
199:             */
200:            public String toString() {
201:                return "Box(" + x + ", " + y + ", " + width + ", " + height
202:                        + ")";
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.