Coverage Report - org.argouml.uml.diagram.static_structure.ui.ClassDiagramRenderer
 
Classes in this File Line Coverage Branch Coverage Complexity
ClassDiagramRenderer
8%
2/25
0%
0/18
6.5
 
 1  
 /* $Id: ClassDiagramRenderer.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.static_structure.ui;
 40  
 
 41  
 import java.util.Map;
 42  
 
 43  
 import org.apache.log4j.Logger;
 44  
 import org.argouml.uml.diagram.GraphChangeAdapter;
 45  
 import org.argouml.uml.diagram.UmlDiagramRenderer;
 46  
 import org.argouml.uml.diagram.ui.FigNodeModelElement;
 47  
 import org.argouml.uml.diagram.ui.UMLDiagram;
 48  
 import org.tigris.gef.base.Diagram;
 49  
 import org.tigris.gef.base.Layer;
 50  
 import org.tigris.gef.base.LayerPerspective;
 51  
 import org.tigris.gef.graph.GraphModel;
 52  
 import org.tigris.gef.presentation.FigEdge;
 53  
 import org.tigris.gef.presentation.FigNode;
 54  
 
 55  
 /**
 56  
  * This class defines a renderer object for UML Class Diagrams. In a
 57  
  * Class Diagram the following UML objects are displayed with the
 58  
  * following Figs: <p>
 59  
  *
 60  
  * <pre>
 61  
  *  UML Object       ---  Fig
 62  
  *  ---------------------------------------
 63  
  *  Class            ---  FigClass
 64  
  *  Interface        ---  FigInterface
 65  
  *  Instance         ---  FigInstance
 66  
  *  Model            ---  FigModel
 67  
  *  Subsystem        ---  FigSubsystem
 68  
  *  Package          ---  FigPackage
 69  
  *  Comment          ---  FigComment
 70  
  *  (CommentEdge)    ---  FigEdgeNote
 71  
  *  Generalization   ---  FigGeneralization
 72  
  *  Realization      ---  FigRealization
 73  
  *  Permission       ---  FigPermission
 74  
  *  Usage            ---  FigUsage
 75  
  *  Dependency       ---  FigDependency
 76  
  *  Association      ---  FigAssociation
 77  
  *  AssociationClass ---  FigAssociationClass
 78  
  *  Dependency       ---  FigDependency
 79  
  *  Link             ---  FigLink
 80  
  *  DataType         ---  FigDataType
 81  
  *  Stereotype       ---  FigStereotypeDeclaration
 82  
  * </pre>
 83  
  *
 84  
  * @author jrobbins
 85  
  */
 86  1928
 public class ClassDiagramRenderer extends UmlDiagramRenderer {
 87  
     
 88  
     /**
 89  
      * The UID.
 90  
      */
 91  
     static final long serialVersionUID = 675407719309039112L;
 92  
 
 93  
     /**
 94  
      * Logger.
 95  
      */
 96  900
     private static final Logger LOG =
 97  
         Logger.getLogger(ClassDiagramRenderer.class);
 98  
 
 99  
     /*
 100  
      * @see org.tigris.gef.graph.GraphNodeRenderer#getFigNodeFor(
 101  
      *         org.tigris.gef.graph.GraphModel,
 102  
      *         org.tigris.gef.base.Layer, java.lang.Object, java.util.Map)
 103  
      */
 104  
     public FigNode getFigNodeFor(GraphModel gm, Layer lay,
 105  
                                  Object node, Map styleAttributes) {
 106  
 
 107  0
         FigNodeModelElement figNode = null;
 108  
 
 109  0
         if (node == null) {
 110  0
             throw new IllegalArgumentException("A node must be supplied");
 111  
         }
 112  
         // Although not generally true for GEF, for Argo we know that the layer
 113  
         // is a LayerPerspective which knows the associated diagram
 114  0
         Diagram diag = ((LayerPerspective) lay).getDiagram(); 
 115  0
         if (diag instanceof UMLDiagram
 116  
                 && ((UMLDiagram) diag).doesAccept(node)) {
 117  0
             figNode = (FigNodeModelElement) ((UMLDiagram) diag)
 118  
                     .drop(node, null);
 119  
         } else {
 120  0
             LOG.error("TODO: ClassDiagramRenderer getFigNodeFor " + node);
 121  0
             throw new IllegalArgumentException(
 122  
                     "Node is not a recognised type. Received "
 123  
                     + node.getClass().getName());
 124  
         }
 125  
 
 126  0
         lay.add(figNode);
 127  0
         figNode.setDiElement(
 128  
                 GraphChangeAdapter.getInstance().createElement(gm, node));
 129  
 
 130  
 
 131  0
         return figNode;
 132  
 
 133  
     }
 134  
 
 135  
     /**
 136  
      * Return a Fig that can be used to represent the given edge.
 137  
      * Throws IllegalArgumentException if the edge is not of an expected type.
 138  
      * Throws IllegalStateException if the edge generated has no source
 139  
      *                               or dest port.
 140  
      * {@inheritDoc}
 141  
      */
 142  
     public FigEdge getFigEdgeFor(GraphModel gm, Layer lay,
 143  
                                  Object edge, Map styleAttribute) {
 144  0
         if (LOG.isDebugEnabled()) {
 145  0
             LOG.debug("making figedge for " + edge);
 146  
         }
 147  0
         if (edge == null) {
 148  0
             throw new IllegalArgumentException("A model edge must be supplied");
 149  
         }
 150  
         
 151  0
         assert lay instanceof LayerPerspective;
 152  
         
 153  
         final FigEdge newEdge;
 154  
 
 155  
         // Although not generally true for GEF, for Argo we know that the layer
 156  
         // is a LayerPerspective which knows the associated diagram
 157  0
         Diagram diag = ((LayerPerspective) lay).getDiagram(); 
 158  0
         if (diag instanceof UMLDiagram
 159  
                 && ((UMLDiagram) diag).doesAccept(edge)) {
 160  0
             newEdge = (FigEdge) ((UMLDiagram) diag)
 161  
                     .drop(edge, null);
 162  
         } else {
 163  0
             LOG.error("TODO: ClassDiagramRenderer getFigEdgeFor " + edge);
 164  0
             throw new IllegalArgumentException(
 165  
                     "Edge is not a recognised type. Received "
 166  
                     + edge.getClass().getName());
 167  
         }
 168  
 
 169  0
         addEdge(lay, newEdge, edge);
 170  0
         return newEdge;
 171  
     }
 172  
 }