ReportCat 1.1

li.netcat.print.util
Class LabelDrawer

java.lang.Object
  extended byli.netcat.print.util.LabelDrawer
All Implemented Interfaces:
Drawer, Painter

public class LabelDrawer
extends java.lang.Object
implements Drawer

This is a lightweight equivalent to the JLabel that implements the Drawer interface. It has an Icon and a Text that can be positioned relative to each other and the text can be aligned in horixontal and vertical direction. If the text does not fit into the bounding box, it gets clipped by adding "..." at th end of the visible text.

Author:
Arthur Marxer

Constructor Summary
LabelDrawer()
          Constructs a new LabelDrawer with non text and no icon and a left horizontal alignment.
LabelDrawer(javax.swing.Icon icon)
          Constructs a new LabelDrawer with the given icon and a centered horizontal alignment.
LabelDrawer(javax.swing.Icon icon, int horizontalAlignment)
          Constructs a new LabelDrawer with the given properties.
LabelDrawer(java.lang.String text)
          Constructs a new LabelDrawer with the given text and a left horizontal alignment.
LabelDrawer(java.lang.String text, javax.swing.Icon icon, int horizontalAlignment)
          Constructs a new LabelDrawer with the given properties.
LabelDrawer(java.lang.String text, int horizontalAlignment)
          Constructs a new LabelDrawer with the given properties.
 
Method Summary
 void draw(java.awt.Graphics g, int x, int y, int width, int height)
          Draws the target on the given Graphics object.
 java.awt.Font getFont()
          Returns the font of the LabelDrawer.
 int getHorizontalAlignment()
          Returns the horizontal alignment.
 int getHorizontalTextPosition()
          Returns the horizontal text position.
 javax.swing.Icon getIcon()
          Returns the icon property.
 int getIconTextGap()
          Returns the gap between icon and text.
 java.awt.Insets getInsets(java.awt.Insets out)
          Returns the insets of this LabelDrawer.
 int getPreferredHeight(java.awt.Graphics g, int availableWith)
          Returns the preferred height of this label.
 java.awt.Dimension getPreferredSize(java.awt.Graphics g, java.awt.Dimension out)
          Returns the preferred size of the target.
 int getPreferredWidth(java.awt.Graphics g)
          Returns the preferred width of this label.
 java.awt.Dimension getSize(java.awt.Graphics g)
          Returns the size of the Painter.
 java.lang.String getText()
          Returns the text property.
 int getVerticalAlignment()
          Returns the vertical alignment.
 int getVerticalTextPosition()
          Returns the vertical text position.
 void paint(java.awt.Graphics g, int x, int y)
          Paints the target on the given Graphics.
 void setFont(java.awt.Font font)
          Sets the font of the LabelDrawer.
 void setHorizontalAlignment(int alignment)
          Sets the horizontal alignment.
 void setHorizontalTextPosition(int textPosition)
          Sets the horizontal text position.
 void setIcon(javax.swing.Icon icon)
          Sets the icon property.
 void setIconTextGap(int iconTextGap)
          Sets the gap between icon and text.
 void setInsets(int top, int left, int bottom, int right)
          Sets the insets to the given values.
 void setText(java.lang.String text)
          Sets the text property.
 void setVerticalAlignment(int alignment)
          Sets the vertical alignment.
 void setVerticalTextPosition(int textPosition)
          Sets the vertical text position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LabelDrawer

public LabelDrawer(java.lang.String text,
                   javax.swing.Icon icon,
                   int horizontalAlignment)
Constructs a new LabelDrawer with the given properties.

Parameters:
text - The text of the LabelDrawer, can be null.
icon - The icon of the LabelDrawer, can be null.
horizontalAlignment - The horizontal alignment of the LabelDrawer, one of LEFT, CENTER or RIGHT.

LabelDrawer

public LabelDrawer(java.lang.String text,
                   int horizontalAlignment)
Constructs a new LabelDrawer with the given properties.

Parameters:
text - The text of the LabelDrawer, can be null.
horizontalAlignment - The horizontalAlignment of the LabelDrawer, one of LEFT, CENTER or RIGHT.

LabelDrawer

public LabelDrawer(java.lang.String text)
Constructs a new LabelDrawer with the given text and a left horizontal alignment.

Parameters:
text - The text of the LabelDrawer, can be null.

LabelDrawer

public LabelDrawer(javax.swing.Icon icon,
                   int horizontalAlignment)
Constructs a new LabelDrawer with the given properties.

Parameters:
icon - The icon of the LabelDrawer, can be null.
horizontalAlignment - The horizontalAlignment of the LabelDrawer, one of LEFT, CENTER or RIGHT.

LabelDrawer

public LabelDrawer(javax.swing.Icon icon)
Constructs a new LabelDrawer with the given icon and a centered horizontal alignment.

Parameters:
icon - The icon of the LabelDrawer, can be null.

LabelDrawer

public LabelDrawer()
Constructs a new LabelDrawer with non text and no icon and a left horizontal alignment.

Method Detail

getText

public java.lang.String getText()
Returns the text property.

Returns:
The text property.

setText

public void setText(java.lang.String text)
Sets the text property.

Parameters:
text - The text property, can be null.

getIcon

public javax.swing.Icon getIcon()
Returns the icon property.

Returns:
The icon property.

setIcon

public void setIcon(javax.swing.Icon icon)
Sets the icon property.

Parameters:
icon - The icon property, can be null.

getIconTextGap

public int getIconTextGap()
Returns the gap between icon and text. The default value is 4.

Returns:
The gap between icon and text in pixel.

setIconTextGap

public void setIconTextGap(int iconTextGap)
Sets the gap between icon and text.

Parameters:
iconTextGap - The gap between icon and text in pixel.

getVerticalAlignment

public int getVerticalAlignment()
Returns the vertical alignment.

Returns:
One of the values TOP, CENTER or BOTTOM.

setVerticalAlignment

public void setVerticalAlignment(int alignment)
Sets the vertical alignment.

Parameters:
alignment - One of the values TOP, CENTER or BOTTOM.

getHorizontalAlignment

public int getHorizontalAlignment()
Returns the horizontal alignment.

Returns:
One of the values LEFT, CENTER or RIGHT.

setHorizontalAlignment

public void setHorizontalAlignment(int alignment)
Sets the horizontal alignment.

Parameters:
alignment - One of the values LEFT, CENTER or RIGHT.

getVerticalTextPosition

public int getVerticalTextPosition()
Returns the vertical text position.

Returns:
One of the values TOP, CENTER or BOTTOM.

setVerticalTextPosition

public void setVerticalTextPosition(int textPosition)
Sets the vertical text position.

Parameters:
textPosition - One of the values TOP, CENTER or BOTTOM.

getHorizontalTextPosition

public int getHorizontalTextPosition()
Returns the horizontal text position.

Returns:
One of the values LEFT, CENTER or RIGHT.

setHorizontalTextPosition

public void setHorizontalTextPosition(int textPosition)
Sets the horizontal text position.

Parameters:
textPosition - One of the values LEFT, CENTER or RIGHT.

getInsets

public java.awt.Insets getInsets(java.awt.Insets out)
Returns the insets of this LabelDrawer.

Parameters:
out - An insets object, not null.
Returns:
The modified out patameter.

setInsets

public void setInsets(int top,
                      int left,
                      int bottom,
                      int right)
Sets the insets to the given values.

Parameters:
top - The top inset.
left - The left inset.
bottom - The bottom inset.
right - The right inset.

getFont

public java.awt.Font getFont()
Returns the font of the LabelDrawer.

Returns:
The font of the LabelDrawer, never null.

setFont

public void setFont(java.awt.Font font)
Sets the font of the LabelDrawer.

Parameters:
font - The font of the LabelDrawer, must not be null.

getPreferredSize

public java.awt.Dimension getPreferredSize(java.awt.Graphics g,
                                           java.awt.Dimension out)
Returns the preferred size of the target.

Parameters:
g - The relevant Graphics object.
out - An instance of Dimension that is used as return value, not null. This avoids the allocation of many rectangles, especially in connection with renderers (e.g. table).
Returns:
The preferred size of the target.

getPreferredWidth

public int getPreferredWidth(java.awt.Graphics g)
Returns the preferred width of this label.

Parameters:
g - The relevant graphics object.
Returns:
The preferred width of this label.

getPreferredHeight

public int getPreferredHeight(java.awt.Graphics g,
                              int availableWith)
Returns the preferred height of this label.

Parameters:
g - The relevant graphics object.
availableWith - The available width that can be used to paint on.
Returns:
The preferred height of this label.

getSize

public java.awt.Dimension getSize(java.awt.Graphics g)
Description copied from interface: Painter
Returns the size of the Painter.

Specified by:
getSize in interface Painter
Parameters:
g - The relevant Graphics context.
Returns:
The size of the Painter.

paint

public void paint(java.awt.Graphics g,
                  int x,
                  int y)
Description copied from interface: Painter
Paints the target on the given Graphics.

Specified by:
paint in interface Painter
Parameters:
g - The Graphics object that is used to paint.
x - The x coordinate of the upper left corner of the target.
y - The y coordinate of the upper left corner of the target.

draw

public void draw(java.awt.Graphics g,
                 int x,
                 int y,
                 int width,
                 int height)
Description copied from interface: Drawer
Draws the target on the given Graphics object.

Specified by:
draw in interface Drawer
Parameters:
g - The Graphics object that is used to draw.
x - The x coordinate of the upper left corner of the target.
y - The y coordinate of the upper left corner of the target.
width - The width that the target should use for drawing.
height - The height that the target should use for drawing.

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