Clover coverage report -
Coverage timestamp: Sun Apr 18 2004 21:32:30 EDT
file stats: LOC: 138   Methods: 5
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StyleSelector.java 50% 58.6% 60% 56.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   
 
 20   
 import java.awt.*;
 21   
 import java.awt.event.*;
 22   
 import javax.swing.*;
 23   
 import javax.swing.event.*;
 24   
 import javax.swing.text.*;
 25   
 import javax.swing.text.html.*;
 26   
 import java.util.*;
 27   
 
 28   
 /**
 29   
  * Component to select styles
 30   
  *
 31   
  * @author Ulrich Hilger
 32   
  * @author Light Development
 33   
  * @author <a href="http://www.lightdev.com">http://www.lightdev.com</a>
 34   
  * @author <a href="mailto:info@lightdev.com">info@lightdev.com</a>
 35   
  * @author published under the terms and conditions of the
 36   
  *      GNU General Public License,
 37   
  *      for details see file gpl.txt in the distribution
 38   
  *      package of this software
 39   
  *
 40   
  * @version stage 11, April 27, 2003
 41   
  */
 42   
 
 43   
 public class StyleSelector extends JComboBox
 44   
     implements AttributeComponent, ChangeListener
 45   
 {
 46   
 
 47   
   /** the CSS attribute key this AttributeComponent object represents */
 48   
   private HTML.Attribute key;
 49   
 
 50   
   /** indicates whether or not to ignore change events */
 51   
   private boolean ignoreChanges = false;
 52   
 
 53   
   private String standardStyleName = FrmMain.dynRes.getResourceString(FrmMain.resources, "standardStyleName");
 54   
 
 55   
   /**
 56   
    * construct a <code>StyleSelector</code>
 57   
    *
 58   
    * @param key  the attribute this component represents
 59   
    */
 60  79
   public StyleSelector(HTML.Attribute key) {
 61  79
     this.key = key;
 62   
   }
 63   
 
 64   
   /**
 65   
    * set the value of this combo box
 66   
    *
 67   
    * @param a  the set of attributes possibly having a
 68   
    *          font size attribute this pick list could display
 69   
    *
 70   
    * @return true, if the set of attributes had a matching attribute,
 71   
    *            false if not
 72   
    */
 73  29
   public boolean setValue(AttributeSet a) {
 74  29
     boolean success = false;
 75  29
     Object attr = a.getAttribute(key);
 76  29
     if(attr != null) {
 77  1
       setSelectedItem(attr.toString());
 78  1
       success = true;
 79   
     }
 80   
     else {
 81  28
       setSelectedItem(standardStyleName);
 82   
     }
 83  29
     return success;
 84   
   }
 85   
 
 86   
   /**
 87   
    * get the value of this <code>AttributeComponent</code>
 88   
    *
 89   
    * @return the value selected from this component
 90   
    */
 91  0
   public AttributeSet getValue() {
 92  0
     SimpleAttributeSet set = new SimpleAttributeSet();
 93  0
     set.addAttribute(key, getSelectedItem());
 94  0
     return set;
 95   
   }
 96   
 
 97  0
   public AttributeSet getValue(boolean includeUnchanged) {
 98  0
     if(includeUnchanged) {
 99  0
       SimpleAttributeSet set = new SimpleAttributeSet();
 100  0
       set.addAttribute(key, getSelectedItem());
 101  0
       return set;
 102   
     }
 103   
     else {
 104  0
       return getValue();
 105   
     }
 106   
   }
 107   
 
 108   
   /* --------------- ChangeListener implementation start --------------- */
 109   
 
 110   
   /**
 111   
    * this method listens and reacts to changes to either the JTabbedPane of FrmMain or
 112   
    * a given StyleSheet this component was registered with. Once either one changes
 113   
    * the list of styles of this componment is refreshed accordingly.
 114   
    */
 115  84
   public void stateChanged(ChangeEvent e) {
 116  84
     Object src = e.getSource();
 117  84
     if(src instanceof JTabbedPane)
 118   
     {
 119  84
       Component c = ((JTabbedPane) src).getSelectedComponent();
 120  84
       if(c != null) {
 121  79
         int activeTabNo = ((JTabbedPane) src).getSelectedIndex();
 122  79
         DocumentPane dp = (DocumentPane) ((JTabbedPane) src).getComponentAt(activeTabNo);
 123  79
         Vector styleNames = Util.getStyleNamesForTag(((SHTMLDocument) dp.getDocument()).getStyleSheet(), HTML.Tag.P.toString());
 124  79
         styleNames.insertElementAt(standardStyleName, 0);
 125  79
         setModel(new DefaultComboBoxModel(styleNames));
 126   
       }
 127   
     }
 128  0
     else if(src instanceof StyleContext.NamedStyle) {
 129  0
       Vector styleNames = Util.getStyleNamesForTag((AttributeSet) src, HTML.Tag.P.toString());
 130  0
       styleNames.insertElementAt(standardStyleName, 0);
 131  0
       setModel(new DefaultComboBoxModel(styleNames));
 132   
     }
 133   
 
 134   
   }
 135   
 
 136   
   /* --------------- ChangeListener implementation end ----------------- */
 137   
 }
 138