org.xith3d.ui.hud.widgets
Class Button

java.lang.Object
  extended by org.xith3d.ui.hud.base.Widget
      extended by org.xith3d.ui.hud.base.AbstractButton
          extended by org.xith3d.ui.hud.widgets.Button
All Implemented Interfaces:
org.jagatoo.datatypes.Enableable, org.jagatoo.datatypes.NamableObject, org.jagatoo.datatypes.NamedObject, org.openmali.types.twodee.Positioned2f, org.openmali.types.twodee.Positioned2fRO, org.openmali.types.twodee.Sized2f, org.openmali.types.twodee.Sized2fRO, TextWidget
Direct Known Subclasses:
ToggleButton

public class Button
extends AbstractButton
implements TextWidget

A simple button Widget. You may specify an image for each state (normal, hover, pressed). You may specify a text.


Nested Class Summary
static class Button.Description
          This class is used to describe a Button Widget.
 
Nested classes/interfaces inherited from class org.xith3d.ui.hud.base.AbstractButton
AbstractButton.ButtonState
 
Nested classes/interfaces inherited from class org.xith3d.ui.hud.base.Widget
Widget.DescriptionBase
 
Field Summary
protected static boolean DEFAULT_HEAVYWEIGHT
           
 
Fields inherited from class org.xith3d.ui.hud.base.AbstractButton
buttonState, isStateChangable
 
Fields inherited from class org.xith3d.ui.hud.base.Widget
transformHeight_Pixels2HUD, transformWidth_Pixels2HUD
 
Constructor Summary
Button(boolean isHeavyWeight, float width, float height, java.lang.String text)
          Creates a new Button.
Button(boolean isHeavyWeight, float width, float height, java.lang.String text, Button.Description desc)
          Creates a new Button.
Button(boolean isHeavyWeight, float width, float height, java.lang.String text, org.openmali.vecmath2.Colorf color)
          Creates a new Button.
Button(boolean isHeavyWeight, float width, float height, java.lang.String text, HUDFont font)
          Creates a new Button.
Button(boolean isHeavyWeight, float width, float height, java.lang.String text, HUDFont font, org.openmali.vecmath2.Colorf color)
          Creates a new Button.
Button(boolean isHeavyWeight, float width, float height, java.lang.String normalTexture, java.lang.String hoveredTexture, java.lang.String pressedTexture)
          Creates a new Image Button (textures will simply be streched over the whole Button area).
Button(boolean isHeavyWeight, float width, float height, java.lang.String normalTexture, java.lang.String hoveredTexture, java.lang.String pressedTexture, java.lang.String text, HUDFont font, org.openmali.vecmath2.Colorf color)
          Creates a new Image Button (textures will simply be streched over the whole Button area).
Button(boolean isHeavyWeight, float width, float height, Texture2D normalTexture, Texture2D hoveredTexture, Texture2D pressedTexture)
          Creates a new Image Button (textures will simply be streched over the whole Button area).
Button(boolean isHeavyWeight, float width, float height, Texture2D normalTexture, Texture2D hoveredTexture, Texture2D pressedTexture, java.lang.String text, HUDFont font, org.openmali.vecmath2.Colorf color)
          Creates a new Image Button (textures will simply be streched over the whole Button area).
Button(float width, float height, java.lang.String text)
          Creates a new Button.
Button(float width, float height, java.lang.String text, Button.Description desc)
          Creates a new Button.
Button(float width, float height, java.lang.String text, org.openmali.vecmath2.Colorf color)
          Creates a new Button.
Button(float width, float height, java.lang.String text, HUDFont font)
          Creates a new Button.
Button(float width, float height, java.lang.String text, HUDFont font, org.openmali.vecmath2.Colorf color)
          Creates a new Button.
Button(float width, float height, java.lang.String normalTexture, java.lang.String hoveredTexture, java.lang.String pressedTexture)
          Creates a new Image Button (textures will simply be streched over the whole Button area).
Button(float width, float height, java.lang.String normalTexture, java.lang.String hoveredTexture, java.lang.String pressedTexture, java.lang.String text, HUDFont font, org.openmali.vecmath2.Colorf color)
          Creates a new Image Button (textures will simply be streched over the whole Button area).
Button(float width, float height, Texture2D normalTexture, Texture2D hoveredTexture, Texture2D pressedTexture)
          Creates a new Image Button (textures will simply be streched over the whole Button area).
Button(float width, float height, Texture2D normalTexture, Texture2D hoveredTexture, Texture2D pressedTexture, java.lang.String text, HUDFont font, org.openmali.vecmath2.Colorf color)
          Creates a new Image Button (textures will simply be streched over the whole Button area).
 
Method Summary
protected  Label createCaptionWidget(java.lang.String text, Label.Description labelDesc)
           
protected static Button.Description createImageButtonDesc(java.lang.String normalTexture, java.lang.String hoveredTexture, java.lang.String pressedTexture, HUDFont font, org.openmali.vecmath2.Colorf color)
           
protected static Button.Description createImageButtonDesc(Texture2D normalTexture, Texture2D hoveredTexture, Texture2D pressedTexture, HUDFont font, org.openmali.vecmath2.Colorf color)
           
protected static Button.Description deriveDesc(HUDFont font, org.openmali.vecmath2.Colorf color)
           
protected  void drawWidget(Texture2DCanvas texCanvas, int offsetX, int offsetY, int width, int height, boolean drawsSelf)
          
 TextAlignment getAlignment()
           
protected  Texture2D getCurrentTexture()
          Gets the texture for the current buttonstate.
 HUDFont getFont()
           
 org.openmali.vecmath2.Colorf getFontColor()
           
 Texture2D getIcon()
          Gets the icon of this Button.
 int getIconGap()
          Gets the gap between the icon and the text.
<Dim2f_ extends org.openmali.types.twodee.Dim2f>
Dim2f_
getOptimalSize(Dim2f_ buffer)
          Calculates implementation dependent optimal size for this Button.
 java.lang.String getText()
           
 Texture2D getTextureHovered()
           
 Texture2D getTextureNormal()
           
 Texture2D getTexturePressed()
           
 boolean hasText()
          Returns whether this Button has a text.
protected  void init()
          This method is called when the WidgetContainer is set.
protected  void onFocusGained()
          This event is fired, when the focus is gained to a Widget.
protected  void onFocusLost()
          This event is fired, when the focus is lost by a Widget.
protected  void onSizeChanged(float oldWidth, float oldHeight, float newWidth, float newHeight)
          
 void setAlignment(TextAlignment align)
          Sets the text alignment of the Button's text.
 boolean setButtonState(AbstractButton.ButtonState buttonState)
          Sets the new AbstractButton.ButtonState for this Button.
protected  void setEnabledImpl(boolean enabled)
          
 void setFont(HUDFont font)
          Sets the Font of the Button's text.
 void setFontColor(org.openmali.vecmath2.Colorf color)
          Sets the font-color of the Button's text.
 void setIcon(java.lang.String icon)
          Sets the icon for this Button.
 void setIcon(Texture2D icon)
          Sets the icon for this Button.
 void setIconGap(int gap)
          Sets the gap between the icon and the text.
 void setText(java.lang.String text)
          Sets this Button's text content.
 void setTextureHovered(java.lang.String resource)
          Sets the Texture by resource to be used for HOVERED ButtonState.
 void setTextureHovered(Texture2D texture)
          Sets the Texture to be used for HOVERED ButtonState.
 void setTextureNormal(java.lang.String resource)
          Sets the Texture by resource to be used for NORMAL ButtonState.
 void setTextureNormal(Texture2D texture)
          Sets the Texture to be used for NORMAL ButtonState.
 void setTexturePressed(java.lang.String resource)
          Sets the Texture by resource to be used for PRESSED ButtonState.
 void setTexturePressed(Texture2D texture)
          Sets the Texture to be used for PRESSED ButtonState.
 java.lang.String toString()
          
 void update()
          Updates the Button's images.
 
Methods inherited from class org.xith3d.ui.hud.base.AbstractButton
addButtonListener, bindAccessor, fireButtonClickedEvent, getButtonState, isDefaultFocusResponsive, isEnabled, isFocusResponsive, onInputStateChanged, onMouseButtonPressed, onMouseButtonReleased, onMouseEntered, onMouseExited, removeButtonListener, setDefaultFocusResponsive, setEnabled, setFocusResponsive, unbindAccessor
 
Methods inherited from class org.xith3d.ui.hud.base.Widget
addContainerListener, addControllerListener, addFocusListener, addInputListener, addKeyboardListener, addLocationListener, addMouseListener, addSizeListener, addVisibilityListener, bindToGlobalMouseMovement, blocksFocusMoveDeviceComponent, calculateTransformHeight_Pixels2HUD, calculateTransformWidth_Pixels2HUD, compareAbsZIndex, createShape, detach, drawAndUpdateWidget, drawBackground, drawBorder, drawWidgetAfterWidgetAssembler, drawWidgetContents, getAbsoluteLocationOnHUD_, getAspect, getAssembly, getBorder, getContainer, getContentAspect, getContentHeight, getContentHeightPX, getContentLeftPX, getContentOffset, getContentTopPX, getContentWidth, getContentWidthPX, getContextMenu, getCursor, getEqualHeight_, getEqualWidth_, getForcedRedrawFrequency, getHeight, getHeightPX, getHUD, getLeft, getLevel, getLocation, getLocation, getLocationHUD2Pixels_, getLocationHUD2SG_, getLocationPixels2HUD_, getLocationSG2HUD_, getMaxRedrawFrequency, getMinHeight, getMinWidth, getName, getParentWindow, getPickHeight, getPickWidth, getRelLocationHUD2Pixels_, getRootHostWidget, getShape, getSize, getSizeHUD2Pixels_, getSizeHUD2SG_, getSizeOfPixels_, getSizePixels2HUD_, getSizeSG2HUD_, getToolTip, getTop, getTransparency, getUserObject, getWidgetAssembler, getWidth, getWidthPX, getZIndex, hasDropShadow, hasFocus, hasFocus, hasToolTip, initSize, isAHostedWidgetDirty, isClickable, isDraggable, isFocussable, isHeavyWeight, isHovered, isInitialized, isInitializing, isPickable, isThisWidgetDirty, isVisible, notifyOnDragStopped, onAttachedToContainer, onAttachedToHUD, onControllerAxisChanged, onControllerButtonPressed, onControllerButtonReleased, onDetachedFromContainer, onDetachedFromHUD, onKeyPressed, onKeyReleased, onKeyTyped, onLocationChanged, onMouseMoved, onMouseStopped, onMouseWheelMoved, onVisibilityChanged, pick, pickConditionsMatch, removeContainerListener, removeControllerListener, removeFocusListener, removeInputListener, removeKeyboardListener, removeLocationListener, removeMouseListener, removeSizeListener, removeVisibilityListener, requestFocus, resetWidgetDirty, setBorder, setBorder, setClickable, setContentClipRect, setContextMenu, setCursor, setDraggable, setFocussable, setForcedRedrawFrequency, setHasDropShadow, setHeight, setHostedWidgetDirty, setHostTextureDirty, setHostTextureDirty, setHostWidget, setLocation, setLocation, setLocation, setMaxRedrawFrequency, setName, setPickable, setSize, setSize, setSize, setSize, setTextureDirty, setTextureDirty, setToolTip, setTransparency, setTransparency, setUserObject, setVisible, setWidgetDirty, setWidth, setZIndex, startDragging, updateAbsZIndex, updateSizeFactors, updateTranslation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_HEAVYWEIGHT

protected static final boolean DEFAULT_HEAVYWEIGHT
See Also:
Constant Field Values
Constructor Detail

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              java.lang.String text,
              Button.Description desc)
Creates a new Button.

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button
desc - Button.Description

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              java.lang.String text)
Creates a new Button.

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              java.lang.String text,
              HUDFont font,
              org.openmali.vecmath2.Colorf color)
Creates a new Button.

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button
font -
color -

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              java.lang.String text,
              HUDFont font)
Creates a new Button.

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button
font -

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              java.lang.String text,
              org.openmali.vecmath2.Colorf color)
Creates a new Button.

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button
color -

Button

public Button(float width,
              float height,
              java.lang.String text,
              Button.Description desc)
Creates a new Button.

Parameters:
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button
desc - Button.Description

Button

public Button(float width,
              float height,
              java.lang.String text)
Creates a new Button.

Parameters:
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button

Button

public Button(float width,
              float height,
              java.lang.String text,
              HUDFont font,
              org.openmali.vecmath2.Colorf color)
Creates a new Button.

Parameters:
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button
font -
color -

Button

public Button(float width,
              float height,
              java.lang.String text,
              HUDFont font)
Creates a new Button.

Parameters:
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button
font -

Button

public Button(float width,
              float height,
              java.lang.String text,
              org.openmali.vecmath2.Colorf color)
Creates a new Button.

Parameters:
width - the new width of this Widget
height - the new height of this Widget
text - the text to display on the Button
color -

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              Texture2D normalTexture,
              Texture2D hoveredTexture,
              Texture2D pressedTexture,
              java.lang.String text,
              HUDFont font,
              org.openmali.vecmath2.Colorf color)
Creates a new Image Button (textures will simply be streched over the whole Button area).

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
texNormal - the texture for the normal button state
texHovered - the texture for the normal button state
texPressed - the texture for the normal button state
text - the text to display on the Button
font -
color -

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              java.lang.String normalTexture,
              java.lang.String hoveredTexture,
              java.lang.String pressedTexture,
              java.lang.String text,
              HUDFont font,
              org.openmali.vecmath2.Colorf color)
Creates a new Image Button (textures will simply be streched over the whole Button area).

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
texNormal - the texture for the normal button state
texHovered - the texture for the normal button state
texPressed - the texture for the normal button state
text - the text to display on the Button
font -
color -

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              Texture2D normalTexture,
              Texture2D hoveredTexture,
              Texture2D pressedTexture)
Creates a new Image Button (textures will simply be streched over the whole Button area).

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
texNormal - the texture for the normal button state
texHovered - the texture for the normal button state
texPressed - the texture for the normal button state

Button

public Button(boolean isHeavyWeight,
              float width,
              float height,
              java.lang.String normalTexture,
              java.lang.String hoveredTexture,
              java.lang.String pressedTexture)
Creates a new Image Button (textures will simply be streched over the whole Button area).

Parameters:
isHeavyWeight -
width - the new width of this Widget
height - the new height of this Widget
texNormal - the texture for the normal button state
texHovered - the texture for the normal button state
texPressed - the texture for the normal button state

Button

public Button(float width,
              float height,
              Texture2D normalTexture,
              Texture2D hoveredTexture,
              Texture2D pressedTexture,
              java.lang.String text,
              HUDFont font,
              org.openmali.vecmath2.Colorf color)
Creates a new Image Button (textures will simply be streched over the whole Button area).

Parameters:
width - the new width of this Widget
height - the new height of this Widget
texNormal - the texture for the normal button state
texHovered - the texture for the normal button state
texPressed - the texture for the normal button state
text - the text to display on the Button
font -
color -

Button

public Button(float width,
              float height,
              java.lang.String normalTexture,
              java.lang.String hoveredTexture,
              java.lang.String pressedTexture,
              java.lang.String text,
              HUDFont font,
              org.openmali.vecmath2.Colorf color)
Creates a new Image Button (textures will simply be streched over the whole Button area).

Parameters:
width - the new width of this Widget
height - the new height of this Widget
texNormal - the texture for the normal button state
texHovered - the texture for the normal button state
texPressed - the texture for the normal button state
text - the text to display on the Button
font -
color -

Button

public Button(float width,
              float height,
              Texture2D normalTexture,
              Texture2D hoveredTexture,
              Texture2D pressedTexture)
Creates a new Image Button (textures will simply be streched over the whole Button area).

Parameters:
width - the new width of this Widget
height - the new height of this Widget
texNormal - the texture for the normal button state
texHovered - the texture for the normal button state
texPressed - the texture for the normal button state

Button

public Button(float width,
              float height,
              java.lang.String normalTexture,
              java.lang.String hoveredTexture,
              java.lang.String pressedTexture)
Creates a new Image Button (textures will simply be streched over the whole Button area).

Parameters:
width - the new width of this Widget
height - the new height of this Widget
texNormal - the texture for the normal button state
texHovered - the texture for the normal button state
texPressed - the texture for the normal button state
Method Detail

setTextureNormal

public void setTextureNormal(Texture2D texture)
Sets the Texture to be used for NORMAL ButtonState.

Parameters:
texture - the new Texture to use

setTextureNormal

public final void setTextureNormal(java.lang.String resource)
Sets the Texture by resource to be used for NORMAL ButtonState.

Parameters:
resource - the texture resource to use

getTextureNormal

public final Texture2D getTextureNormal()
Returns:
the Texture used for NORMAL ButtonState.

setTextureHovered

public void setTextureHovered(Texture2D texture)
Sets the Texture to be used for HOVERED ButtonState.

Parameters:
texture - the new Texture to use

setTextureHovered

public final void setTextureHovered(java.lang.String resource)
Sets the Texture by resource to be used for HOVERED ButtonState.

Parameters:
resource - the texture resource to use

getTextureHovered

public final Texture2D getTextureHovered()
Returns:
the Texture used for HOVERED ButtonState.

setTexturePressed

public void setTexturePressed(Texture2D texture)
Sets the Texture to be used for PRESSED ButtonState.

Parameters:
texture - the new Texture to use

setTexturePressed

public final void setTexturePressed(java.lang.String resource)
Sets the Texture by resource to be used for PRESSED ButtonState.

Parameters:
resource - the texture resource to use

getTexturePressed

public final Texture2D getTexturePressed()
Returns:
the Texture used for PRESSED ButtonState.

getCurrentTexture

protected Texture2D getCurrentTexture()
Gets the texture for the current buttonstate.


onFocusGained

protected void onFocusGained()
This event is fired, when the focus is gained to a Widget.

Overrides:
onFocusGained in class Widget

onFocusLost

protected void onFocusLost()
This event is fired, when the focus is lost by a Widget.

Overrides:
onFocusLost in class Widget

update

public void update()
Updates the Button's images.

Overrides:
update in class Widget

setButtonState

public boolean setButtonState(AbstractButton.ButtonState buttonState)
Sets the new AbstractButton.ButtonState for this Button.

Overrides:
setButtonState in class AbstractButton
Returns:
has state changed?

onSizeChanged

protected void onSizeChanged(float oldWidth,
                             float oldHeight,
                             float newWidth,
                             float newHeight)

Overrides:
onSizeChanged in class Widget

hasText

public final boolean hasText()
Returns whether this Button has a text.

Returns:
whether this Button has a text.

setText

public void setText(java.lang.String text)
Sets this Button's text content.

Specified by:
setText in interface TextWidget
Parameters:
text - the new Text

getText

public final java.lang.String getText()
Specified by:
getText in interface TextWidget
Returns:
this Button's text content

setFont

public void setFont(HUDFont font)
Sets the Font of the Button's text.

Specified by:
setFont in interface TextWidget
Parameters:
font - the new Font

getFont

public final HUDFont getFont()
Specified by:
getFont in interface TextWidget
Returns:
the Font of the Button's text

setFontColor

public void setFontColor(org.openmali.vecmath2.Colorf color)
Sets the font-color of the Button's text.

Specified by:
setFontColor in interface TextWidget
Parameters:
color - the new Font

getFontColor

public final org.openmali.vecmath2.Colorf getFontColor()
Specified by:
getFontColor in interface TextWidget
Returns:
the font-color of the Button's text

setAlignment

public void setAlignment(TextAlignment align)
Sets the text alignment of the Button's text.

Specified by:
setAlignment in interface TextWidget
Parameters:
align - the new alignment

getAlignment

public final TextAlignment getAlignment()
Specified by:
getAlignment in interface TextWidget
Returns:
the text alignment of the Button's text

setIcon

public void setIcon(Texture2D icon)
Sets the icon for this Button.

Parameters:
icon -

setIcon

public void setIcon(java.lang.String icon)
Sets the icon for this Button.

Parameters:
icon -

getIcon

public final Texture2D getIcon()
Gets the icon of this Button.

Returns:
the icon of this Button.

setIconGap

public void setIconGap(int gap)
Sets the gap between the icon and the text.

Parameters:
gap - the gap in pixels

getIconGap

public final int getIconGap()
Gets the gap between the icon and the text.

Returns:
gap the gap in pixels

setEnabledImpl

protected void setEnabledImpl(boolean enabled)

Specified by:
setEnabledImpl in class AbstractButton

drawWidget

protected void drawWidget(Texture2DCanvas texCanvas,
                          int offsetX,
                          int offsetY,
                          int width,
                          int height,
                          boolean drawsSelf)

Specified by:
drawWidget in class Widget

getOptimalSize

public <Dim2f_ extends org.openmali.types.twodee.Dim2f> Dim2f_ getOptimalSize(Dim2f_ buffer)
Calculates implementation dependent optimal size for this Button.

Specified by:
getOptimalSize in class AbstractButton
Returns:
the buffer back again.

toString

public java.lang.String toString()

Overrides:
toString in class Widget

init

protected void init()
This method is called when the WidgetContainer is set.

Specified by:
init in class Widget

createCaptionWidget

protected Label createCaptionWidget(java.lang.String text,
                                    Label.Description labelDesc)

deriveDesc

protected static Button.Description deriveDesc(HUDFont font,
                                               org.openmali.vecmath2.Colorf color)

createImageButtonDesc

protected static Button.Description createImageButtonDesc(Texture2D normalTexture,
                                                          Texture2D hoveredTexture,
                                                          Texture2D pressedTexture,
                                                          HUDFont font,
                                                          org.openmali.vecmath2.Colorf color)

createImageButtonDesc

protected static Button.Description createImageButtonDesc(java.lang.String normalTexture,
                                                          java.lang.String hoveredTexture,
                                                          java.lang.String pressedTexture,
                                                          HUDFont font,
                                                          org.openmali.vecmath2.Colorf color)