Source Code Cross Referenced for State.java in  » UML » jrefactory » org » acm » seguin » print » xml » 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 » UML » jrefactory » org.acm.seguin.print.xml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Author:  Chris Seguin
003:         *
004:         *  This software has been developed under the copyleft
005:         *  rules of the GNU General Public License.  Please
006:         *  consult the GNU General Public License for more
007:         *  details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.print.xml;
010:
011:        import java.awt.Color;
012:        import java.awt.Font;
013:        import java.awt.FontMetrics;
014:        import java.awt.Graphics;
015:
016:        /**
017:         *  State pattern that is used to print the XML file
018:         *
019:         *@author    Chris Seguin
020:         */
021:        public abstract class State {
022:            /**
023:             *  the font
024:             */
025:            protected Font font;
026:            protected Color color;
027:            private Graphics g;
028:            private int x;
029:            private int y;
030:            private int fontSize;
031:
032:            /**
033:             *  Constructor for the State object
034:             */
035:            public State() {
036:                font = null;
037:                fontSize = -1;
038:                color = Color.black;
039:            }
040:
041:            /**
042:             *  Sets the FontSize attribute of the State object
043:             *
044:             *@param  value  The new FontSize value
045:             */
046:            public void setFontSize(int value) {
047:                if (value != fontSize) {
048:                    fontSize = value;
049:                    font = null;
050:                }
051:            }
052:
053:            /**
054:             *  Sets the Graphics attribute of the State object
055:             *
056:             *@param  value  The new Graphics value
057:             */
058:            public void setGraphics(Graphics value) {
059:                g = value;
060:            }
061:
062:            /**
063:             *  Sets the X attribute of the State object
064:             *
065:             *@param  value  The new X value
066:             */
067:            public void setX(int value) {
068:                x = value;
069:            }
070:
071:            /**
072:             *  Sets the Y attribute of the State object
073:             *
074:             *@param  value  The new Y value
075:             */
076:            public void setY(int value) {
077:                y = value;
078:            }
079:
080:            /**
081:             *  Gets the FontSize attribute of the State object
082:             *
083:             *@return    The FontSize value
084:             */
085:            public int getFontSize() {
086:                return fontSize;
087:            }
088:
089:            /**
090:             *  Gets the Font attribute of the State object
091:             *
092:             *@return    The Font value
093:             */
094:            public abstract Font getFont();
095:
096:            /**
097:             *  Gets the Graphics attribute of the State object
098:             *
099:             *@return    The Graphics value
100:             */
101:            public Graphics getGraphics() {
102:                return g;
103:            }
104:
105:            /**
106:             *  Gets the X attribute of the State object
107:             *
108:             *@return    The X value
109:             */
110:            public int getX() {
111:                return x;
112:            }
113:
114:            /**
115:             *  Gets the Y attribute of the State object
116:             *
117:             *@return    The Y value
118:             */
119:            public int getY() {
120:                return y;
121:            }
122:
123:            /**
124:             *  Processes a single line and returns the state that is in effect at the
125:             *  end of the line.
126:             *
127:             *@param  line  the line
128:             *@return       the state
129:             */
130:            public State processLine(String line) {
131:                return processLine(line, 0, new StringBuffer());
132:            }
133:
134:            /**
135:             *  The actual worker method that processes the line. This is what is defined
136:             *  by the various states
137:             *
138:             *@param  line   the line
139:             *@param  index  the index of the character
140:             *@param  buf    the buffer
141:             *@return        the state at the end of the line
142:             */
143:            protected abstract State processLine(String line, int index,
144:                    StringBuffer buf);
145:
146:            /**
147:             *  Set the state for the next state
148:             *
149:             *@param  next  the next state
150:             */
151:            protected void initState(State next) {
152:                next.setGraphics(getGraphics());
153:                next.setX(getX());
154:                next.setY(getY());
155:                next.setFontSize(getFontSize());
156:            }
157:
158:            /**
159:             *  Prints the buffer
160:             *
161:             *@param  buf  the buffer
162:             */
163:            protected void print(StringBuffer buf) {
164:                String out = buf.toString();
165:                if (out.length() == 0) {
166:                    return;
167:                }
168:
169:                //System.out.println("Printing:  [" + out + "] (" + getClass().getName() + ") " + fontSize + "(" + x + ", " + y +")");
170:                //font = new Font("Monospaced", Font.PLAIN, fontSize);
171:                g.setFont(getFont());
172:                g.setColor(color);
173:                g.drawString(out, x, y);
174:
175:                FontMetrics fm = g.getFontMetrics();
176:                x = x + fm.stringWidth(out);
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.