Source Code Cross Referenced for HSSFClientAnchor.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » usermodel » 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 » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hssf.usermodel 
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:        package org.apache.poi.hssf.usermodel;
019:
020:        /**
021:         * A client anchor is attached to an excel worksheet.  It anchors against a
022:         * top-left and buttom-right cell.
023:         *
024:         * @author Glen Stampoultzis (glens at apache.org)
025:         */
026:        public class HSSFClientAnchor extends HSSFAnchor {
027:            short col1;
028:            int row1;
029:            short col2;
030:            int row2;
031:            int anchorType;
032:
033:            /**
034:             * Creates a new client anchor and defaults all the anchor positions to 0.
035:             */
036:            public HSSFClientAnchor() {
037:            }
038:
039:            /**
040:             * Creates a new client anchor and sets the top-left and bottom-right
041:             * coordinates of the anchor.
042:             *
043:             * @param dx1   the x coordinate within the first cell.
044:             * @param dy1   the y coordinate within the first cell.
045:             * @param dx2   the x coordinate within the second cell.
046:             * @param dy2   the y coordinate within the second cell.
047:             * @param col1  the column (0 based) of the first cell.
048:             * @param row1  the row (0 based) of the first cell.
049:             * @param col2  the column (0 based) of the second cell.
050:             * @param row2  the row (0 based) of the second cell.
051:             */
052:            public HSSFClientAnchor(int dx1, int dy1, int dx2, int dy2,
053:                    short col1, int row1, short col2, int row2) {
054:                super (dx1, dy1, dx2, dy2);
055:
056:                checkRange(dx1, 0, 1023, "dx1");
057:                checkRange(dx2, 0, 1023, "dx2");
058:                checkRange(dy1, 0, 255, "dy1");
059:                checkRange(dy2, 0, 255, "dy2");
060:                checkRange(col1, 0, 255, "col1");
061:                checkRange(col2, 0, 255, "col2");
062:                checkRange(row1, 0, 255 * 256, "row1");
063:                checkRange(row2, 0, 255 * 256, "row2");
064:
065:                this .col1 = col1;
066:                this .row1 = row1;
067:                this .col2 = col2;
068:                this .row2 = row2;
069:            }
070:
071:            /**
072:             * Calculates the height of a client anchor in points.
073:             *
074:             * @param sheet     the sheet the anchor will be attached to
075:             * @return          the shape height.
076:             */
077:            public float getAnchorHeightInPoints(HSSFSheet sheet) {
078:                int y1 = getDy1();
079:                int y2 = getDy2();
080:                int row1 = Math.min(getRow1(), getRow2());
081:                int row2 = Math.max(getRow1(), getRow2());
082:
083:                float points = 0;
084:                if (row1 == row2) {
085:                    points = ((y2 - y1) / 256.0f)
086:                            * getRowHeightInPoints(sheet, row2);
087:                } else {
088:                    points += ((256.0f - y1) / 256.0f)
089:                            * getRowHeightInPoints(sheet, row1);
090:                    for (int i = row1 + 1; i < row2; i++) {
091:                        points += getRowHeightInPoints(sheet, i);
092:                    }
093:                    points += (y2 / 256.0f) * getRowHeightInPoints(sheet, row2);
094:                }
095:
096:                return points;
097:            }
098:
099:            private float getRowHeightInPoints(HSSFSheet sheet, int rowNum) {
100:                HSSFRow row = sheet.getRow(rowNum);
101:                if (row == null)
102:                    return sheet.getDefaultRowHeightInPoints();
103:                else
104:                    return row.getHeightInPoints();
105:            }
106:
107:            public short getCol1() {
108:                return col1;
109:            }
110:
111:            public void setCol1(short col1) {
112:                checkRange(col1, 0, 255, "col1");
113:                this .col1 = col1;
114:            }
115:
116:            public short getCol2() {
117:                return col2;
118:            }
119:
120:            public void setCol2(short col2) {
121:                checkRange(col2, 0, 255, "col2");
122:                this .col2 = col2;
123:            }
124:
125:            public int getRow1() {
126:                return row1;
127:            }
128:
129:            public void setRow1(int row1) {
130:                checkRange(row1, 0, 256 * 256, "row1");
131:                this .row1 = row1;
132:            }
133:
134:            public int getRow2() {
135:                return row2;
136:            }
137:
138:            public void setRow2(int row2) {
139:                checkRange(row2, 0, 256 * 256, "row2");
140:                this .row2 = row2;
141:            }
142:
143:            /**
144:             * Dets the top-left and bottom-right
145:             * coordinates of the anchor.
146:             *
147:             * @param x1   the x coordinate within the first cell.
148:             * @param y1   the y coordinate within the first cell.
149:             * @param x2   the x coordinate within the second cell.
150:             * @param y2   the y coordinate within the second cell.
151:             * @param col1  the column (0 based) of the first cell.
152:             * @param row1  the row (0 based) of the first cell.
153:             * @param col2  the column (0 based) of the second cell.
154:             * @param row2  the row (0 based) of the second cell.
155:             */
156:            public void setAnchor(short col1, int row1, int x1, int y1,
157:                    short col2, int row2, int x2, int y2) {
158:                checkRange(dx1, 0, 1023, "dx1");
159:                checkRange(dx2, 0, 1023, "dx2");
160:                checkRange(dy1, 0, 255, "dy1");
161:                checkRange(dy2, 0, 255, "dy2");
162:                checkRange(col1, 0, 255, "col1");
163:                checkRange(col2, 0, 255, "col2");
164:                checkRange(row1, 0, 255 * 256, "row1");
165:                checkRange(row2, 0, 255 * 256, "row2");
166:
167:                this .col1 = col1;
168:                this .row1 = row1;
169:                this .dx1 = x1;
170:                this .dy1 = y1;
171:                this .col2 = col2;
172:                this .row2 = row2;
173:                this .dx2 = x2;
174:                this .dy2 = y2;
175:            }
176:
177:            /**
178:             * @return  true if the anchor goes from right to left.
179:             */
180:            public boolean isHorizontallyFlipped() {
181:                if (col1 == col2)
182:                    return dx1 > dx2;
183:                else
184:                    return col1 > col2;
185:            }
186:
187:            /**
188:             * @return  true if the anchor goes from bottom to top.
189:             */
190:            public boolean isVerticallyFlipped() {
191:                if (row1 == row2)
192:                    return dy1 > dy2;
193:                else
194:                    return row1 > row2;
195:            }
196:
197:            /**
198:             * Gets the anchor type
199:             * <p>
200:             * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
201:             */
202:            public int getAnchorType() {
203:                return anchorType;
204:            }
205:
206:            /**
207:             * Sets the anchor type
208:             * <p>
209:             * 0 = Move and size with Cells, 2 = Move but don't size with cells, 3 = Don't move or size with cells.
210:             */
211:            public void setAnchorType(int anchorType) {
212:                this .anchorType = anchorType;
213:            }
214:
215:            private void checkRange(int value, int minRange, int maxRange,
216:                    String varName) {
217:                if (value < minRange || value > maxRange)
218:                    throw new IllegalArgumentException(varName
219:                            + " must be between " + minRange + " and "
220:                            + maxRange);
221:            }
222:
223:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.