Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 126   Methods: 8
NCLOC: 63   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
FontOptionComponent.java 33.3% 77.8% 75% 72%
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.FontChooser;
 43    import edu.rice.cs.util.swing.SwingFrame;
 44   
 45    import java.awt.*;
 46    import java.awt.event.*;
 47   
 48    /** The Graphical form of a FontOption.
 49    * @version $Id: FontOptionComponent.java 5232 2010-04-24 00:14:05Z mgricken $
 50    */
 51    public class FontOptionComponent extends OptionComponent<Font,JPanel> {
 52   
 53    private final JButton _button;
 54    private final JTextField _fontField;
 55    private final JPanel _panel;
 56    private volatile Font _font;
 57   
 58  155 public FontOptionComponent(FontOption opt, String text, SwingFrame parent) {
 59  155 super(opt, text, parent);
 60  155 _button = new JButton();
 61  155 _button.addActionListener(new ActionListener() {
 62  0 public void actionPerformed(ActionEvent e) { chooseFont(); }
 63    });
 64  155 _button.setText("...");
 65  155 _button.setMaximumSize(new Dimension(10,10));
 66  155 _button.setMinimumSize(new Dimension(10,10));
 67   
 68  155 _fontField = new JTextField();
 69  155 _fontField.setEditable(false);
 70  155 _fontField.setBackground(Color.white);
 71  155 _fontField.setHorizontalAlignment(JTextField.CENTER);
 72  155 _panel = new JPanel(new BorderLayout());
 73  155 _panel.add(_fontField, BorderLayout.CENTER);
 74  155 _panel.add(_button, BorderLayout.EAST);
 75   
 76  155 _font = DrJava.getConfig().getSetting(_option);
 77  155 _updateField(_font);
 78  155 setComponent(_panel);
 79    }
 80   
 81    /** Constructor that allows for a tooltip description. */
 82  152 public FontOptionComponent(FontOption opt, String text, SwingFrame parent, String description) {
 83  152 this(opt, text, parent);
 84  152 setDescription(description);
 85    }
 86   
 87    /** Sets the tooltip description text for this option.
 88    * @param description the tooltip text
 89    */
 90  152 public void setDescription(String description) {
 91  152 _panel.setToolTipText(description);
 92  152 _fontField.setToolTipText(description);
 93  152 _label.setToolTipText(description);
 94    }
 95   
 96    /** Updates the font field to display the given font. */
 97  163 private void _updateField(Font f) {
 98  163 _fontField.setFont(f);
 99  163 _fontField.setText(_option.format(f));
 100    }
 101   
 102    /** Shows a custom font chooser dialog to pick a new font. */
 103  0 public void chooseFont() {
 104  0 String oldText = _fontField.getText();
 105  0 Font f = FontChooser.showDialog(_parent, "Choose '" + getLabelText() + "'", _font);
 106  0 if (f != null) {
 107  0 _font = f;
 108  0 _updateField(_font);
 109  0 if (!oldText.equals(_fontField.getText())) { notifyChangeListeners(); }
 110    }
 111    }
 112   
 113    /** Updates the config object with the new setting.
 114    * @return true if the new value is set successfully
 115    */
 116  4 public boolean updateConfig() {
 117  3 if (! _font.equals(DrJava.getConfig().getSetting(_option))) DrJava.getConfig().setSetting(_option, _font);
 118  4 return true;
 119    }
 120   
 121    /** Displays the given value. */
 122  8 public void setValue(Font value) {
 123  8 _font = value;
 124  8 _updateField(value);
 125    }
 126    }