ReportCat 1.1

li.netcat.print.util
Class StringDrawDevice

java.lang.Object
  extended byli.netcat.print.util.StringDrawDevice

public class StringDrawDevice
extends java.lang.Object

The StringDrawDevice is a pluggable strategy to draw Strings. All string printing use the installed device. The exact determination of the width of a String (used for right alignment) seems to be a non trivial problem. The various solutions (e.g. TextLayout) have all advantages and disadvantages. Override the various methods to implement your needs.

Default fonts can also be retrieved and defined with static metods of the StringDrawDevice.

Author:
Arthur Marxer

Constructor Summary
StringDrawDevice()
           
 
Method Summary
 int charsWidth(java.awt.Graphics g, java.awt.Font font, char[] text, int offset, int length)
          Returns the width of a String.
 void drawChars(java.awt.Graphics g, char[] text, int offset, int length, int x, int y, int align)
          Draws a String at the specified position with the specified horizontal alignment.
protected  void drawCharsCenter(java.awt.Graphics g, char[] text, int offset, int length, int x, int y)
          Callback to be overridden.
protected  void drawCharsLeft(java.awt.Graphics g, char[] text, int offset, int length, int x, int y)
          Callback to be overridden.
protected  void drawCharsRight(java.awt.Graphics g, char[] text, int offset, int length, int x, int y)
          Callback to be overridden.
 void drawString(java.awt.Graphics g, java.lang.String s, int x, int y, int align)
          Draws a String at the specified position with the specified horizontal alignment.
protected  void drawStringCenter(java.awt.Graphics g, java.lang.String s, int x, int y)
          Callback to be overridden.
protected  void drawStringLeft(java.awt.Graphics g, java.lang.String s, int x, int y)
          Callback to be overridden.
protected  void drawStringRigth(java.awt.Graphics g, java.lang.String s, int x, int y)
          Callback to be overridden.
static java.awt.Font getDefaultBoldFont()
          Returns the default bold font.
static java.awt.Font getDefaultPlainFont()
          Returns the default plain font.
static StringDrawDevice getDevice()
          Returns the current installed device.
static void setDefaultBoldFont(java.awt.Font font)
          Sets the default bold font.
static void setDefaultPlainFont(java.awt.Font font)
          Sets the default plain font.
static void setDevice(StringDrawDevice device)
          Sets a new implementation of the device.
 int stringWidth(java.awt.Graphics g, java.awt.Font font, java.lang.String s)
          Returns the width of a String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringDrawDevice

public StringDrawDevice()
Method Detail

getDevice

public static StringDrawDevice getDevice()
Returns the current installed device.

Returns:
The current installed device.

setDevice

public static void setDevice(StringDrawDevice device)
Sets a new implementation of the device.

Parameters:
device - A new implementation of the device, not null.

getDefaultPlainFont

public static java.awt.Font getDefaultPlainFont()
Returns the default plain font.

Returns:
The default plain font.

setDefaultPlainFont

public static void setDefaultPlainFont(java.awt.Font font)
Sets the default plain font.

Parameters:
font - The default plain font.

getDefaultBoldFont

public static java.awt.Font getDefaultBoldFont()
Returns the default bold font.

Returns:
The default bold font.

setDefaultBoldFont

public static void setDefaultBoldFont(java.awt.Font font)
Sets the default bold font.

Parameters:
font - The default bold font.

drawString

public void drawString(java.awt.Graphics g,
                       java.lang.String s,
                       int x,
                       int y,
                       int align)
Draws a String at the specified position with the specified horizontal alignment.

Parameters:
g - The Graphics to draw on.
s - The text as String.
x - The left, center or right x coordinate of the baseline.
y - The y coordinate of the baseline.
align - The horizontal alignment, LEFT, CENTER or RIGHT.

drawChars

public void drawChars(java.awt.Graphics g,
                      char[] text,
                      int offset,
                      int length,
                      int x,
                      int y,
                      int align)
Draws a String at the specified position with the specified horizontal alignment.

Parameters:
g - The Graphics to draw on.
text - The text as char[].
offset - The first character to be printed.
length - The number of characters to print.
x - The x coordinate of the left, center or right of the baseline.
y - The y coordinate of the baseline.
align - The horizontal alignment, LEFT, CENTER or RIGHT.

stringWidth

public int stringWidth(java.awt.Graphics g,
                       java.awt.Font font,
                       java.lang.String s)
Returns the width of a String. It is implemented as g.getFontMetrics(font).stringWidth(s). Override this method for an other implementation.

Parameters:
g - The relevant Graphics object.
font - The font to be used.
s - The text as String.

charsWidth

public int charsWidth(java.awt.Graphics g,
                      java.awt.Font font,
                      char[] text,
                      int offset,
                      int length)
Returns the width of a String. It is implemented as g.getFontMetrics(font).charsWidth(text, offset, length). Override this method for an other implementation.

Parameters:
g - The relevant Graphics object.
font - The font to be used.
text - The text as char[].
offset - The first character to be printed.
length - The number of characters to print.

drawStringLeft

protected void drawStringLeft(java.awt.Graphics g,
                              java.lang.String s,
                              int x,
                              int y)
Callback to be overridden.

Parameters:
g - The Graphics to draw on.
s - The text as String.
x - The left x coordinate of the baseline.
y - The y coordinate of the baseline.

drawCharsLeft

protected void drawCharsLeft(java.awt.Graphics g,
                             char[] text,
                             int offset,
                             int length,
                             int x,
                             int y)
Callback to be overridden.

Parameters:
g - The Graphics to draw on.
text - The text as char[].
offset - The first character to be printed.
length - The number of characters to print.
x - The left x coordinate of the baseline.
y - The y coordinate of the baseline.

drawStringCenter

protected void drawStringCenter(java.awt.Graphics g,
                                java.lang.String s,
                                int x,
                                int y)
Callback to be overridden.

Parameters:
g - The Graphics to draw on.
s - The text as String.
x - The centered x coordinate of the baseline.
y - The y coordinate of the baseline.

drawCharsCenter

protected void drawCharsCenter(java.awt.Graphics g,
                               char[] text,
                               int offset,
                               int length,
                               int x,
                               int y)
Callback to be overridden.

Parameters:
g - The Graphics to draw on.
text - The text as char[].
offset - The first character to be printed.
length - The number of characters to print.
x - The centered x coordinate of the baseline.
y - The y coordinate of the baseline.

drawStringRigth

protected void drawStringRigth(java.awt.Graphics g,
                               java.lang.String s,
                               int x,
                               int y)
Callback to be overridden.

Parameters:
g - The Graphics to draw on.
s - The text as String.
x - The right x coordinate of the baseline.
y - The y coordinate of the baseline.

drawCharsRight

protected void drawCharsRight(java.awt.Graphics g,
                              char[] text,
                              int offset,
                              int length,
                              int x,
                              int y)
Callback to be overridden.

Parameters:
g - The Graphics to draw on.
text - The text as char[].
offset - The first character to be printed.
length - The number of characters to print.
x - The right x coordinate of the baseline.
y - The y coordinate of the baseline.

ReportCat 1.1

Copyright © 2003 - 2005 NetCat Inc.. All rights reserved. Feedback

Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation, Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation, Print,Printing,Printer,Java,Java Print,SDK,Java Printing,Printing Java,Print Java,Library,Java Library,Print Library,Report,Reports,Java Report,Java Programming,Java Output,Layout,Page,API,Preview,Print Preview,Content,A4,Free,Output,Header,Footer,Download,Package,Jar,Evaluation