Clover coverage report -
Coverage timestamp: Sun Apr 18 2004 21:32:30 EDT
file stats: LOC: 175   Methods: 6
NCLOC: 99   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BoundariesPanel.java 50% 67.3% 66.7% 63.8%
coverage coverage
 1   
 /*
 2   
  * SimplyHTML, a word processor based on Java, HTML and CSS
 3   
  * Copyright (C) 2002 Ulrich Hilger
 4   
  *
 5   
  * This program is free software; you can redistribute it and/or
 6   
  * modify it under the terms of the GNU General Public License
 7   
  * as published by the Free Software Foundation; either version 2
 8   
  * of the License, or (at your option) any later version.
 9   
  *
 10   
  * This program is distributed in the hope that it will be useful,
 11   
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12   
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13   
  * GNU General Public License for more details.
 14   
  *
 15   
  * You should have received a copy of the GNU General Public License
 16   
  * along with this program; if not, write to the Free Software
 17   
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 18   
  */
 19   
 import javax.swing.JPanel;
 20   
 import javax.swing.JLabel;
 21   
 import java.awt.GridBagLayout;
 22   
 import java.awt.GridBagConstraints;
 23   
 import java.util.Vector;
 24   
 import javax.swing.text.SimpleAttributeSet;
 25   
 import javax.swing.text.AttributeSet;
 26   
 import javax.swing.text.html.CSS;
 27   
 import java.util.Enumeration;
 28   
 
 29   
 /**
 30   
  * Panel to show and manipulate boundaries of a rectangular object
 31   
  * such as a table cell.
 32   
  *
 33   
  * @author Ulrich Hilger
 34   
  * @author Light Development
 35   
  * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
 36   
  * @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
 37   
  * @author published under the terms and conditions of the
 38   
  *      GNU General Public License,
 39   
  *      for details see file gpl.txt in the distribution
 40   
  *      package of this software
 41   
  *
 42   
  * @version stage 11, April 27, 2003
 43   
  */
 44   
 
 45   
 public class BoundariesPanel extends JPanel implements AttributeComponent {
 46   
 
 47   
   /** the components used for single attributes */
 48   
   private Vector components = new Vector();
 49   
 
 50   
   /** the attributes represented by this compoent */
 51   
   private CombinedAttribute ca;
 52   
 
 53   
   /** the value to compare to determine changes */
 54   
   private String originalValue;
 55   
 
 56   
   /** indicates if a call to setValue is for initial setting or for changes */
 57   
   private int setValueCalls = 0;
 58   
 
 59   
   /** the attribute key this component represents */
 60   
   private Object key;
 61   
 
 62   
   /**
 63   
    * construct a <code>BoundariesPanel</code>.
 64   
    */
 65  6
   public BoundariesPanel(Object attrKey) {
 66  6
     super();
 67   
 
 68  6
     this.key = attrKey;
 69   
 
 70   
     // set layout
 71  6
     GridBagLayout g = new GridBagLayout();
 72  6
     setLayout(g);
 73   
 
 74   
     // constraints to use on our GridBagLayout
 75  6
     GridBagConstraints c = new GridBagConstraints();
 76   
 
 77  6
     Util.addGridBagComponent(this, new JLabel(
 78   
         FrmMain.dynRes.getResourceString(FrmMain.resources, "topLabel")),
 79   
         g, c, 0, 0, GridBagConstraints.EAST);
 80  6
     Util.addGridBagComponent(this, new JLabel(
 81   
         FrmMain.dynRes.getResourceString(FrmMain.resources, "rightLabel")),
 82   
         g, c, 2, 0, GridBagConstraints.EAST);
 83  6
     Util.addGridBagComponent(this, new JLabel(
 84   
         FrmMain.dynRes.getResourceString(FrmMain.resources, "bottomLabel")),
 85   
         g, c, 0, 1, GridBagConstraints.EAST);
 86  6
     Util.addGridBagComponent(this, new JLabel(
 87   
         FrmMain.dynRes.getResourceString(FrmMain.resources, "leftLabel")),
 88   
         g, c, 2, 1, GridBagConstraints.EAST);
 89   
 
 90  6
     addSizeSelector(g, c, attrKey, 1, 0); // top
 91  6
     addSizeSelector(g, c, attrKey, 3, 0); // right
 92  6
     addSizeSelector(g, c, attrKey, 1, 1); // bottom
 93  6
     addSizeSelector(g, c, attrKey, 3, 1); // left
 94   
   }
 95   
 
 96  24
   private void addSizeSelector(GridBagLayout g, GridBagConstraints c,
 97   
                                Object attr, int x, int y)
 98   
   {
 99  24
     SizeSelectorPanel ssp = new SizeSelectorPanel(
 100   
                                       attr,
 101   
                                       null,
 102   
                                       false,
 103   
                                       SizeSelectorPanel.TYPE_LABEL);
 104  24
     Util.addGridBagComponent(this, ssp, g, c, x, y, GridBagConstraints.WEST);
 105  24
     components.addElement(ssp);
 106   
   }
 107   
 
 108   
   /**
 109   
    * set the value of this <code>AttributeComponent</code>
 110   
    *
 111   
    * @param a  the set of attributes possibly having an
 112   
    *          attribute this component can display
 113   
    *
 114   
    * @return true, if the set of attributes had a matching attribute,
 115   
    *            false if not
 116   
    */
 117  6
   public boolean setValue(AttributeSet a) {
 118  6
     boolean success = true;
 119  6
     ca = new CombinedAttribute(key, a, true);
 120  6
     if(++setValueCalls < 2) {
 121  6
       originalValue = ca.getAttribute();
 122   
     }
 123  6
     SizeSelectorPanel ssp;
 124  6
     for(int i = 0; i < components.size(); i++) {
 125  24
       ssp = (SizeSelectorPanel) components.elementAt(i);
 126  24
       ssp.setValue(ca.getAttribute(i));
 127   
     }
 128  6
     return success;
 129   
   }
 130   
 
 131   
   /**
 132   
    * get the value of this <code>AttributeComponent</code>
 133   
    *
 134   
    * @return the value selected from this component
 135   
    */
 136  4
   public AttributeSet getValue() {
 137  4
     SimpleAttributeSet set = new SimpleAttributeSet();
 138  4
     SizeSelectorPanel ssp;
 139  4
     for(int i = 0; i < components.size(); i++) {
 140  16
       ssp = (SizeSelectorPanel) components.elementAt(i);
 141  16
       if(ssp.valueChanged()) {
 142  0
         ca.setAttribute(i, ssp.getAttr());
 143   
       }
 144   
     }
 145  4
     String newValue = ca.getAttribute();
 146  4
     if(!originalValue.equalsIgnoreCase(newValue)) {
 147  0
       set.addAttribute(key, newValue);
 148  0
       Util.styleSheet().addCSSAttribute(set, (CSS.Attribute) key, newValue);
 149   
     }
 150  4
     return set;
 151   
   }
 152   
 
 153  0
   public AttributeSet getValue(boolean includeUnchanged) {
 154  0
     if(includeUnchanged) {
 155  0
       SimpleAttributeSet set = new SimpleAttributeSet();
 156  0
       SizeSelectorPanel ssp;
 157  0
       for(int i = 0; i < components.size(); i++) {
 158  0
         ssp = (SizeSelectorPanel) components.elementAt(i);
 159  0
         ca.setAttribute(i, ssp.getAttr());
 160   
       }
 161  0
       String newValue = ca.getAttribute();
 162  0
       set.addAttribute(key, newValue);
 163  0
       Util.styleSheet().addCSSAttribute(set, (CSS.Attribute) key, newValue);
 164  0
       return set;
 165   
     }
 166   
     else {
 167  0
       return getValue();
 168   
     }
 169   
   }
 170   
 
 171  0
   public void reset() {
 172  0
     setValueCalls = 0;
 173  0
     originalValue = null;
 174   
   }
 175   
 }