Coverage report

  %line %branch
ca.spaz.gui.SpazLayout
0% 
0% 

 1  
 package ca.spaz.gui;
 2  
 
 3  
 import java.awt.*;
 4  
 import java.util.Hashtable;
 5  
 
 6  
 /** 
 7  
  */
 8  
 
 9  
 public class SpazLayout implements LayoutManager2 {
 10  0
     Hashtable compTable = new Hashtable();
 11  
     
 12  
     /**
 13  
      */
 14  0
     public SpazLayout() { }
 15  
     
 16  
     public void setConstraints(Component comp, SpazPosition constraints) {
 17  0
         compTable.put(comp, new SpazPosition(constraints));
 18  0
     }
 19  
     
 20  
     /**
 21  
      * Adds the specified component with the specified name to
 22  
      * the layout.  This does nothing in GraphPaperLayout, since constraints
 23  
      * are required.
 24  
      */
 25  0
     public void addLayoutComponent(String name, Component comp) {}
 26  
 
 27  
     /**
 28  
      * Removes the specified component from the layout.
 29  
      * @param comp the component to be removed
 30  
      */
 31  
     public void removeLayoutComponent(Component comp) {
 32  0
         compTable.remove(comp);
 33  0
     }
 34  
     
 35  
     public SpazPosition getPosition(Component comp) {
 36  0
     	return  (SpazPosition)compTable.get(comp);
 37  
     }
 38  
 
 39  
     public void setPosition(Component comp, SpazPosition lp) {
 40  0
     	compTable.put(comp, lp);
 41  0
     }
 42  
 
 43  
 
 44  
     /**
 45  
      * Calculates the preferred size dimensions for the specified 
 46  
      * panel given the components in the specified parent container.
 47  
      * @param parent the component to be laid out
 48  
      *  
 49  
      * @see #minimumLayoutSize
 50  
      */
 51  
     public Dimension preferredLayoutSize(Container parent) {
 52  0
     	int ncomponents = parent.getComponentCount();
 53  0
 		if (ncomponents == 0) return new Dimension(1,1);
 54  0
 		Rectangle totalRect = new Rectangle(0,0,1,1);
 55  0
 		Dimension size = parent.getSize();
 56  0
       Insets insets = parent.getInsets();		
 57  0
 		int totalW = size.width - (insets.left + insets.right);
 58  0
 		int totalH = size.height - (insets.top + insets.bottom);
 59  0
 		for ( int i = 0; i < ncomponents; i++ ) {
 60  0
 			Component c = parent.getComponent(i);
 61  0
 			SpazPosition lp = (SpazPosition)compTable.get(c);
 62  0
          Rectangle rect = lp.getRectangle(totalW, totalH);
 63  0
          if ( rect != null ) 
 64  0
          	totalRect = totalRect.union(rect); 
 65  
 
 66  
 		}
 67  0
 		return new Dimension(totalRect.width,totalRect.height);
 68  
     }
 69  
 
 70  
     /** 
 71  
      * Calculates the minimum size dimensions for the specified 
 72  
      * panel given the components in the specified parent container.
 73  
      * @param parent the component to be laid out
 74  
      * @see #preferredLayoutSize
 75  
      */
 76  
     public Dimension minimumLayoutSize(Container parent) {
 77  0
     	int ncomponents = parent.getComponentCount();
 78  0
 		if (ncomponents == 0) return new Dimension(1,1);
 79  0
 		Rectangle totalRect = new Rectangle(0,0,1,1);
 80  0
 		Dimension size = parent.getSize();
 81  0
       Insets insets = parent.getInsets();		
 82  0
 		int totalW = size.width - (insets.left + insets.right);
 83  0
 		int totalH = size.height - (insets.top + insets.bottom);
 84  0
 		for ( int i = 0; i < ncomponents; i++ ) {
 85  0
 			Component c = parent.getComponent(i);
 86  0
 			SpazPosition lp = (SpazPosition)compTable.get(c);
 87  0
          Rectangle rect = lp.getMinRectangle();
 88  0
          if ( rect != null ) 
 89  0
          	totalRect = totalRect.union(rect); 
 90  
 
 91  
 		}
 92  0
 		return new Dimension(totalRect.width,totalRect.height);
 93  
     }
 94  
     
 95  
 
 96  
     /** 
 97  
      * Lays out the container in the specified container.
 98  
      * @param parent the component which needs to be laid out 
 99  
      */
 100  
     public void layoutContainer(Container parent) {
 101  0
         synchronized (parent.getTreeLock()) {
 102  0
             Insets insets = parent.getInsets();
 103  0
             int ncomponents = parent.getComponentCount();
 104  0
             if (ncomponents == 0) return;
 105  
             
 106  
             // Total parent dimensions
 107  0
             Dimension size = parent.getSize();
 108  0
             int totalW = size.width - (insets.left + insets.right);
 109  0
             int totalH = size.height - (insets.top + insets.bottom);
 110  
 
 111  0
             for ( int i = 0; i < ncomponents; i++ ) {
 112  0
                 Component c = parent.getComponent(i);
 113  0
                 SpazPosition lp = getPosition(c);
 114  0
                 Rectangle rect = lp.getRectangle(totalW, totalH);
 115  0
                 if ( rect != null ) {
 116  0
                     int x = insets.left + rect.x;
 117  0
                     int y = insets.top + rect.y;
 118  0
                     c.setBounds(x, y, rect.width,  rect.height);
 119  
                 }
 120  
             }
 121  0
         }
 122  0
     }
 123  
     
 124  
     // LayoutManager2 /////////////////////////////////////////////////////////
 125  
     
 126  
     /**
 127  
      * Adds the specified component to the layout, using the specified
 128  
      * constraint object.
 129  
      * @param comp the component to be added
 130  
      * @param constraints  where/how the component is added to the layout.
 131  
      */
 132  
     public void addLayoutComponent(Component comp, Object constraints) {
 133  0
         if (constraints instanceof SpazPosition) {
 134  0
             SpazPosition cons = (SpazPosition)constraints;
 135  0
             setConstraints(comp, cons);
 136  0
         } else if (constraints != null) {
 137  0
             throw new IllegalArgumentException(
 138  
                 "cannot add to layout: constraint must be a SpazPostion");
 139  
         }
 140  0
     }
 141  
 
 142  
     /** 
 143  
      * Returns the maximum size of this component.
 144  
      * @see java.awt.Component#getMinimumSize()
 145  
      * @see java.awt.Component#getPreferredSize()
 146  
      * @see LayoutManager
 147  
      */
 148  
     public Dimension maximumLayoutSize(Container target) {
 149  0
         return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
 150  
     }
 151  
 
 152  
     /**
 153  
      * Returns the alignment along the x axis.  This specifies how
 154  
      * the component would like to be aligned relative to other 
 155  
      * components.  The value should be a number between 0 and 1
 156  
      * where 0 represents alignment along the origin, 1 is aligned
 157  
      * the furthest away from the origin, 0.5 is centered, etc.
 158  
      */
 159  
     public float getLayoutAlignmentX(Container target) {
 160  0
         return 0.5f;
 161  
     }
 162  
 
 163  
     /**
 164  
      * Returns the alignment along the y axis.  This specifies how
 165  
      * the component would like to be aligned relative to other 
 166  
      * components.  The value should be a number between 0 and 1
 167  
      * where 0 represents alignment along the origin, 1 is aligned
 168  
      * the furthest away from the origin, 0.5 is centered, etc.
 169  
      */
 170  
     public float getLayoutAlignmentY(Container target) {
 171  0
         return 0.5f;
 172  
     }
 173  
 
 174  
     /**
 175  
      * Invalidates the layout, indicating that if the layout manager
 176  
      * has cached information it should be discarded.
 177  
      */
 178  
     public void invalidateLayout(Container target) {
 179  
         // Do nothing
 180  0
     }
 181  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.