net.sourceforge.toscanaj.view.diagram
Class LabelView

java.lang.Object
  extended byorg.tockit.canvas.CanvasItem
      extended bynet.sourceforge.toscanaj.view.diagram.LabelView
All Implemented Interfaces:
ChangeObserver, org.tockit.events.EventBrokerListener
Direct Known Subclasses:
AttributeLabelView, ObjectLabelView, SqlClauseLabelView

public abstract class LabelView
extends org.tockit.canvas.CanvasItem
implements ChangeObserver, org.tockit.events.EventBrokerListener

This class encapsulates all generic label drawing code. The actual classes to use are the AttributeLabelView and the ObjectLabelView which are distinguished by position (above vs. below the node) and default display type (list vs. number).


Nested Class Summary
protected static class LabelView.DragMode
           
static interface LabelView.LabelFactory
           
 
Field Summary
protected static int ABOVE
          Used when the label should be drawn above the given point.
protected static int BELOW
          Used when the label should be drawn below the given point.
protected static int DEFAULT_DISPLAY_LINES
          Gives the number of display lines used on a new label.
protected  DiagramView diagramView
          Store the diagram view that the label belongs to.
protected  int displayLines
          The current display size in lines.
protected  LabelView.DragMode dragMode
           
protected  int firstItem
          The first item displayed in the list.
protected  LabelInfo labelInfo
          The label information that should be drawn.
protected  float lineHeight
          The height of a single line in the view.
protected static int MIN_DISPLAY_LINES
          Gives the minimum number of display lines possible.
protected static LabelView.DragMode MOVING
           
protected  NodeView nodeView
           
protected static LabelView.DragMode NOT_DRAGGING
           
protected  java.util.Vector observers
           
protected  java.awt.geom.Rectangle2D rect
          The bounding rectangle for the label itself.
protected static LabelView.DragMode RESIZING
           
protected  boolean scrollbarShown
           
protected static LabelView.DragMode SCROLLING
           
 
Constructor Summary
protected LabelView(DiagramView diagramView, NodeView nodeView, LabelInfo label)
          Creates a view for the given label information.
 
Method Summary
 void addObserver(ChangeObserver observer)
           
 boolean containsPoint(java.awt.geom.Point2D point)
          Returns true whenever the point is in the bounding rectangle.
 void draw(java.awt.Graphics2D graphics)
          Draws the label at the given position in the graphic context.
 java.awt.geom.Rectangle2D getCanvasBounds(java.awt.Graphics2D graphics)
           
protected  java.awt.Color getConnectorColor()
           
protected  java.awt.geom.Point2D getConnectorEndPosition()
           
abstract  java.lang.Object getEntryAt(int position)
           
static LabelView.LabelFactory getFactory()
           
 java.awt.Font getFont()
           
 int getIndexOfPosition(java.awt.geom.Point2D pos)
          Calculates which item was hit.
 double getLabelHeight()
          Return Label height
 double getLabelWidth()
          Return Label width
 NodeView getNodeView()
           
abstract  int getNumberOfEntries()
           
protected abstract  int getPlacement()
          Returns the placement of the label (above or below the node).
 java.awt.geom.Point2D getPosition()
           
protected abstract  boolean highlightedInFilter()
           
protected abstract  boolean highlightedInIdeal()
           
protected abstract  boolean isFaded()
           
 boolean isVisible()
           
protected  void notifyObservers()
           
 void processClickEvent(java.awt.geom.Point2D pos)
          Handles scrolling of the items.
 void processDragEvent(java.awt.geom.Point2D from, java.awt.geom.Point2D to, boolean isDrop)
           
 void processEvent(org.tockit.events.Event e)
           
 void setFont(java.awt.Font font)
           
 void setScrollbarShown(boolean scrollbarShown)
           
 void startDrag(java.awt.geom.Point2D from, java.awt.geom.Point2D to)
           
 void update(java.lang.Object source)
          Update label view as label info has change.
 void updateBounds(java.awt.Graphics2D graphics)
           
 void updateEntries()
           
 
Methods inherited from class org.tockit.canvas.CanvasItem
hasAutoRaise
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ABOVE

protected static final int ABOVE
Used when the label should be drawn above the given point. See Draw( Graphics2D, double ,double ,int ).

See Also:
Constant Field Values

BELOW

protected static final int BELOW
Used when the label should be drawn below the given point. See Draw( Graphics2D, double ,double ,int ).

See Also:
Constant Field Values

MIN_DISPLAY_LINES

protected static final int MIN_DISPLAY_LINES
Gives the minimum number of display lines possible.

See Also:
displayLines, Constant Field Values

DEFAULT_DISPLAY_LINES

protected static final int DEFAULT_DISPLAY_LINES
Gives the number of display lines used on a new label.

See Also:
displayLines, Constant Field Values

rect

protected java.awt.geom.Rectangle2D rect
The bounding rectangle for the label itself.


labelInfo

protected LabelInfo labelInfo
The label information that should be drawn.


diagramView

protected DiagramView diagramView
Store the diagram view that the label belongs to.


nodeView

protected NodeView nodeView

displayLines

protected int displayLines
The current display size in lines. This is the number of items currently displayed.


firstItem

protected int firstItem
The first item displayed in the list. This is used if the number of displayed lines is smaller than the number of items to display to determine the top element in the displayed part.


scrollbarShown

protected boolean scrollbarShown

lineHeight

protected float lineHeight
The height of a single line in the view.


observers

protected java.util.Vector observers

dragMode

protected LabelView.DragMode dragMode

NOT_DRAGGING

protected static final LabelView.DragMode NOT_DRAGGING

RESIZING

protected static final LabelView.DragMode RESIZING

MOVING

protected static final LabelView.DragMode MOVING

SCROLLING

protected static final LabelView.DragMode SCROLLING
Constructor Detail

LabelView

protected LabelView(DiagramView diagramView,
                    NodeView nodeView,
                    LabelInfo label)
Creates a view for the given label information. Protected since the factory should be used instead.

See Also:
getFactory()
Method Detail

getFactory

public static LabelView.LabelFactory getFactory()

updateEntries

public void updateEntries()

update

public void update(java.lang.Object source)
Update label view as label info has change. This implements the callback in ChangeObserver, the parameter is the object sending the event.

Specified by:
update in interface ChangeObserver

getLabelWidth

public double getLabelWidth()
Return Label width


getLabelHeight

public double getLabelHeight()
Return Label height


getPosition

public java.awt.geom.Point2D getPosition()

isVisible

public boolean isVisible()

draw

public void draw(java.awt.Graphics2D graphics)
Draws the label at the given position in the graphic context. The position is placed above or below the label, horizontally centered plus the offset from the LabelInfo. The placement should be either LabelView::ABOVE or LabelView::BELOW. A dashed line will be drawn from the central top/bottom point to the given point. The scaling information is needed to scale the offset.


updateBounds

public void updateBounds(java.awt.Graphics2D graphics)

getConnectorEndPosition

protected java.awt.geom.Point2D getConnectorEndPosition()

isFaded

protected abstract boolean isFaded()

getConnectorColor

protected java.awt.Color getConnectorColor()

getPlacement

protected abstract int getPlacement()
Returns the placement of the label (above or below the node). Possible return values are LabelView.ABOVE or LabelView.BELOW. This is used to draw the labels in their appropriate position.


containsPoint

public boolean containsPoint(java.awt.geom.Point2D point)
Returns true whenever the point is in the bounding rectangle.


processDragEvent

public void processDragEvent(java.awt.geom.Point2D from,
                             java.awt.geom.Point2D to,
                             boolean isDrop)

startDrag

public void startDrag(java.awt.geom.Point2D from,
                      java.awt.geom.Point2D to)

processClickEvent

public void processClickEvent(java.awt.geom.Point2D pos)
Handles scrolling of the items.


getCanvasBounds

public java.awt.geom.Rectangle2D getCanvasBounds(java.awt.Graphics2D graphics)

getIndexOfPosition

public int getIndexOfPosition(java.awt.geom.Point2D pos)
Calculates which item was hit. This is the number of the entry, not on the screen but in the full list, i.e. the offset from scrolling is used. If no item was hit (e.g. a click on the scrollbar or the position is not on the label), -1 will be returned.


highlightedInIdeal

protected abstract boolean highlightedInIdeal()

highlightedInFilter

protected abstract boolean highlightedInFilter()

getNumberOfEntries

public abstract int getNumberOfEntries()

getEntryAt

public abstract java.lang.Object getEntryAt(int position)

processEvent

public void processEvent(org.tockit.events.Event e)
Specified by:
processEvent in interface org.tockit.events.EventBrokerListener

addObserver

public void addObserver(ChangeObserver observer)

notifyObservers

protected void notifyObservers()

getNodeView

public NodeView getNodeView()

getFont

public java.awt.Font getFont()

setFont

public void setFont(java.awt.Font font)

setScrollbarShown

public void setScrollbarShown(boolean scrollbarShown)


The ToscanaJ project