org.rhq.enterprise.gui.image
Class WebImage

java.lang.Object
  extended by org.rhq.enterprise.gui.image.WebImage
Direct Known Subclasses:
AvailabilityReport, Chart, ResourceTree

public class WebImage
extends Object


Field Summary
protected  boolean antiAliased
          Use an IndexColorModel.
protected static String ARG_CANNOT_BE_NULL
           
 Color backgroundColor
          Background color for the image.
 int bottomBorder
          Height of the image border on the bottom side of the image
protected static Color DEFAULT_BACKGROUND_COLOR
           
protected static String DEFAULT_BOLD_TYPEFACE
           
protected static Color DEFAULT_BORDER_COLOR
           
protected static int DEFAULT_BORDER_SIZE
           
protected static Font DEFAULT_FONT
           
protected static FontMetrics DEFAULT_FONT_METRICS
           
protected static int DEFAULT_HEIGHT
           
protected static String DEFAULT_PLAIN_TYPEFACE
           
protected static int DEFAULT_SHADOW_WIDTH
           
protected static Color DEFAULT_TEXT_COLOR
           
protected static int DEFAULT_WIDTH
           
 Font font
          Text font.
 boolean frameImage
          Draws a two pixel light gray frame at the edge of the image
 int height
          Height of the image.
protected  boolean indexColors
          Anti-alias shapes and text.
 int leftBorder
          Width of the image border on the left side of the image
protected  Graphics2D m_graphics
           
 int rightBorder
          Width of the image border on the right side of the image
 int shadowWidth
          Width of the shadow around the image.
static Font SMALL_FONT
           
 Color textColor
          Color for text in the image.
 int topBorder
          Height of the image border on the top side of the image
 int width
          Width of the image.
 
Constructor Summary
protected WebImage(int width, int height)
           
 
Method Summary
protected  void draw(Graphics2D g)
           
 FontMetrics getFontMetrics()
          Retrieves the font metrics.
 Image getImage()
          Retrieves the image as a java.awt.Image object.
protected  Point getTextCenter(String text)
           
protected  Point getTextCenter(String text, Rectangle rect)
           
protected static Point getTextCenter(String text, Rectangle rect, FontMetrics metrics)
           
static boolean isRunnable()
          Determine if a graphics environment is available.
protected  void postInit(Graphics2D graphics)
           
protected  void preInit()
           
 void setBorder(int border)
          Sets the size of the top, left, right and bottom borders.
 void writeJpegImage(OutputStream stream)
          Writes the chart image as a JPEG image.
 void writeJpegImage(String filename)
          Writes the chart image as a JPEG image.
 void writePngImage(OutputStream stream)
          Writes the chart image as a PNG image.
 void writePngImage(String filename)
          Writes the chart image as a PNG image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARG_CANNOT_BE_NULL

protected static final String ARG_CANNOT_BE_NULL
See Also:
Constant Field Values

DEFAULT_HEIGHT

protected static final int DEFAULT_HEIGHT
See Also:
Constant Field Values

DEFAULT_WIDTH

protected static final int DEFAULT_WIDTH
See Also:
Constant Field Values

DEFAULT_BACKGROUND_COLOR

protected static final Color DEFAULT_BACKGROUND_COLOR

DEFAULT_BORDER_SIZE

protected static final int DEFAULT_BORDER_SIZE
See Also:
Constant Field Values

DEFAULT_BORDER_COLOR

protected static final Color DEFAULT_BORDER_COLOR

DEFAULT_TEXT_COLOR

protected static final Color DEFAULT_TEXT_COLOR

DEFAULT_SHADOW_WIDTH

protected static final int DEFAULT_SHADOW_WIDTH
See Also:
Constant Field Values

DEFAULT_BOLD_TYPEFACE

protected static final String DEFAULT_BOLD_TYPEFACE
See Also:
Constant Field Values

DEFAULT_PLAIN_TYPEFACE

protected static final String DEFAULT_PLAIN_TYPEFACE
See Also:
Constant Field Values

DEFAULT_FONT

protected static final Font DEFAULT_FONT

DEFAULT_FONT_METRICS

protected static final FontMetrics DEFAULT_FONT_METRICS

SMALL_FONT

public static final Font SMALL_FONT

m_graphics

protected Graphics2D m_graphics

font

public Font font
Text font.


height

public int height
Height of the image.


width

public int width
Width of the image.


leftBorder

public int leftBorder
Width of the image border on the left side of the image


topBorder

public int topBorder
Height of the image border on the top side of the image


rightBorder

public int rightBorder
Width of the image border on the right side of the image


bottomBorder

public int bottomBorder
Height of the image border on the bottom side of the image


frameImage

public boolean frameImage
Draws a two pixel light gray frame at the edge of the image


backgroundColor

public Color backgroundColor
Background color for the image.


textColor

public Color textColor
Color for text in the image.


shadowWidth

public int shadowWidth
Width of the shadow around the image.


antiAliased

protected boolean antiAliased
Use an IndexColorModel.


indexColors

protected boolean indexColors
Anti-alias shapes and text.

Constructor Detail

WebImage

protected WebImage(int width,
                   int height)
Method Detail

draw

protected void draw(Graphics2D g)

preInit

protected void preInit()

postInit

protected void postInit(Graphics2D graphics)

setBorder

public void setBorder(int border)
Sets the size of the top, left, right and bottom borders.

Parameters:
border - The size to set the borders to.
See Also:
#LeftBorder

getFontMetrics

public FontMetrics getFontMetrics()
Retrieves the font metrics.

Returns:
A java.awt.Font object that contains the label font.
See Also:
Font

getImage

public Image getImage()
Retrieves the image as a java.awt.Image object. The image is redrawn with the latest data and properties each time this method is called.

Returns:
A java.awt.Image that contains the drawn chart image.
See Also:
Image

writeJpegImage

public void writeJpegImage(String filename)
                    throws FileNotFoundException,
                           IOException
Writes the chart image as a JPEG image. The chart is redrawn with the latest data and properties each time this method is called.

Parameters:
filename - The path and filename that specifies where the PNG image should be written.
Throws:
FileNotFoundException - If the filename is not a valid name for a file.
IOException - If there is an IO error while writing to the file.
IllegalArgumentException - If the filename parameter is null.

writeJpegImage

public void writeJpegImage(OutputStream stream)
                    throws IOException
Writes the chart image as a JPEG image. The chart is redrawn with the latest data and properties each time this method is called.

Parameters:
stream - The java.io.OutputStream to write the PNG image to.
Throws:
IOException - If there is an IO error while streaming the PNG image.
IllegalArgumentException - If the stream parameter is null.
See Also:
OutputStream

writePngImage

public void writePngImage(String filename)
                   throws FileNotFoundException,
                          IOException
Writes the chart image as a PNG image. The chart is redrawn with the latest data and properties each time this method is called.

Parameters:
filename - The path and filename that specifies where the PNG image should be written.
Throws:
FileNotFoundException - If the filename is not a valid name for a file.
IOException - If there is an IO error while writing to the file.
IllegalArgumentException - If the filename parameter is null.

writePngImage

public void writePngImage(OutputStream stream)
                   throws IOException
Writes the chart image as a PNG image. The chart is redrawn with the latest data and properties each time this method is called.

Parameters:
stream - The java.io.OutputStream to write the PNG image to.
Throws:
IOException - If there is an IO error while streaming the PNG image.
IllegalArgumentException - If the stream parameter is null.
See Also:
OutputStream

getTextCenter

protected Point getTextCenter(String text)

getTextCenter

protected Point getTextCenter(String text,
                              Rectangle rect)

getTextCenter

protected static Point getTextCenter(String text,
                                     Rectangle rect,
                                     FontMetrics metrics)

isRunnable

public static boolean isRunnable()
Determine if a graphics environment is available. The graphics environment would be X on Unix. GDI on Windows, Mac, etc. This is primarily used as a check for X because it is very difficult to run without a graphics environment on the Windows and Mac operating systems.

Returns:
A boolean that is true if a graphics environment is available, false otherwise.


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.