public class Widget extends Object implements Accessible, Lookup.Provider
Each widget has a origin location specified relatively to the location its parent widget and placement is specified be its boundary.
The widget is also responsible for rendering the region. The widget is an abstract implementation and does not have render anything except borders and background. There are various built-in widget each for a specific visualization. The widget also holds general properties like foreground, opacity, ... that could be reused by the high-level widgets.
The widget has a layout assigned. The layout takes care about resolving the placement of children widgets. For that it can use various properties like preferredLocation, preferredBounds, ... When the widget is resolved (placed) than the read only location and bounds properties contains resolved location and boundary of a widget.
Each widget has a chain of actions. Actions defined defines a behaviour of the widget. E.g. MoveAction makes the widget moveable. Also there is possible to create/assign other chains that will be activated based on the active tool of a scene.
The widget have its state specified by ObjectState class. When the widget state is change, notifyStateChanged is called to notify about it. The state is automatically updated by high-level scenes and actions. Yherefore you can define your own look and feel directly in the that method. Since version 2.6 Widget class implements Accessible interface.
Modifier and Type | Class and Description |
---|---|
static interface |
Widget.Dependency
The dependency listener which is used for notifying dependent widgets, anchor, ...
|
Constructor and Description |
---|
Widget(Scene scene)
Creates a new widget which will be used in a specified scene.
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(int index,
Widget child)
Adds a child at a specified index
|
void |
addChild(int index,
Widget child,
Object constraint)
Adds a child at a specified index
|
void |
addChild(Widget child)
Adds a child widget as the last one.
|
void |
addChild(Widget child,
Object constraint)
Adds a child widget as the last one.
|
void |
addChildren(List<? extends Widget> children)
Adds all children in a specified list.
|
void |
addDependency(Widget.Dependency dependency)
Adds a dependency listener which is notified when the widget placement or boundary is going to be changed or similar thing happens to its parent widget.
|
void |
bringToBack()
Brings the widget to the back.
|
void |
bringToFront()
Brings the widget to the front.
|
protected Rectangle |
calculateClientArea()
Called to calculate the client area required by the widget without the children widgets.
|
Point |
convertLocalToScene(Point localLocation)
Converts a location in the local coordination system to the scene coordination system.
|
Rectangle |
convertLocalToScene(Rectangle localRectangle)
Converts a rectangle in the local coordination system to the scene coordination system.
|
Point |
convertSceneToLocal(Point sceneLocation)
Converts a location in the scene coordination system to the local coordination system.
|
Rectangle |
convertSceneToLocal(Rectangle sceneRectangle)
Converts a rectangle in the scene coordination system to the local coordination system.
|
WidgetAction.Chain |
createActions(String tool)
Creates and returns an action chain for a specified tool.
|
boolean |
equals(Object object)
Returns whether a specified object is the same as the widget.
|
AccessibleContext |
getAccessibleContext()
Returns an accessible context of the widget.
|
WidgetAction.Chain |
getActions()
Returns a default action chain.
|
WidgetAction.Chain |
getActions(String tool)
Returns already created action chain for a specified tool.
|
Paint |
getBackground()
Returns the widget background paint.
|
Border |
getBorder()
Returns the border of the widget.
|
Rectangle |
getBounds()
Returns the resolved bounds of the widget.
|
Object |
getChildConstraint(Widget child)
Returns constraint assigned to a specified child widget.
|
List<Widget> |
getChildren()
Returns a list of children widgets.
|
Rectangle |
getClientArea()
Returns a client area of the widget.
|
Cursor |
getCursor()
Returns a mouse cursor for the widget.
|
protected Cursor |
getCursorAt(Point localLocation)
Returns a mouse cursor for a specified local location in the widget.
|
Collection<Widget.Dependency> |
getDependencies()
Returns a collection of registered dependencies.
|
Font |
getFont()
Returns the font assigned to the widget.
|
Color |
getForeground()
Returns the widget foreground color.
|
protected Graphics2D |
getGraphics()
Returns a Graphics2D instance with is assigned to the scene.
|
Layout |
getLayout()
Returns the layout of the widget.
|
Point |
getLocation()
Returns the resolved location of the widget.
|
Lookup |
getLookup()
Returns a lookup of the widget.
|
Dimension |
getMaximumSize()
Returns a maximum size of the widget.
|
Dimension |
getMinimumSize()
Returns a minimum size of the widget.
|
Widget |
getParentWidget()
Returns a parent widget.
|
Rectangle |
getPreferredBounds()
Returns a preferred bounds relatively to the location of the widget.
|
Point |
getPreferredLocation()
Returns a preferred location of the widget.
|
Dimension |
getPreferredSize()
Returns a preferred size of the widget.
|
ResourceTable |
getResourceTable()
Retreives the widgets resource table.
|
Scene |
getScene()
Returns a scene where the widget is assigned
|
ObjectState |
getState()
Returns a state of the widget.
|
String |
getToolTipText()
Returns a tool-tip text of the widget.
|
int |
hashCode()
Returns the object hash code.
|
boolean |
isCheckClipping()
Returns whether clipping is used in the widget.
|
boolean |
isEnabled()
Returns whether the widget is enabled.
|
boolean |
isHitAt(Point localLocation)
Called to whether a particular location in local coordination system is controlled (otionally also painted) by the widget.
|
boolean |
isOpaque()
Returns whether the widget is opaque.
|
boolean |
isPreferredBoundsSet()
Returns whether a preferred bounds are set.
|
protected boolean |
isRepaintRequiredForRevalidating()
Returns whether whole area of the widget has to be repainted after the validation of the widget.
|
boolean |
isValidated()
Returns true if the widget is validated (is not scheduled to revalidation).
|
boolean |
isVisible()
Returns whether the widget is visible.
|
protected void |
notifyAdded()
This method is called to notify that the view is shown.
|
protected void |
notifyBackgroundChanged(Paint paint) |
protected void |
notifyFontChanged(Font font) |
protected void |
notifyForegroundChanged(Color newColor) |
protected void |
notifyRemoved()
This method is called to notify that the view is hidden.
|
protected void |
notifyStateChanged(ObjectState previousState,
ObjectState state)
Called to notify about the change of the widget state.
|
void |
paint()
Paints the widget with its children widget into the Graphics2D instance acquired from Scene.getGraphics method.
|
protected void |
paintBackground()
Called to paint the widget background itself only using the Graphics2D instance acquired from Scene.getGraphics method.
|
protected void |
paintBorder()
Called to paint the widget border itself only using the Graphics2D instance acquired from Scene.getGraphics method.
|
protected void |
paintChildren()
Called to paint the children widgets only using the Graphics2D instance acquired from Scene.getGraphics method.
|
protected void |
paintWidget()
Called to paint the widget itself only using the Graphics2D instance acquired from Scene.getGraphics method.
|
void |
removeChild(Widget child)
Removes a child widget.
|
void |
removeChildren()
Removes all children widgets.
|
void |
removeChildren(List<Widget> widgets)
Removes all children widget that are in a specified list.
|
void |
removeDependency(Widget.Dependency dependency)
Removes a dependency listener.
|
void |
removeFromParent()
Removes the widget from its parent.
|
void |
repaint()
Schedules the widget for repainting.
|
void |
resolveBounds(Point location,
Rectangle bounds)
Sets resolved location and bounds of the widget
This method is usually called from implementations of
Layout interface. |
void |
revalidate()
Schedules the widget for revalidation.
|
void |
revalidate(boolean repaintOnly)
Schedules the widget to repaint or revalidation.
|
void |
setAccessibleContext(AccessibleContext accessibleContext)
Sets a accessible context of the widget.
|
void |
setBackground(Paint background)
Sets the widget background paint.
|
void |
setBackgroundFromResource(String property)
Sets the widget background color to be based on a resource property.
|
void |
setBorder(Border border)
Sets the border of the widget.
|
void |
setBorder(Border swingBorder)
Sets the Swing layout as the border of the widget.
|
void |
setCheckClipping(boolean checkClipping)
Sets a clipping for the widget.
|
void |
setChildConstraint(Widget child,
Object constraint)
Assigns a constraint to a child widget.
|
void |
setCursor(Cursor cursor)
Sets a cursor for the widget.
|
void |
setEnabled(boolean enabled)
Sets whether the widget is enabled.
|
void |
setFont(Font font)
Sets the widget font.
|
void |
setFontFromResource(String property)
Sets the widget background color to be based on a resource property.
|
void |
setForeground(Color foreground)
Sets the widget foreground color.
|
void |
setForegroundFromResource(String property)
Sets the widget foreground color to be based on a resource property.
|
void |
setLayout(Layout layout)
Sets the layout of the widget.
|
void |
setMaximumSize(Dimension maximumSize)
Sets a maximum size of the widget
|
void |
setMinimumSize(Dimension minimumSize)
Sets a minumum size of the widget
|
void |
setOpaque(boolean opaque)
Sets the widget opacity.
|
void |
setPreferredBounds(Rectangle preferredBounds)
Sets a preferred bounds that are specified relatively to the location of the widget.
|
void |
setPreferredLocation(Point preferredLocation)
Sets a preferred location of the widget.
|
void |
setPreferredSize(Dimension preferredSize)
Sets a preferred size of the widget
|
void |
setResourceTable(ResourceTable table)
Sets the resource table.
|
void |
setState(ObjectState state)
Sets a state of the widget.
|
void |
setToolTipText(String toolTipText)
Sets a tool-tip of the widget.
|
void |
setVisible(boolean visible)
Sets whether the widget is visible.
|
protected void |
updateResources(Widget parent,
boolean added) |
public Widget(Scene scene)
scene
- the scene where the widget is going to be usedpublic final Scene getScene()
protected Graphics2D getGraphics()
public final Widget getParentWidget()
public final List<Widget> getChildren()
public final void addChild(Widget child)
child
- the child widget to be addedpublic final void addChild(Widget child, Object constraint)
child
- the child widget to be addedconstraint
- the constraint assigned to the child widgetpublic final void addChild(int index, Widget child)
index
- the index (the child is added before the one that is not the index place)child
- the child widgetpublic final void addChild(int index, Widget child, Object constraint)
index
- the index (the child is added before the one that is not the index place)child
- the child widgetconstraint
- the constraint assigned to the child widgetpublic final void removeChild(Widget child)
child
- the child widgetpublic final void removeFromParent()
public final void removeChildren()
public final void addChildren(List<? extends Widget> children)
children
- the list of children widgetspublic final void removeChildren(List<Widget> widgets)
widgets
- the list of children widgets to be removedprotected void notifyAdded()
protected void notifyRemoved()
public final void bringToFront()
public final void bringToBack()
public final Object getChildConstraint(Widget child)
child
- the child widgetpublic final void setChildConstraint(Widget child, Object constraint)
child
- the child widgetconstraint
- the constraintpublic final boolean isVisible()
public final void setVisible(boolean visible)
visible
- if true, then the widget is visiblepublic final boolean isEnabled()
public final void setEnabled(boolean enabled)
enabled
- if true, then the widget is enabledpublic final WidgetAction.Chain getActions()
public final WidgetAction.Chain getActions(String tool)
tool
- the toolpublic final WidgetAction.Chain createActions(String tool)
tool
- the toolpublic Lookup getLookup()
getLookup
in interface Lookup.Provider
public final void addDependency(Widget.Dependency dependency)
dependency
- the dependency listenerpublic final void removeDependency(Widget.Dependency dependency)
dependency
- the dependency listenerpublic final Collection<Widget.Dependency> getDependencies()
public final boolean isOpaque()
public final void setOpaque(boolean opaque)
opaque
- if true, then the widget is opaquepublic final Paint getBackground()
public final void setBackground(Paint background)
background
- the background paintpublic final void setBackgroundFromResource(String property)
property
- the background property nameprotected void notifyBackgroundChanged(Paint paint)
public final Color getForeground()
public final void setForeground(Color foreground)
foreground
- the foreground colorpublic final void setForegroundFromResource(String property)
property
- the foreground property nameprotected void notifyForegroundChanged(Color newColor)
public final Font getFont()
public final void setFont(Font font)
font
- the font; if null, then widget unassignes its font.public final void setFontFromResource(String property)
property
- the foreground property nameprotected final void updateResources(Widget parent, boolean added)
protected void notifyFontChanged(Font font)
public final Border getBorder()
public final void setBorder(Border border)
border
- the borderpublic final void setBorder(Border swingBorder)
swingBorder
- the Swing borderpublic final Layout getLayout()
public final void setLayout(Layout layout)
layout
- the layoutpublic final Dimension getMinimumSize()
public final void setMinimumSize(Dimension minimumSize)
minimumSize
- the minimum size; if null, then minimum size are unset.public final Dimension getMaximumSize()
public final void setMaximumSize(Dimension maximumSize)
maximumSize
- the maximum size; if null, then maximum size are unset.public final Dimension getPreferredSize()
public final void setPreferredSize(Dimension preferredSize)
preferredSize
- the preferred size; if null, then preferred size are unset.public final Point getPreferredLocation()
public final void setPreferredLocation(Point preferredLocation)
preferredLocation
- the preferred location; if null, then the preferred location is unsetpublic final boolean isPreferredBoundsSet()
public final Rectangle getPreferredBounds()
This method can be called after child widgets are layed out which is assured in method calls of the Layout
interface implementation.
If preferred bounds are set (check it using isPreferredBoundsSet
method), you can call this method at any time.
protected Rectangle calculateClientArea()
public final void setPreferredBounds(Rectangle preferredBounds)
preferredBounds
- the preferred bounds; if null, then the preferred bounds are unsetpublic final boolean isCheckClipping()
public final void setCheckClipping(boolean checkClipping)
checkClipping
- if true, then the clipping is usedprotected Cursor getCursorAt(Point localLocation)
localLocation
- the local locationpublic final Cursor getCursor()
public final void setCursor(Cursor cursor)
cursor
- the mouse cursor; if null, the cursor is unsetpublic final String getToolTipText()
public final void setToolTipText(String toolTipText)
toolTipText
- the tool tip textpublic final AccessibleContext getAccessibleContext()
getAccessibleContext
in interface Accessible
public final void setAccessibleContext(AccessibleContext accessibleContext)
accessibleContext
- the accessible contextpublic final ObjectState getState()
public final void setState(ObjectState state)
state
- the widget stateprotected void notifyStateChanged(ObjectState previousState, ObjectState state)
previousState
- the previous statestate
- the new statepublic final Point convertLocalToScene(Point localLocation)
localLocation
- the local location@NonNull public final Rectangle convertLocalToScene(@NonNull Rectangle localRectangle)
localRectangle
- the local rectanglepublic final Point convertSceneToLocal(Point sceneLocation)
sceneLocation
- the scene locationpublic final Rectangle convertSceneToLocal(Rectangle sceneRectangle)
sceneRectangle
- the scene rectanglepublic final Point getLocation()
The location is resolved/set by calling resolveBounds
method which should be called from Layout
interface implementation only.
Therefore the corrent value is available only after the scene is validated (SceneListener.sceneValidated
method).
Before validation a previous/obsolete or [0,0]
value could be returned.
See Layout section in documentation.
@CheckForNull public final Rectangle getBounds()
The location is resolved/set by calling resolveBounds
method which should be called from Layout
interface implementation only.
Therefore the corrent value is available only after the scene is validated (SceneListener.sceneValidated
method).
Before validation a previous/obsolete or null
value could be returned.
See Layout section in documentation.
public final void resolveBounds(Point location, Rectangle bounds)
Layout
interface.location
- the resolved location; if null then [0,0] point is used insteadbounds
- the resolved bounds; if null then the preferred bounds are used insteadpublic final Rectangle getClientArea()
public boolean isHitAt(Point localLocation)
localLocation
- the local locationpublic final void repaint()
public boolean isValidated()
public final void revalidate(boolean repaintOnly)
repaintOnly
- if true, then the widget is scheduled for repainting only;
if false, then widget is scheduled for revalidation (the Scene.validate method has to be called after all changes to invoke validation)public final void revalidate()
protected boolean isRepaintRequiredForRevalidating()
public final void paint()
protected void paintBackground()
protected void paintBorder()
protected void paintWidget()
protected void paintChildren()
public final int hashCode()
public final boolean equals(Object object)
public ResourceTable getResourceTable()
public void setResourceTable(ResourceTable table)
table
- The widgets resource table.