001: /*
002: * Copyright Javelin Software, All rights reserved.
003: */
004:
005: package com.javelin.swinglets;
006:
007: import java.util.*;
008: import java.io.*;
009:
010: import com.javelin.swinglets.*;
011: import com.javelin.swinglets.plaf.*;
012: import com.javelin.swinglets.theme.*;
013:
014: /**
015: * SwingletWriter defines the paint writer for a Swinglet.
016: * <P>
017: * SwingletWriters are passed down thru the UI classes.
018: *
019: * @author Robin Sharp
020: */
021:
022: public class SwingletWriter {
023: /**
024: * Get a writer from the pool, and set its properties.
025: */
026: public static synchronized SwingletWriter getWriter(Object out,
027: SComponent component) {
028: SwingletWriter writer = getWriter(component);
029:
030: if (out instanceof PrintWriter)
031: writer.setPrintWriter((PrintWriter) out);
032: else if (out instanceof PrintStream)
033: writer.setPrintStream((PrintStream) out);
034:
035: return writer;
036: }
037:
038: /**
039: * Get a writer from the pool, and set its properties.
040: */
041: public static synchronized SwingletWriter getWriter(
042: SComponent component) {
043: SwingletWriter writer = null;
044:
045: if (writers.size() > 0) {
046: writer = (SwingletWriter) writers
047: .remove(writers.size() - 1);
048: } else {
049: writer = new SwingletWriter();
050: writers.add(writer);
051: }
052:
053: writer.setSwingletManager(component.getSwingletManager());
054:
055: return writer;
056: }
057:
058: /**
059: * Return a writer to the pool.
060: */
061: public static synchronized void returnWriter(SwingletWriter writer) {
062: writer.setSwingletManager(null);
063: writer.setPrintStream(null);
064: writer.setPrintWriter(null);
065: writer.setLookAndFeel(null);
066: writer.setTheme(null);
067:
068: writers.add(writer);
069: }
070:
071: /**
072: * Get the PrintWriter.
073: */
074: public PrintWriter getPrintWriter() {
075: return printWriter;
076: }
077:
078: /**
079: * Set the PrintWriter.
080: */
081: public void setPrintWriter(PrintWriter printWriter) {
082: this .printWriter = printWriter;
083: }
084:
085: /**
086: * Get the PrintStream.
087: */
088: public PrintStream getPrintStream() {
089: return printStream;
090: }
091:
092: /**
093: * Set the PrintStream.
094: */
095: public void setPrintStream(PrintStream printStream) {
096: this .printStream = printStream;
097: }
098:
099: /**
100: * Get the SwingletManager.
101: */
102: public SwingletManager getSwingletManager() {
103: return swingletManager;
104: }
105:
106: /**
107: * Set the SwingletManager.
108: */
109: public void setSwingletManager(SwingletManager swingletManager) {
110: this .swingletManager = swingletManager;
111: }
112:
113: /**
114: * Get the LookAndFeel
115: */
116: public SLookAndFeel getLookAndFeel() {
117: return lookAndFeel;
118: }
119:
120: /**
121: * Set the Look and Feel.
122: */
123: public void setLookAndFeel(SLookAndFeel lookAndFeel) {
124: this .lookAndFeel = lookAndFeel;
125: }
126:
127: /**
128: * Get the STheme
129: */
130: public STheme getTheme() {
131: return theme;
132: }
133:
134: /**
135: * Set the STheme.
136: */
137: public void setTheme(STheme theme) {
138: this .theme = theme;
139: }
140:
141: protected SwingletManager swingletManager;
142: protected STheme theme;
143: protected SLookAndFeel lookAndFeel;
144:
145: protected PrintStream printStream;
146: protected PrintWriter printWriter;
147:
148: protected static ArrayList writers = new ArrayList();
149: }
|