01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.print.xml;
10:
11: import java.awt.Font;
12:
13: /**
14: * State pattern that is used to print the XML file
15: *
16: *@author Chris Seguin
17: */
18: public class TextState extends State {
19: private static State state = null;
20:
21: /**
22: * Gets the Font attribute of the State object
23: *
24: *@return The Font value
25: */
26: public Font getFont() {
27: if (font == null) {
28: font = new Font("Monospaced", Font.PLAIN, getFontSize());
29: }
30: return font;
31: }
32:
33: /**
34: * The actual worker method that processes the line. This is what is defined
35: * by the various states
36: *
37: *@param line the line
38: *@param index the index of the character
39: *@param buf the buffer
40: *@return the state at the end of the line
41: */
42: protected State processLine(String line, int index, StringBuffer buf) {
43: State nextState = null;
44: int length = line.length();
45:
46: while (nextState == null) {
47: if (index == length) {
48: print(buf);
49: return this ;
50: }
51:
52: if ((length != index + 1)
53: && (line.charAt(index + 1) == '<')) {
54: nextState = TagState.getState();
55: }
56:
57: buf.append(line.charAt(index));
58: index++;
59: }
60:
61: print(buf);
62: initState(nextState);
63: buf.setLength(0);
64: return nextState.processLine(line, index, buf);
65: }
66:
67: /**
68: * Gets the State attribute of the TextState class
69: *
70: *@return The State value
71: */
72: public static State getState() {
73: if (state == null) {
74: state = new TextState();
75: }
76: return state;
77: }
78: }
|