ucot.ui.gui.dot
Class DotPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by ucot.ui.gui.dot.DotPanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.Observer, javax.accessibility.Accessible

public class DotPanel
extends javax.swing.JPanel
implements java.util.Observer

A dot panel class inherited from JPanel class which is used for drawing dot graphs from the given analyze model.

This class implements the Observer interface which allows this panel to keep track of the current status of analyze model. Panel automatically updates the graph when the model changes

DotPanel contains also a method highlight for highlighting any submodels from the given Analyzemodel.

Author:
ilanliuk, tujupien, vevijopi.
See Also:
AnalyzeModel, Serialized Form

Nested Class Summary
private  class DotPanel.DotJob
          This class is a container for a dot job which includes all required information for rendering both highlighted and regular dot graphs.
static class DotPanel.ExportImageType
          Imageformats that are usable when exporting graph as image.
private  class DotPanel.ExportJob
           Class for giving needed info for executeExport() method.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 DotColorTheme colorTheme
           
static DotPanel.ExportImageType DEFAULT_EXPORT_IMAGE_TYPE
           
private static java.util.Stack<DotPanel.DotJob> DOT_JOB_STACK
           
private static java.lang.Thread EXECUTING_DOT_THREAD
           
private static java.lang.Thread EXECUTING_EXPORT_THREAD
           
private static java.util.Stack<DotPanel.ExportJob> EXPORT_JOB_STACK
           
protected  int fontSize
           
private  boolean horizontalLayout
           
private  boolean isUpdating
           
private  java.util.logging.Logger logger
           
private  java.awt.image.BufferedImage modelImage
           
protected  GraphicalUI owner
           
static int SCROLL_SPEED
           
static long serialVersionUID
           
private static boolean THREAD_RUNNING
           
protected  long timeElapsed
           
protected  javax.swing.JLabel timerComponent
           
 
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
DotPanel(GraphicalUI owner)
           Constructor for DotPanel.
 
Method Summary
private  void convertEPSToPDF(java.io.File epsImage, java.io.File target)
           Converts eps file to pdf using epstopdf program.
private  java.io.File createDotFile(DotPanel.DotJob job)
           Writes the analyze model to an external file in dot syntax.
private  void executeDot()
           This method should be executed in its own thread.
private  void executeExport()
           This method should be used inside a new thread.
 void exportImage(java.io.File target)
           Saves current image to given file in format that is tried to guess from filename.
 void exportImage(java.io.File target, DotPanel.ExportImageType imageType)
           This method starts a new thread for export actions if one has not been started yet.
protected  void finalize()
           This finalize method makes sure the thread running for panel update shuts down.
 boolean getHorizontalLayout()
           Returns the current value of horizontal layouting.
 void highlight(AnalyzeModel highlight)
           Method for highlighting submodels from the analyze model.
 void highlight(AnalyzeModel highlight, boolean drawNewElements)
           Method for highlighting submodels from the analyze model.
private  void mapCurrentModel(DotPanel.DotJob job)
           Method for mapping the current analyze model.
private  void mapHighlightRequest(DotPanel.DotJob job, boolean drawNewElements)
           Method for mapping the submodel for highlight request.
 void paintComponent(java.awt.Graphics g)
           This method draws the graph generated by dot to the panel's canvas.
private  java.io.File runDot(java.io.File dotInputFile)
           Overloaded runDot method.
private  java.io.File runDot(java.io.File dotInputFile, java.io.File outputFile, java.lang.String args)
           This method runs the dot executable with the given dot input file and returns the location of the image file.
private  java.io.File runDot(java.io.File dotInputFile, java.lang.String args)
           Overloaded runDot method which uses the default temporary output file as a target for the file.
private  void saveExport(java.io.File target, DotPanel.ExportImageType imageType)
           This method generates a new graph from the analyze model and exports it to the given target file in a format specified by imageType.
private  void saveImage(java.awt.image.BufferedImage graph, java.io.File target, DotPanel.ExportImageType imageType)
           This method writes the graph given as a buffered image to the given file in the format specified by imageType.
 void setHorizontalLayout(boolean horizontalLayout)
           Sets wether or not the dot should use the horizontal layout for the entities and their relationships.
 void setTimerComponent(javax.swing.JLabel timerComponent)
          JLabel where the updation time of this DotPanel is drawn.
 void update(java.util.Observable observableObject, java.lang.Object updationArg)
           
 void updateModel(AnalyzeModel analyzeModel)
           Method for updating the analyze model.
private  void updateModel(DotPanel.DotJob job)
           Method for updating the model.
private  void writeEntities(DotPanel.DotJob job, java.io.BufferedWriter writer)
           Method for writing all entities to the dot file with all their attribute, method and parent relationships.
private  void writeEntityAttributes(DotPanel.DotJob job, java.io.BufferedWriter writer, java.lang.String entity)
           Method for writing the attributes of one entity to the dot file.
private  void writeEntityMethods(DotPanel.DotJob job, java.io.BufferedWriter writer, java.lang.String entity)
           Method for writing the methods of one entity to the dot file.
private  void writeEntityParents(DotPanel.DotJob job, java.io.BufferedWriter writer, java.lang.String entity)
           Method for writing the parents of one entity to the dot file.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getWidth, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, 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
 
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, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

THREAD_RUNNING

private static boolean THREAD_RUNNING

DOT_JOB_STACK

private static java.util.Stack<DotPanel.DotJob> DOT_JOB_STACK

EXECUTING_DOT_THREAD

private static java.lang.Thread EXECUTING_DOT_THREAD

EXPORT_JOB_STACK

private static java.util.Stack<DotPanel.ExportJob> EXPORT_JOB_STACK

EXECUTING_EXPORT_THREAD

private static java.lang.Thread EXECUTING_EXPORT_THREAD

logger

private java.util.logging.Logger logger

DEFAULT_EXPORT_IMAGE_TYPE

public static final DotPanel.ExportImageType DEFAULT_EXPORT_IMAGE_TYPE

timeElapsed

protected long timeElapsed

timerComponent

protected javax.swing.JLabel timerComponent

fontSize

protected int fontSize

colorTheme

public DotColorTheme colorTheme

SCROLL_SPEED

public static final int SCROLL_SPEED
See Also:
Constant Field Values

modelImage

private java.awt.image.BufferedImage modelImage

owner

protected GraphicalUI owner

horizontalLayout

private boolean horizontalLayout

isUpdating

private boolean isUpdating
Constructor Detail

DotPanel

public DotPanel(GraphicalUI owner)

Constructor for DotPanel. This constructor adds an observer to the analyze model and sets its own status to updating.

TODO fix this param, it was analyzeModel before

Parameters:
owner - AnalyzeModel which this DotPanel should draw.
Method Detail

setHorizontalLayout

public void setHorizontalLayout(boolean horizontalLayout)

Sets wether or not the dot should use the horizontal layout for the entities and their relationships.

Parameters:
horizontalLayout - New value for horizontal layout, true means yay for horizontal layouting.

getHorizontalLayout

public boolean getHorizontalLayout()

Returns the current value of horizontal layouting.

Returns:
Boolean true if horizontal layout is in use, else false.

update

public void update(java.util.Observable observableObject,
                   java.lang.Object updationArg)
Specified by:
update in interface java.util.Observer

saveImage

private void saveImage(java.awt.image.BufferedImage graph,
                       java.io.File target,
                       DotPanel.ExportImageType imageType)
                throws java.io.IOException

This method writes the graph given as a buffered image to the given file in the format specified by imageType.

Parameters:
graph - Graph as BufferedImage to be written.
target - File where the graph should be saved.
imageType - File format to use when saving as ExportImageType.
Throws:
java.io.IOException - If something goes wrong with the writing.

saveExport

private void saveExport(java.io.File target,
                        DotPanel.ExportImageType imageType)
                 throws java.io.IOException

This method generates a new graph from the analyze model and exports it to the given target file in a format specified by imageType.

Parameters:
target - File where the graph should be saved.
imageType - File format to use when saving as ExportImageType.
Throws:
java.io.IOException - If something goes wrong with the writing.

executeExport

private void executeExport()

This method should be used inside a new thread. Once started, this method will keep on running until the DotPanel gets finalized and while running, this method will perform all graph exporting scheduled for DotPanel.


exportImage

public void exportImage(java.io.File target,
                        DotPanel.ExportImageType imageType)

This method starts a new thread for export actions if one has not been started yet. In each case a new export job is pushed to the top of the export job stack and the thread is notified about this action, which wakes the thread and it will start doing the topmost job from the stack when it wakes up.

Parameters:
target - File where the image should be saved.
imageType - Format for the image to be saved as ExportImageType.

exportImage

public void exportImage(java.io.File target)

Saves current image to given file in format that is tried to guess from filename.

Parameters:
target - File pointing the saving destination.

convertEPSToPDF

private void convertEPSToPDF(java.io.File epsImage,
                             java.io.File target)
                      throws java.io.IOException

Converts eps file to pdf using epstopdf program.

Parameters:
epsImage - File pointing eps file to convert.
target - File where the converted pdf file should be saved.
Throws:
java.io.IOException - if something went wrong when accessing the files.

runDot

private java.io.File runDot(java.io.File dotInputFile,
                            java.io.File outputFile,
                            java.lang.String args)

This method runs the dot executable with the given dot input file and returns the location of the image file.

Parameters:
dotInputFile - File which should be executed with Dot.
outputFile - Path to the output file.
args - Command line arguments for dot.
Returns:
File where the image is located. Null is returned if something went wrog.

runDot

private java.io.File runDot(java.io.File dotInputFile,
                            java.lang.String args)

Overloaded runDot method which uses the default temporary output file as a target for the file.

Parameters:
dotInputFile - File which should be executed with Dot.
args - Command line arguments for dot.
Returns:
File where the image is located. Null is returned if something went wrog.
See Also:
runDot(File, File, String)

runDot

private java.io.File runDot(java.io.File dotInputFile)

Overloaded runDot method. This will create the dot graph with default settings (PNG image with the paths defined in settings XML).

Parameters:
dotInputFile - File which should be executed with Dot.
Returns:
File where the image is located. Null is returned if something went wrog.
See Also:
runDot(File, String)

writeEntityMethods

private void writeEntityMethods(DotPanel.DotJob job,
                                java.io.BufferedWriter writer,
                                java.lang.String entity)
                         throws java.io.IOException

Method for writing the methods of one entity to the dot file.

Parameters:
job - DotJob that contains the AnalyzeModel where the entity we are accessing is located.
writer - BufferedWriter to use for writing.
entity - Name of the entity which methods are being written.
Throws:
java.io.IOException - If something goes wrong when accessing the file.

writeEntityAttributes

private void writeEntityAttributes(DotPanel.DotJob job,
                                   java.io.BufferedWriter writer,
                                   java.lang.String entity)
                            throws java.io.IOException

Method for writing the attributes of one entity to the dot file. Method also highlights the attribute relation if it's needed.

Parameters:
job - DotJob that contains the AnalyzeModel where the entity which attributes we are accessing is located.
writer - BufferedWriter to use for writing.
entity - Name of the entity whose attributes are being written.
Throws:
java.io.IOException - If something goes wrong when accessing the file.

writeEntityParents

private void writeEntityParents(DotPanel.DotJob job,
                                java.io.BufferedWriter writer,
                                java.lang.String entity)
                         throws java.io.IOException

Method for writing the parents of one entity to the dot file. Method also highlights the parent-child relation if it's needed.

Parameters:
job - DotJob that contains the AnalyzeModel where the entity which parents we are accessing is located.
writer - BufferedWriter to use for writing.
entity - Name of the entity whose parents are being written.
Throws:
java.io.IOException - If something goes wrong when accessing the file.

writeEntities

private void writeEntities(DotPanel.DotJob job,
                           java.io.BufferedWriter writer)
                    throws java.io.IOException

Method for writing all entities to the dot file with all their attribute, method and parent relationships.

Parameters:
job - DotJob that contains the AnalyzeModel where are the entities we need to write.
writer - BufferedWriter to use for writing.
Throws:
IOExceptionis - thrown if something goes wrong when accessing the file.
java.io.IOException

createDotFile

private java.io.File createDotFile(DotPanel.DotJob job)

Writes the analyze model to an external file in dot syntax.

Parameters:
job - DotJob that contains the AnalyzeModel we need to write.
Returns:
File containing the analyze model in dot language. Null is returned if something went wrong.

mapCurrentModel

private void mapCurrentModel(DotPanel.DotJob job)

Method for mapping the current analyze model. This is required to figure out differences with the submodel that needs to be highlighted.

Parameters:
job - DotJob where mapping will be done.

mapHighlightRequest

private void mapHighlightRequest(DotPanel.DotJob job,
                                 boolean drawNewElements)

Method for mapping the submodel for highlight request.

Parameters:
job - DotJob to be handled.
drawNewElements - Indicates wether or not the new elements are supposed to be drawn in the highlighted model. New elements are those that exist in the highlight request but do not exist in the current analyze model.

highlight

public void highlight(AnalyzeModel highlight,
                      boolean drawNewElements)

Method for highlighting submodels from the analyze model.

Parameters:
highlight - The submodel to be highlighted. If this argument is null, then all applied highlights are removed.
drawNewElements - Indicates wether or not those elements which do not exist in the current analyze model should be also drawn and highlighted.

highlight

public void highlight(AnalyzeModel highlight)

Method for highlighting submodels from the analyze model. As default we assume that new entities don't need to be drawn.

Parameters:
highlight - Submodel to be highlighted.

updateModel

private void updateModel(DotPanel.DotJob job)

Method for updating the model. This method pushes the given dot job to the top of the dot job stack and notifies the running thread about it. If no updation thread is running yet, one is created.

Parameters:
job - DotJob to be run next.

updateModel

public void updateModel(AnalyzeModel analyzeModel)

Method for updating the analyze model.

Parameters:
analyzeModel - New AnalyzeModel.

finalize

protected void finalize()
                 throws java.lang.Throwable

This finalize method makes sure the thread running for panel update shuts down.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

paintComponent

public void paintComponent(java.awt.Graphics g)

This method draws the graph generated by dot to the panel's canvas.

Overrides:
paintComponent in class javax.swing.JComponent

executeDot

private void executeDot()

This method should be executed in its own thread. This thread keeps running until threadRunning class variable is set to false.

It takes the latest job from the dot job stack and disposes all the other jobs in the stack at the same time. The newest job is then modeled and drawn to the canvas. After that the thread sleeps until waken again by notification [executing.notify()].


setTimerComponent

public void setTimerComponent(javax.swing.JLabel timerComponent)
JLabel where the updation time of this DotPanel is drawn.

Parameters:
timerComponent - JLabel on which you need to get the updation time to.