Clover coverage report - PLT Utilities Test Coverage (plt-20120304-r5436)
Coverage timestamp: Sat Mar 3 2012 22:01:56 CST
file stats: LOC: 101   Methods: 2
NCLOC: 44   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
TextAreaMessageDialog.java 0% 0% 0% 0%
coverage
 1    /*BEGIN_COPYRIGHT_BLOCK*
 2   
 3    PLT Utilities BSD License
 4   
 5    Copyright (c) 2007-2010 JavaPLT group at Rice University
 6    All rights reserved.
 7   
 8    Developed by: Java Programming Languages Team
 9    Rice University
 10    http://www.cs.rice.edu/~javaplt/
 11   
 12    Redistribution and use in source and binary forms, with or without modification, are permitted
 13    provided that the following conditions are met:
 14   
 15    - Redistributions of source code must retain the above copyright notice, this list of conditions
 16    and the following disclaimer.
 17    - Redistributions in binary form must reproduce the above copyright notice, this list of
 18    conditions and the following disclaimer in the documentation and/or other materials provided
 19    with the distribution.
 20    - Neither the name of the JavaPLT group, Rice University, nor the names of the library's
 21    contributors may be used to endorse or promote products derived from this software without
 22    specific prior written permission.
 23   
 24    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 25    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 26    FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND
 27    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 28    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 29    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 30    IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 31    OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 32   
 33    *END_COPYRIGHT_BLOCK*/
 34   
 35    package edu.rice.cs.plt.swing;
 36   
 37    import java.awt.BorderLayout;
 38    import java.awt.Dimension;
 39    import java.awt.Component;
 40    import java.awt.Frame;
 41    import java.awt.Container;
 42    import java.awt.SystemColor;
 43    import javax.swing.JDialog;
 44    import javax.swing.JTextArea;
 45    import javax.swing.JOptionPane;
 46    import javax.swing.JButton;
 47    import javax.swing.WindowConstants;
 48    import javax.swing.BorderFactory;
 49    import javax.swing.border.Border;
 50   
 51    /** Message dialog with a word-wrapping text area that allows copy & paste. */
 52    public class TextAreaMessageDialog extends JDialog {
 53   
 54    /**
 55    * Show the initialized dialog. Should be invoked from the event thread.
 56    * @param comp parent component, or null
 57    * @param title dialog title
 58    * @param message message for the text area
 59    */
 60  0 public static void showDialog(Component comp, String title, String message) {
 61  0 Frame frame = JOptionPane.getFrameForComponent(comp);
 62  0 TextAreaMessageDialog dialog = new TextAreaMessageDialog(frame, comp, title, message);
 63  0 SwingUtil.setPopupLoc(dialog, frame);
 64  0 dialog.setVisible(true);
 65    }
 66   
 67    /** Private constructor for this dialog. Only gets used in the static showDialog method.
 68    * @param frame owner frame
 69    * @param comp parent component
 70    * @param title dialog title
 71    * @param message message for the text area
 72    */
 73  0 private TextAreaMessageDialog(Frame frame, Component comp, String title, String message) {
 74  0 super(frame, title, true);
 75  0 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
 76   
 77    //buttons
 78  0 JButton okButton = new JButton("OK");
 79  0 okButton.addActionListener(SwingUtil.disposeAction(this));
 80  0 getRootPane().setDefaultButton(okButton);
 81   
 82  0 JTextArea textArea = new JTextArea(message);
 83  0 textArea.setEditable(false);
 84  0 textArea.setLineWrap(true);
 85  0 textArea.setWrapStyleWord(false);
 86  0 textArea.setBackground(SystemColor.window);
 87   
 88  0 Border emptyBorder = BorderFactory.createEmptyBorder(10, 10, 10, 10);
 89  0 textArea.setBorder(emptyBorder);
 90   
 91  0 Container contentPane = getContentPane();
 92  0 contentPane.add(textArea, BorderLayout.CENTER);
 93  0 contentPane.add(okButton, BorderLayout.SOUTH);
 94   
 95  0 Dimension parentDim = (comp!=null)?(comp.getSize()):getToolkit().getScreenSize();
 96  0 int xs = (int)parentDim.getWidth()/4;
 97  0 int ys = (int)parentDim.getHeight()/5;
 98  0 setSize(Math.max(xs,350), Math.max(ys, 250));
 99  0 setLocationRelativeTo(comp);
 100    }
 101    }