Clover coverage report - DrJava Test Coverage (drjava-20100718-r5321)
Coverage timestamp: Sun Jul 18 2010 03:26:51 CDT
file stats: LOC: 132   Methods: 9
NCLOC: 44   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
BooleanOptionComponent.java 100% 95.2% 88.9% 94.4%
coverage coverage
 1    /*BEGIN_COPYRIGHT_BLOCK
 2    *
 3    * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu)
 4    * All rights reserved.
 5    *
 6    * Redistribution and use in source and binary forms, with or without
 7    * modification, are permitted provided that the following conditions are met:
 8    * * Redistributions of source code must retain the above copyright
 9    * notice, this list of conditions and the following disclaimer.
 10    * * Redistributions in binary form must reproduce the above copyright
 11    * notice, this list of conditions and the following disclaimer in the
 12    * documentation and/or other materials provided with the distribution.
 13    * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
 14    * names of its contributors may be used to endorse or promote products
 15    * derived from this software without specific prior written permission.
 16    *
 17    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18    * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 19    * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 20    * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 21    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24    * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 25    * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 26    * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27    * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28    *
 29    * This software is Open Source Initiative approved Open Source Software.
 30    * Open Source Initative Approved is a trademark of the Open Source Initiative.
 31    *
 32    * This file is part of DrJava. Download the current version of this project
 33    * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
 34    *
 35    * END_COPYRIGHT_BLOCK*/
 36   
 37    package edu.rice.cs.drjava.ui.config;
 38   
 39    import java.awt.event.*;
 40    import javax.swing.*;
 41    import edu.rice.cs.drjava.config.*;
 42    import edu.rice.cs.drjava.*;
 43    import edu.rice.cs.util.swing.SwingFrame;
 44   
 45    /** Graphical form of a BooleanOption.
 46    * @version $Id: BooleanOptionComponent.java 5232 2010-04-24 00:14:05Z mgricken $
 47    */
 48    public class BooleanOptionComponent extends OptionComponent<Boolean,JCheckBox> {
 49    protected JCheckBox _jcb;
 50   
 51    /** Constructs a new BooleanOptionComponent.
 52    * @param opt the BooleanOption this component represents
 53    * @param text the text to display with the option
 54    * @param parent the parent frame
 55    * @param left whether the descriptive text should be on the left
 56    */
 57  2625 public BooleanOptionComponent(BooleanOption opt, String text, SwingFrame parent, boolean left) {
 58  2625 super(opt, left?text:"", parent);
 59  2625 _jcb = new JCheckBox();
 60  2625 _jcb.setText(left?"":text);
 61  2625 _jcb.addActionListener(new ActionListener() {
 62  0 public void actionPerformed(ActionEvent e) { notifyChangeListeners(); }
 63    });
 64   
 65  2625 _jcb.setSelected(DrJava.getConfig().getSetting(_option).booleanValue());
 66  2625 setComponent(_jcb);
 67    }
 68   
 69    /** Constructs a new BooleanOptionComponent with a tooltip description.
 70    * @param opt the BooleanOption this component represents
 71    * @param text the text to display with the option
 72    * @param parent the parent frame
 73    * @param description text to show in a tooltip over
 74    * @param left whether the descriptive text should be on the left
 75    */
 76  1596 public BooleanOptionComponent(BooleanOption opt, String text, SwingFrame parent, String description, boolean left) {
 77  1596 this(opt, text, parent, left);
 78  1596 setDescription(description);
 79    }
 80   
 81    /** Constructs a new BooleanOptionComponent.
 82    * @param opt the BooleanOption this component represents
 83    * @param text the text to display with the option
 84    * @param parent the parent frame
 85    */
 86  3 public BooleanOptionComponent(BooleanOption opt, String text, SwingFrame parent) {
 87  3 this(opt, text, parent, true);
 88    }
 89   
 90    /** Constructs a new BooleanOptionComponent with a tooltip description.
 91    * @param opt the BooleanOption this component represents
 92    * @param text the text to display with the option
 93    * @param parent the parent frame
 94    * @param description text to show in a tooltip over
 95    */
 96  1026 public BooleanOptionComponent(BooleanOption opt, String text, SwingFrame parent, String description) {
 97  1026 this(opt, text, parent, true);
 98    }
 99   
 100    /** Sets the tooltip description text for this option.
 101    * @param description the tooltip text
 102    */
 103  1596 public void setDescription(String description) {
 104  1596 _jcb.setToolTipText(description);
 105  1596 _label.setToolTipText(description);
 106    }
 107   
 108    /** Updates the config object with the new setting.
 109    * @return true if the new value is set successfully
 110    */
 111  4 public boolean updateConfig() {
 112  4 Boolean oldValue = DrJava.getConfig().getSetting(_option);
 113  4 Boolean newValue = Boolean.valueOf(_jcb.isSelected());
 114   
 115  3 if (! oldValue.equals(newValue)) DrJava.getConfig().setSetting(_option, newValue);
 116   
 117  4 return true;
 118    }
 119   
 120    /** Displays the given value. */
 121  8 public void setValue(Boolean value) { _jcb.setSelected(value.booleanValue()); }
 122   
 123    // /** Return's this OptionComponent's configurable component. */
 124    // public JCheckBox getComponent() { return _jcb; }
 125   
 126    /** Whether the component should occupy the entire column. */
 127  1596 public BooleanOptionComponent setEntireColumn(boolean entireColumn) {
 128  1596 _entireColumn = entireColumn;
 129  1596 return this;
 130    }
 131   
 132    }