Clover coverage report - DrJava Test Coverage (drjava-20120304-r5456)
Coverage timestamp: Sun Mar 4 2012 03:13:23 CST
file stats: LOC: 174   Methods: 8
NCLOC: 95   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConfigPanel.java 25% 76.1% 37.5% 63.7%
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.border.EmptyBorder;
 41    import java.awt.event.*;
 42    import java.awt.*;
 43   
 44    // TODO: Check synchronization.
 45    import java.util.Vector;
 46   
 47    /** The panel that set of configuration options (e.g. Fonts, Colors) uses to display its configurable items as read
 48    * from OptionConstants.
 49    * @version $Id: ConfigPanel.java 5439 2011-08-11 17:13:04Z rcartwright $
 50    */
 51    public class ConfigPanel extends JPanel {
 52   
 53    protected final String _title;
 54    protected final Vector<OptionComponent<?,?>> _components;
 55   
 56    /** Constructor for this ConfigPanel
 57    * @param title the title for this panel
 58    */
 59  608 public ConfigPanel(String title) {
 60    //_title = new JLabel(title);
 61  608 _title = title;
 62  608 _components = new Vector<OptionComponent<?,?>>();
 63    }
 64   
 65  0 public String getTitle() { return _title; }
 66   
 67    /** The method for adding new OptionComponents to this ConfigPanel
 68    * @param oc the OptionComponent to be added
 69    */
 70  18244 public void addComponent(OptionComponent<?,?> oc) { _components.add(oc); }
 71   
 72  570 public void displayComponents() {
 73  570 this.setLayout(new BorderLayout());
 74   
 75  570 JPanel panel = new JPanel(); // sits in scrollpane and compresses layout
 76  570 panel.setLayout(new BorderLayout());
 77  570 JPanel panel2 = new JPanel(); // contains OptionComponents
 78  570 panel.add(panel2, BorderLayout.NORTH);
 79   
 80  570 JScrollPane scroll =
 81    new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
 82  570 scroll.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), _title));
 83   
 84    // Fix increment on scrollbar
 85  570 JScrollBar bar = scroll.getVerticalScrollBar();
 86  570 bar.setUnitIncrement(25);
 87  570 bar.setBlockIncrement(400);
 88   
 89  570 GridBagLayout gridbag = new GridBagLayout();
 90  570 GridBagConstraints c = new GridBagConstraints();
 91  570 panel2.setLayout(gridbag);
 92  570 c.fill = GridBagConstraints.HORIZONTAL;
 93  570 Insets labelInsets = new Insets(0, 10, 0, 10);
 94  570 Insets compInsets = new Insets(0, 0, 0, 0);
 95  570 for (int i = 0; i < _components.size(); i++) {
 96  18244 OptionComponent<?,?> comp = _components.get(i);
 97   
 98  18244 if (!comp.useEntireColumn()) {
 99  16648 c.anchor = GridBagConstraints.CENTER;
 100  16648 c.weightx = 0.0;
 101  16648 c.gridwidth = 1;
 102  16648 c.insets = labelInsets;
 103   
 104  16648 JLabel label= comp.getLabel();
 105  16648 gridbag.setConstraints(label, c);
 106  16648 panel2.add(label);
 107   
 108  16648 c.weightx = 1.0;
 109  16648 c.gridwidth = GridBagConstraints.REMAINDER;
 110  16648 c.insets = compInsets;
 111   
 112  16648 JComponent otherC = comp.getComponent();
 113  16648 gridbag.setConstraints(otherC, c);
 114  16648 panel2.add(otherC);
 115    }
 116    else {
 117  1596 c.anchor = GridBagConstraints.NORTH;
 118  1596 c.weightx = 0.0;
 119  1596 c.gridwidth = 2;
 120  1596 c.gridwidth = GridBagConstraints.REMAINDER;
 121  1596 c.insets = compInsets;
 122   
 123  1596 JComponent otherC = comp.getComponent();
 124  1596 gridbag.setConstraints(otherC, c);
 125  1596 panel2.add(otherC);
 126    }
 127    }
 128   
 129    // Reset Button
 130  570 JButton _resetToDefaultButton = new JButton("Reset to Defaults");
 131  570 _resetToDefaultButton.addActionListener(new ActionListener() {
 132  0 public void actionPerformed(ActionEvent e) { resetToDefault(); }
 133    });
 134  570 JPanel resetPanel = new JPanel();
 135  570 resetPanel.setLayout(new FlowLayout());
 136  570 resetPanel.setBorder(new EmptyBorder(5,5,5,5));
 137  570 resetPanel.add(_resetToDefaultButton);
 138  570 panel.add(resetPanel, BorderLayout.SOUTH);
 139   
 140  570 this.add(scroll, BorderLayout.CENTER);
 141    }
 142   
 143    /** Tells each component in the vector to update Config with its value. Should run in event thread.
 144    * @return whether update() of all the components succeeded
 145    */
 146  0 public boolean update() {
 147   
 148  0 for (int i = 0; i < _components.size(); i++) {
 149  0 boolean isValidUpdate = _components.get(i).updateConfig();
 150  0 if (! isValidUpdate) return false;
 151    }
 152  0 return true;
 153    }
 154   
 155    /** Tells each component to reset its display field to the current value. */
 156  0 public void resetToCurrent() {
 157  0 for (int i = 0; i < _components.size(); i++) {
 158  0 _components.get(i).resetToCurrent();
 159  0 if (_components.get(i) instanceof VectorOptionComponent<?>)
 160  0 ((VectorOptionComponent<?>)_components.get(i)).resizeTable();
 161    }
 162    }
 163   
 164    /** Tells each component to reset its value to its default. Each component creates an event thread task. */
 165  0 public void resetToDefault() {
 166  0 for (int i = 0; i < _components.size(); i++) {
 167  0 _components.get(i).resetToDefault();
 168  0 if (_components.get(i) instanceof VectorOptionComponent<?>)
 169  0 ((VectorOptionComponent<?>)_components.get(i)).resizeTable();
 170    }
 171    // must reset the "current keystroke map" when resetting
 172  0 VectorKeyStrokeOptionComponent.resetCurrentKeyStrokeMap();
 173    }
 174    }