kaapo.project.graphics
Class DCGraphics
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
kaapo.project.graphics.DCGraphics
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, Observer
- Direct Known Subclasses:
- ActorGraphics, ConnectionGraphics, DataBaseGraphics, SolidGraphics
public abstract class DCGraphics
- extends JComponent
- implements Observer
Graphical representation of an element or connection.
The DCGraphics instance can be added to a Swing container or drawn to
a Graphics context.
The constructor receives a ProjectManager instance as parameter.
If DCGraphics modifies the component, e.g. sets element attributes,
it is important to run the changes through ProjectManager with a
Edit; don't set attributes directly. Directly modifying the
diagram component would bypass the undo system.
- See Also:
- Serialized Form
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, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getWidth, getVisibleRect, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, 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 |
dc
protected DiagramComponent dc
dcw
protected DiagramComponentWrapper dcw
pm
protected transient ProjectManager pm
DCGraphics
public DCGraphics(DiagramComponent dc,
DiagramComponentWrapper dcw,
ProjectManager pm)
getDiagramComponent
public DiagramComponent getDiagramComponent()
- Returns the diagram component associated to this DCGraphics
instance.
getDiagramComponentWrapper
public DiagramComponentWrapper getDiagramComponentWrapper()
- Returns the diagram component wrapper associated to this DCGraphics
instance.
getProjectManager
protected ProjectManager getProjectManager()
- Returns the Project Manager that is bound to this
DCGraphics instance.
getOuterBoundary
public abstract Shape getOuterBoundary()
- Returns the outer boundary (shape) of graphical representation of the
element. The boundary can be used for checking whether a mouse click
is inside the element.
The shape closely follows the borders of the element: for a circular
element, the shape is circular as well. If an enclosing rectangle
is needed, it can be obtained from the Shape instance with
Shape.getBounds2D().
For connection types, the outer boundary should be larger than the
actual connection line, since it is hard to select a 1 pixel wide
line with the mouse.
- Returns:
- area around the DiagramComponent.
getConnectionBoundary
public Shape getConnectionBoundary()
- Returns the boundary where connection points may be attached. For
solid-shape elements, this is usually the shape itself.
For other shapes, an appropriate boundary must be created.
The default implementation simply call getOuterBoundary and
this should be fine for rectangular elements. If
you need to fine-tune the boundary, override this method.
- Returns:
- boundaries for connecting
updateDCGraphics
public abstract void updateDCGraphics()
- Update the graphical appearance after element properties
have been changed. This method is called when other parties
have modified the diagram component. Example: the element
is present in several diagrams (and thus has several
DiagramComponentWrapper's) and a global attribute of the
element is modiefied in another diagram. Then, update()
must be called for all DCGraphics instances for the element.
updateDCGraphicsLater
public void updateDCGraphicsLater()
- Schedule updateDCGraphics() into Swing event queue.
Use this method instead of updateDCGraphics if you
modify Swing components from a non-Swing thread.
update
public void update(Observable subject,
Object message)
- Description copied from interface:
Observer
- This method is called whenever the observed object is changed. An
application calls an Observable object's
notifyObservers method to have all the object's observers
notified of the change.
It's safe to modify the subject's observer list from update
method. It won't affect the current notify round though, but the next.
- Specified by:
update
in interface Observer
- Parameters:
subject
- the subject that fires the updatemessage
- the message delivered to observer
getHotSpots
public List<HotSpot> getHotSpots()
- Returns a list of hotspots for this component.
Elements have hotspots for resizing the element,
connections have hotspots for moving the connection
points.
- See Also:
HotSpot
calcConnectionIntersectPoint
public Point2D calcConnectionIntersectPoint(Point2D startPoint,
Point2D endPoint)
- Calculates the intersection point between a line
and the connection boundary.
The default implementation of this method works
for solid, convex elements (such as rectangles
and ellipses). It doesn't work for connections
or non-convex elements. Run time complexity is O(log n),
where n is the length of the line. The precision
is about 1..2 pixels.
On implementation: the algorithm is a
modification of the binary search algorithm.
We keep the low and high points and check
if the center point is inside the element.
We halve the segment on each step. Usually,
the algorithm finishes in 6..8 steps. There
is a call to Shape.contains in each step.
This method should be fast enough for real-time
calculation, but if more speed is required,
subclasses can override this method with their
own implementation.
- Parameters:
startPoint
- Start point of the line. This
must be inside the element.endPoint
- End point of the line. This must
be outside the element.
- Returns:
- Intersection point that is on the connection
boundary, or null if the intersection point can't be
calculated.
removeObserver
public void removeObserver()
- Description copied from interface:
Observer
- This method should be called before disposing an observer. The
implementation should take care to save reference to observable so that
it can remove itself from observables observer list whern asked.
The reason for this is that the observer will remain in memory as long
as there is references to it in it's observables' observer list.
Observer will also receive updates until it's removed from all lists.
- Specified by:
removeObserver
in interface Observer