|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
com.ccg.awt.TallButton
com.ccg.awt.ImageButton
public class ImageButton
A lightweight push button which allows pressed/released images.
This class extends the TallButton class and is intended to
provide the ability to use GIF/JPG images for the purpose of
drawing the button in its pressed, when
the mouse is over the button, and its
normal released state. Here is a set of
highlights of the features you can adjust:
set the characteristics of the
button.
preferred size
for its rendering. If you disable "scaling", then the button will
be centered in the components area.
TallButton.AROUND_TEXT or TallButton.UNDERLINE_TEXT.
semi-pushed look is not supported if
bitmaps are being used.
set(com.ccg.util.TagLookup, com.ccg.awt.ImageHolder) method has been enhanced to allow one to
specify the bitmaps (and whether they are scaled) at run-time via
a TagLookup table.
set the image to be used if
the button has been disabled.
I would highly recommend building and invoking the sample ButtonViewer.java
application (it requires a Swing enabled JVM to run). This sample
application allows one to play with almost all of the settings to
create both TallButton and ImageButton objects and
see how the behave. Assuming you have a JDK available and properly
setup (check your CLASSPATH), if you saved the file to a directory
named "/tmp", you should be able to do the following:
cd /tmp javac ButtonViewer.java java ButtonViewer
If you have other bit maps you'd like to try (other than the defaults provided). You can specify their locations by typing in their full path name or a URL address (GIF/JPG format files only).
Note, this class does not yet properly serialize itself.
ImageUtility,
Serialized Form| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary |
|---|
| Fields inherited from class com.ccg.awt.TallButton |
|---|
AROUND_TEXT, INSIDE, NONE, OUTSIDE, UNDERLINE_TEXT |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
ImageButton()
Initializes the object to the default button images. |
|
| Method Summary | |
|---|---|
static Image |
getDefaultPressedImage()
Get default image to use for the "pressed" state. |
static Image |
getDefaultReleasedImage()
Get default image to use for the "released" state. |
static Image |
getDefaultRolloverImage()
Get default image to use for the "pressed" state. |
Image |
getDisabledImage()
Get the image to display when button is disabled. |
Dimension |
getMaximumSize()
Computes the maximum size of the button. |
Dimension |
getMinimumSize()
Computes the minimum size of the button. |
Dimension |
getPreferredSize()
Computes the preferred size of the button. |
Image |
getPressedImage()
Get the image to display when button is pressed. |
Image |
getReleasedImage()
Get the image to display when button is released. |
Image |
getRolloverImage()
Get the image to display when the mouse
moves over the button. |
boolean |
isImageScaled()
Indicates whether images scaled to the size of the component set. |
void |
paint(Graphics g)
Paints the component on a graphics context. |
void |
set(TagLookup info,
ImageHolder ih)
Set properties for button based on values in TagLookup table. |
static void |
setDefaultImages(Image released,
Image pressed,
Image over)
Set the default images to use for the buttons. |
static void |
setDefaultPressedImage(Image val)
Set default image to use for the "pressed" state. |
static void |
setDefaultReleasedImage(Image val)
Set default image to use for the "released" state. |
static void |
setDefaultRolloverImage(Image val)
Set default image to use for the
"roll-over" state. |
void |
setDisabledImage(Image val)
Set the image to display when button is disabled. |
void |
setImageScaled(boolean val)
Set whether images scaled to the size of the component. |
void |
setPressedImage(Image val)
Set the image to display when button is pressed. |
void |
setReleasedImage(Image val)
Set the image to display when button is released. |
void |
setRolloverImage(Image val)
Set the image to display when the mouse
moves over the button. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ImageButton()
This method initializes the object to use the default image bitmaps for the pressed/released view of the button. After contstruction in this manner, you can use the various "set" methods to affect how the text is drawn on the images. You can also set either (or both) the pressed/released images to null, if you'd prefer to have the buttons drawn for you.
set(com.ccg.util.TagLookup, com.ccg.awt.ImageHolder)| Method Detail |
|---|
public static void setDefaultImages(Image released,
Image pressed,
Image over)
images to use for the buttons.
This method allows one to set the default images to be used when
a button is first created. You should call this button prior to
creating buttons if you want to make use of it. If you don't use
this method, the system default images will be used if
available. Also, if you would prefer for either or both states of
your button to be drawn (using the drawing methods in TallButton, you can set either (or both) of these values to
null.
released - Default Image to display when the button is
in the "released" state - or null if you want the button drawn.pressed - Default Image to display when the button is
in the "pressed" state - or null if you want the button drawn.rollover - Default Image to display when the mouse rolls
over the button - or null if you want the same image as the
released image to be used.setReleasedImage(java.awt.Image),
setPressedImage(java.awt.Image)
public void set(TagLookup info,
ImageHolder ih)
throws ParseException
TagLookup table.
This method will set all of the properties it can find from the
specified TagLookup table. Any images specified will first be searched for in the
ImageHolder object passed - and if not found
there, an attempt will be made to load them (using either the
ImageHolder passed
or directly via the ImageUtility class. The
"keys" which we recognize are as follows:
Image resource. If a string value is specified
that we can convert to a image resouce, the result will be passed
to setPressedImage(java.awt.Image). If the string values specified has a
zero length, then the pressed version of the button graphic will
be drawn using the parent classes method.
Image resource. If a string value is specified
that we can convert to a image resouce, the result will be passed
to setPressedImage(java.awt.Image). If the string values specified has a
zero length, then the released version of the button
graphic will be drawn using the parent classes method.
Image resource. If a string value is specified
that we can convert to a image resouce, the result will be passed
to setRolloverImage(java.awt.Image). If the string values specified has a
zero length, then the released
image will be used to display a button in this state (special
highlighting of the text may still occur occur).
Image resource. If a string value is specified
that we can convert to a image resouce, the result will be passed
to setDisabledImage(java.awt.Image).
setImageScaled(boolean) - set to "true"/"false"
(default is "true") indicating whether you want the bitmap to
fill the components area (streched/shrunk).
TallButton.setText(java.lang.String)Component.setFont(java.awt.Font)TagLookup.getFont(java.lang.String, java.awt.Font) for details on
specifying font strings.
TallButton.setButtonHeight(int)TallButton.setMargin(int)TallButton.setSemiPush(int)Component.setForeground(java.awt.Color)TagLookup.getColor(java.lang.String, java.awt.Color) for details on specifying colors.
Component.setBackground(java.awt.Color)TagLookup.getColor(java.lang.String, java.awt.Color) for details on specifying colors.
TallButton.setTextPressedColor(java.awt.Color)TagLookup.getColor(java.lang.String, java.awt.Color) for details on specifying colors.
TallButton.setTextEchoOn(boolean)TagLookup.getBoolean(java.lang.String, java.lang.Boolean) for details on
specifying colors (or use "true"/"false").
TallButton.setTextEchoColor(java.awt.Color)TagLookup.getColor(java.lang.String, java.awt.Color) for details on specifying colors.
TallButton.setTextEchoReleasedColor(java.awt.Color)TagLookup.getColor(java.lang.String, java.awt.Color) for details on specifying
colors.
TallButton.setButtonPressedColor(java.awt.Color)TagLookup.getColor(java.lang.String, java.awt.Color) for details on specifying
colors.
TallButton.setFocusMode(int)TallButton.getFocusModeChoices() and is used to set the focus mode.
TallButton.setFocusColor(java.awt.Color)TagLookup.getColor(java.lang.String, java.awt.Color) for details on specifying colors.
TallButton.setInsets(java.awt.Insets)).
aligned. Valid values: "c"
- centered, "l" - left, "r" - right. This parameter has no affect if you have a single line of
text.
aligned. By default, this will be
"cp.5,cp.5" which results in text centered on the button. Refer
to Align.parse(java.lang.String) for details on the numerous ways to adjust
the alignment.
tl - A TagLookup to fetch values from.ih - A ImageHolder object used to fetch any named image from.
ParseExceptionpublic void paint(Graphics g)
graphics context.
This method takes care of drawing the button in its proper
state. The following items are taken into consideration (the
settings of the object determine color and whether or not they
are done):
pressed
image if available (or fall back to parent class to draw button
for us if not).
released
image if available (or fall back to parent class to draw button
for us if not).
focus mode).
rollover
image has been defined for the button, it will be used -
otherwise the button will be drawn as if it were released.
paint in class TallButtong - Graphics context to draw button image onto.TallButton.paint(java.awt.Graphics)public void setReleasedImage(Image val)
image to display when button is released.
val - New Image value to assign - if you set this value to null,
then the released image will be drawn using the TallButton implementation.getReleasedImage()public Image getReleasedImage()
image to display when button is released.
setReleasedImage(java.awt.Image)public void setPressedImage(Image val)
image to display when button is pressed.
val - New Image value to assign - if you set this value to null,
then the released image will be drawn using the TallButton implementation.getPressedImage()public Image getPressedImage()
image to display when button is pressed.
setPressedImage(java.awt.Image)public void setDisabledImage(Image val)
image to display when button is disabled.
val - New Image value to assign - if you set this value to null,
then the released image will be drawn using the TallButton implementation.getDisabledImage()public Image getDisabledImage()
image to display when button is disabled.
setDisabledImage(java.awt.Image)public void setRolloverImage(Image val)
image to display when the mouse
moves over the button.
If you would like to display a different image when the mouse
enters the button area, you can set the image to display using
this method. By default the ImageButton
doesn't display a different "rollover" image.
val - New Image value to assign.getRolloverImage()public Image getRolloverImage()
image to display when the mouse
moves over the button.
setRolloverImage(java.awt.Image)public Dimension getPreferredSize()
getPreferredSize in class TallButtonsize required to properly draw
the button.public Dimension getMaximumSize()
getMaximumSize in class Componentscaling of the image has been enabled, we
return the parent classes implementation.public Dimension getMinimumSize()
getMinimumSize in class Componentscaling of the image has been enabled, we
return the parent classes implementation.public void setImageScaled(boolean val)
val - New boolean value to assign.
see #getImageScaledpublic boolean isImageScaled()
public static void setDefaultRolloverImage(Image val)
image to use for the
"roll-over" state.
Setting this value specifis the default for all ImageButtons created after the call is invoked.
val - New Image value to assign.getDefaultRolloverImage()public static Image getDefaultRolloverImage()
image to use for the "pressed" state.
setDefaultRolloverImage(java.awt.Image)public static void setDefaultPressedImage(Image val)
image to use for the "pressed" state.
Setting this value specifis the default for all ImageButtons created after the call is invoked.
val - New Image value to assign.getDefaultPressedImage()public static Image getDefaultPressedImage()
image to use for the "pressed" state.
setDefaultPressedImage(java.awt.Image)public static void setDefaultReleasedImage(Image val)
image to use for the "released" state.
Setting this value specifis the default for all ImageButtons created after the call is invoked.
val - New Image value to assign.getDefaultReleasedImage()public static Image getDefaultReleasedImage()
image to use for the "released" state.
setDefaultReleasedImage(java.awt.Image)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||