Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 129   Methods: 8
NCLOC: 44   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ForcedChoiceOptionComponent.java 75% 95.5% 100% 94.1%
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 edu.rice.cs.drjava.config.*;
 41    import edu.rice.cs.drjava.*;
 42    import edu.rice.cs.util.swing.SwingFrame;
 43   
 44    import java.awt.event.*;
 45    import java.util.Iterator;
 46   
 47    /** This component displays all legal choices for a ForcedChoiceOption as a list
 48    * of radio buttons. The radio buttons are placed within a framed panel titled
 49    * with the OptionComponent's label.
 50    * @version $Id: ForcedChoiceOptionComponent.java 5232 2010-04-24 00:14:05Z mgricken $
 51    */
 52    public class ForcedChoiceOptionComponent extends OptionComponent<String,JComboBox> {
 53    private volatile JComboBox _comboBox;
 54   
 55    /** Main constructor builds a panel containing a set of radio buttons for the
 56    * legal values of the ForcedChoiceOption.
 57    */
 58  459 public ForcedChoiceOptionComponent(ForcedChoiceOption option, String labelText, SwingFrame parent) {
 59  459 super(option, labelText, parent);
 60   
 61    // Build the combo box from the Iterator of legal values
 62  459 Iterator<String> values = option.getLegalValues();
 63  459 _comboBox = new JComboBox();
 64   
 65  459 _comboBox.addActionListener(new ActionListener() {
 66  923 public void actionPerformed(ActionEvent e) { notifyChangeListeners(); }
 67    });
 68   
 69  459 while(values.hasNext()) {
 70  3128 String currValue = values.next();
 71  3128 _comboBox.addItem(currValue);
 72    }
 73   
 74  459 resetToCurrent(DrJava.getConfig().getSetting(_option));
 75  459 setComponent(_comboBox);
 76    }
 77   
 78    /** Constructor that allows for a tooltip description. */
 79  456 public ForcedChoiceOptionComponent(ForcedChoiceOption option, String labelText, SwingFrame parent, String description) {
 80  456 this(option, labelText, parent);
 81  456 setDescription(description);
 82    }
 83   
 84    /** Sets the tooltip description text for this option.
 85    * @param description the tooltip text
 86    */
 87  456 public void setDescription(String description) {
 88  456 _comboBox.setToolTipText(description);
 89  456 _label.setToolTipText(description);
 90    }
 91   
 92    /** Selects the radio button corresponding to the current config options. */
 93  464 public void resetToCurrent(String current) {
 94    // _comboBox.setEnabled(DrJava.getConfig().isOptionEditable(_option));
 95  464 _comboBox.setSelectedItem(current);
 96   
 97    // String current = DrJava.getConfig().getSetting(_option);
 98    // Iterator values = ((ForcedChoiceOption)_option).getLegalValues();
 99    // int i = 0;
 100    //
 101    // while(values.hasNext()) {
 102    // if (current.equals(values.next())) {
 103    //
 104    // return;
 105    // }
 106    // i++;
 107    // }
 108    }
 109   
 110    /** Updates the config object with the new setting. Should run in event thread.
 111    * @return true if the new value is set successfully
 112    */
 113  4 public boolean updateConfig() {
 114  4 String oldValue = DrJava.getConfig().getSetting(_option);
 115  4 String newValue = _comboBox.getSelectedItem().toString();
 116   
 117  0 if (! newValue.equals(oldValue)) { DrJava.getConfig().setSetting(_option, newValue); }
 118   
 119  4 return true;
 120    }
 121   
 122    /** @return the value currently displayed in the combo box. */
 123  76 public String getCurrentComboBoxValue() {
 124  76 return _comboBox.getSelectedItem().toString();
 125    }
 126   
 127    /** Displays the given value. */
 128  5 public void setValue(String value) { resetToCurrent(value); }
 129    }