| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| StateDiagramRenderer |
|
| 3.5;3.5 |
| 1 | /* $Id: StateDiagramRenderer.java 18729 2010-09-10 16:10:34Z bobtarling $ | |
| 2 | ***************************************************************************** | |
| 3 | * Copyright (c) 2009-2010 Contributors - see below | |
| 4 | * All rights reserved. This program and the accompanying materials | |
| 5 | * are made available under the terms of the Eclipse Public License v1.0 | |
| 6 | * which accompanies this distribution, and is available at | |
| 7 | * http://www.eclipse.org/legal/epl-v10.html | |
| 8 | * | |
| 9 | * Contributors: | |
| 10 | * Bob Tarling | |
| 11 | ***************************************************************************** | |
| 12 | * | |
| 13 | * Some portions of this file was previously release using the BSD License: | |
| 14 | */ | |
| 15 | ||
| 16 | // Copyright (c) 1996-2008 The Regents of the University of California. All | |
| 17 | // Rights Reserved. Permission to use, copy, modify, and distribute this | |
| 18 | // software and its documentation without fee, and without a written | |
| 19 | // agreement is hereby granted, provided that the above copyright notice | |
| 20 | // and this paragraph appear in all copies. This software program and | |
| 21 | // documentation are copyrighted by The Regents of the University of | |
| 22 | // California. The software program and documentation are supplied "AS | |
| 23 | // IS", without any accompanying services from The Regents. The Regents | |
| 24 | // does not warrant that the operation of the program will be | |
| 25 | // uninterrupted or error-free. The end-user understands that the program | |
| 26 | // was developed for research purposes and is advised not to rely | |
| 27 | // exclusively on the program for any reason. IN NO EVENT SHALL THE | |
| 28 | // UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, | |
| 29 | // SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, | |
| 30 | // ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF | |
| 31 | // THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF | |
| 32 | // SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY | |
| 33 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
| 34 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE | |
| 35 | // PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF | |
| 36 | // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, | |
| 37 | // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | |
| 38 | ||
| 39 | package org.argouml.uml.diagram.state.ui; | |
| 40 | ||
| 41 | import java.util.Map; | |
| 42 | ||
| 43 | import org.apache.log4j.Logger; | |
| 44 | import org.argouml.model.Model; | |
| 45 | import org.argouml.uml.CommentEdge; | |
| 46 | import org.argouml.uml.diagram.ArgoDiagram; | |
| 47 | import org.argouml.uml.diagram.DiagramSettings; | |
| 48 | import org.argouml.uml.diagram.UmlDiagramRenderer; | |
| 49 | import org.argouml.uml.diagram.static_structure.ui.FigEdgeNote; | |
| 50 | import org.argouml.uml.diagram.ui.UMLDiagram; | |
| 51 | import org.tigris.gef.base.Diagram; | |
| 52 | import org.tigris.gef.base.Layer; | |
| 53 | import org.tigris.gef.base.LayerPerspective; | |
| 54 | import org.tigris.gef.graph.GraphModel; | |
| 55 | import org.tigris.gef.presentation.FigEdge; | |
| 56 | import org.tigris.gef.presentation.FigNode; | |
| 57 | ||
| 58 | /** | |
| 59 | * This class defines a renderer object for UML Statechart Diagrams. In a | |
| 60 | * Statechart Diagram the following UML objects are displayed with the | |
| 61 | * following Figs: <p> | |
| 62 | * <pre> | |
| 63 | * UML Object --- Fig | |
| 64 | * --------------------------------------- | |
| 65 | * State --- FigSimpleState | |
| 66 | * CompositeState --- FigCompositeState | |
| 67 | * ActionState --- FigActionState | |
| 68 | * FinalState --- FigFinalState | |
| 69 | * Pseudostate --- FigPseudostate | |
| 70 | * Inititial --- FigInitialState | |
| 71 | * Branch (Choice) --- FigBranchState | |
| 72 | * Junction --- FigJunctionState | |
| 73 | * Fork --- FigForkState | |
| 74 | * Join --- FigJoinState | |
| 75 | * DeepHistory --- FigDeepHistoryState | |
| 76 | * ShallowHistory --- FigShallowistoryState | |
| 77 | * SynchState --- FigSynchState | |
| 78 | * Transition --- FigTransition | |
| 79 | * more... | |
| 80 | * </pre> | |
| 81 | * | |
| 82 | * @author ics125b spring 1998 | |
| 83 | */ | |
| 84 | 114 | public class StateDiagramRenderer extends UmlDiagramRenderer { |
| 85 | ||
| 86 | 56 | private static final Logger LOG = |
| 87 | Logger.getLogger(StateDiagramRenderer.class); | |
| 88 | ||
| 89 | /* | |
| 90 | * @see org.tigris.gef.graph.GraphNodeRenderer#getFigNodeFor( | |
| 91 | * org.tigris.gef.graph.GraphModel, org.tigris.gef.base.Layer, | |
| 92 | * java.lang.Object, java.util.Map) | |
| 93 | */ | |
| 94 | public FigNode getFigNodeFor(GraphModel gm, Layer lay, Object node, | |
| 95 | Map styleAttributes) { | |
| 96 | ||
| 97 | 0 | assert node != null; |
| 98 | ||
| 99 | 0 | FigNode figNode = null; |
| 100 | // Although not generally true for GEF, for Argo we know that the layer | |
| 101 | // is a LayerPerspective which knows the associated diagram | |
| 102 | 0 | Diagram diag = ((LayerPerspective) lay).getDiagram(); |
| 103 | 0 | if (diag instanceof UMLDiagram |
| 104 | && ((UMLDiagram) diag).doesAccept(node)) { | |
| 105 | 0 | figNode = (FigNode) ((UMLDiagram) diag).drop(node, null); |
| 106 | } else { | |
| 107 | 0 | LOG.debug("TODO: StateDiagramRenderer getFigNodeFor"); |
| 108 | 0 | throw new IllegalArgumentException( |
| 109 | "Node is not a recognised type. Received " | |
| 110 | + node.getClass().getName()); | |
| 111 | } | |
| 112 | ||
| 113 | 0 | lay.add(figNode); |
| 114 | 0 | return figNode; |
| 115 | } | |
| 116 | ||
| 117 | /* | |
| 118 | * @see org.tigris.gef.graph.GraphEdgeRenderer#getFigEdgeFor( | |
| 119 | * org.tigris.gef.graph.GraphModel, org.tigris.gef.base.Layer, | |
| 120 | * java.lang.Object, java.util.Map) | |
| 121 | */ | |
| 122 | public FigEdge getFigEdgeFor(GraphModel gm, Layer lay, Object edge, | |
| 123 | Map styleAttributes) { | |
| 124 | 0 | assert edge != null; |
| 125 | 0 | assert lay instanceof LayerPerspective; |
| 126 | ||
| 127 | 0 | ArgoDiagram diag = (ArgoDiagram) ((LayerPerspective) lay).getDiagram(); |
| 128 | 0 | DiagramSettings settings = diag.getDiagramSettings(); |
| 129 | 0 | FigEdge newEdge = null; |
| 130 | ||
| 131 | 0 | if (Model.getFacade().isATransition(edge)) { |
| 132 | 0 | newEdge = new FigTransition(edge, settings); |
| 133 | 0 | } else if (edge instanceof CommentEdge) { |
| 134 | 0 | newEdge = new FigEdgeNote(edge, settings); // TODO -> settings |
| 135 | } | |
| 136 | 0 | addEdge(lay, newEdge, edge); |
| 137 | 0 | return newEdge; |
| 138 | } | |
| 139 | ||
| 140 | } |