ewe.fx
Class IconAndText

java.lang.Object
  extended byewe.fx.IconAndText
All Implemented Interfaces:
IImage, ImageRefresher, OnScreenImage

public class IconAndText
extends Object
implements OnScreenImage, ImageRefresher

IconAndText is a special type of IImage that draws an Icon and then a line of text. It is used by a number of UI objects, including Menu, buttons, etc.

IconAndText also supports multiple images and text placed at a particular position along the width of the image. This is used by some controls to display images and text lined up in columns (e.g. the ewe.filechooser.FileChooser).

IconAndText objects are mutable/re-usable. You can change the icon and text and add and remove columns dynamically.

When using the IconAndText in column mode, the background of the image is drawn using the background of the destination graphics if the background field is null. If the destination graphics background is null, then the background will not be drawn.


Field Summary
 Color background
          A background color.
 FontMetrics fontMetrics
          The FontMetrics being used.
 int height
          This is the height of the IconAndText
 IImage icon
          The icon being used.
 String[] lines
          The text being used if it consists of multiple lines.
 int multiLineTextAlignment
          If multiple lines are used for the text this denotes how those lines are aligned within the space allocated for the text.
 String text
          The text being used.
 Color textColor
          If this is null, then the text will be drawn in the foreground color of the destination Graphics context.
 int textHeight
          This is the height of the text.
 int textPosition
          The textPosition which can be Graphics.Right, Left, Up or Down.
 int textWidth
          This is the height of the text.
 int width
          This is the width of the IconAndText
 
Fields inherited from interface ewe.fx.IImage
DISABLED, OUTLINED
 
Fields inherited from interface ewe.fx.ImageRefresher
KEEP_VISIBLE
 
Constructor Summary
IconAndText()
           
IconAndText(IImage icon, String text, FontMetrics fontMetrics)
          Create an IconAndText for the specified icon and text.
IconAndText(IImage icon, String text, FontMetrics fontMetrics, int textPosition)
          Create an IconAndText for the specified icon and text.
IconAndText(String text, String iconName, Object maskOrColor, FontMetrics fm)
          Create an IconAndText using the ImageCache.
 
Method Summary
 void addColumn(Object textOrIcon)
          This adds a new column of data along the line.
 void addColumn(Object textOrIcon, int width, int anchor)
          This adds a new column of data along the line.
 void addColumn(Object textOrIcon, int width, int anchor, int addIndex)
          This adds a new column of data along the line.
 void changeFontMetrics(FontMetrics fontMetrics)
          Change the Font used by the IconAndText and recalculate its size.
 boolean changeRefresher(ImageRefresher newRefresher, ImageRefresher oldRefresher)
          Change the ImageRefresher for the Image only if the old Refresher is the same as the one specified.
 void changeTextPosition(int textPosition, int multiLineTextAlignment)
          Change the text alignment parameters and recalculate the IconAndText size.
 void clear()
          Set the icon and text to null and clear all column information.
 void clearColumns()
          Clear all column information for this IconAndText.
 void draw(Graphics g, int x, int y, int options)
          Draw the full image at the specified co-ordinates in the graphics provided.
 void free()
          This frees system resources associated with the Image.
 Color getBackground()
          This returns a background color if one is set for the image.
 int getHeight()
          This returns the height of the image.
 int[] getPixels(int[] dest, int offset, int x, int y, int width, int height, int options)
          This always returns null.
 ImageRefresher getRefresher()
          Retrieve the ImageRefresher for the image which is weakly referenced by the OnScreenImage.
 int getWidth()
          This returns the width of the image.
 void refresh(IImage icon, int options)
           
 void set(IImage icon, String text)
          This can be used to change the icon and text, clearing any extra column data if any is present.
 void set(IImage icon, String text, FontMetrics fontMetrics, int textPosition)
          This can be used to reset the IconAndText to new icon and text.
 IconAndText setColor(Color textColor, Color backgroundColor)
          Set the text and background colors.
 void setRefresher(ImageRefresher refresher)
          Weakly set the ImageRefresher for the Image.
 boolean usesAlpha()
          This always returns false.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

icon

public IImage icon
The icon being used.


text

public String text
The text being used.


lines

public String[] lines
The text being used if it consists of multiple lines.


fontMetrics

public FontMetrics fontMetrics
The FontMetrics being used.


textPosition

public int textPosition
The textPosition which can be Graphics.Right, Left, Up or Down. When a textPosition of Up or Down is used, you cannot use the addColumns methods.


multiLineTextAlignment

public int multiLineTextAlignment
If multiple lines are used for the text this denotes how those lines are aligned within the space allocated for the text. By default this is Graphics.Center but you could also make it Graphics.LEFT or Graphics.RIGHT;


background

public Color background
A background color. Defaults to null.


textColor

public Color textColor
If this is null, then the text will be drawn in the foreground color of the destination Graphics context.


width

public int width
This is the width of the IconAndText


height

public int height
This is the height of the IconAndText


textHeight

public int textHeight
This is the height of the text.


textWidth

public int textWidth
This is the height of the text.

Constructor Detail

IconAndText

public IconAndText()

IconAndText

public IconAndText(IImage icon,
                   String text,
                   FontMetrics fontMetrics,
                   int textPosition)
Create an IconAndText for the specified icon and text.

Parameters:
icon - The image to use for the icon.
text - The text to display with the icon.
fontMetrics - optional FontMetrics and Font to be used with the icon.

IconAndText

public IconAndText(IImage icon,
                   String text,
                   FontMetrics fontMetrics)
Create an IconAndText for the specified icon and text.

Parameters:
icon - The image to use for the icon.
text - The text to display with the icon.
fontMetrics - optional FontMetrics and Font to be used with the icon.

IconAndText

public IconAndText(String text,
                   String iconName,
                   Object maskOrColor,
                   FontMetrics fm)
Create an IconAndText using the ImageCache.

Parameters:
text - The text for the IconAndText
iconName - The name of the saved image.
maskOrColor - A name of a mask image or a color mask, or null.
fm - optional FontMetrics to be used.
Method Detail

getPixels

public int[] getPixels(int[] dest,
                       int offset,
                       int x,
                       int y,
                       int width,
                       int height,
                       int options)
This always returns null.

Specified by:
getPixels in interface IImage
Parameters:
dest - The destination int array. If this is null then a new array should be created.
offset - The offset into the array to start placing pixels.
x - the x co-ordinate within the image.
y - the y co-ordinate within the image.
width - the width of the pixel block to get.
height - the height of the pixel block to get.
options - options for retrieving pixels - currently unused.
Returns:
The array containing the pixels, or null if getting pixels is not supported.

usesAlpha

public boolean usesAlpha()
This always returns false.

Specified by:
usesAlpha in interface IImage

setRefresher

public void setRefresher(ImageRefresher refresher)
Description copied from interface: OnScreenImage
Weakly set the ImageRefresher for the Image.

Specified by:
setRefresher in interface OnScreenImage

getRefresher

public ImageRefresher getRefresher()
Description copied from interface: OnScreenImage
Retrieve the ImageRefresher for the image which is weakly referenced by the OnScreenImage.

Specified by:
getRefresher in interface OnScreenImage

changeRefresher

public boolean changeRefresher(ImageRefresher newRefresher,
                               ImageRefresher oldRefresher)
Description copied from interface: OnScreenImage
Change the ImageRefresher for the Image only if the old Refresher is the same as the one specified.

Specified by:
changeRefresher in interface OnScreenImage
Parameters:
newRefresher - The new ImageRefresher for the image.
oldRefresher - What the old ImageRefresher was expected to be.
Returns:
true if the refresher was changed, false if it was not changed because the old Refresher was not the same as that specified in the parameter.

refresh

public void refresh(IImage icon,
                    int options)
Specified by:
refresh in interface ImageRefresher

setColor

public IconAndText setColor(Color textColor,
                            Color backgroundColor)
Set the text and background colors.

Returns:
this IconAndText.

changeTextPosition

public void changeTextPosition(int textPosition,
                               int multiLineTextAlignment)
Change the text alignment parameters and recalculate the IconAndText size.


changeFontMetrics

public void changeFontMetrics(FontMetrics fontMetrics)
Change the Font used by the IconAndText and recalculate its size.


set

public void set(IImage icon,
                String text)
This can be used to change the icon and text, clearing any extra column data if any is present. The original Font and text position is used.

Parameters:
icon - The new icon to use.
text - The new text to use.

set

public void set(IImage icon,
                String text,
                FontMetrics fontMetrics,
                int textPosition)
This can be used to reset the IconAndText to new icon and text. is present. The original Font and text position is used.

Parameters:
icon - The new icon to use.
text - The new text to use.

clear

public void clear()
Set the icon and text to null and clear all column information.


clearColumns

public void clearColumns()
Clear all column information for this IconAndText.


addColumn

public void addColumn(Object textOrIcon,
                      int width,
                      int anchor)
This adds a new column of data along the line. It is added to the right of the previous column or original text and icon.

Parameters:
textOrIcon - either a String or an IImage to display in this column.
width - The width of this new column. If this is -1 then the width will be calculated.
anchor - The anchor (either Graphics.RIGHT or LEFT OR'ed with TOP or BOTTOM) for the text or image.

addColumn

public void addColumn(Object textOrIcon,
                      int width,
                      int anchor,
                      int addIndex)
This adds a new column of data along the line. It is added to the right of the previous column or original text and icon.

Parameters:
textOrIcon - either a String or an IImage to display in this column.
width - The width of this new column. If this is -1 then the width will be calculated.
anchor - The anchor (one of Graphics.RIGHT or LEFT OR'ed with TOP or BOTTOM) for the text or image.
addIndex - The index at which the column will be inserted, which may be -1 to indicate that it should be added to the end.

addColumn

public void addColumn(Object textOrIcon)
This adds a new column of data along the line. It is added to the right of the previous column or original text and icon.

Parameters:
textOrIcon - either a String or an IImage to display in this column.

getHeight

public int getHeight()
Description copied from interface: IImage
This returns the height of the image.

Specified by:
getHeight in interface IImage

getWidth

public int getWidth()
Description copied from interface: IImage
This returns the width of the image.

Specified by:
getWidth in interface IImage

draw

public void draw(Graphics g,
                 int x,
                 int y,
                 int options)
Description copied from interface: IImage
Draw the full image at the specified co-ordinates in the graphics provided.

Specified by:
draw in interface IImage

getBackground

public Color getBackground()
Description copied from interface: IImage
This returns a background color if one is set for the image.

Specified by:
getBackground in interface IImage

free

public void free()
Description copied from interface: IImage
This frees system resources associated with the Image.

Specified by:
free in interface IImage