cz.cuni.pogamut.shed.widget
Class ShedWidget

Package class diagram package ShedWidget
java.lang.Object
  extended by org.netbeans.api.visual.widget.Widget
      extended by cz.cuni.pogamut.shed.widget.ShedWidget
Type Parameters:
T - Type of element this widget is attached to.
All Implemented Interfaces:
IPresentedWidget, Accessible, org.netbeans.api.visual.action.PopupMenuProvider
Direct Known Subclasses:
ShedVariableWidget

public class ShedWidget
extends org.netbeans.api.visual.widget.Widget
implements org.netbeans.api.visual.action.PopupMenuProvider, IPresentedWidget

Ancestor of all widgets in the ShedScene. It provides common infrastructure and helper methods for all widgets, e.g. drag and drop, display name ect.

The widget is painted as colored rectangle with text drawn over it. * If size of widget is too small, the text will be truncated (three dots will be appended to the truncated text) so it fits.

The origin of the widget ([0, 0]) is at the top left corner.

Author:
HonzaH

Nested Class Summary
 
Nested classes/interfaces inherited from class org.netbeans.api.visual.widget.Widget
org.netbeans.api.visual.widget.Widget.Dependency
 
Field Summary
protected  IPresenter actionProvider
          Provider of actions for this widget, menu, accept and others.
protected  Color color
          Color of the widget
protected static Font font
          Font used to display text on the widget
protected static int height
          Default height of ShedWidget.
protected static int textOfs
          Distance between left border of the widget and first letter of the text
protected static int width
          Default width of ShedWidget.
 
Method Summary
protected  void drawString(Graphics2D g, Font font, Color color, String text)
          Draw vertically centered string at TextWidget#textOfs that will fit into the widget.
 String getDisplayName()
          Get display name of the widget
protected  String getFittingString(String text, FontMetrics metrics, int maxWidth)
          Get string that will be shorter than maxWidth.
protected  Action[] getMenuActions()
          Get(create) list of actions for the context menu of the widget.
 JPopupMenu getPopupMenu(org.netbeans.api.visual.widget.Widget widget, Point localLocation)
          Return menu associated with the widget (will be used as context menu).
 IPresenter getPresenter()
          Get presenter of the widget.
 ShedScene getShedScene()
          Method wrapping Widget.getScene() to avoid casting every time.
protected  void paintWidget()
           
 void setDisplayName(String newDisplayName)
           
 void setPresenter(IPresenter newPresenter)
          Set new presenter of the widget.
 String toString()
           
 
Methods inherited from class org.netbeans.api.visual.widget.Widget
addChild, addChild, addChild, addChild, addChildren, addDependency, bringToBack, bringToFront, calculateClientArea, convertLocalToScene, convertLocalToScene, convertSceneToLocal, convertSceneToLocal, createActions, equals, getAccessibleContext, getActions, getActions, getBackground, getBorder, getBounds, getChildConstraint, getChildren, getClientArea, getCursor, getCursorAt, getDependencies, getFont, getForeground, getGraphics, getLayout, getLocation, getLookup, getMaximumSize, getMinimumSize, getParentWidget, getPreferredBounds, getPreferredLocation, getPreferredSize, getResourceTable, getScene, getState, getToolTipText, hashCode, isCheckClipping, isEnabled, isHitAt, isOpaque, isPreferredBoundsSet, isRepaintRequiredForRevalidating, isValidated, isVisible, notifyAdded, notifyBackgroundChanged, notifyFontChanged, notifyForegroundChanged, notifyRemoved, notifyStateChanged, paint, paintBackground, paintBorder, paintChildren, removeChild, removeChildren, removeChildren, removeDependency, removeFromParent, repaint, resolveBounds, revalidate, revalidate, setAccessibleContext, setBackground, setBackgroundFromResource, setBorder, setBorder, setCheckClipping, setChildConstraint, setCursor, setEnabled, setFont, setFontFromResource, setForeground, setForegroundFromResource, setLayout, setMaximumSize, setMinimumSize, setOpaque, setPreferredBounds, setPreferredLocation, setPreferredSize, setResourceTable, setState, setToolTipText, setVisible, updateResources
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

textOfs

protected static final int textOfs
Distance between left border of the widget and first letter of the text

See Also:
Constant Field Values

color

protected Color color
Color of the widget


actionProvider

protected IPresenter actionProvider
Provider of actions for this widget, menu, accept and others.


width

protected static final int width
Default width of ShedWidget.

See Also:
Constant Field Values

height

protected static final int height
Default height of ShedWidget.

See Also:
Constant Field Values

font

protected static final Font font
Font used to display text on the widget

Method Detail

getDisplayName

public final String getDisplayName()
Get display name of the widget

Returns:
display name

setDisplayName

public final void setDisplayName(String newDisplayName)

getShedScene

public ShedScene getShedScene()
Method wrapping Widget.getScene() to avoid casting every time.

Returns:
the scene this widget belongs to

getPopupMenu

public final JPopupMenu getPopupMenu(org.netbeans.api.visual.widget.Widget widget,
                                     Point localLocation)
Return menu associated with the widget (will be used as context menu).

Specified by:
getPopupMenu in interface org.netbeans.api.visual.action.PopupMenuProvider
Parameters:
widget - widget on which the popup menu is requested (always this)
localLocation - Where was popup menu invoked, if null, invoked by keyboard
Returns:
Created menu or null, if no actions from getMenuActions().

getMenuActions

protected final Action[] getMenuActions()
Get(create) list of actions for the context menu of the widget.

Returns:
Array of actions (can be null).

getPresenter

public final IPresenter getPresenter()
Description copied from interface: IPresentedWidget
Get presenter of the widget.

Specified by:
getPresenter in interface IPresentedWidget

setPresenter

public final void setPresenter(IPresenter newPresenter)
Set new presenter of the widget. Upon creation of the widget, it should be null.

Parameters:
newPresenter - New presenter.

paintWidget

protected void paintWidget()
Overrides:
paintWidget in class org.netbeans.api.visual.widget.Widget

drawString

protected final void drawString(Graphics2D g,
                                Font font,
                                Color color,
                                String text)
Draw vertically centered string at TextWidget#textOfs that will fit into the widget. If text is too long, truncate it and add ellipsis (three dots) at the end.

Parameters:
g - context used to draw
font - font which should be used to compute
color - what color should text have
text - text to draw.

getFittingString

protected final String getFittingString(String text,
                                        FontMetrics metrics,
                                        int maxWidth)
Get string that will be shorter than maxWidth. If Passed text is too long return part of text with "..." at the end.

Parameters:
text - Text we want to fit into maxWidth
metrics - font metrics to measure length of strings
maxWidth - maximal length the returned string can fit into.
Returns:
text if it fits into maxWidth, otherwise maximal text.substring(0,X).concat("...") that will fit into maxWidth.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.