Class Widget
- All Implemented Interfaces:
Accessible
,org.openide.util.Lookup.Provider
- Direct Known Subclasses:
ComponentWidget
,ConnectionWidget
,ConvolveWidget
,IconNodeWidget
,ImageWidget
,LabelWidget
,LayerWidget
,LevelOfDetailsWidget
,ListWidget
,Scene
,ScrollWidget
,SeparatorWidget
,SwingScrollWidget
,VMDGlyphSetWidget
,VMDNodeWidget
,VMDPinWidget
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
The dependency listener which is used for notifying dependent widgets, anchor, ... -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal void
Adds a child at a specified indexfinal void
Adds a child at a specified indexfinal void
Adds a child widget as the last one.final void
Adds a child widget as the last one.final void
addChildren
(List<? extends Widget> children) Adds all children in a specified list.final 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.final void
Brings the widget to the back.final void
Brings the widget to the front.protected Rectangle
Called to calculate the client area required by the widget without the children widgets.final Point
convertLocalToScene
(Point localLocation) Converts a location in the local coordination system to the scene coordination system.final Rectangle
convertLocalToScene
(Rectangle localRectangle) Converts a rectangle in the local coordination system to the scene coordination system.final Point
convertSceneToLocal
(Point sceneLocation) Converts a location in the scene coordination system to the local coordination system.final Rectangle
convertSceneToLocal
(Rectangle sceneRectangle) Converts a rectangle in the scene coordination system to the local coordination system.final WidgetAction.Chain
createActions
(String tool) Creates and returns an action chain for a specified tool.final boolean
Returns whether a specified object is the same as the widget.final AccessibleContext
Returns an accessible context of the widget.final WidgetAction.Chain
Returns a default action chain.final WidgetAction.Chain
getActions
(String tool) Returns already created action chain for a specified tool.final Paint
Returns the widget background paint.final Border
Returns the border of the widget.final Rectangle
Returns the resolved bounds of the widget.final Object
getChildConstraint
(Widget child) Returns constraint assigned to a specified child widget.Returns a list of children widgets.final Rectangle
Returns a client area of the widget.final Cursor
Returns a mouse cursor for the widget.protected Cursor
getCursorAt
(Point localLocation) Returns a mouse cursor for a specified local location in the widget.final Collection
<Widget.Dependency> Returns a collection of registered dependencies.final Font
getFont()
Returns the font assigned to the widget.final Color
Returns the widget foreground color.protected Graphics2D
Returns a Graphics2D instance with is assigned to the scene.final Layout
Returns the layout of the widget.final Point
Returns the resolved location of the widget.org.openide.util.Lookup
Returns a lookup of the widget.final Dimension
Returns a maximum size of the widget.final Dimension
Returns a minimum size of the widget.final Widget
Returns a parent widget.final Rectangle
Returns a preferred bounds relatively to the location of the widget.final Point
Returns a preferred location of the widget.final Dimension
Returns a preferred size of the widget.Retreives the widgets resource table.final Scene
getScene()
Returns a scene where the widget is assignedfinal ObjectState
getState()
Returns a state of the widget.final String
Returns a tool-tip text of the widget.final int
hashCode()
Returns the object hash code.final boolean
Returns whether clipping is used in the widget.final boolean
Returns whether the widget is enabled.boolean
Called to whether a particular location in local coordination system is controlled (otionally also painted) by the widget.final boolean
isOpaque()
Returns whether the widget is opaque.final boolean
Returns whether a preferred bounds are set.protected boolean
Returns whether whole area of the widget has to be repainted after the validation of the widget.boolean
Returns true if the widget is validated (is not scheduled to revalidation).final boolean
Returns whether the widget is visible.protected void
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
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.final void
paint()
Paints the widget with its children widget into the Graphics2D instance acquired from Scene.getGraphics method.protected void
Called to paint the widget background itself only using the Graphics2D instance acquired from Scene.getGraphics method.protected void
Called to paint the widget border itself only using the Graphics2D instance acquired from Scene.getGraphics method.protected void
Called to paint the children widgets only using the Graphics2D instance acquired from Scene.getGraphics method.protected void
Called to paint the widget itself only using the Graphics2D instance acquired from Scene.getGraphics method.final void
removeChild
(Widget child) Removes a child widget.final void
Removes all children widgets.final void
removeChildren
(List<Widget> widgets) Removes all children widget that are in a specified list.final void
removeDependency
(Widget.Dependency dependency) Removes a dependency listener.final void
Removes the widget from its parent.final void
repaint()
Schedules the widget for repainting.final void
resolveBounds
(Point location, Rectangle bounds) Sets resolved location and bounds of the widget This method is usually called from implementations ofLayout
interface.final void
Schedules the widget for revalidation.final void
revalidate
(boolean repaintOnly) Schedules the widget to repaint or revalidation.final void
setAccessibleContext
(AccessibleContext accessibleContext) Sets a accessible context of the widget.final void
setBackground
(Paint background) Sets the widget background paint.final void
setBackgroundFromResource
(String property) Sets the widget background color to be based on a resource property.final void
Sets the Swing layout as the border of the widget.final void
Sets the border of the widget.final void
setCheckClipping
(boolean checkClipping) Sets a clipping for the widget.final void
setChildConstraint
(Widget child, Object constraint) Assigns a constraint to a child widget.final void
Sets a cursor for the widget.final void
setEnabled
(boolean enabled) Sets whether the widget is enabled.final void
Sets the widget font.final void
setFontFromResource
(String property) Sets the widget background color to be based on a resource property.final void
setForeground
(Color foreground) Sets the widget foreground color.final void
setForegroundFromResource
(String property) Sets the widget foreground color to be based on a resource property.final void
Sets the layout of the widget.final void
setMaximumSize
(Dimension maximumSize) Sets a maximum size of the widgetfinal void
setMinimumSize
(Dimension minimumSize) Sets a minumum size of the widgetfinal void
setOpaque
(boolean opaque) Sets the widget opacity.final void
setPreferredBounds
(Rectangle preferredBounds) Sets a preferred bounds that are specified relatively to the location of the widget.final void
setPreferredLocation
(Point preferredLocation) Sets a preferred location of the widget.final void
setPreferredSize
(Dimension preferredSize) Sets a preferred size of the widgetvoid
setResourceTable
(ResourceTable table) Sets the resource table.final void
setState
(ObjectState state) Sets a state of the widget.final void
setToolTipText
(String toolTipText) Sets a tool-tip of the widget.final void
setVisible
(boolean visible) Sets whether the widget is visible.protected final void
updateResources
(Widget parent, boolean added)
-
Constructor Details
-
Widget
Creates a new widget which will be used in a specified scene.- Parameters:
scene
- the scene where the widget is going to be used
-
-
Method Details
-
getScene
-
getGraphics
Returns a Graphics2D instance with is assigned to the scene. Usually used in the calculatedClientArea and paintWidget method.- Returns:
- the Graphics2D instance; null if the scene view is not created or visible yet
-
getParentWidget
-
getChildren
-
addChild
Adds a child widget as the last one.- Parameters:
child
- the child widget to be added
-
addChild
-
addChild
Adds a child at a specified index- Parameters:
index
- the index (the child is added before the one that is not the index place)child
- the child widget
-
addChild
-
removeChild
Removes a child widget.- Parameters:
child
- the child widget
-
removeFromParent
public final void removeFromParent()Removes the widget from its parent. -
removeChildren
public final void removeChildren()Removes all children widgets. -
addChildren
-
removeChildren
-
notifyAdded
protected void notifyAdded()This method is called to notify that the view is shown. Note: You must not modify a tree of widgets from within this method. It means: do not call addChild, removeChild and similar methods. -
notifyRemoved
protected void notifyRemoved()This method is called to notify that the view is hidden. Note: You must not modify a tree of widgets from within this method. It means: do not call addChild, removeChild and similar methods. -
bringToFront
public final void bringToFront()Brings the widget to the front. Means: the widget becomes the last child in the list of children of the parent widget. -
bringToBack
public final void bringToBack()Brings the widget to the back. Means: the widget becomes the first child in the list of children of the parent widget. -
getChildConstraint
-
setChildConstraint
-
isVisible
public final boolean isVisible()Returns whether the widget is visible.- Returns:
- true if the widget is visible
-
setVisible
public final void setVisible(boolean visible) Sets whether the widget is visible.- Parameters:
visible
- if true, then the widget is visible
-
isEnabled
public final boolean isEnabled()Returns whether the widget is enabled. If the widget is disabled then any event is processed by assigned actions.- Returns:
- true if the widget is enabled.
-
setEnabled
public final void setEnabled(boolean enabled) Sets whether the widget is enabled. If the widget is disabled then any event is processed by assigned actions.- Parameters:
enabled
- if true, then the widget is enabled
-
getActions
Returns a default action chain.- Returns:
- the default action chain.
-
getActions
Returns already created action chain for a specified tool.- Parameters:
tool
- the tool- Returns:
- the action chain; null, if no chain for the tool exists
-
createActions
Creates and returns an action chain for a specified tool.- Parameters:
tool
- the tool- Returns:
- the action chain
-
getLookup
public org.openide.util.Lookup getLookup()Returns a lookup of the widget.- Specified by:
getLookup
in interfaceorg.openide.util.Lookup.Provider
- Returns:
- the lookup
-
addDependency
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.- Parameters:
dependency
- the dependency listener
-
removeDependency
Removes a dependency listener.- Parameters:
dependency
- the dependency listener
-
getDependencies
Returns a collection of registered dependencies.- Returns:
- the unmodifiable collection of dependencies
- Since:
- 2.6
-
isOpaque
public final boolean isOpaque()Returns whether the widget is opaque.- Returns:
- true, if the widget is opaque
-
setOpaque
public final void setOpaque(boolean opaque) Sets the widget opacity.- Parameters:
opaque
- if true, then the widget is opaque
-
getBackground
Returns the widget background paint.- Returns:
- the background paint
-
setBackground
Sets the widget background paint.- Parameters:
background
- the background paint
-
setBackgroundFromResource
Sets the widget background color to be based on a resource property.- Parameters:
property
- the background property name
-
notifyBackgroundChanged
-
getForeground
Returns the widget foreground color.- Returns:
- the foreground color
-
setForeground
Sets the widget foreground color.- Parameters:
foreground
- the foreground color
-
setForegroundFromResource
Sets the widget foreground color to be based on a resource property.- Parameters:
property
- the foreground property name
-
notifyForegroundChanged
-
getFont
Returns the font assigned to the widget. If not set yet, then it returns the font of its parent widget.- Returns:
- the font
-
setFont
Sets the widget font.- Parameters:
font
- the font; if null, then widget unassignes its font.
-
setFontFromResource
Sets the widget background color to be based on a resource property.- Parameters:
property
- the foreground property name
-
updateResources
-
notifyFontChanged
-
getBorder
-
setBorder
Sets the border of the widget.- Parameters:
border
- the border
-
setBorder
Sets the Swing layout as the border of the widget.- Parameters:
swingBorder
- the Swing border
-
getLayout
-
setLayout
Sets the layout of the widget.- Parameters:
layout
- the layout
-
getMinimumSize
Returns a minimum size of the widget.- Returns:
- the minimum size; if null, then no minumum size are set.
-
setMinimumSize
Sets a minumum size of the widget- Parameters:
minimumSize
- the minimum size; if null, then minimum size are unset.
-
getMaximumSize
Returns a maximum size of the widget.- Returns:
- the maximum size; if null, then no maximum size are set.
-
setMaximumSize
Sets a maximum size of the widget- Parameters:
maximumSize
- the maximum size; if null, then maximum size are unset.
-
getPreferredSize
Returns a preferred size of the widget.- Returns:
- the preferred size; if null, then no preferred size are set.
-
setPreferredSize
Sets a preferred size of the widget- Parameters:
preferredSize
- the preferred size; if null, then preferred size are unset.
-
getPreferredLocation
Returns a preferred location of the widget.- Returns:
- the preferred location; if null, then no preferred location is set
-
setPreferredLocation
Sets a preferred location of the widget.- Parameters:
preferredLocation
- the preferred location; if null, then the preferred location is unset
-
isPreferredBoundsSet
public final boolean isPreferredBoundsSet()Returns whether a preferred bounds are set.- Returns:
- true, if preferred bounds are set
-
getPreferredBounds
Returns a preferred bounds relatively to the location of the widget. If no preferred bounds are set, then it returns a preferred bounds that are calculated from the calculateClientArea method of this widget and location and bounds of the children widgets. This calculated bounds are processed by the minimum and maximum bounds too.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 usingisPreferredBoundsSet
method), you can call this method at any time.- Returns:
- the preferred bounds
-
calculateClientArea
Called to calculate the client area required by the widget without the children widgets.- Returns:
- the calculated client area
-
setPreferredBounds
Sets a preferred bounds that are specified relatively to the location of the widget.- Parameters:
preferredBounds
- the preferred bounds; if null, then the preferred bounds are unset
-
isCheckClipping
public final boolean isCheckClipping()Returns whether clipping is used in the widget.- Returns:
- true, if the check clipping is used
-
setCheckClipping
public final void setCheckClipping(boolean checkClipping) Sets a clipping for the widget.- Parameters:
checkClipping
- if true, then the clipping is used
-
getCursorAt
-
getCursor
-
setCursor
Sets a cursor for the widget.- Parameters:
cursor
- the mouse cursor; if null, the cursor is unset
-
getToolTipText
Returns a tool-tip text of the widget.- Returns:
- the tool-tip text
-
setToolTipText
Sets a tool-tip of the widget.- Parameters:
toolTipText
- the tool tip text
-
getAccessibleContext
Returns an accessible context of the widget.- Specified by:
getAccessibleContext
in interfaceAccessible
- Returns:
- the accessible context
-
setAccessibleContext
Sets a accessible context of the widget.- Parameters:
accessibleContext
- the accessible context
-
getState
-
setState
Sets a state of the widget.- Parameters:
state
- the widget state
-
notifyStateChanged
Called to notify about the change of the widget state.- Parameters:
previousState
- the previous statestate
- the new state
-
convertLocalToScene
-
convertLocalToScene
-
convertSceneToLocal
-
convertSceneToLocal
-
getLocation
Returns the resolved location of the widget. The location is specified relatively to the location of the parent widget.The location is resolved/set by calling
resolveBounds
method which should be called fromLayout
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.- Returns:
- the location in the local coordination system of the parent widget
-
getBounds
Returns the resolved bounds of the widget. The bounds are specified relatively to the location of the widget.The location is resolved/set by calling
resolveBounds
method which should be called fromLayout
interface implementation only. Therefore the corrent value is available only after the scene is validated (SceneListener.sceneValidated
method). Before validation a previous/obsolete ornull
value could be returned. See Layout section in documentation.- Returns:
- the bounds in local coordination system
-
resolveBounds
Sets resolved location and bounds of the widget This method is usually called from implementations ofLayout
interface.- Parameters:
location
- the resolved location; if null then [0,0] point is used insteadbounds
- the resolved bounds; if null then the preferred bounds are used instead
-
getClientArea
Returns a client area of the widget.- Returns:
- the client area
-
isHitAt
Called to whether a particular location in local coordination system is controlled (otionally also painted) by the widget.- Parameters:
localLocation
- the local location- Returns:
- true, if the location belong to the widget
-
repaint
public final void repaint()Schedules the widget for repainting. -
isValidated
public boolean isValidated()Returns true if the widget is validated (is not scheduled to revalidation).- Returns:
- true, if is validated
-
revalidate
public final void revalidate(boolean repaintOnly) Schedules the widget to repaint or revalidation.- Parameters:
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)
-
revalidate
public final void revalidate()Schedules the widget for revalidation. The Scene.validate method has to be called after all changes to invoke validation. In some cases it is invoked automatically. -
isRepaintRequiredForRevalidating
protected boolean isRepaintRequiredForRevalidating()Returns whether whole area of the widget has to be repainted after the validation of the widget. Used be LayerWidget for performance optiomalization.- Returns:
- true, if requires; false, if does not require
-
paint
public final void paint()Paints the widget with its children widget into the Graphics2D instance acquired from Scene.getGraphics method. -
paintBackground
protected void paintBackground()Called to paint the widget background itself only using the Graphics2D instance acquired from Scene.getGraphics method. -
paintBorder
protected void paintBorder()Called to paint the widget border itself only using the Graphics2D instance acquired from Scene.getGraphics method.- Since:
- 2.1
-
paintWidget
protected void paintWidget()Called to paint the widget itself only using the Graphics2D instance acquired from Scene.getGraphics method. Do not call methods which modify state of the widget (all methods which calls revalidate like setFont(), setVisible(), setLayout(),...). It can cause another repaint and result in infinite paint cycle. -
paintChildren
protected void paintChildren()Called to paint the children widgets only using the Graphics2D instance acquired from Scene.getGraphics method. -
hashCode
-
equals
-
getResourceTable
Retreives the widgets resource table. If the widgets resource table is not set then the widgets parent resource table it retrieved.- Returns:
- The resource table.
-
setResourceTable
Sets the resource table.- Parameters:
table
- The widgets resource table.
-