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