public class Button extends AbstractFocusable implements Action.ShortcutNotifier
Modifier and Type | Class and Description |
---|---|
static class |
Button.ClickEvent
Click event.
|
static interface |
Button.ClickListener
Interface for listening for a
Button.ClickEvent fired by a
Component . |
static class |
Button.ClickShortcut
A
ShortcutListener specifically made to define a keyboard
shortcut that invokes a click on the given button. |
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
Modifier and Type | Field and Description |
---|---|
protected Button.ClickShortcut |
clickShortcut |
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Constructor and Description |
---|
Button()
Creates a new push button.
|
Button(Resource icon)
Creates a new push button with the given icon.
|
Button(String caption)
Creates a new push button with the given caption.
|
Button(String caption,
Button.ClickListener listener)
Creates a new push button with a click listener.
|
Button(String caption,
Resource icon)
Creates a new push button with the given caption and icon.
|
Modifier and Type | Method and Description |
---|---|
void |
addClickListener(Button.ClickListener listener)
Adds the button click listener.
|
void |
addListener(Button.ClickListener listener)
Deprecated.
As of 7.0, replaced by
addClickListener(ClickListener) |
void |
click()
Simulates a button click, notifying all server-side listeners.
|
protected void |
fireClick()
Fires a click event to all listeners without any event details.
|
protected void |
fireClick(MouseEventDetails details)
Fires a click event to all listeners.
|
protected Collection<String> |
getCustomAttributes()
Returns a collection of attributes that should not be handled by the
basic implementation of the
readDesign and writeDesign
methods. |
String |
getIconAlternateText()
Returns the icon's alt text.
|
protected ButtonState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected ButtonState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
boolean |
isDisableOnClick()
Determines if a button is automatically disabled when clicked.
|
boolean |
isHtmlContentAllowed()
Return HTML rendering setting
|
void |
readDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Reads the component state from the given design.
|
void |
removeClickListener(Button.ClickListener listener)
Removes the button click listener.
|
void |
removeClickShortcut()
Removes the keyboard shortcut previously set with
setClickShortcut(int, int...) . |
void |
removeListener(Button.ClickListener listener)
Deprecated.
As of 7.0, replaced by
removeClickListener(ClickListener) |
void |
setClickShortcut(int keyCode,
int... modifiers)
Makes it possible to invoke a click on this button by pressing the given
ShortcutAction.KeyCode and (optional) ShortcutAction.ModifierKey s.The shortcut is global (bound to the containing Window). |
void |
setDisableOnClick(boolean disableOnClick)
Determines if a button is automatically disabled when clicked.
|
void |
setHtmlContentAllowed(boolean htmlContentAllowed)
Set whether the caption text is rendered as HTML or not.
|
void |
setIcon(Resource icon,
String iconAltText)
Sets the component's icon and alt text.
|
void |
setIconAlternateText(String iconAltText) |
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext designContext)
Writes the component state to the given design.
|
addBlurListener, addFocusListener, addListener, addListener, focus, getTabIndex, removeBlurListener, removeFocusListener, removeListener, removeListener, setTabIndex
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getExplicitImmediateValue, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isImmediate, isOrHasAncestor, isReadOnly, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setEnabled, setHeight, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setLocale, setParent, setPrimaryStyleName, setReadOnly, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
addShortcutListener, removeShortcutListener
addListener, addStyleName, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
protected Button.ClickShortcut clickShortcut
public Button()
public Button(String caption)
caption
- the Button caption.public Button(Resource icon)
icon
- the iconpublic Button(String caption, Resource icon)
caption
- the captionicon
- the iconpublic Button(String caption, Button.ClickListener listener)
caption
- the Button caption.listener
- the Button click listener.public void addClickListener(Button.ClickListener listener)
listener
- the Listener to be added.@Deprecated public void addListener(Button.ClickListener listener)
addClickListener(ClickListener)
public void removeClickListener(Button.ClickListener listener)
listener
- the Listener to be removed.@Deprecated public void removeListener(Button.ClickListener listener)
removeClickListener(ClickListener)
public void click()
protected void fireClick()
fireClick(MouseEventDetails)
instead of
this method.protected void fireClick(MouseEventDetails details)
details
- MouseEventDetails from which keyboard modifiers and other
information about the mouse click can be obtained. If the
button was clicked by a keyboard event, some of the fields may
be empty/undefined.public void setClickShortcut(int keyCode, int... modifiers)
ShortcutAction.KeyCode
and (optional) ShortcutAction.ModifierKey
s.keyCode
- the keycode for invoking the shortcutmodifiers
- the (optional) modifiers for invoking the shortcut, null for
nonepublic void removeClickShortcut()
setClickShortcut(int, int...)
.public boolean isDisableOnClick()
setDisableOnClick(boolean)
for details.public void setDisableOnClick(boolean disableOnClick)
Note that this is only used when the click comes from the user, not when
calling click()
method programmatically. Also, if developer
wants to re-enable the button, it needs to be done programmatically.
disableOnClick
- true to disable button when it is clicked, false otherwiseprotected ButtonState getState()
AbstractComponent
getState
in class AbstractFocusable
protected ButtonState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractFocusable
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public void setIcon(Resource icon, String iconAltText)
icon
- the icon to be shown with the component's caption.iconAltText
- String to use as alt textpublic String getIconAlternateText()
public void setIconAlternateText(String iconAltText)
public void setHtmlContentAllowed(boolean htmlContentAllowed)
htmlContentAllowed
- true
if caption is rendered as HTML,
false
otherwisepublic boolean isHtmlContentAllowed()
true
if the caption text is to be rendered as HTML,
false
otherwisepublic void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
readDesign
in interface Component
readDesign
in class AbstractComponent
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the designprotected Collection<String> getCustomAttributes()
AbstractComponent
readDesign
and writeDesign
methods. Typically these are handled in a custom way in the overridden
versions of the above methodsgetCustomAttributes
in class AbstractComponent
public void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
writeDesign
in interface Component
writeDesign
in class AbstractComponent
design
- The element to write the component state to. Any previous
attributes or child nodes are not cleared.designContext
- The DesignContext instance used for writing the designCopyright © 2019 Vaadin Ltd. All rights reserved.