01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.codegen.builder;
20:
21: import java.util.Iterator;
22: import java.util.LinkedList;
23: import java.util.StringTokenizer;
24:
25: public class Block implements CodeSegment {
26: private LinkedList m_codeLines = new LinkedList();
27:
28: public void addCode(String codeLines) {
29: m_codeLines.add(codeLines);
30: }
31:
32: public void println() {
33: m_codeLines.add("\n");
34: }
35:
36: public void output(SourceBuilder builder) {
37: Iterator iter = m_codeLines.iterator();
38: while (iter.hasNext()) {
39: String code = (String) iter.next();
40: StringTokenizer st = new StringTokenizer(code, "{};\n",
41: true);
42: while (st.hasMoreTokens()) {
43: String token = st.nextToken();
44: if (token.equals("{")) {
45: builder.openBrace();
46: builder.println();
47: builder.indent();
48: } else if (token.equals("}")) {
49: builder.dedent();
50: builder.closeBrace();
51: } else if (token.equals(";")) {
52: builder.println(";");
53: } else {
54: if (token.equals("\n")) {
55: builder.println();
56: } else {
57: builder.print(token);
58: }
59: }
60: }
61: }
62: }
63: }
|