Clover coverage report - Maven Clover report
Coverage timestamp: Thu Oct 11 2007 08:41:48 CEST
file stats: LOC: 125   Methods: 11
NCLOC: 93   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Item.java 85.7% 100% 100% 96.4%
coverage coverage
 1    /*
 2    * Copyright (C) 2007 Eric MIGNOT - mignots.eric@free.fr
 3    *
 4    * This library is free software; you can redistribute it and/or
 5    * modify it under the terms of the GNU Lesser General Public
 6    * License as published by the Free Software Foundation; either
 7    * version 2.1 of the License, or (at your option) any later version.
 8    *
 9    * This library is distributed in the hope that it will be useful,
 10    * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 12    * Lesser General Public License for more details.
 13    *
 14    * You should have received a copy of the GNU Lesser General Public
 15    * License along with this library; if not, write to the Free Software
 16    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 17    */
 18    package org.ericmignot.modeler.gui.workarea;
 19   
 20    import java.awt.Dimension;
 21    import java.awt.Point;
 22   
 23    import javax.swing.JPanel;
 24   
 25    import org.ericmignot.modeler.data.BusinessObject;
 26    import org.ericmignot.modeler.data.BusinessObjectListener;
 27    import org.ericmignot.modeler.gui.layout.Zoomable;
 28   
 29   
 30    public abstract class Item extends JPanel implements Zoomable, BusinessObjectListener
 31    {
 32    private Class expectedBusinessObjectClass;
 33    private BusinessObject businessObject;
 34    private WorkArea workArea;
 35   
 36  362 protected Item()
 37    {
 38  362 this.setExpectedBusinessObjectClass (BusinessObject.class);
 39  362 this.businessObject = null;
 40    }
 41   
 42  5852 public BusinessObject getBusinessObject()
 43    {
 44  5852 return businessObject;
 45    }
 46   
 47  725 public Class getExpectedBusinessObjectClass()
 48    {
 49  725 return this.expectedBusinessObjectClass;
 50    }
 51  366 public void setExpectedBusinessObjectClass(Class aClass)
 52    {
 53  366 if (this.businessObject != null && aClass!=null)
 54    {
 55  3 if (! (aClass.isAssignableFrom(this.businessObject.getClass())))
 56    {
 57  1 throw new IllegalArgumentException();
 58    }
 59    }
 60  365 this.expectedBusinessObjectClass = aClass;
 61    }
 62   
 63  361 protected void checkSetBusinessObjectAllowed(BusinessObject businessObject)
 64    {
 65  361 if (businessObject != null && this.getExpectedBusinessObjectClass()!=null)
 66    {
 67  361 if (! (this.getExpectedBusinessObjectClass().isAssignableFrom(businessObject.getClass())))
 68    {
 69  1 throw new IllegalArgumentException();
 70    }
 71    }
 72    }
 73   
 74  361 public void setBusinessObject(BusinessObject businessObject)
 75    {
 76  361 this.checkSetBusinessObjectAllowed(businessObject);
 77  360 if (this.businessObject != null)
 78    {
 79  2 this.businessObject.removeListener(this);
 80    }
 81  360 this.businessObject = businessObject;
 82  360 if (this.businessObject != null)
 83    {
 84  360 this.businessObject.addListener(this);
 85    }
 86  360 this.businessObjectUpdated(businessObject);
 87    }
 88   
 89  936 public Point getZoomedLocation(double zoomFactor)
 90    {
 91  936 Dimension halfSize = this.businessObject.getHalfSize();
 92  936 Point center = this.businessObject.getCenter();
 93  936 return new Point (
 94    (int) (zoomFactor*(center.x-halfSize.width)),
 95    (int) (zoomFactor*(center.y-halfSize.height)));
 96    }
 97   
 98  936 public Dimension getZoomedSize(double zoomFactor)
 99    {
 100  936 Dimension halfSize = this.businessObject.getHalfSize();
 101  936 int width = (int) (1+2*halfSize.width*zoomFactor);
 102  936 int height = (int) (1+2*halfSize.height*zoomFactor);
 103  936 return new Dimension (width, height);
 104    }
 105   
 106  754 public WorkArea getWorkArea()
 107    {
 108  754 return workArea;
 109    }
 110   
 111  349 public void setWorkArea(WorkArea workArea)
 112    {
 113  349 this.workArea = workArea;
 114    }
 115   
 116  521 final public void businessObjectUpdated(BusinessObject businessObject)
 117    {
 118  521 this.businessObjectUpdatedImpl(businessObject);
 119  521 if (this.getWorkArea()!=null)
 120    {
 121  129 this.getWorkArea().doLayout();
 122    }
 123    }
 124    protected abstract void businessObjectUpdatedImpl(BusinessObject businessObject);
 125    }