Clover coverage report -
Coverage timestamp: Sat Jul 7 2007 16:41:13 CEST
file stats: LOC: 117   Methods: 5
NCLOC: 74   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ErrorMessageFrame.java 80% 100% 100% 96.2%
coverage coverage
 1    /*
 2    * ErrorMessageFrame.java
 3    *
 4    * Created on March 17, 2007, 5:48 PM
 5    *
 6    * JTR is free software; you can redistribute it and/or modify it under the
 7    * terms of the GNU General Public License as published by the Free Software
 8    * Foundation; either version 2, or (at your option) any later version.
 9    */
 10   
 11    package jtr.ui.swing;
 12   
 13    /**
 14    * Frame for showing the detail explaination of an error occurred during the
 15    * execution of a test.
 16    *
 17    * @author frusso
 18    * @version 4.0
 19    * @since 4.0
 20    */
 21    public class ErrorMessageFrame extends javax.swing.JFrame {
 22   
 23    /**
 24    * Creates new form ErrorMessageFrame
 25    * @param t
 26    * @param userMsg
 27    */
 28  7 public ErrorMessageFrame(Throwable t, String userMsg) {
 29  7 initComponents();
 30  7 this.setIconImage(IconImageProvider.getIcon());
 31   
 32  7 String msg = "";
 33  7 msg = addUserMsg(msg,userMsg);
 34  7 msg = addException(msg,t);
 35   
 36  7 errorMsgTextPane.setText(msg);
 37  7 errorMsgTextPane.setCaretPosition(0);
 38    }
 39   
 40    /** This method is called from within the constructor to
 41    * initialize the form.
 42    * WARNING: Do NOT modify this code. The content of this method is
 43    * always regenerated by the Form Editor.
 44    */
 45    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
 46  7 private void initComponents() {
 47  7 errorMsgScrollPane = new javax.swing.JScrollPane();
 48  7 errorMsgTextPane = new javax.swing.JTextPane();
 49   
 50  7 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
 51  7 setTitle("JTR 4.0 Runner's Message Details");
 52  7 setName("errorMsgFrame");
 53  7 errorMsgTextPane.setEditable(false);
 54  7 errorMsgTextPane.setCaretColor(new java.awt.Color(255, 255, 255));
 55  7 errorMsgScrollPane.setViewportView(errorMsgTextPane);
 56   
 57  7 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
 58  7 getContentPane().setLayout(layout);
 59  7 layout.setHorizontalGroup(
 60    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
 61    .add(errorMsgScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 579, Short.MAX_VALUE)
 62    );
 63  7 layout.setVerticalGroup(
 64    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
 65    .add(org.jdesktop.layout.GroupLayout.TRAILING, errorMsgScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
 66    );
 67  7 pack();
 68    }// </editor-fold>//GEN-END:initComponents
 69   
 70  7 private String addException(String msg, Throwable t) {
 71  7 if(t!=null) {
 72  3 String stackTrace = generateStackTrace(t);
 73  3 msg = msg+EXCEPTION_MSG_HEADER+"\n"+
 74    EXCEPTION_MSG_SPACING+"\n"+
 75    stackTrace;
 76    }
 77  7 return msg;
 78    }
 79   
 80  7 private String addUserMsg(String msg, String userMsg) {
 81  7 if(userMsg!=null) {
 82  7 msg = msg+USER_MSG_HEADER+"\n"+
 83    USER_MSG_SPACING+"\n"+
 84    userMsg+"\n\n";
 85    }
 86  7 return msg;
 87    }
 88   
 89  6 private String generateStackTrace(Throwable t) {
 90  6 String res = "";
 91  6 if(t!=null) {
 92  6 res = t.toString()+"\n";
 93  6 StackTraceElement[] st = t.getStackTrace();
 94  6 for(int i=0;i<st.length;i++) {
 95  80 res += st[i].toString()+"\n";
 96    }
 97    // recursive call
 98  6 Throwable cause = t.getCause();
 99  6 if(cause!=null & t!=cause) {
 100  3 res = res+"\n"+NESTED_EXCEPTION_HEADER+"\n"+generateStackTrace(cause);
 101    }
 102    }
 103  6 return res;
 104    }
 105   
 106    // Variables declaration - do not modify//GEN-BEGIN:variables
 107    private javax.swing.JScrollPane errorMsgScrollPane;
 108    private javax.swing.JTextPane errorMsgTextPane;
 109    // End of variables declaration//GEN-END:variables
 110    private final static String EXCEPTION_MSG_HEADER = "Exception Message:";
 111    private final static String EXCEPTION_MSG_SPACING = "----------------";
 112    private final static String STACKTRACE_HEADER = "StackTrace:";
 113    private final static String STACKTRACE_SPACING = "----------------";
 114    private final static String NESTED_EXCEPTION_HEADER = "Nested exception is:";
 115    private final static String USER_MSG_HEADER = "User Message:";
 116    private final static String USER_MSG_SPACING = "----------------";
 117    }