venice
Class ZVisualization

java.lang.Object
  |
  +--venice.ZVisualization
All Implemented Interfaces:
Visualization

public class ZVisualization
extends java.lang.Object
implements Visualization

ZVisualization is a concrete implementation of Visualization interface.

ZVisualization uses Jazz zoomable user interface library as its backend.

Author:
Hannu Laurila, Antti Pietarinen, Petteri Kamppuri

Field Summary
private  edu.umd.cs.jazz.util.ZCanvas mCanvas
          jazz canvas which is a Swing component which can be placed to UI
private  edu.umd.cs.jazz.event.ZEventHandler mCurrentEventHandler
          reference to the currently active event handler
private  int mCurrentMode
          current mode of the visualization (one of Visualization.MODE...)
private  java.util.Hashtable mIndexById
          Hashtable for quickly accessing vmodelelements
private  boolean mInInteractiveMode
           
private  edu.umd.cs.jazz.event.ZPanEventHandler mPanEventHandler
          event handler which is active in panning mode
private  ZPackage mRootPackage
          the root VPackage in which everything from the model is contained
private  VCompositeSelectionHandler mSelectionHandler
          event handler which is active in selection mode
private  edu.umd.cs.jazz.ZLayerGroup mSelectionLayer
          selection layer is used to draw the selection marquee
private  VSelectionListener mSelectionListener
          a listener (e.g. the GUI) which is notified on selection changes
private  VZoomEventHandler mZoomEventHandler
          event handler which is active in zooming mode
private static boolean RELATIONSHIP_SPEEDUP_ENABLED
          if this is set true, all relationships are put to the root package.
private static java.awt.Cursor stNoneCursor
          cursor which is used when visualization area has no active mode
private static java.awt.Cursor stPanCursor
          cursor which is used in panning mode
private static java.awt.Cursor stSelectCursor
          cursor which is used in select mode
protected static ZVisualization stVisualizationReference
          reference to instantiated visualization
private static java.awt.Cursor stZoomCursor
          cursor which is used in zooming mode
private static double ZOOMSPACING
          how much space is left to edges when zooming to an element
private static int ZOOMTIME
          animation length for zoomTo
 
Fields inherited from interface venice.Visualization
MODE_NONE, MODE_PAN, MODE_SELECT, MODE_ZOOM
 
Constructor Summary
ZVisualization()
          constructor which sets up all internal data structures.
 
Method Summary
private  void addToIndex(VModelElement inElement)
          adds a VModelElement to the indexing hashtable with checks
 void addVRelationship(VRelationship inRelship)
          Adds a relationship to the visualization.
 void addVRelationshipWithoutAddingOriginalReference(VRelationship inRelship)
          Adds the given VRelationship to the visualization, but does not add it as an original relationship to the source and destination nodes.
 void clear()
          Clears the visualization (drops everything from the root package).
 void enterNonInteractiveMode()
          enters non-interactive mode.
 VModelElement findElementById(java.lang.String inId)
          findElementById finds a model element stored in visualization subsystem data structures by its id.
private  void fireSelectionChanged()
           
 javax.swing.JMenu getDebugMenu()
          getDebugMenu returns a menu which can be placed to a menubar.
 VPackage getRootPackage()
          returns a reference to the root package of the visualization.
 VModelElement[] getSelection()
          returns currently selected items in the visualization
private  edu.umd.cs.jazz.util.ZBounds getSelectionBounds()
          calculates bounds for current selection.
 javax.swing.JComponent getSwingComponent()
          returns a Swing component representing the visualization.
 int getToolMode()
          gets the current mode of the visualization area.
static ZVisualization getZVisualizationInstance()
          Returns the current instance of ZVisualization.
private  void initEventHandlers()
          Initialize the event handlers
 void leaveNonInteractiveMode()
          leaves non-interactive mode.
 void loadLayout(java.io.InputStream inoutStream)
          Load layout information from a stream
 void makeDefaultLayout()
          constructs a default layout for the visualization.
 VComponent newVComponent(java.lang.String inId)
          a factory method for generating new VComponents.
 VDependency newVDependency(java.lang.String inId)
          a factory method for generating new VDependencies.
 VGeneralization newVGeneralization(java.lang.String inId)
          a factory method for generating new VGeneralizations.
 VInterface newVInterface(java.lang.String inId)
          a factory method for generating new VInterfaces.
 VPackage newVPackage(java.lang.String inId)
          a factory method for generating new VPackages.
 VRealization newVRealization(java.lang.String inId)
          a factory method for generating new VRealizations.
 void printCurrentView()
          brings up a print dialog which user can use to send currently visible view to printer.
 void removeElement(java.lang.String inId)
          removes element specified by inId from lookup structures.
private  void removeFromIndex(java.lang.String outElement)
           
 void removeVRelationship(VRelationship inRelship)
          remove a relationship from the visualization.
private  boolean removeVRelationshipFromPackage(VPackage inPackage, VRelationship inRel)
          Removes the relationship from this package.
 void saveLayout(java.io.OutputStream inoutStream)
          Saves the layout information to an output stream.
 void setSelection(VModelElement[] inSelection)
          sets the currently selected model elements in the visualization.
 void setSelectionListener(VSelectionListener inListener)
          sets the object which receives notifications about selection changes.
 void setToolMode(int inMode)
          sets the current operating mode of the visualization area.
private  void setupTestModel1()
          sets up an test model for testing visualization subsystem and different graphical components.
private  void setupTestModel2()
          sets up another test model for testing the subsystem
 void setZoomVolume(int inDx)
          sets the current speed of zooming
 void zoomTo(VModelElement inElement)
          Zooms the visualization area to a particular element. zooms the visualization area so that inElement is as big as possible but still fully visible.
private  void zoomTo(edu.umd.cs.jazz.util.ZBounds myTargetBounds)
          zooms to specified bounds. if bounds width or height is zero, returns without zooming to avoid odd effects.
 void zoomToSelection()
          Zooms to the current selection on the visualization area.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

RELATIONSHIP_SPEEDUP_ENABLED

private static final boolean RELATIONSHIP_SPEEDUP_ENABLED
if this is set true, all relationships are put to the root package. It makes things faster but the visual look is not as good when they relationships are put to deeper level packages. This speedup is not needed much anymore, because of optimizations we made to Jazz library.

ZOOMSPACING

private static final double ZOOMSPACING
how much space is left to edges when zooming to an element

ZOOMTIME

private static final int ZOOMTIME
animation length for zoomTo

stNoneCursor

private static java.awt.Cursor stNoneCursor
cursor which is used when visualization area has no active mode

stPanCursor

private static java.awt.Cursor stPanCursor
cursor which is used in panning mode

stSelectCursor

private static java.awt.Cursor stSelectCursor
cursor which is used in select mode

stZoomCursor

private static java.awt.Cursor stZoomCursor
cursor which is used in zooming mode

mCanvas

private edu.umd.cs.jazz.util.ZCanvas mCanvas
jazz canvas which is a Swing component which can be placed to UI

mCurrentEventHandler

private edu.umd.cs.jazz.event.ZEventHandler mCurrentEventHandler
reference to the currently active event handler

mPanEventHandler

private edu.umd.cs.jazz.event.ZPanEventHandler mPanEventHandler
event handler which is active in panning mode

mZoomEventHandler

private VZoomEventHandler mZoomEventHandler
event handler which is active in zooming mode

mSelectionHandler

private VCompositeSelectionHandler mSelectionHandler
event handler which is active in selection mode

mSelectionLayer

private edu.umd.cs.jazz.ZLayerGroup mSelectionLayer
selection layer is used to draw the selection marquee

mIndexById

private java.util.Hashtable mIndexById
Hashtable for quickly accessing vmodelelements

mRootPackage

private ZPackage mRootPackage
the root VPackage in which everything from the model is contained

mSelectionListener

private VSelectionListener mSelectionListener
a listener (e.g. the GUI) which is notified on selection changes

mCurrentMode

private int mCurrentMode
current mode of the visualization (one of Visualization.MODE...)

stVisualizationReference

protected static ZVisualization stVisualizationReference
reference to instantiated visualization

mInInteractiveMode

private boolean mInInteractiveMode
Constructor Detail

ZVisualization

public ZVisualization()
constructor which sets up all internal data structures.
Method Detail

getZVisualizationInstance

public static ZVisualization getZVisualizationInstance()
Returns the current instance of ZVisualization.

addVRelationship

public void addVRelationship(VRelationship inRelship)
Adds a relationship to the visualization. Relationships is either a realization, a generalization or a dependency. The relationship is added to a list of original relationships in both source and destination node. That information is used in various Commands to perform for example relationship grouping on parent level. This means that the given VRelationship must have its source and destination set.
Specified by:
addVRelationship in interface Visualization
Parameters:
inRelship - relationship to add to visualization.

addVRelationshipWithoutAddingOriginalReference

public void addVRelationshipWithoutAddingOriginalReference(VRelationship inRelship)
Adds the given VRelationship to the visualization, but does not add it as an original relationship to the source and destination nodes.
Specified by:
addVRelationshipWithoutAddingOriginalReference in interface Visualization
Parameters:
inRelship - relationship to add to visualization

findElementById

public VModelElement findElementById(java.lang.String inId)
Description copied from interface: Visualization
findElementById finds a model element stored in visualization subsystem data structures by its id.
Specified by:
findElementById in interface Visualization
Following copied from interface: venice.Visualization
Parameters:
inId - ID of the model element to find
Returns:
reference to the element if found, null otherwise

getDebugMenu

public javax.swing.JMenu getDebugMenu()
Description copied from interface: Visualization
getDebugMenu returns a menu which can be placed to a menubar. Debug menu includes menu items for getting debug information regarding the visualization. The information is mainly ment for developers
Specified by:
getDebugMenu in interface Visualization

getRootPackage

public VPackage getRootPackage()
Description copied from interface: Visualization
returns a reference to the root package of the visualization.
Specified by:
getRootPackage in interface Visualization

getSelection

public VModelElement[] getSelection()
Description copied from interface: Visualization
returns currently selected items in the visualization
Specified by:
getSelection in interface Visualization
Following copied from interface: venice.Visualization
Returns:
array consisting of currently selected elements

getSwingComponent

public javax.swing.JComponent getSwingComponent()
Description copied from interface: Visualization
returns a Swing component representing the visualization. The swing component can then be placed on the user interface of the visualization software
Specified by:
getSwingComponent in interface Visualization
Following copied from interface: venice.Visualization
Returns:
a reference to a Swing JComponent.

getToolMode

public int getToolMode()
Description copied from interface: Visualization
gets the current mode of the visualization area. Constants beginning with a MODE_ describe the possible visualization area modes.
Specified by:
getToolMode in interface Visualization

makeDefaultLayout

public void makeDefaultLayout()
Description copied from interface: Visualization
constructs a default layout for the visualization. What is 'the default layout' depends on the particular visualization subsystem implementation used. This method should be called after all model elements loaded from the model data source have been inserted to the visualization.
Specified by:
makeDefaultLayout in interface Visualization

newVComponent

public VComponent newVComponent(java.lang.String inId)
Description copied from interface: Visualization
a factory method for generating new VComponents.
Specified by:
newVComponent in interface Visualization

newVInterface

public VInterface newVInterface(java.lang.String inId)
Description copied from interface: Visualization
a factory method for generating new VInterfaces.
Specified by:
newVInterface in interface Visualization

newVPackage

public VPackage newVPackage(java.lang.String inId)
Description copied from interface: Visualization
a factory method for generating new VPackages.
Specified by:
newVPackage in interface Visualization

newVDependency

public VDependency newVDependency(java.lang.String inId)
Description copied from interface: Visualization
a factory method for generating new VDependencies.
Specified by:
newVDependency in interface Visualization

newVGeneralization

public VGeneralization newVGeneralization(java.lang.String inId)
Description copied from interface: Visualization
a factory method for generating new VGeneralizations.
Specified by:
newVGeneralization in interface Visualization

newVRealization

public VRealization newVRealization(java.lang.String inId)
Description copied from interface: Visualization
a factory method for generating new VRealizations.
Specified by:
newVRealization in interface Visualization

removeElement

public void removeElement(java.lang.String inId)
Description copied from interface: Visualization
removes element specified by inId from lookup structures. After removeElement the element can not be looked up using findElementById. Note that this does not remove the element from any VPackage if it is there.
Specified by:
removeElement in interface Visualization

removeVRelationship

public void removeVRelationship(VRelationship inRelship)
Description copied from interface: Visualization
remove a relationship from the visualization.
Specified by:
removeVRelationship in interface Visualization

removeVRelationshipFromPackage

private boolean removeVRelationshipFromPackage(VPackage inPackage,
                                               VRelationship inRel)
Removes the relationship from this package. If the relationship doesn't belong to this package, this method will try to remove the relationship from this package's children. Returns whether the relationship was removed.
Parameters:
inPackage - the from which to remove the relationship
inRel - the relationships to remove
Returns:
whether relationships was removed

saveLayout

public void saveLayout(java.io.OutputStream inoutStream)
                throws java.io.IOException
Description copied from interface: Visualization
Saves the layout information to an output stream. Layout is saved in a format which can be loaded using loadLayout() method.
Specified by:
saveLayout in interface Visualization
Following copied from interface: venice.Visualization
Parameters:
layoutStream - a stream where to save to layout information

loadLayout

public void loadLayout(java.io.InputStream inoutStream)
                throws java.io.IOException
Description copied from interface: Visualization
Load layout information from a stream
Specified by:
loadLayout in interface Visualization
Following copied from interface: venice.Visualization
Parameters:
layoutStream - Layout stream which has been saved using saveLayout-method.

setSelection

public void setSelection(VModelElement[] inSelection)
Description copied from interface: Visualization
sets the currently selected model elements in the visualization.
Specified by:
setSelection in interface Visualization

setSelectionListener

public void setSelectionListener(VSelectionListener inListener)
Description copied from interface: Visualization
sets the object which receives notifications about selection changes. The object must implement the VSelectionListener interface. After been notified, the object can query the currently selected model elements via getSelection method.
Specified by:
setSelectionListener in interface Visualization
Following copied from interface: venice.Visualization
Parameters:
inListener - a reference to a VSelectionListener which will receive notifications about changes in selection.

setToolMode

public void setToolMode(int inMode)
Description copied from interface: Visualization
sets the current operating mode of the visualization area.
Specified by:
setToolMode in interface Visualization
Following copied from interface: venice.Visualization
Parameters:
inMode - one of constants beginning with a MODE_ keyword.

setZoomVolume

public void setZoomVolume(int inDx)
Description copied from interface: Visualization
sets the current speed of zooming
Specified by:
setZoomVolume in interface Visualization
Following copied from interface: venice.Visualization
Parameters:
inDx - FIXME: What is this really

zoomTo

public void zoomTo(VModelElement inElement)
Description copied from interface: Visualization
Zooms the visualization area to a particular element. zooms the visualization area so that inElement is as big as possible but still fully visible.
Specified by:
zoomTo in interface Visualization
Following copied from interface: venice.Visualization
Parameters:
inElement - the model element to be zoomed on.

zoomToSelection

public void zoomToSelection()
Description copied from interface: Visualization
Zooms to the current selection on the visualization area. The currently selected model elements will be visible.
Specified by:
zoomToSelection in interface Visualization

zoomTo

private void zoomTo(edu.umd.cs.jazz.util.ZBounds myTargetBounds)
zooms to specified bounds. if bounds width or height is zero, returns without zooming to avoid odd effects.

getSelectionBounds

private edu.umd.cs.jazz.util.ZBounds getSelectionBounds()
calculates bounds for current selection. Returns null if there is no selection.

clear

public void clear()
Description copied from interface: Visualization
Clears the visualization (drops everything from the root package).

Note that VPackages which were in the visualization lose their childs so don't rely on getVChildren() after clearing the visualization. In general, the VModelElement instances in the visualization should not be used after the visualization has been cleared.

Specified by:
clear in interface Visualization

fireSelectionChanged

private void fireSelectionChanged()

initEventHandlers

private void initEventHandlers()
Initialize the event handlers

setupTestModel1

private void setupTestModel1()
sets up an test model for testing visualization subsystem and different graphical components.

setupTestModel2

private void setupTestModel2()
sets up another test model for testing the subsystem

addToIndex

private void addToIndex(VModelElement inElement)
adds a VModelElement to the indexing hashtable with checks

removeFromIndex

private void removeFromIndex(java.lang.String outElement)

enterNonInteractiveMode

public void enterNonInteractiveMode()
Description copied from interface: Visualization
enters non-interactive mode.

In non-interactive mode processing speed is gained by not updating the visualization area constantly.

Non-interactive mode should be entered before doing heavy tasks like setting up the initial view.

No user interaction should be allowed during non-interactive mode.

Specified by:
enterNonInteractiveMode in interface Visualization

leaveNonInteractiveMode

public void leaveNonInteractiveMode()
Description copied from interface: Visualization
leaves non-interactive mode.
Specified by:
leaveNonInteractiveMode in interface Visualization

printCurrentView

public void printCurrentView()
Description copied from interface: Visualization
brings up a print dialog which user can use to send currently visible view to printer.
Specified by:
printCurrentView in interface Visualization