Clover coverage report - DrJava Test Coverage (drjava-20100718-r5321)
Coverage timestamp: Sun Jul 18 2010 03:26:51 CDT
file stats: LOC: 162   Methods: 7
NCLOC: 79   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AbortablePanel.java - 0% 0% 0%
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;
 38   
 39    import javax.swing.*;
 40    import java.awt.event.*;
 41    import java.awt.*;
 42   
 43    import edu.rice.cs.drjava.model.SingleDisplayModel;
 44   
 45    /** Panel for displaying some component with buttons, one of which is an "Abort" button.
 46    * This should be used to display the output of an external process.
 47    * This class is a swing class that should only be accessed from the event thread.
 48    * @version $Id: AbortablePanel.java 5236 2010-04-27 01:43:36Z mgricken $
 49    */
 50    public abstract class AbortablePanel extends TabbedPanel {
 51    protected JPanel _leftPane;
 52    protected JScrollPane _scrollPane;
 53   
 54    protected final SingleDisplayModel _model;
 55    protected final MainFrame _frame;
 56   
 57    protected String _title;
 58    protected JPanel _buttonPanel;
 59   
 60    protected JButton _abortButton;
 61   
 62    /** Constructs a new abortable panel.
 63    * This is swing view class and hence should only be accessed from the event thread.
 64    * @param frame the MainFrame
 65    * @param title title of the pane
 66    */
 67  0 public AbortablePanel(MainFrame frame, String title) {
 68  0 super(frame, title);
 69    //MainFrame.LOG.log("\tAbortablePanel ctor");
 70  0 _title = title;
 71  0 this.setLayout(new BorderLayout());
 72   
 73  0 _frame = frame;
 74  0 _model = frame.getModel();
 75   
 76  0 this.removeAll(); // override the behavior of TabbedPanel
 77   
 78    // remake closePanel
 79  0 _closePanel = new JPanel(new BorderLayout());
 80  0 _closePanel.add(_closeButton, BorderLayout.NORTH);
 81   
 82  0 _leftPane = new JPanel(new BorderLayout());
 83  0 Component leftPanel = makeLeftPanel();
 84  0 _scrollPane = new JScrollPane(leftPanel);
 85  0 _leftPane.add(_scrollPane);
 86  0 _setColors(leftPanel);
 87   
 88  0 this.add(_leftPane, BorderLayout.CENTER);
 89   
 90  0 _buttonPanel = new JPanel(new BorderLayout());
 91  0 _setupButtonPanel();
 92  0 this.add(_buttonPanel, BorderLayout.EAST);
 93  0 updateButtons();
 94    //MainFrame.LOG.log("\tAbortablePanel ctor done");
 95    }
 96   
 97    /** Quick helper for setting up color listeners. */
 98  0 protected static void _setColors(Component c) {
 99  0 new ForegroundColorListener(c);
 100  0 new BackgroundColorListener(c);
 101    }
 102   
 103    /** Close the pane. Override to make sure that the abort action is performed. */
 104  0 @Override
 105    protected void _close() {
 106  0 super._close();
 107  0 abortActionPerformed(null);
 108  0 updateButtons();
 109    }
 110   
 111    /** Setup left panel. Must be overridden to return the component on the left side. */
 112    protected abstract Component makeLeftPanel();
 113   
 114    /** Abort action was performed. Must be overridden to return the component on the left side. */
 115    protected abstract void abortActionPerformed(ActionEvent e);
 116   
 117    /** Update button state and text. Should be overridden if additional buttons are added besides "Go To", "Remove" and "Remove All". */
 118  0 protected void updateButtons() { }
 119   
 120    /** Creates the buttons for controlling the regions. Should be overridden. */
 121  0 protected JComponent[] makeButtons() {
 122  0 return new JComponent[0];
 123    }
 124   
 125    /** Creates the buttons for controlling the regions. */
 126  0 private void _setupButtonPanel() {
 127  0 JPanel mainButtons = new JPanel();
 128  0 JPanel emptyPanel = new JPanel();
 129  0 JPanel closeButtonPanel = new JPanel(new BorderLayout());
 130  0 GridBagLayout gbLayout = new GridBagLayout();
 131  0 GridBagConstraints c = new GridBagConstraints();
 132  0 mainButtons.setLayout(gbLayout);
 133   
 134  0 JComponent[] buts = makeButtons();
 135   
 136  0 closeButtonPanel.add(_closeButton, BorderLayout.NORTH);
 137  0 mainButtons.add(_abortButton = new JButton("Abort"));
 138  0 _abortButton.addActionListener(new ActionListener() {
 139  0 public void actionPerformed(ActionEvent e) { abortActionPerformed(e); }
 140    });
 141  0 for (JComponent b: buts) { mainButtons.add(b); }
 142  0 mainButtons.add(emptyPanel);
 143   
 144  0 c.fill = GridBagConstraints.HORIZONTAL;
 145  0 c.anchor = GridBagConstraints.NORTH;
 146  0 c.gridwidth = GridBagConstraints.REMAINDER;
 147  0 c.weightx = 1.0;
 148   
 149  0 gbLayout.setConstraints(_abortButton, c);
 150  0 for (JComponent b: buts) { gbLayout.setConstraints(b, c); }
 151   
 152  0 c.fill = GridBagConstraints.BOTH;
 153  0 c.anchor = GridBagConstraints.SOUTH;
 154  0 c.gridheight = GridBagConstraints.REMAINDER;
 155  0 c.weighty = 1.0;
 156   
 157  0 gbLayout.setConstraints(emptyPanel, c);
 158   
 159  0 _buttonPanel.add(mainButtons, BorderLayout.CENTER);
 160  0 _buttonPanel.add(closeButtonPanel, BorderLayout.EAST);
 161    }
 162    }