public class IconAndText extends AnimatedDrawing implements ImageRefresher, FontSizable
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.
Modifier and Type | Field and Description |
---|---|
static boolean |
defaultResizeWithFont |
FontMetrics |
fontMetrics
The FontMetrics being used.
|
IImage |
icon
The icon being used.
|
boolean |
iconIsFreeSized
If this is true then the icon is not positioned to match the text size.
|
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.
|
boolean |
resizeWithFont
Set this true to allow the IconAndText to change its font and size.
|
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.
|
AlwaysOnTop, CompletelyIn, freeImageWithDrawing, HasBorder, HasChanged, HasMoved, hotArea, hotPolygon, image, InUse, IsAnimated, IsEmpty, IsInvisible, IsLocked, IsMoveable, IsNotHot, IsNotStill, IsPrepared, IsPreparing, KeepOnScreen, lastDrawn, location, MouseMustBeOver, properties, RelativeToOrigin
background, height, width
KEEP_VISIBLE
CREATE_OPTION_DONT_SCALE_UP, CREATE_OPTION_IGNORE_ALPHA, CREATE_OPTION_KEEP_ASPECT_RATIO, CREATE_OPTION_ROUGH_SCALING, SCAN_LINE_BYTE_ARRAY, SCAN_LINE_INT_ARRAY, TYPE_ARGB, TYPE_GRAY_SCALE_16, TYPE_GRAY_SCALE_2, TYPE_GRAY_SCALE_256, TYPE_GRAY_SCALE_4, TYPE_INDEXED_16, TYPE_INDEXED_2, TYPE_INDEXED_256, TYPE_INDEXED_4, TYPE_MASK, TYPE_MONO, TYPE_RGB, TYPE_UNKNOWN
Constructor and Description |
---|
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,
FontMetrics fm)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
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 |
changeFont(FontMetrics fontMetrics)
This calls changeFontMetrics() only if resizeWithFont is true;
|
void |
changeFontMetrics(FontMetrics fontMetrics)
Change the Font used by the IconAndText and recalculate its size.
|
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)
Draws itself on the graphic g at a specfied co-ordinate.
|
void |
free() |
static void |
noTextColor(Object possibleIconAndText)
Sets the textColor of an object that may be an IconAndText to null.
|
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.
|
IconAndText |
setFontChange(FontChange fc)
This sets a FontChange that will adjust the FontMetrics used by this IconAndText.
|
boolean |
usesAlpha()
This always returns true.
|
changeRefresher, getRefresher, newRefresher, refresh, refresh, setRefresher, startAnimate, stopAnimate
compareTo, copyFrom, doDraw, draw, drawBorder, drawn, getBackground, getCopy, getDim, getHotArea, getImage, getImageScanLines, getLocation, getNew, getPixels, getSize, getUnusedColor, isWriteableImage, onHotArea, setHotAreaInImage, setImage, setImageScanLines, setLocation, setPixels, setRect, setSize
createImageFor, draw, draw, freeImage, getCompatibleImagePoints, getDPI, getHeight, getImageColorTable, getImageData, getImageHeight, getImageScanLineLength, getImageScanLineType, getImageType, getImageWidth, getNativeDrawable, getPixelsUsingScanLines, getScanLinesUsingPixels, getWidth, isReadableImage, scanLinesComplete, setPixelsUsingScanLines, setScanLinePixels, setScanLinesUsingPixels
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getBackground
freeImage, getImageColorTable, getImageHeight, getImageScanLineLength, getImageScanLines, getImageScanLineType, getImageType, getImageWidth, getPixels, isReadableImage, isWriteableImage, setImageScanLines, setPixels
public static boolean defaultResizeWithFont
public boolean resizeWithFont
public IImage icon
public String text
public String[] lines
public FontMetrics fontMetrics
public int textPosition
public int multiLineTextAlignment
public Color textColor
public int textHeight
public int textWidth
public boolean iconIsFreeSized
public IconAndText()
public IconAndText(IImage icon, String text, FontMetrics fontMetrics, int textPosition)
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.public IconAndText(IImage icon, String text, FontMetrics fontMetrics)
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.public IconAndText(String text, String iconName, FontMetrics fm)
text
- The text for the IconAndTexticonName
- The name of the saved image.fm
- optional FontMetrics to be used.public boolean usesAlpha()
public static void noTextColor(Object possibleIconAndText)
possibleIconAndText
- an Object that may be an IconAndText.public void refresh(IImage icon, int options)
refresh
in interface ImageRefresher
public IconAndText setColor(Color textColor, Color backgroundColor)
public void changeTextPosition(int textPosition, int multiLineTextAlignment)
public void changeFontMetrics(FontMetrics fontMetrics)
public void changeFont(FontMetrics fontMetrics)
changeFont
in interface FontSizable
public IconAndText setFontChange(FontChange fc)
fc
- the FontChange to apply.public void set(IImage icon, String text)
icon
- The new icon to use.text
- The new text to use.public void set(IImage icon, String text, FontMetrics fontMetrics, int textPosition)
icon
- The new icon to use.text
- The new text to use.public void clear()
public void clearColumns()
public void addColumn(Object textOrIcon, int width, int anchor)
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.public void addColumn(Object textOrIcon, int width, int anchor, int addIndex)
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. If it is -2 or less then the width
is calculated and a padding of -width-1 is added.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.public void addColumn(Object textOrIcon)
textOrIcon
- either a String or an IImage to display in this column.public void draw(Graphics g, int x, int y, int options)
Drawing