Coverage Report - org.argouml.uml.cognitive.critics.ClOperationCompartment
 
Classes in this File Line Coverage Branch Coverage Complexity
ClOperationCompartment
0%
0/40
0%
0/18
3
 
 1  
 /* $Id: ClOperationCompartment.java 17849 2010-01-12 19:50:34Z linus $
 2  
  *****************************************************************************
 3  
  * Copyright (c) 2009 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  
  *    mvw
 11  
  *****************************************************************************
 12  
  *
 13  
  * Some portions of this file was previously release using the BSD License:
 14  
  */
 15  
 
 16  
 // Copyright (c) 1996-2009 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.cognitive.critics;
 40  
 
 41  
 import java.awt.Color;
 42  
 import java.awt.Component;
 43  
 import java.awt.Graphics;
 44  
 import java.awt.Rectangle;
 45  
 
 46  
 import org.argouml.cognitive.ToDoItem;
 47  
 import org.argouml.model.Model;
 48  
 import org.argouml.ui.Clarifier;
 49  
 import org.argouml.uml.diagram.ui.FigCompartment;
 50  
 import org.argouml.uml.diagram.ui.FigCompartmentBox;
 51  
 import org.tigris.gef.presentation.Fig;
 52  
 
 53  
 
 54  
 
 55  
 /**
 56  
  * The clarifier (red wavy line) for the operation compartment.
 57  
  *
 58  
  */
 59  0
 public class ClOperationCompartment implements Clarifier {
 60  0
     private static ClOperationCompartment theInstance =
 61  
         new ClOperationCompartment();
 62  
     private static final int WAVE_LENGTH = 4;
 63  
     private static final int WAVE_HEIGHT = 2;
 64  
 
 65  
     ////////////////////////////////////////////////////////////////
 66  
     // instance variables
 67  
     private Fig fig;
 68  
 
 69  
     /**
 70  
      * @return Returns the theInstance.
 71  
      */
 72  
     public static ClOperationCompartment getTheInstance() {
 73  0
         return theInstance;
 74  
     }
 75  
     
 76  
     /*
 77  
      * @see org.argouml.ui.Clarifier#setFig(org.tigris.gef.presentation.Fig)
 78  
      */
 79  0
     public void setFig(Fig f) { fig = f; }
 80  
 
 81  
     /*
 82  
      * @see org.argouml.ui.Clarifier#setToDoItem(org.argouml.cognitive.ToDoItem)
 83  
      */
 84  0
     public void setToDoItem(ToDoItem i) { }
 85  
 
 86  
     /*
 87  
      * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics,
 88  
      *      int, int)
 89  
      */
 90  
     public void paintIcon(Component c, Graphics g, int x, int y) {
 91  0
         if (fig instanceof FigCompartmentBox) {
 92  0
             final FigCompartment fc = ((FigCompartmentBox)
 93  
                     fig).getCompartment(Model.getMetaTypes().getOperation());
 94  0
             if (fc == null) return;
 95  
 
 96  
             // added by Eric Lefevre 13 Mar 1999: we must check if the
 97  
             // FigText for operations is drawn before drawing things
 98  
             // over it
 99  0
             if (!fc.isVisible()) {
 100  0
                 fig = null;
 101  0
                 return;
 102  
             }
 103  
 
 104  0
             Rectangle fr = fc.getBounds();
 105  0
             int left  = fr.x + 10;
 106  0
             int height = fr.y + fr.height - 7;
 107  0
             int right = fr.x + fr.width - 10;
 108  0
             g.setColor(Color.red);
 109  0
             int i = left;
 110  
             while (true) {
 111  0
                 g.drawLine(i, height, i + WAVE_LENGTH, height + WAVE_HEIGHT);
 112  0
                 i += WAVE_LENGTH;
 113  0
                 if (i >= right) break;
 114  0
                 g.drawLine(i, height + WAVE_HEIGHT, i + WAVE_LENGTH, height);
 115  0
                 i += WAVE_LENGTH;
 116  0
                 if (i >= right) break;
 117  0
                 g.drawLine(i, height, i + WAVE_LENGTH,
 118  
                            height + WAVE_HEIGHT / 2);
 119  0
                 i += WAVE_LENGTH;
 120  0
                 if (i >= right) break;
 121  0
                 g.drawLine(i, height + WAVE_HEIGHT / 2, i + WAVE_LENGTH,
 122  
                            height);
 123  0
                 i += WAVE_LENGTH;
 124  0
                 if (i >= right) break;
 125  
             }
 126  0
             fig = null;
 127  
         }
 128  0
     }
 129  
 
 130  
     /*
 131  
      * @see javax.swing.Icon#getIconWidth()
 132  
      */
 133  0
     public int getIconWidth() { return 0; }
 134  
 
 135  
     /*
 136  
      * @see javax.swing.Icon#getIconHeight()
 137  
      */
 138  0
     public int getIconHeight() { return 0; }
 139  
 
 140  
     /*
 141  
      * @see org.argouml.ui.Clarifier#hit(int, int)
 142  
      */
 143  
     public boolean hit(int x, int y) {
 144  0
         if (!(fig instanceof FigCompartmentBox)) return false;
 145  0
         FigCompartment compartment = ((FigCompartmentBox) fig)
 146  
             .getCompartment(Model.getMetaTypes().getOperation());
 147  0
         if (compartment == null) return false;
 148  0
         Rectangle fr = compartment.getBounds();
 149  0
         boolean res = fr.contains(x, y);
 150  0
         fig = null;
 151  0
         return res;
 152  
     }
 153  
 
 154  
 } /* end class ClOperationCompartment */
 155  
 
 156