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.text;
10:
11: import java.awt.Color;
12: import java.awt.Font;
13: import java.awt.FontMetrics;
14: import java.awt.Graphics;
15:
16: /**
17: * Prints a single line
18: *
19: *@author Chris Seguin
20: */
21: public class LinePrinter {
22: /**
23: * Description of the Field
24: */
25: protected int fontSize = -1;
26: private Font font = null;
27:
28: /**
29: * Sets the FontSize attribute of the LinePrinter object
30: *
31: *@param value The new FontSize value
32: */
33: public void setFontSize(int value) {
34: if (fontSize != value) {
35: fontSize = value;
36: font = null;
37: }
38: }
39:
40: /**
41: * Gets the LineHeight attribute of the LinePrinter object
42: *
43: *@param g Description of Parameter
44: *@return The LineHeight value
45: */
46: public int getLineHeight(Graphics g) {
47: init(g);
48:
49: FontMetrics fm = g.getFontMetrics();
50: return fm.getHeight();
51: }
52:
53: /**
54: * Initializes the graphics object to begin printing
55: *
56: *@param g the graphics object
57: */
58: public void init(Graphics g) {
59: if (font == null) {
60: font = new Font("Monospaced", Font.PLAIN, fontSize);
61: }
62: g.setColor(Color.black);
63: g.setFont(font);
64: }
65:
66: /**
67: * Prints the line
68: *
69: *@param g The graphics device
70: *@param line The string to print
71: *@param x The x location on the graphics device
72: *@param y The y location on the graphics device
73: *@param set The set of lines
74: *@param index The line we are printing
75: */
76: public void print(Graphics g, String line, int x, int y,
77: LineSet set, int index) {
78: if (line.length() > 0) {
79: g.drawString(line, x, y);
80: }
81: }
82: }
|