Source Code Cross Referenced for ReferencePtg.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » record » formula » 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.record.formula 
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.record.formula;
019:
020:        import org.apache.poi.util.LittleEndian;
021:        import org.apache.poi.util.BitField;
022:        import org.apache.poi.util.BitFieldFactory;
023:
024:        import org.apache.poi.hssf.util.CellReference;
025:        import org.apache.poi.hssf.model.Workbook;
026:        import org.apache.poi.hssf.record.RecordInputStream;
027:
028:        /**
029:         * ReferencePtg - handles references (such as A1, A2, IA4)
030:         * @author  Andrew C. Oliver (acoliver@apache.org)
031:         * @author Jason Height (jheight at chariot dot net dot au)
032:         */
033:
034:        public class ReferencePtg extends Ptg {
035:            private final static int SIZE = 5;
036:            public final static byte sid = 0x24;
037:            private final static int MAX_ROW_NUMBER = 65536;
038:            //public final static byte sid = 0x44;
039:
040:            /** 
041:             * The row number, between 0 and 65535, but stored as a signed
042:             *  short between -32767 and 32768.
043:             * Take care about which version you fetch back!
044:             */
045:            private short field_1_row;
046:            /**
047:             * The column number, between 0 and ??
048:             */
049:            private short field_2_col;
050:            private BitField rowRelative = BitFieldFactory.getInstance(0x8000);
051:            private BitField colRelative = BitFieldFactory.getInstance(0x4000);
052:            private BitField column = BitFieldFactory.getInstance(0x3FFF);
053:
054:            protected ReferencePtg() {
055:                //Required for clone methods
056:            }
057:
058:            /**
059:             * Takes in a String represnetation of a cell reference and fills out the 
060:             * numeric fields.
061:             */
062:            public ReferencePtg(String cellref) {
063:                CellReference c = new CellReference(cellref);
064:                setRow((short) c.getRow());
065:                setColumn((short) c.getCol());
066:                setColRelative(!c.isColAbsolute());
067:                setRowRelative(!c.isRowAbsolute());
068:            }
069:
070:            public ReferencePtg(short row, short column, boolean isRowRelative,
071:                    boolean isColumnRelative) {
072:                setRow(row);
073:                setColumn(column);
074:                setRowRelative(isRowRelative);
075:                setColRelative(isColumnRelative);
076:            }
077:
078:            /** Creates new ValueReferencePtg */
079:
080:            public ReferencePtg(RecordInputStream in) {
081:                field_1_row = in.readShort();
082:                field_2_col = in.readShort();
083:            }
084:
085:            public String getRefPtgName() {
086:                return "ReferencePtg";
087:            }
088:
089:            public String toString() {
090:                StringBuffer buffer = new StringBuffer("[");
091:                buffer.append(getRefPtgName());
092:                buffer.append("]\n");
093:
094:                buffer.append("row = ").append(getRow()).append("\n");
095:                buffer.append("col = ").append(getColumn()).append("\n");
096:                buffer.append("rowrelative = ").append(isRowRelative()).append(
097:                        "\n");
098:                buffer.append("colrelative = ").append(isColRelative()).append(
099:                        "\n");
100:                return buffer.toString();
101:            }
102:
103:            public void writeBytes(byte[] array, int offset) {
104:                array[offset] = (byte) (sid + ptgClass);
105:
106:                LittleEndian.putShort(array, offset + 1, field_1_row);
107:                LittleEndian.putShort(array, offset + 3, field_2_col);
108:            }
109:
110:            public void setRow(short row) {
111:                field_1_row = row;
112:            }
113:
114:            public void setRow(int row) {
115:                if (row < 0 || row >= MAX_ROW_NUMBER) {
116:                    throw new IllegalArgumentException(
117:                            "The row number, when specified as an integer, must be between 0 and "
118:                                    + MAX_ROW_NUMBER);
119:                }
120:
121:                // Save, wrapping as needed
122:                if (row > Short.MAX_VALUE) {
123:                    field_1_row = (short) (row - MAX_ROW_NUMBER);
124:                } else {
125:                    field_1_row = (short) row;
126:                }
127:            }
128:
129:            /**
130:             * Returns the row number as a short, which will be
131:             *  wrapped (negative) for values between 32769 and 65535
132:             */
133:            public short getRow() {
134:                return field_1_row;
135:            }
136:
137:            /**
138:             * Returns the row number as an int, between 0 and 65535
139:             */
140:            public int getRowAsInt() {
141:                if (field_1_row < 0) {
142:                    return field_1_row + MAX_ROW_NUMBER;
143:                }
144:                return field_1_row;
145:            }
146:
147:            public boolean isRowRelative() {
148:                return rowRelative.isSet(field_2_col);
149:            }
150:
151:            public void setRowRelative(boolean rel) {
152:                field_2_col = rowRelative.setShortBoolean(field_2_col, rel);
153:            }
154:
155:            public boolean isColRelative() {
156:                return colRelative.isSet(field_2_col);
157:            }
158:
159:            public void setColRelative(boolean rel) {
160:                field_2_col = colRelative.setShortBoolean(field_2_col, rel);
161:            }
162:
163:            public void setColumnRaw(short col) {
164:                field_2_col = col;
165:            }
166:
167:            public short getColumnRaw() {
168:                return field_2_col;
169:            }
170:
171:            public void setColumn(short col) {
172:                field_2_col = column.setShortValue(field_2_col, col);
173:            }
174:
175:            public short getColumn() {
176:                return column.getShortValue(field_2_col);
177:            }
178:
179:            public int getSize() {
180:                return SIZE;
181:            }
182:
183:            public String toFormulaString(Workbook book) {
184:                //TODO -- should we store a cellreference instance in this ptg?? but .. memory is an issue, i believe!
185:                return (new CellReference(getRowAsInt(), getColumn(),
186:                        !isRowRelative(), !isColRelative())).toString();
187:            }
188:
189:            public byte getDefaultOperandClass() {
190:                return Ptg.CLASS_REF;
191:            }
192:
193:            public Object clone() {
194:                ReferencePtg ptg = new ReferencePtg();
195:                ptg.field_1_row = field_1_row;
196:                ptg.field_2_col = field_2_col;
197:                ptg.setClass(ptgClass);
198:                return ptg;
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.