Clover coverage report -
Coverage timestamp: Sun Apr 18 2004 21:32:30 EDT
file stats: LOC: 144   Methods: 5
NCLOC: 91   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
EffectPanel.java 11.1% 47.8% 60% 39.1%
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   
 
 20   
 import java.awt.*;
 21   
 import javax.swing.*;
 22   
 import javax.swing.text.AttributeSet;
 23   
 import javax.swing.border.TitledBorder;
 24   
 import javax.swing.border.EtchedBorder;
 25   
 import javax.swing.text.html.CSS;
 26   
 import javax.swing.text.SimpleAttributeSet;
 27   
 import javax.swing.text.html.StyleSheet;
 28   
 
 29   
 /**
 30   
  * a panel to display and change line attributes
 31   
  *
 32   
  * @author Ulrich Hilger
 33   
  * @author Light Development
 34   
  * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
 35   
  * @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
 36   
  * @author published under the terms and conditions of the
 37   
  *      GNU General Public License,
 38   
  *      for details see file gpl.txt in the distribution
 39   
  *      package of this software
 40   
  *
 41   
  * @version stage 11, April 27, 2003
 42   
  */
 43   
 public class EffectPanel extends JPanel implements AttributeComponent {
 44   
 
 45   
   /** a radio button for the underline attribute */
 46   
   JRadioButton uLine;
 47   
 
 48   
   /** a radio button for the strike through attribute */
 49   
   JRadioButton strike;
 50   
 
 51   
   /** a radio button if no line effect is set */
 52   
   JRadioButton noLine;
 53   
 
 54   
   private Object originalValue;
 55   
 
 56   
   private int setValCount = 0;
 57   
 
 58   
   String selection = Util.CSS_ATTRIBUTE_NONE;
 59   
 
 60  4
   public EffectPanel() {
 61  4
     super(new GridLayout(3,1,3,3));
 62   
 
 63   
     /** initialize the line effects button group */
 64  4
     noLine = new JRadioButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "noLineLabel"));
 65  4
     uLine = new JRadioButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "uLineLabel"));
 66  4
     strike = new JRadioButton(FrmMain.dynRes.getResourceString(FrmMain.resources, "strikeLabel"));
 67  4
     ButtonGroup effectGroup = new ButtonGroup();
 68  4
     effectGroup.add(noLine);
 69  4
     effectGroup.add(uLine);
 70  4
     effectGroup.add(strike);
 71   
 
 72   
     //JPanel linePanel = new JPanel(new GridLayout(3,1,3,3));
 73  4
     setBorder(new TitledBorder(new EtchedBorder(
 74   
             EtchedBorder.LOWERED), FrmMain.dynRes.getResourceString(FrmMain.resources, "effectLabel")));
 75  4
     Font font = UIManager.getFont("TextField.font");
 76  4
     uLine.setFont(font);
 77  4
     strike.setFont(font);
 78  4
     noLine.setFont(font);
 79  4
     add(noLine);
 80  4
     add(uLine);
 81  4
     add(strike);
 82   
   }
 83   
 
 84  0
   public AttributeSet getValue(boolean includeUnchanged) {
 85  0
     if(includeUnchanged) {
 86  0
       return getAttributes();
 87   
     }
 88   
     else {
 89  0
       return getValue();
 90   
     }
 91   
   }
 92   
 
 93  0
   private AttributeSet getAttributes() {
 94  0
     SimpleAttributeSet set = new SimpleAttributeSet();
 95  0
     selection = Util.CSS_ATTRIBUTE_NONE;
 96  0
     if(uLine.isSelected()) {
 97  0
       selection = Util.CSS_ATTRIBUTE_UNDERLINE;
 98   
     }
 99  0
     else if(strike.isSelected()) {
 100  0
       selection = Util.CSS_ATTRIBUTE_LINE_THROUGH;
 101   
     }
 102  0
     Util.styleSheet().addCSSAttribute(set, CSS.Attribute.TEXT_DECORATION, selection);
 103  0
     return set;
 104   
   }
 105   
 
 106  3
   public AttributeSet getValue() {
 107  3
     if(((originalValue == null) && (!selection.equalsIgnoreCase(Util.CSS_ATTRIBUTE_NONE))) ||
 108   
         ((originalValue != null) && (!originalValue.toString().equalsIgnoreCase(selection))))
 109   
     {
 110  0
       return getAttributes();
 111   
     }
 112   
     else {
 113  3
       return new SimpleAttributeSet();
 114   
     }
 115   
   }
 116   
 
 117  4
   public boolean setValue(AttributeSet a) {
 118  4
     boolean success = false;
 119  4
     if(a.isDefined(CSS.Attribute.TEXT_DECORATION)) {
 120  0
       String value = a.getAttribute(CSS.Attribute.TEXT_DECORATION).toString();
 121  0
       if(value.equalsIgnoreCase(Util.CSS_ATTRIBUTE_UNDERLINE)) {
 122  0
         uLine.setSelected(true);
 123  0
         if(++setValCount < 2) {
 124  0
           originalValue = Util.CSS_ATTRIBUTE_UNDERLINE;
 125   
         }
 126  0
     success = true;
 127   
       }
 128  0
       else if(value.equalsIgnoreCase(Util.CSS_ATTRIBUTE_LINE_THROUGH)) {
 129  0
         strike.setSelected(true);
 130  0
         if(++setValCount < 2) {
 131  0
           originalValue = Util.CSS_ATTRIBUTE_LINE_THROUGH;
 132   
         }
 133  0
     success = true;
 134   
       }
 135   
       else {
 136  0
         noLine.setSelected(true);
 137   
       }
 138   
     }
 139   
     else {
 140  4
       noLine.setSelected(true);
 141   
     }
 142  4
     return success;
 143   
   }
 144   
 }