|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
java.awt.Panel
com.tecnick.jwtm.ImageButton
public class ImageButton
Title: ImageButton Class
Description: Class to create image buttons with text and behaviour
Nested Class Summary | |
---|---|
(package private) class |
ImageButton.imageButtonMouseAdapter
Inner class for handling mouse events. |
Nested classes/interfaces inherited from class java.awt.Panel |
---|
java.awt.Panel.AccessibleAWTPanel |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
protected java.lang.String |
actionCommand
action command to be returned to the listener |
protected java.awt.event.ActionListener |
actionListener
the action listener (for events) |
private java.applet.AudioClip |
audio_click
audio clip for button click event |
private java.applet.AudioClip |
audio_over
audio clip for mouse over event |
private int |
bevel_width
3D bevel width in pixels |
private int |
bh
height of background image in pixels |
static int |
BOTTOM
constant BOTTOM |
private java.awt.Graphics |
bufferGraphics
graphics for double buffering |
private int |
buttonID
menu item id to be returned on event as actionCommand |
private int |
bw
width of background image in pixels |
private int |
bx
horizontal position of background image |
private int |
by
vertical position of background image |
static int |
CENTER
constant CENTER |
private boolean |
center_block
if true center the block [image + label] |
private java.awt.Color |
col_off_bck
background color for mouse-off state |
private java.awt.Color |
col_off_sdw
text shadow color for mouse-off state |
private java.awt.Color |
col_off_txt
text color for mouse-off state |
private java.awt.Color |
col_on_bck
background color for mouse-on state |
private java.awt.Color |
col_on_sdw
text shadow color for mouse-on state |
private java.awt.Color |
col_on_txt
text color for mouse-on state |
private java.awt.Color |
col_over_bck
background color for mouse-over state |
private java.awt.Color |
col_over_sdw
text shadow color for mouse-over state |
private java.awt.Color |
col_over_txt
text color for mouse-over state |
private java.awt.Color |
col_shadow
remember current text shadow color |
protected int |
current_action
current button action to send to listener -1 means no action |
private boolean |
fDrawPushedIn
if true make the button "depress" when clicked. |
private boolean |
fShowBorder
if true display the 3D button border |
private int |
gap
distance in pixels between image and label |
private int |
ih
height of internal button icon image in pixels |
private float |
imageScale
float parameter to scale the image size |
private java.awt.Image |
img
current button icon |
private java.awt.Image |
img_bg
current background button image |
private java.awt.Image |
img_bg_off
button background image for normal state |
private java.awt.Image |
img_bg_on
button background image for button pressed |
private java.awt.Image |
img_bg_over
button background image for mouse over |
private java.awt.Image |
img_off
button icon for normal state |
private java.awt.Image |
img_on
button icon for button pressed |
private java.awt.Image |
img_over
button icon for mouse over |
private java.awt.Image |
inactive_img
inactive image for disabled button |
protected boolean |
isButtonPushed
Remember mouse up/down status |
private int |
iw
width of internal button icon image in pixels |
private int |
ix
horizontal position of internal button icon image |
private int |
iy
vertical position of internal button icon image |
private java.lang.String |
label
button label |
static int |
LEFT
constant LEFT |
private java.awt.Image |
offscreen
offscreen image to handle double buffering |
private int[] |
padding
array of button paddings (Left, Right, Top, Bottom) distance in pixels between button border and button objects (image or label) |
private int |
pos
label position relative to icon position. |
static int |
RIGHT
constant RIGHT |
private static long |
serialVersionUID
serialVersionUID |
private int |
shadow_x
text shadow relative horizontal position in pixels |
private int |
shadow_y
text shadow relative vertical position in pixels |
static int |
TOP
constant TOP |
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(java.awt.Image image)
Constructor for void label |
|
ImageButton(java.awt.Image image,
java.lang.String label)
Constructor |
|
ImageButton(java.lang.String label)
Constructor for void image |
Method Summary | |
---|---|
void |
addActionListener(java.awt.event.ActionListener l)
Adds the specified action listener to receive action events from this button. |
void |
addNotify()
Creates the Panel's peer. |
protected void |
fireActionEvent(int actiontype)
Fire an action event to the listeners. |
java.lang.String |
getActionCommand()
Returns the command name of the action event fired by this button. |
int |
getButtonID()
Get the buttonID (unique numeric identifier for current component) |
int |
getImageLabelGap()
Get the gap in pixels between the label (if any) and image. |
java.lang.String |
getLabel()
Get the button text label |
int |
getLabelPosition()
Get the label position (relative to button icon) possible values are: ImageButton.LEFT, ImageButton.RIGHT, ImageButton.TOP, ImageButton.BOTTOM |
int[] |
getPadding()
Get button paddings in pixels as array (Left, Right, Top, Bottom). |
protected void |
imageButton_MouseOff()
Gets called when the mouse crosses out of the button area. |
protected void |
imageButton_MouseOver(boolean sound_on)
Gets called when the mouse crosses into the button area. |
protected void |
imageButton_MousePushed()
Gets called when the mouse button is pressed. |
boolean |
isFocusable()
Returns whether this Component can become the focus owner. |
boolean |
isFocusTraversable()
Returns whether this Component can become the focus owner. |
void |
paint(java.awt.Graphics g)
Draw button elements (border, image and label) at calculated positions |
void |
removeActionListener(java.awt.event.ActionListener l)
Removes the specified action listener so it no longer receives action events from this button. |
protected void |
repaintImages(java.awt.Graphics gbuffer)
Redraw the button images |
void |
resize()
Resize the size of button and components. |
void |
setActionCommand(java.lang.String command)
Sets the command name of the action event fired by this button. |
void |
setAudioStateClips(java.applet.AudioClip a,
java.applet.AudioClip b)
Set the audio clips to play for mouse-on and mouse over events. |
void |
setBgImage(java.awt.Image i)
Set the current background image to be shown. |
void |
setBorderWidth(int bb)
Set the button bevel width in pixels |
private void |
setButtonComponents(java.applet.AudioClip sound,
java.awt.Color foreground,
java.awt.Color background,
java.awt.Color shadow,
java.awt.Image bg,
java.awt.Image icon)
Set and repaint button components |
void |
setButtonID(int id)
Set buttonID (unique numeric identifier for current component) |
void |
setCenterBlock(boolean a)
Set the position of the block (label + image) |
void |
setDrawPushedIn(boolean b)
Make the button "depress" when clicked. |
void |
setEnable(boolean a)
Enables or disables this component, depending on the value of the parameter b. |
void |
setFont(java.awt.Font f)
Set the button label font |
void |
setImage(java.awt.Image i)
Set the current image icon to be shown. |
void |
setImageLabelGap(int g)
Set the gap in pixels between the label (if any) and image. |
void |
setImageScale(double f)
Scale the image to the given value (1.0 = 100%). |
void |
setImageScale(float pct)
Scale the image to the given value (1.0 = 100%). |
void |
setLabel(java.lang.String l)
Set the button text label |
void |
setLabelPosition(int a)
Set the position of the label relative to icon |
void |
setPadding(int[] p)
Set the padding in pixels. |
void |
setShadowPosition(int x,
int y)
Set shadow relative position |
void |
setStateBgImages(java.awt.Image imgoff,
java.awt.Image imgon,
java.awt.Image imgover)
Set the background state images (one image for each button/mouse state) |
void |
setStateColors(java.awt.Color ba,
java.awt.Color bb,
java.awt.Color bc,
java.awt.Color ta,
java.awt.Color tb,
java.awt.Color tc,
java.awt.Color sa,
java.awt.Color sb,
java.awt.Color sc)
Set the button colors for each state |
void |
setStateImages(java.awt.Image imgoff,
java.awt.Image imgon,
java.awt.Image imgover)
Set the state images (one image for each button/mouse state) |
Methods inherited from class java.awt.Panel |
---|
getAccessibleContext |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
private java.awt.Graphics bufferGraphics
private java.awt.Image offscreen
protected java.lang.String actionCommand
protected java.awt.event.ActionListener actionListener
protected boolean isButtonPushed
private int buttonID
private int bevel_width
public static final int LEFT
public static final int TOP
public static final int RIGHT
public static final int BOTTOM
public static final int CENTER
private java.lang.String label
private java.awt.Image img
private java.awt.Image img_off
private java.awt.Image img_on
private java.awt.Image img_over
private java.awt.Image img_bg
private java.awt.Image img_bg_off
private java.awt.Image img_bg_on
private java.awt.Image img_bg_over
private java.awt.Image inactive_img
private float imageScale
private java.applet.AudioClip audio_click
private java.applet.AudioClip audio_over
private boolean fShowBorder
private boolean fDrawPushedIn
private int pos
private boolean center_block
private int[] padding
private int gap
private int shadow_x
private int shadow_y
private int ix
private int iy
private int iw
private int ih
private int bx
private int by
private int bw
private int bh
private java.awt.Color col_off_bck
private java.awt.Color col_over_bck
private java.awt.Color col_on_bck
private java.awt.Color col_off_txt
private java.awt.Color col_over_txt
private java.awt.Color col_on_txt
private java.awt.Color col_off_sdw
private java.awt.Color col_over_sdw
private java.awt.Color col_on_sdw
private java.awt.Color col_shadow
protected int current_action
Constructor Detail |
---|
public ImageButton(java.awt.Image image)
image
- Button Imagepublic ImageButton(java.lang.String label)
label
- Text label of the buttonpublic ImageButton(java.awt.Image image, java.lang.String label)
image
- Button Imagelabel
- Text label of the buttonMethod Detail |
---|
public boolean isFocusTraversable()
isFocusTraversable
in class java.awt.Component
public boolean isFocusable()
isFocusable
in class java.awt.Component
public void addNotify()
addNotify
in class java.awt.Panel
public void setFont(java.awt.Font f)
setFont
in class java.awt.Container
f
- fontpublic void setStateColors(java.awt.Color ba, java.awt.Color bb, java.awt.Color bc, java.awt.Color ta, java.awt.Color tb, java.awt.Color tc, java.awt.Color sa, java.awt.Color sb, java.awt.Color sc)
ba
- background button color when mouse is offbb
- background button color when mouse is overbc
- background button color when button is clickedta
- foreground text color when mouse is offtb
- foreground text color when mouse is overtc
- foreground text color when button is clickedsa
- shadow text color when mouse is offsb
- shadow text color when mouse is oversc
- shadow text color when button is clickedpublic void setShadowPosition(int x, int y)
x
- horizontal pixels between text position and shadow positiony
- vertical pixels between text position and shadow positionpublic void setButtonID(int id)
id
- button IDpublic int getButtonID()
public void setBorderWidth(int bb)
bb
- bevel sizepublic void setDrawPushedIn(boolean b)
b
- true or falsepublic int getLabelPosition()
public void setLabelPosition(int a)
a
- ImageButton.LEFT, ImageButton.RIGHT, ImageButton.TOP, ImageButton.BOTTOMpublic void setCenterBlock(boolean a)
a
- if true center the blockpublic java.lang.String getLabel()
public void setLabel(java.lang.String l)
l
- button text labelpublic void setAudioStateClips(java.applet.AudioClip a, java.applet.AudioClip b)
a
- audio clip when button is clickedb
- audio clip when mouse is overpublic void setPadding(int[] p)
p
- array of button paddings in pixels (Left, Right, Top, Bottom)public int[] getPadding()
public void setImageLabelGap(int g)
g
- pixelspublic int getImageLabelGap()
public void setStateImages(java.awt.Image imgoff, java.awt.Image imgon, java.awt.Image imgover)
imgoff
- button icon image when mouse is offimgon
- button icon image when button is pressedimgover
- button icon image when mouse is offpublic void setStateBgImages(java.awt.Image imgoff, java.awt.Image imgon, java.awt.Image imgover)
imgoff
- button background image when mouse is offimgon
- button background image when button is pressedimgover
- button background image when mouse is offpublic void setImage(java.awt.Image i)
i
- Button Imagepublic void setBgImage(java.awt.Image i)
i
- Button Background Imagepublic void setImageScale(double f)
f
- floatpublic void setImageScale(float pct)
pct
- floatpublic void setEnable(boolean a)
a
- If true, this component is enabled; otherwise this component is disabledpublic void resize()
protected void repaintImages(java.awt.Graphics gbuffer)
gbuffer
- current graphic contextpublic void paint(java.awt.Graphics g)
paint
in class java.awt.Container
g
- the graphic area when diplay button elementspublic void setActionCommand(java.lang.String command)
command
- The name of the action event command fired by this buttonpublic java.lang.String getActionCommand()
public void addActionListener(java.awt.event.ActionListener l)
l
- the action listenerpublic void removeActionListener(java.awt.event.ActionListener l)
l
- the action listenerprotected void fireActionEvent(int actiontype)
actiontype
- ActionEvent.ACTION_PERFORMED,protected void imageButton_MousePushed()
protected void imageButton_MouseOver(boolean sound_on)
sound_on
- boolean to turn off soundprotected void imageButton_MouseOff()
private void setButtonComponents(java.applet.AudioClip sound, java.awt.Color foreground, java.awt.Color background, java.awt.Color shadow, java.awt.Image bg, java.awt.Image icon)
sound
- audioclip to playforeground
- foreground colorbackground
- background colorshadow
- text shadow colorbg
- background imageicon
- image icon
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |