Clover coverage report - DrJava Test Coverage (drjava-20120422-r5456)
Coverage timestamp: Sun Apr 22 2012 03:13:25 CDT
file stats: LOC: 173   Methods: 8
NCLOC: 66   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ScrollableDialog.java 0% 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.util.swing;
 38   
 39    import edu.rice.cs.util.swing.Utilities;
 40    import java.awt.*;
 41    import java.awt.event.*;
 42    import javax.swing.*;
 43    import javax.swing.border.*;
 44    //import java.io.Serializable;
 45   
 46    /** Manages a JDialog with a scrollable text area and a button panel.
 47    * @version $Id: ScrollableDialog.java 5175 2010-01-20 08:46:32Z mgricken $
 48    */
 49    public class ScrollableDialog /* implements Serializable */ {
 50    /** Default width for all ScrollableDialogs. */
 51    public static final int DEFAULT_WIDTH = 500;
 52    /** Default height for all ScrollableDialogs. */
 53    public static final int DEFAULT_HEIGHT = 400;
 54    /** JDialog managed by this component. */
 55    protected JDialog _dialog;
 56    /** JTextArea contained in a scroll pane in this dialog. */
 57    protected JTextArea _textArea;
 58    /** Panel of buttons at the bottom of this dialog. */
 59    protected JPanel _buttonPanel;
 60    /** ScrollPane that contains the text area. */
 61    protected JScrollPane _textScroll;
 62   
 63    /** Creates a new ScrollableDialog with the default width and height.
 64    * @param parent Parent frame for this dialog
 65    * @param title Title for this dialog
 66    * @param header Message to display at the top of this dialog
 67    * @param text Text to insert into the scrollable JTextArea
 68    */
 69  0 public ScrollableDialog(JFrame parent, String title, String header, String text) {
 70  0 this(parent, title, header, text, DEFAULT_WIDTH, DEFAULT_HEIGHT, false);
 71    }
 72   
 73    /** Creates a new ScrollableDialog.
 74    * @param parent Parent frame for this dialog
 75    * @param title Title for this dialog
 76    * @param header Message to display at the top of this dialog
 77    * @param text Text to insert into the scrollable JTextArea
 78    * @param width Width for this dialog
 79    * @param height Height for this dialog
 80    */
 81  0 public ScrollableDialog(JFrame parent, String title, String header, String text, int width, int height) {
 82  0 this(parent, title, header, text, width, height, false);
 83    }
 84   
 85    /** Creates a new ScrollableDialog with the default width and height.
 86    * @param parent Parent frame for this dialog
 87    * @param title Title for this dialog
 88    * @param header Message to display at the top of this dialog
 89    * @param text Text to insert into the scrollable JTextArea
 90    * @param wrap whether to wrap long lines
 91    */
 92  0 public ScrollableDialog(JFrame parent, String title, String header, String text, boolean wrap) {
 93  0 this(parent, title, header, text, DEFAULT_WIDTH, DEFAULT_HEIGHT, wrap);
 94    }
 95   
 96    /** Creates a new ScrollableDialog.
 97    * @param parent Parent frame for this dialog
 98    * @param title Title for this dialog
 99    * @param header Message to display at the top of this dialog
 100    * @param text Text to insert into the scrollable JTextArea
 101    * @param width Width for this dialog
 102    * @param height Height for this dialog
 103    * @param wrap whether to wrap long lines
 104    */
 105  0 public ScrollableDialog(JFrame parent, String title, String header, String text, int width, int height, boolean wrap) {
 106  0 _dialog = new JDialog(parent, title, true);
 107  0 Container content = _dialog.getContentPane();
 108   
 109  0 content.setLayout(new BorderLayout());
 110   
 111    // Create the text area
 112  0 _textArea = new JTextArea();
 113  0 _textArea.setEditable(false);
 114  0 _textArea.setText(text);
 115  0 _textArea.setLineWrap(wrap);
 116  0 _textArea.setWrapStyleWord(true);
 117   
 118    // Arrange the dialog
 119  0 _dialog.setSize(width, height);
 120   
 121    // Add components
 122  0 _textScroll = new BorderlessScrollPane(_textArea,
 123    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
 124  0 wrap?JScrollPane.HORIZONTAL_SCROLLBAR_NEVER:JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
 125  0 JPanel scrollWrapper = new JPanel(new BorderLayout(0,5));
 126  0 scrollWrapper.setBorder(new EmptyBorder(5,5,0,5));
 127  0 scrollWrapper.add(new JLabel(header),BorderLayout.NORTH);
 128  0 scrollWrapper.add(_textScroll,BorderLayout.CENTER);
 129  0 JPanel bottomPanel = new JPanel(new BorderLayout());
 130  0 _buttonPanel = new JPanel(new GridLayout(1,0,5,5));
 131  0 bottomPanel.add(_buttonPanel,BorderLayout.EAST);
 132  0 bottomPanel.setBorder(new EmptyBorder(5,5,5,5));
 133  0 _addButtons();
 134   
 135  0 content.add(scrollWrapper, BorderLayout.CENTER);
 136  0 content.add(bottomPanel, BorderLayout.SOUTH);
 137   
 138    // This method is deprecated. There are alternatives, but it is
 139    // probably best to let defer to the standard focus-management
 140    // policy rather than trying to customize it.
 141    //_textArea.requestDefaultFocus();
 142    }
 143   
 144    /** Adds buttons to this dialog's button panel.
 145    * Subclasses can override this to add different buttons.
 146    */
 147  0 protected void _addButtons() {
 148  0 _buttonPanel.add(new JButton(_okAction));
 149    }
 150   
 151    /** A default "OK" action which disposes this dialog when invoked. */
 152    private Action _okAction = new AbstractAction("OK") {
 153  0 public void actionPerformed(ActionEvent e) {
 154  0 _dialog.dispose();
 155    }
 156    };
 157   
 158    /** Sets the font for the text area in this dialog.
 159    * @param f New font for the text
 160    */
 161  0 public void setTextFont(Font f) {
 162  0 _textArea.setFont(f);
 163    }
 164   
 165    /** Shows this dialog. */
 166  0 public void show() {
 167  0 Utilities.setPopupLoc(_dialog, _dialog.getOwner());
 168  0 _textArea.setCaretPosition(0);
 169  0 _textScroll.getHorizontalScrollBar().setValue(_textScroll.getHorizontalScrollBar().getMinimum());
 170  0 _textScroll.getVerticalScrollBar().setValue(_textScroll.getVerticalScrollBar().getMinimum());
 171  0 _dialog.setVisible(true);
 172    }
 173    }