Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 103   Methods: 8
NCLOC: 43   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
IntegerOptionComponent.java 100% 87.5% 87.5% 88.2%
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 javax.swing.*;
 40    import javax.swing.event.*;
 41   
 42    import edu.rice.cs.drjava.config.*;
 43    import edu.rice.cs.drjava.*;
 44    import edu.rice.cs.util.swing.SwingFrame;
 45   
 46    /** Graphical form of an IntegerOption.
 47    * @version $Id: IntegerOptionComponent.java 5232 2010-04-24 00:14:05Z mgricken $
 48    */
 49    public class IntegerOptionComponent extends OptionComponent<Integer,JTextField> {
 50    private volatile JTextField _jtf;
 51   
 52  421 public IntegerOptionComponent (IntegerOption opt, String text, SwingFrame parent) {
 53  421 super(opt, text, parent);
 54  421 _jtf = new JTextField();
 55  421 _jtf.setText(_option.format(DrJava.getConfig().getSetting(_option)));
 56  421 _jtf.getDocument().addDocumentListener(new DocumentListener() {
 57  9 public void insertUpdate(DocumentEvent e) { notifyChangeListeners(); }
 58  9 public void removeUpdate(DocumentEvent e) { notifyChangeListeners(); }
 59  0 public void changedUpdate(DocumentEvent e) { notifyChangeListeners(); }
 60    });
 61  421 setComponent(_jtf);
 62    }
 63   
 64    /** Constructor that allows for a tooltip description. */
 65  418 public IntegerOptionComponent (IntegerOption opt, String text, SwingFrame parent, String description) {
 66  418 this(opt, text, parent);
 67  418 setDescription(description);
 68    }
 69   
 70    /** Sets the tooltip description text for this option.
 71    * @param description the tooltip text
 72    */
 73  418 public void setDescription(String description) {
 74  418 _jtf.setToolTipText(description);
 75  418 _label.setToolTipText(description);
 76    }
 77   
 78    /** Updates the config object with the new setting. Should run in event thread.
 79    * @return true if the new value is set successfully
 80    */
 81  4 public boolean updateConfig() {
 82   
 83  4 Integer currentValue = DrJava.getConfig().getSetting(_option);
 84  4 String enteredString = _jtf.getText().trim();
 85    //If the current value is the same as the enterd value, there is nothing to do.
 86  1 if (currentValue.toString().equals(enteredString)) return true;
 87   
 88  3 Integer enteredValue;
 89  3 try { enteredValue = _option.parse(enteredString); }
 90    catch (OptionParseException ope) {
 91  0 showErrorMessage("Invalid Integer!", ope);
 92  0 return false;
 93    }
 94   
 95  3 DrJava.getConfig().setSetting(_option, enteredValue);
 96  3 return true;
 97    }
 98   
 99    /** Displays the given value. */
 100  9 public void setValue(Integer value) {
 101  9 _jtf.setText(_option.format(value));
 102    }
 103    }