templates.presentation
Class TemplateEditableCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by templates.presentation.TemplateCanvas
                  extended by templates.presentation.TemplateEditableCanvas
All Implemented Interfaces:
ides.api.plugin.presentation.Presentation, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, TemplateDiagramSubscriber
Direct Known Subclasses:
TemplateConsistencyCanvas

public class TemplateEditableCanvas
extends TemplateCanvas
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

A TemplateCanvas which allows the manipulation of a TemplateModel by the user via the GUI.

Author:
Lenko Grigorov
See Also:
Serialized Form

Nested Class Summary
protected static class TemplateEditableCanvas.CanvasSettings
          Canvas appearance settings.
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected static java.lang.String CANVAS_SETTINGS
          The key to be used to annotate a TemplateModel with the appearance settings of the canvas (zoom level and viewport position).
protected  java.awt.Point connectorOrigin
          The point of origin for the new connector when the user is drawing a new connector.
protected  boolean drawConnector
          Information about whether to paint the line representing the new connector when the user is drawing a new connector.
protected  DiagramElement hilitedElement
          The diagram element which is highlighted.
protected  boolean ignoreNextMouseEvent
          Toggle to turn on and off the processing of mouse events by the canvas when a dialog appears over the canvas (e.g., when the user enters a new label for an entity).
protected  MouseInterpreter interpreter
          The interpreter of the mouse events for this canvas.
protected  java.awt.Rectangle selectionBox
          The rectangle which defines the boundaries of the selection box when the user drags the mouse around diagram components to select them.
protected static java.awt.Stroke SELECTIONBOX_STROKE
          The stroke used to paint the boundary of the selection box when the user drags the mouse around diagram components to select them.
 
Fields inherited from class templates.presentation.TemplateCanvas
diagram, DIAGRAM, graphics, model, scaleFactor, scaleToFit
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
TemplateEditableCanvas(TemplateModel model)
          Construct a new canvas to enable the editing of the given template design.
 
Method Summary
protected  void autoScroll()
          Scroll the viewport of the canvas to the rectangle stored as an annotation in the template design.
protected  void autoZoom()
          Set the scaling factor according to the zoom level setting stored as an annotation in the template design.
 java.awt.Point componentToLocal(java.awt.Point p)
          Transform a point from the space of the canvas component to the space of the template diagram, accounting for the scaling factor.
 void finishConnector()
          Stop painting a line to denote a new connector.
 javax.swing.JComponent getGUI()
           
 DiagramElement getHighlightedElement()
          Get the currently highlighted diagram element.
 java.awt.Rectangle getSelectionBox()
          Retrieve the rectangle which defines the boundaries of the selection box when the user drags the mouse around diagram components to select them.
 void highlight(DiagramElement element)
          Specify which diagram element should be highlighted.
 boolean isDrawingConnector()
          Determine if the canvas is set to paint a line to denote a new connector.
 java.awt.Point localToComponent(java.awt.Point p)
          Transform a point from the space of the template diagram to the space of canvas component, accounting for the scaling factor.
 java.awt.Point localToScreen(java.awt.Point p)
          Transform a point from the space of the template diagram to the space of the screen, accounting for the scaling factor and the location of the canvas on the screen.
 void mouseClicked(java.awt.event.MouseEvent arg0)
          Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.
 void mouseDragged(java.awt.event.MouseEvent e)
          Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.
 void mouseEntered(java.awt.event.MouseEvent arg0)
          Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.
 void mouseExited(java.awt.event.MouseEvent arg0)
          Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.
 void mouseMoved(java.awt.event.MouseEvent e)
          Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.
 void mousePressed(java.awt.event.MouseEvent arg0)
          Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.
 void mouseReleased(java.awt.event.MouseEvent arg0)
          Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.
 void paint(java.awt.Graphics g)
           
protected  void paintCore(java.awt.Graphics2D g2d)
          In addition to painting the template diagram, also paint the highlighting of the highlighted diagram element (if any).
 void refresh()
          Refresh the rendering of the diagram.
 void release()
          Before releasing the template design, annotate it with the current appearance settings so that they can be reloaded if the user activates again the model in the workspace.
 void removeHighlight()
          Stop highlighting the currently highlighted diagram element.
 void setSelectionBox(java.awt.Rectangle r)
          Update the rectangle which defines the boundaries of the selection box when the user drags the mouse around diagram components to select them.
 void setUIInteraction(boolean b)
          Specify whether the user is engaged in an interaction with a dialog which appears over the canvas (e.g., when the user enters a new label for an entity).
 void startConnector(java.awt.Point origin)
          Start painting a line to denote a new connector with the given origin.
protected  void storeCanvasInfo()
          Create a descriptor of the appearance settings of the canvas and create an annotation with it in the template design.
 void templateDiagramChanged(TemplateDiagramMessage message)
          In addition to refreshing the rendering of the template diagram, update the highlighting of diagram elements.
 java.awt.event.MouseEvent transformMouseCoords(java.awt.event.MouseEvent me)
          Construct a new mouse event based on the given mouse event, where the mouse cursor coordinates are transformed to account for the scaling factor used in painting the template diagram.
 
Methods inherited from class templates.presentation.TemplateCanvas
forceRepaint, getDiagram, getModel, getPreferredSize, setTrackModel, templateDiagramSelectionChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ides.api.plugin.presentation.Presentation
getName
 

Field Detail

CANVAS_SETTINGS

protected static final java.lang.String CANVAS_SETTINGS
The key to be used to annotate a TemplateModel with the appearance settings of the canvas (zoom level and viewport position). This annotation is used to restore the last appearance of the template diagram when the user re-activates the diagram in the workspace.

See Also:
Annotable, Constant Field Values

SELECTIONBOX_STROKE

protected static final java.awt.Stroke SELECTIONBOX_STROKE
The stroke used to paint the boundary of the selection box when the user drags the mouse around diagram components to select them.


ignoreNextMouseEvent

protected boolean ignoreNextMouseEvent
Toggle to turn on and off the processing of mouse events by the canvas when a dialog appears over the canvas (e.g., when the user enters a new label for an entity). Set to true to turn off the processing of mouse events, set to false to turn on the processing of mouse events. The mouse event of releasing the mouse button always sets this toggle to false as the user is assumed to have started interacting with the canvas directly.

See Also:
setUIInteraction(boolean)

interpreter

protected MouseInterpreter interpreter
The interpreter of the mouse events for this canvas.


hilitedElement

protected DiagramElement hilitedElement
The diagram element which is highlighted. This is the element under the mouse cursor. If there is no diagram element under the mouse cursor, the variable is set to null.


selectionBox

protected java.awt.Rectangle selectionBox
The rectangle which defines the boundaries of the selection box when the user drags the mouse around diagram components to select them. If the user is not in the process of making such a selection, the variable is set to null.


connectorOrigin

protected java.awt.Point connectorOrigin
The point of origin for the new connector when the user is drawing a new connector.


drawConnector

protected boolean drawConnector
Information about whether to paint the line representing the new connector when the user is drawing a new connector. Set to true to paint the connector, set to false otherwise.

Constructor Detail

TemplateEditableCanvas

public TemplateEditableCanvas(TemplateModel model)
Construct a new canvas to enable the editing of the given template design.

Parameters:
model - the template design which the user will manipulate
Method Detail

getGUI

public javax.swing.JComponent getGUI()
Specified by:
getGUI in interface ides.api.plugin.presentation.Presentation
Overrides:
getGUI in class TemplateCanvas

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class TemplateCanvas

paintCore

protected void paintCore(java.awt.Graphics2D g2d)
In addition to painting the template diagram, also paint the highlighting of the highlighted diagram element (if any).

Overrides:
paintCore in class TemplateCanvas
Parameters:
g2d - the graphics context where the template diagram should be painted

templateDiagramChanged

public void templateDiagramChanged(TemplateDiagramMessage message)
In addition to refreshing the rendering of the template diagram, update the highlighting of diagram elements.

Specified by:
templateDiagramChanged in interface TemplateDiagramSubscriber
Overrides:
templateDiagramChanged in class TemplateCanvas
Parameters:
message - the description of the change

autoZoom

protected void autoZoom()
Set the scaling factor according to the zoom level setting stored as an annotation in the template design. If this annotation cannot be found, set the scaling factor to 1.

See Also:
TemplateEditableCanvas.CanvasSettings, Annotable

autoScroll

protected void autoScroll()
Scroll the viewport of the canvas to the rectangle stored as an annotation in the template design. After the scrolling, the annotation is removed. If the annotation cannot be found, do nothing.

See Also:
TemplateEditableCanvas.CanvasSettings, Annotable

storeCanvasInfo

protected void storeCanvasInfo()
Create a descriptor of the appearance settings of the canvas and create an annotation with it in the template design.

See Also:
TemplateEditableCanvas.CanvasSettings, Annotable

refresh

public void refresh()
Description copied from class: TemplateCanvas
Refresh the rendering of the diagram. Compute the new scaling factor and repaint.

Overrides:
refresh in class TemplateCanvas

release

public void release()
Before releasing the template design, annotate it with the current appearance settings so that they can be reloaded if the user activates again the model in the workspace.

Specified by:
release in interface ides.api.plugin.presentation.Presentation
Overrides:
release in class TemplateCanvas

transformMouseCoords

public java.awt.event.MouseEvent transformMouseCoords(java.awt.event.MouseEvent me)
Construct a new mouse event based on the given mouse event, where the mouse cursor coordinates are transformed to account for the scaling factor used in painting the template diagram.

Parameters:
me - the original mouse event
Returns:
the mouse event where the mouse cursor coordinates are transformed to account for the scaling factor used in painting the template diagram

localToScreen

public java.awt.Point localToScreen(java.awt.Point p)
Transform a point from the space of the template diagram to the space of the screen, accounting for the scaling factor and the location of the canvas on the screen.

Parameters:
p - the point in the space of the template diagram
Returns:
the point in the space of the screen

localToComponent

public java.awt.Point localToComponent(java.awt.Point p)
Transform a point from the space of the template diagram to the space of canvas component, accounting for the scaling factor.

Parameters:
p - the point in the space of the template diagram
Returns:
the point in the space of canvas component

componentToLocal

public java.awt.Point componentToLocal(java.awt.Point p)
Transform a point from the space of the canvas component to the space of the template diagram, accounting for the scaling factor.

Parameters:
p - the point in the space of the canvas component
Returns:
the point in the space of the template diagram

setUIInteraction

public void setUIInteraction(boolean b)
Specify whether the user is engaged in an interaction with a dialog which appears over the canvas (e.g., when the user enters a new label for an entity).

Parameters:
b - set to true when the user engages in an interaction with a dialog which appears over the canvas; set to false when the user finishes interacting with a dialog which appears over the canvas
See Also:
ignoreNextMouseEvent

setSelectionBox

public void setSelectionBox(java.awt.Rectangle r)
Update the rectangle which defines the boundaries of the selection box when the user drags the mouse around diagram components to select them.

Parameters:
r - the new boundaries of the selection box

getSelectionBox

public java.awt.Rectangle getSelectionBox()
Retrieve the rectangle which defines the boundaries of the selection box when the user drags the mouse around diagram components to select them.

Returns:
the boundaries of the selection box

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent arg0)
Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
See Also:
interpreter

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent arg0)
Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
See Also:
interpreter

mouseExited

public void mouseExited(java.awt.event.MouseEvent arg0)
Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.

Specified by:
mouseExited in interface java.awt.event.MouseListener
See Also:
interpreter

mousePressed

public void mousePressed(java.awt.event.MouseEvent arg0)
Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.

Specified by:
mousePressed in interface java.awt.event.MouseListener
See Also:
interpreter

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent arg0)
Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
See Also:
interpreter

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
See Also:
interpreter

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Transform the mouse cursor coordinates accounting for the scaling factor and forward the event to the mouse event interpreter.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
See Also:
interpreter

highlight

public void highlight(DiagramElement element)
Specify which diagram element should be highlighted.

Parameters:
element - the diagram element to be highlighted

getHighlightedElement

public DiagramElement getHighlightedElement()
Get the currently highlighted diagram element.

Returns:
the currently highlighted diagram element, if an element is highlighted; null otherwise

removeHighlight

public void removeHighlight()
Stop highlighting the currently highlighted diagram element.


startConnector

public void startConnector(java.awt.Point origin)
Start painting a line to denote a new connector with the given origin. The end-point of the line will be the tracking the location of the mouse cursor.

Parameters:
origin - the origin of the line denoting a new connector

finishConnector

public void finishConnector()
Stop painting a line to denote a new connector.


isDrawingConnector

public boolean isDrawingConnector()
Determine if the canvas is set to paint a line to denote a new connector.

Returns:
true if the canvas is set to paint a line to denote a new connector; false otherwise