bibliothek.gui.dock.themes.basic.action
Class BasicButtonModel

java.lang.Object
  extended by bibliothek.gui.dock.themes.basic.action.BasicButtonModel
Direct Known Subclasses:
BasicDropDownButtonModel

public class BasicButtonModel
extends Object

A class containing all properties and methods needed to handle a button-component that shows the contents of a DockAction.
A model is normally instantiated by a JComponent which uses this as argument for the constructor of the model. The component can use a subclass of the model to override changed(), which is invoked every time when a property of this model changes. The model will add some listeners to the button and update its properties when necessary.

Author:
Benjamin Sigg

Constructor Summary
BasicButtonModel(JComponent owner, BasicTrigger trigger, BasicResourceInitializer initializer)
          Creates a new model.
BasicButtonModel(JComponent owner, BasicTrigger trigger, BasicResourceInitializer initializer, boolean createListener)
          Creates a new model.
 
Method Summary
 void addListener(BasicButtonModelListener listener)
          Adds a listener to this model.
 void changed()
          Called whenever a property of the model has been changed.
 void clearIcons()
          Removes any icon that was ever set by setIcon(ActionContentModifier, Icon).
 DockAction getAction()
          Gets the DockAction which is handled by this model.
 BackgroundPaint getBackground()
          Gets the algorithm which should be used to paint the background of components.
 BackgroundComponent getBackgroundComponent()
          Gets the source of getBackground().
 BorderModifier getBorder(String key)
          Gets the border which is used for the state key.
 Dockable getDockable()
          Gets the Dockable for which the button is shown.
 ActionContentModifier[] getIconContexts()
          Gets all the ActionContentModifiers for which an icon is set.
 Dimension getMaxIconSize()
          Gets the maximum size the icons need.
 DockTitle.Orientation getOrientation()
          Gets the orientation of the DockTitle on which the view of this model is displayed.
 JComponent getOwner()
          Gets the view which paints the properties of this model.
 Icon getPaintIcon()
          Gets the icon which should be painted on the view.
 Icon getPaintIcon(boolean enabled)
          Gets the icon which should be painted on the view.
 String getText()
          Gets the text of this button.
 boolean isEnabled()
          Tells whether this model reacts on mouse-clicks or not.
 boolean isMouseInside()
          Tells whether the mouse currently is inside the owner or not.
 boolean isMousePressed()
          Tells whether the left mouse button is currently pressed or not.
 boolean isSelected()
          Tells whether this model is selected or not.
protected  List<Triple<KeyStroke,String,Action>> listActions()
          Gets a list of KeyStrokes, String keys and Actions which are to be applied to the owner of this model.
protected  BasicButtonModelListener[] listeners()
          Gets all the listeners that are known to this model.
 void removeListener(BasicButtonModelListener listener)
          Removes a listener from this model.
 void setBackground(BackgroundPaint background, BackgroundComponent backgroundComponent)
          Sets the algorithm which should be used to paint the background of the owner.
 void setBorder(String key, BorderModifier border)
          Sets the border for some state of the component that displays this model.
 void setController(DockController controller)
          Informs this model about the DockController in whose realm it is used.
 void setDockableRepresentative(Dockable dockable)
          Sets the Dockable for which a DockElementRepresentative has to be installed.
 void setEnabled(boolean enabled)
          Sets the enabled property of this model.
 void setIcon(ActionContentModifier modifier, Icon icon)
          Sets the icon which is normally shown on the view.
protected  void setMouseInside(boolean mouseInside)
          Changes the mouseInside property.
protected  void setMousePressed(boolean mousePressed)
          Changes the mousePressed property.
 void setOrientation(DockTitle.Orientation orientation)
          Tells this model which orientation the DockTitle has, on which the view of this model is displayed.
 void setSelected(boolean selected)
          Sets the selected property.
 void setText(String text)
          Sets the text of this button, some button implementations may ignore the text.
 void setToolTipText(String tooltip)
          Sets the text which should be used as tooltip.
protected  void trigger()
          Called when the left mouse button has been pressed and released within the owner and when this model is enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicButtonModel

public BasicButtonModel(JComponent owner,
                        BasicTrigger trigger,
                        BasicResourceInitializer initializer)
Creates a new model.

Parameters:
owner - the view of this model
trigger - the callback used when the user clicks on the view
initializer - a strategy to lazily initialize resources, can be null

BasicButtonModel

public BasicButtonModel(JComponent owner,
                        BasicTrigger trigger,
                        BasicResourceInitializer initializer,
                        boolean createListener)
Creates a new model.

Parameters:
owner - the view of this model
trigger - the callback used when the user clicks on the view
initializer - a strategy to lazily initialize resources, can be null
createListener - whether to create and add a MouseListener and a MouseMotionListener to owner. If this argument is false, then the client is responsible to update all properties of this model.
Method Detail

listActions

protected List<Triple<KeyStroke,String,Action>> listActions()
Gets a list of KeyStrokes, String keys and Actions which are to be applied to the owner of this model.

Returns:
the list of actions

addListener

public void addListener(BasicButtonModelListener listener)
Adds a listener to this model.

Parameters:
listener - the new listener

setController

public void setController(DockController controller)
Informs this model about the DockController in whose realm it is used.

Parameters:
controller - the realm in which this model works

removeListener

public void removeListener(BasicButtonModelListener listener)
Removes a listener from this model.

Parameters:
listener - the listener to remove

listeners

protected BasicButtonModelListener[] listeners()
Gets all the listeners that are known to this model.

Returns:
the listeners

getOwner

public JComponent getOwner()
Gets the view which paints the properties of this model.

Returns:
the view

setBackground

public void setBackground(BackgroundPaint background,
                          BackgroundComponent backgroundComponent)
Sets the algorithm which should be used to paint the background of the owner.

Parameters:
background - the background algorithm, can be null
backgroundComponent - the source of background. Must not be null if background is not null, must represents getOwner() as Component.

getBackground

public BackgroundPaint getBackground()
Gets the algorithm which should be used to paint the background of components.

Returns:
the background, can be null

getBackgroundComponent

public BackgroundComponent getBackgroundComponent()
Gets the source of getBackground().

Returns:
the source, can be null if getBackground() returns null

getAction

public DockAction getAction()
Gets the DockAction which is handled by this model. This method may return null because not every button actually is connected to a DockAction.

Returns:
the action or null

getDockable

public Dockable getDockable()
Gets the Dockable for which the button is shown. This method may return null because not every button is connected to a Dockable.

Returns:
the dockable or null

setBorder

public void setBorder(String key,
                      BorderModifier border)
Sets the border for some state of the component that displays this model. Which identifiers for key are actually used depends on that component.

Parameters:
key - the key of the border
border - the new border or null

getBorder

public BorderModifier getBorder(String key)
Gets the border which is used for the state key. The exact value of key depends on the component which shows this model.

Parameters:
key - the key for some border
Returns:
the border or null if not found

clearIcons

public void clearIcons()
Removes any icon that was ever set by setIcon(ActionContentModifier, Icon).


getIconContexts

public ActionContentModifier[] getIconContexts()
Gets all the ActionContentModifiers for which an icon is set.

Returns:
all the contexts in which an icon is available

setText

public void setText(String text)
Sets the text of this button, some button implementations may ignore the text.

Parameters:
text - the new text, can be null

getText

public String getText()
Gets the text of this button.

Returns:
the text, which may be null

setIcon

public void setIcon(ActionContentModifier modifier,
                    Icon icon)
Sets the icon which is normally shown on the view.

Parameters:
modifier - the context in which to use the icon, not null
icon - the new icon, can be null

setSelected

public void setSelected(boolean selected)
Sets the selected property. The view may be painted in a different way dependent on this value.

Parameters:
selected - the new value

isSelected

public boolean isSelected()
Tells whether this model is selected or not.

Returns:
the property

setEnabled

public void setEnabled(boolean enabled)
Sets the enabled property of this model. A model will not react on a mouse-click if it is not enabled.

Parameters:
enabled - the value

isEnabled

public boolean isEnabled()
Tells whether this model reacts on mouse-clicks or not.

Returns:
the property

setToolTipText

public void setToolTipText(String tooltip)
Sets the text which should be used as tooltip. The text is directly forwarded to the owner of this model using setToolTipText.

Parameters:
tooltip - the text, can be null

setOrientation

public void setOrientation(DockTitle.Orientation orientation)
Tells this model which orientation the DockTitle has, on which the view of this model is displayed.

Parameters:
orientation - the orientation, not null

setDockableRepresentative

public void setDockableRepresentative(Dockable dockable)
Sets the Dockable for which a DockElementRepresentative has to be installed.

Parameters:
dockable - the dockable to monitor, can be null

getOrientation

public DockTitle.Orientation getOrientation()
Gets the orientation of the DockTitle on which the view of this model is displayed.

Returns:
the orientation
See Also:
setOrientation(DockTitle.Orientation)

changed

public void changed()
Called whenever a property of the model has been changed. The default behavior is just to call repaint of the owner. Clients are encouraged to override this method.


getMaxIconSize

public Dimension getMaxIconSize()
Gets the maximum size the icons need.

Returns:
the maximum size of all icons

getPaintIcon

public Icon getPaintIcon()
Gets the icon which should be painted on the view.

Returns:
the icon to paint, can be null

getPaintIcon

public Icon getPaintIcon(boolean enabled)
Gets the icon which should be painted on the view.

Parameters:
enabled - whether the enabled or the disabled version of the icon is requested.
Returns:
the icon or null

setMouseInside

protected void setMouseInside(boolean mouseInside)
Changes the mouseInside property. The property tells whether the mouse is currently inside the border of the owner or not. Clients should not call this method unless they handle all mouse events.

Parameters:
mouseInside - whether the mouse is inside

isMouseInside

public boolean isMouseInside()
Tells whether the mouse currently is inside the owner or not.

Returns:
true if the mouse is inside

setMousePressed

protected void setMousePressed(boolean mousePressed)
Changes the mousePressed property. The property tells whether the left mouse button is currently pressed or not. Clients should not invoke this method unless they handle all mouse events.

Parameters:
mousePressed - whether button 1 is pressed

isMousePressed

public boolean isMousePressed()
Tells whether the left mouse button is currently pressed or not.

Returns:
true if the button is pressed

trigger

protected void trigger()
Called when the left mouse button has been pressed and released within the owner and when this model is enabled.