Source Code Cross Referenced for cPrintVariable.java in  » Mail-Clients » columba-1.4 » org » columba » core » print » 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 » Mail Clients » columba 1.4 » org.columba.core.print 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the 
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003. 
014:        //
015:        //All Rights Reserved.
016:        package org.columba.core.print;
017:
018:        import java.awt.Graphics2D;
019:        import java.lang.reflect.Array;
020:        import java.lang.reflect.Method;
021:        import java.text.DateFormat;
022:        import java.util.Date;
023:
024:        /**
025:         * cPrintVariable class
026:         * 
027:         * @author unknown
028:         * 
029:         */
030:        public class cPrintVariable extends cParagraph {
031:            String codeString;
032:            CodeStringParser[] parser;
033:            int parserCount = -1;
034:            String[] keys = { "PAGE_NR", "PAGE_COUNT", "DATE_TODAY" };
035:            String[] methods = { "getPageNr", "getPageCount", "getDateToday" };
036:
037:            /**
038:             * Default Constructor for cPrintVariable
039:             */
040:            public cPrintVariable() {
041:                Class c = this .getClass();
042:                parserCount = Array.getLength(keys);
043:                parser = new CodeStringParser[parserCount];
044:
045:                for (int i = 0; i < parserCount; i++) {
046:                    try {
047:                        parser[i] = new CodeStringParser(this , keys[i], c
048:                                .getMethod(methods[i], new Class[0]));
049:                    } catch (NoSuchMethodException e) {
050:                        e.printStackTrace();
051:                    }
052:                }
053:            }
054:
055:            /*
056:             * Methods called by the Variable parsers
057:             */
058:
059:            /**
060:             * getPageNr method
061:             * 
062:             * @return PageNr
063:             */
064:            public String getPageNr() {
065:                return Integer.toString(page.getDocument().getPageNr(page));
066:            }
067:
068:            /**
069:             * getPageCount method
070:             * 
071:             * @return PageCount
072:             */
073:            public String getPageCount() {
074:                return Integer.toString(page.getDocument().getPageCount());
075:            }
076:
077:            /**
078:             * getDateToday method
079:             * 
080:             * @return df Today's Date in Java Format
081:             */
082:            public String getDateToday() {
083:                DateFormat df = DateFormat.getDateInstance();
084:
085:                return df.format(new Date());
086:            }
087:
088:            /**
089:             * setCodeString method
090:             * 
091:             * @param n
092:             */
093:            public void setCodeString(String n) {
094:                codeString = n;
095:                setText(n); // For getHeight() to return the right Value
096:            }
097:
098:            /* (non-Javadoc)
099:             * @see org.columba.core.print.cParagraph#print(java.awt.Graphics2D)
100:             */
101:            public void print(Graphics2D g) {
102:                setText(processCodeString());
103:                super .print(g);
104:            }
105:
106:            /**
107:             * processCodeString method
108:             * @return result
109:             */
110:            public String processCodeString() {
111:                StringBuffer result = new StringBuffer();
112:                boolean isDecoding = false;
113:                char c;
114:
115:                for (int i = 0; i < codeString.length(); i++) {
116:                    c = codeString.charAt(i);
117:
118:                    if (c == '%') {
119:                        isDecoding = !isDecoding;
120:
121:                        if (!isDecoding) {
122:                            for (int j = 0; j < parserCount; j++) {
123:                                parser[j].reset();
124:                            }
125:                        }
126:                    } else {
127:                        if (isDecoding) {
128:                            for (int j = 0; j < parserCount; j++) {
129:                                if (parser[j].clock(c)) {
130:                                    result.append(parser[j].getValue());
131:                                }
132:                            }
133:                        } else {
134:                            result.append(c);
135:                        }
136:                    }
137:                }
138:                return result.toString();
139:            }
140:        }
141:
142:        /** 
143:         * CodeStringParser method
144:         * 
145:         * @author unknown
146:         *
147:         */
148:        class CodeStringParser {
149:            Method hit;
150:            char[] match;
151:            int length;
152:            Object parent;
153:            int pos;
154:
155:            public CodeStringParser(Object p, String m, Method h) {
156:                parent = p;
157:                match = m.toCharArray();
158:                length = m.length();
159:                hit = h;
160:                pos = 0;
161:            }
162:
163:            //TODO: Should this be renamed to cLoc or something more appropriate than clock?
164:            /**
165:             * clock method
166:             * 
167:             * @param in
168:             * @return boolean
169:             */
170:            public boolean clock(char in) {
171:                if (in == match[pos]) {
172:                    pos++;
173:
174:                    if (pos == length) {
175:                        pos = 0;
176:                        return true;
177:                    }
178:                } else {
179:                    pos = 0;
180:                }
181:                return false;
182:            }
183:
184:            /**
185:             * getValue method
186:             * 
187:             * @return value
188:             */
189:            public String getValue() {
190:                try {
191:                    return (String) hit.invoke((Object) parent, (Object) null);
192:                } catch (Exception e) {
193:                    return new String("<Unhandled Exception occcured>");
194:                }
195:            }
196:
197:            /**
198:             * reset method - reset (int) pos to 0
199:             */
200:            public void reset() {
201:                pos = 0;
202:            }
203:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.