se.umu.cs.SequenceDiagramEditor
Class DrawingArea

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byse.umu.cs.SequenceDiagramEditor.DrawingArea
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class DrawingArea
extends javax.swing.JPanel
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.ActionListener

This class represents the drawingarea where all objects in a sequence diagram is drawn.

Author:
Matilda Östling
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  java.util.Vector actorsAndObjects
          The list with all classEntitys(actors and objects) in the drawingarea.
protected  bluej.extensions.BlueJ bluej
          The BlueJ object used when the editor is connected to a BlueJ-project
private  javax.swing.JButton classCancel
          Button when the user chose cancel instead of a new class
private  javax.swing.JDialog classDialog
          A dialog that let the user chose a new class
private  bluej.extensions.BClass[] classes
          All classes belonging to a given project
private  javax.swing.JComboBox classList
          A list of available classes to chose from
private  javax.swing.JButton classOk
          Button when the user chose a new class
private  Entity currentEntity
          The active entity in the drawingarea.
private  java.io.File currentFile
          The file for the current sequence diagram
private  CurrentState currentState
          The current state for the drawingarea.
static float[] dash1
          Used for a dashed line
static java.awt.BasicStroke dashed
          Used for a dashed line
private  java.util.Vector drawingObjects
          The list with all objects to draw in the drawingarea.
private  java.util.Vector lifelines
          The list with all lifelines in the drawingarea.
private  javax.swing.JDialog messageDialog
          A dialog that lets the user chose a method
private  javax.swing.JComboBox messageList
          A list of available methods
private  javax.swing.JButton messageOk
          Button when the user chose a new method
private  bluej.extensions.BMethod[] methods
          Contains all methods for a choosen object
private  long newtime
          The time for the second click, used to check doubleclicking
private  java.lang.String notes
          Contains the notes belonging to a sequence diagram
protected  int nrOfObjects
          The number of classEntitys(actor and objects) in the drawingarea.
private  long oldtime
          The time for the first click, used to check doubleclicking
private  SeqDiagramEditor seqDiagramEditor
          The Sequence Diagram Editor this drawingArea belongs to
private  java.util.Vector sequence
          The messages belonging to a sequence in a diagram
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
DrawingArea(bluej.extensions.BlueJ b, SeqDiagramEditor s)
          The constructor for the class, used when the editor is started from BlueJ.
DrawingArea(SeqDiagramEditor s)
          The constructor for the class.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          This method is called when an event takes place.
 void addClassEntity(Entity e)
          This method adds an object or an actor to the drawingarea.
 void addEntity(Entity e)
          This method adds an entity to the drawingarea.
 void addToSequence(Message newMessage, Message oldMessage)
          This method is called when the user has placed a new message between another message and its returnmessage.
 void arrangeReturnMessages()
          This method is used to arrange all return messages.
protected  void chooseMethod(Entity e)
          This methos is used when the editor is in "BlueJ"-mode.
private  void chooseNewObject(Entity e)
          This method is used when the editor is in "BlueJ"-mode.
 void clear()
          This method is called when the user wants to open a new sequence diagram.
 java.util.Vector getActorsAndObject()
          This method returns all actors and object in the drawing area.
 Entity getCurrentEntity()
          This method returns the CurrentEntity of the drawing area.
 java.io.File getCurrentFile()
          This method returns the currently open file in the drawingarea.
 CurrentState getCurrState()
          This method return the currentstate of the drawing area.
 java.util.Vector getDrawingObjects()
          This method returns all objects to draw in the drawing area.
 java.util.Vector getLifelines()
          This method returns all lifelines in the drawing area.
private  Message getMessage(org.w3c.dom.Element e)
          This method is used by the method readInMessage.
 java.lang.String getNoteFile()
          This method returns the notes belonging to the current sequence diagram.
 SeqDiagramEditor getSeqDiagramEditor()
          This method returns the object of the class SeqDiagramEditor.
 java.util.Vector getSequence()
          This method returns all messages in a sequence in the current sequence diagram.
 void hideReturnMessages()
          This method is used to remove all return messages from the drawingobjects.
 void mouseClicked(java.awt.event.MouseEvent e)
          This method is called when the mouse is clicked in the drawingarea.
 void mouseDragged(java.awt.event.MouseEvent e)
          This method is called when the mouse is dragged.
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
          This method is called when the mouse is moved in the drawingarea.
 void mousePressed(java.awt.event.MouseEvent e)
          This method is called when the mouse is pressed in the drawingarea.
 void mouseReleased(java.awt.event.MouseEvent e)
          This method is called when the mouse is released on the drawingarea.
 void openFromFile(java.io.File file)
          This method is called when the user wants to open a saved sequence diagram.
 void paintComponent(java.awt.Graphics g)
          This method draws all objects on the drawingarea by calling the draw-method for all objects.
private  void readInDestroySymbol(ClassEntity c, org.w3c.dom.Element d)
          This method is used by the readInObject method.
private  void readInLifeLine(ClassEntity c, org.w3c.dom.Element m)
          This method is used by the readInObject method to read in a lifeline for an object/actor.
private  void readInMessage(ClassEntity c, org.w3c.dom.Element m)
          This method is used by the readInObject method.
private  void readInObject(org.w3c.dom.Element object)
          This method is called to read in an actor or a sequenceobject from a file.
 org.w3c.dom.Document saveToFile(java.io.File file)
          This method is called when the editor tells the drawingarea that it should save itself to a file.
 void setCurrentFile(java.io.File f)
          This method sets the currently open file of the drawing area.
 void setNoteFile(java.lang.String n)
          This methods sets the notes belonging to the currently open sequence diagram.
 void showReturnMessages()
          This method is used to add all return messages to the drawingobjects.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getWidth, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

Field Detail

currentState

private CurrentState currentState
The current state for the drawingarea.


drawingObjects

private java.util.Vector drawingObjects
The list with all objects to draw in the drawingarea.


lifelines

private java.util.Vector lifelines
The list with all lifelines in the drawingarea.


actorsAndObjects

private java.util.Vector actorsAndObjects
The list with all classEntitys(actors and objects) in the drawingarea.


currentEntity

private Entity currentEntity
The active entity in the drawingarea.


nrOfObjects

protected int nrOfObjects
The number of classEntitys(actor and objects) in the drawingarea.


bluej

protected bluej.extensions.BlueJ bluej
The BlueJ object used when the editor is connected to a BlueJ-project


seqDiagramEditor

private SeqDiagramEditor seqDiagramEditor
The Sequence Diagram Editor this drawingArea belongs to


currentFile

private java.io.File currentFile
The file for the current sequence diagram


sequence

private java.util.Vector sequence
The messages belonging to a sequence in a diagram


dash1

public static final float[] dash1
Used for a dashed line


dashed

public static final java.awt.BasicStroke dashed
Used for a dashed line


messageDialog

private javax.swing.JDialog messageDialog
A dialog that lets the user chose a method


messageList

private javax.swing.JComboBox messageList
A list of available methods


messageOk

private javax.swing.JButton messageOk
Button when the user chose a new method


methods

private bluej.extensions.BMethod[] methods
Contains all methods for a choosen object


classDialog

private javax.swing.JDialog classDialog
A dialog that let the user chose a new class


classList

private javax.swing.JComboBox classList
A list of available classes to chose from


classOk

private javax.swing.JButton classOk
Button when the user chose a new class


classCancel

private javax.swing.JButton classCancel
Button when the user chose cancel instead of a new class


classes

private bluej.extensions.BClass[] classes
All classes belonging to a given project


notes

private java.lang.String notes
Contains the notes belonging to a sequence diagram


oldtime

private long oldtime
The time for the first click, used to check doubleclicking


newtime

private long newtime
The time for the second click, used to check doubleclicking

Constructor Detail

DrawingArea

public DrawingArea(SeqDiagramEditor s)
The constructor for the class.

Parameters:
s - The editor window that creates the drawingArea

DrawingArea

public DrawingArea(bluej.extensions.BlueJ b,
                   SeqDiagramEditor s)
The constructor for the class, used when the editor is started from BlueJ.

Parameters:
b - The BlueJ-object
s - The editor window that creates the drawingArea
Method Detail

addEntity

public void addEntity(Entity e)
This method adds an entity to the drawingarea.

Parameters:
e - The Entity to add

addClassEntity

public void addClassEntity(Entity e)
This method adds an object or an actor to the drawingarea.

Parameters:
e - The entity to add

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
This method is called when the mouse is clicked in the drawingarea. Depending on the currents state of the drawingarea the event is handled.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - The mouseEvent.

paintComponent

public void paintComponent(java.awt.Graphics g)
This method draws all objects on the drawingarea by calling the draw-method for all objects.

Parameters:
g - The graphics used for the drawing.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
This method is called when the mouse is dragged. Depending on the current state of the drawingarea the event is handled.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - The mouseEvent.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
This method is called when the mouse is moved in the drawingarea. Depending on the current state for the drawingarea the event is handled.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - The mouseEvent.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
This method is called when the mouse is pressed in the drawingarea. Depending on the current state of the drawingarea the event is handled.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - The mouseevent.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
This method is called when the mouse is released on the drawingarea. Depending on the current state of the drawingarea the event is handled.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - The mouseEvent.

saveToFile

public org.w3c.dom.Document saveToFile(java.io.File file)
                                throws java.io.FileNotFoundException
This method is called when the editor tells the drawingarea that it should save itself to a file.

Parameters:
file - The file where the sequence diagram should be saved.
Returns:
A reference to the document where the drawingarea is saved.
Throws:
java.io.FileNotFoundException

openFromFile

public void openFromFile(java.io.File file)
                  throws javax.xml.parsers.ParserConfigurationException
This method is called when the user wants to open a saved sequence diagram.

Parameters:
file - The file for the saved sequence diagram.
Throws:
javax.xml.parsers.ParserConfigurationException

readInObject

private void readInObject(org.w3c.dom.Element object)
This method is called to read in an actor or a sequenceobject from a file.

Parameters:
object - The actor/sequence-object to read in.

readInLifeLine

private void readInLifeLine(ClassEntity c,
                            org.w3c.dom.Element m)
This method is used by the readInObject method to read in a lifeline for an object/actor.

Parameters:
c - The ClassEntity for this lifeline
m - The lifeline

readInMessage

private void readInMessage(ClassEntity c,
                           org.w3c.dom.Element m)
This method is used by the readInObject method. It is called to read in a message belonging to the calling classEntity.

Parameters:
c - The startEntity or endEntity of this message.
m - The message.

getMessage

private Message getMessage(org.w3c.dom.Element e)
This method is used by the method readInMessage. It checks wether the message already excist or not.

Parameters:
e - The Message
Returns:
Returns the message if it already excists, otherwise it returns null

readInDestroySymbol

private void readInDestroySymbol(ClassEntity c,
                                 org.w3c.dom.Element d)
This method is used by the readInObject method. It is called to read in a destroysymbol belonging to the calling classEntity.

Parameters:
c - The ownerentity of this destroysymbol.
d - The destroysymbol.

clear

public void clear()
This method is called when the user wants to open a new sequence diagram. It clears all variables for the drawingarea and repaints it.


chooseMethod

protected void chooseMethod(Entity e)
This methos is used when the editor is in "BlueJ"-mode. It is used to let the user choose one of the possible methods for the choosen object. This method creates and shows a dialog where the user can choose a method.

Parameters:
e - The current entity of the drawingArea

chooseNewObject

private void chooseNewObject(Entity e)
This method is used when the editor is in "BlueJ"-mode. This method is used to let the user choose which object to create, from which class. This method creates and shows a dialog where the user can make his choice.

Parameters:
e - The current entity of the drawingArea.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
This method is called when an event takes place.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - The ActionEvent

showReturnMessages

public void showReturnMessages()
This method is used to add all return messages to the drawingobjects. It is called If the user wants to add return messages to the sequence diagram.


hideReturnMessages

public void hideReturnMessages()
This method is used to remove all return messages from the drawingobjects. It is called if the user choose to hide all return messages in the sequence diagram.


arrangeReturnMessages

public void arrangeReturnMessages()
This method is used to arrange all return messages. If the user choose to show return messages in the sequence diagram all messages have to be arranged in a correct way.


addToSequence

public void addToSequence(Message newMessage,
                          Message oldMessage)
This method is called when the user has placed a new message between another message and its returnmessage. Meaning that the new message should be added to the sequence.

Parameters:
newMessage - The message that should be added to the sequence
oldMessage - The message that is already in the sequence

getDrawingObjects

public java.util.Vector getDrawingObjects()
This method returns all objects to draw in the drawing area.

Returns:
All objects to draw

getLifelines

public java.util.Vector getLifelines()
This method returns all lifelines in the drawing area.

Returns:
All lifelines

getActorsAndObject

public java.util.Vector getActorsAndObject()
This method returns all actors and object in the drawing area.

Returns:
All actors and objects

getCurrState

public CurrentState getCurrState()
This method return the currentstate of the drawing area.

Returns:
The Currentstate

getCurrentFile

public java.io.File getCurrentFile()
This method returns the currently open file in the drawingarea.

Returns:
Returns the open file, otherwise null is returned.

setCurrentFile

public void setCurrentFile(java.io.File f)
This method sets the currently open file of the drawing area.

Parameters:
f - The file

getSeqDiagramEditor

public SeqDiagramEditor getSeqDiagramEditor()
This method returns the object of the class SeqDiagramEditor.

Returns:
The object of SeqDiagramEditor

getCurrentEntity

public Entity getCurrentEntity()
This method returns the CurrentEntity of the drawing area.

Returns:
The CurrentEntity

getNoteFile

public java.lang.String getNoteFile()
This method returns the notes belonging to the current sequence diagram.

Returns:
The string with the notes

setNoteFile

public void setNoteFile(java.lang.String n)
This methods sets the notes belonging to the currently open sequence diagram.

Parameters:
n - A string containing the notes

getSequence

public java.util.Vector getSequence()
This method returns all messages in a sequence in the current sequence diagram.

Returns:
The sequence

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener