1 17 18 package org.sape.carbon.services.exception; 19 20 21 import java.util.ArrayList ; 22 import java.util.List ; 23 24 import javax.swing.UIManager ; 25 26 import org.sape.carbon.core.exception.ExceptionUtility; 27 28 35 public class ExceptionViewer extends javax.swing.JFrame { 36 37 List exceptionList = new ArrayList (); 38 int currentIndex = 0; 39 40 41 public ExceptionViewer() { 42 initComponents(); 43 44 45 this.errorIconLabel.setIcon(UIManager.getIcon("OptionPane.errorIcon")); 46 } 47 48 public void addException(Throwable throwable) { 49 this.exceptionList.add(throwable); 50 pickException(this.exceptionList.size() - 1); 51 } 52 53 private void pickException(int index) { 54 Throwable throwable = (Throwable ) this.exceptionList.get(index); 55 if (throwable != null) { 56 this.jEditorPane1.setText(ExceptionUtility.printStackTracesToString(throwable)); 57 58 this.classLabel.setText(throwable.getClass().getName()); 59 this.messageLabel.setText(throwable.getMessage()); 60 61 this.currentIndex = index; 62 } 63 64 this.nextButton.setEnabled((this.exceptionList.size()-1) > this.currentIndex); 65 66 this.previousButton.setEnabled(this.currentIndex > 0); 67 68 this.setTitle("Carbon Exception Viewer - Showing " + this.currentIndex + 69 " out of " + this.exceptionList.size()); 70 } 71 72 77 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 79 80 jPanel1 = new javax.swing.JPanel (); 81 jButton1 = new javax.swing.JButton (); 82 previousButton = new javax.swing.JButton (); 83 nextButton = new javax.swing.JButton (); 84 jScrollPane1 = new javax.swing.JScrollPane (); 85 jEditorPane1 = new javax.swing.JEditorPane (); 86 jPanel2 = new javax.swing.JPanel (); 87 errorIconLabel = new javax.swing.JLabel (); 88 classLabelLabel = new javax.swing.JLabel (); 89 classLabel = new javax.swing.JLabel (); 90 messageLabelLabel = new javax.swing.JLabel (); 91 messageLabel = new javax.swing.JLabel (); 92 93 addWindowListener(new java.awt.event.WindowAdapter () { 94 public void windowClosing(java.awt.event.WindowEvent evt) { 95 exitForm(evt); 96 } 97 }); 98 99 jPanel1.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.CENTER, 7, 5)); 100 101 jButton1.setText("Close"); 102 jButton1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); 103 jButton1.addActionListener(new java.awt.event.ActionListener () { 104 public void actionPerformed(java.awt.event.ActionEvent evt) { 105 jButton1ActionPerformed(evt); 106 } 107 }); 108 109 jPanel1.add(jButton1); 110 111 previousButton.setText("<< Previous"); 112 previousButton.addActionListener(new java.awt.event.ActionListener () { 113 public void actionPerformed(java.awt.event.ActionEvent evt) { 114 previousButtonActionPerformed(evt); 115 } 116 }); 117 118 jPanel1.add(previousButton); 119 120 nextButton.setText("Next >>"); 121 nextButton.addActionListener(new java.awt.event.ActionListener () { 122 public void actionPerformed(java.awt.event.ActionEvent evt) { 123 nextButtonActionPerformed(evt); 124 } 125 }); 126 127 jPanel1.add(nextButton); 128 129 getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH); 130 131 jScrollPane1.setViewportView(jEditorPane1); 132 133 getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER); 134 135 jPanel2.setLayout(new java.awt.GridBagLayout ()); 136 137 jPanel2.setBorder(new javax.swing.border.SoftBevelBorder (javax.swing.border.BevelBorder.RAISED)); 138 errorIconLabel.setPreferredSize(new java.awt.Dimension (48, 48)); 139 gridBagConstraints = new java.awt.GridBagConstraints (); 140 gridBagConstraints.gridheight = 2; 141 gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; 142 gridBagConstraints.insets = new java.awt.Insets (11, 7, 11, 14); 143 jPanel2.add(errorIconLabel, gridBagConstraints); 144 145 classLabelLabel.setText("Exception"); 146 classLabelLabel.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); 147 gridBagConstraints = new java.awt.GridBagConstraints (); 148 gridBagConstraints.insets = new java.awt.Insets (3, 0, 3, 5); 149 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; 150 jPanel2.add(classLabelLabel, gridBagConstraints); 151 152 classLabel.setFont(new java.awt.Font ("Courier New", 0, 12)); 153 classLabel.setText("jLabel2"); 154 classLabel.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); 155 classLabel.setPreferredSize(new java.awt.Dimension (150, 14)); 156 gridBagConstraints = new java.awt.GridBagConstraints (); 157 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 158 gridBagConstraints.insets = new java.awt.Insets (3, 0, 3, 0); 159 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 160 gridBagConstraints.weightx = 1.0; 161 jPanel2.add(classLabel, gridBagConstraints); 162 163 messageLabelLabel.setText("Message"); 164 messageLabelLabel.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); 165 gridBagConstraints = new java.awt.GridBagConstraints (); 166 gridBagConstraints.gridx = 1; 167 gridBagConstraints.gridy = 1; 168 gridBagConstraints.insets = new java.awt.Insets (3, 0, 3, 5); 169 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST; 170 jPanel2.add(messageLabelLabel, gridBagConstraints); 171 172 messageLabel.setFont(new java.awt.Font ("Courier New", 0, 12)); 173 messageLabel.setText("jLabel4"); 174 messageLabel.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM); 175 messageLabel.setPreferredSize(new java.awt.Dimension (150, 14)); 176 gridBagConstraints = new java.awt.GridBagConstraints (); 177 gridBagConstraints.gridx = 2; 178 gridBagConstraints.gridy = 1; 179 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 180 gridBagConstraints.insets = new java.awt.Insets (3, 0, 3, 0); 181 gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; 182 gridBagConstraints.weightx = 1.0; 183 jPanel2.add(messageLabel, gridBagConstraints); 184 185 getContentPane().add(jPanel2, java.awt.BorderLayout.NORTH); 186 187 pack(); 188 java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); 189 setSize(new java.awt.Dimension (583, 478)); 190 setLocation((screenSize.width-583)/2,(screenSize.height-478)/2); 191 } 193 private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) { this.pickException(this.currentIndex+1); 196 } 198 private void previousButtonActionPerformed(java.awt.event.ActionEvent evt) { this.pickException(this.currentIndex - 1); 201 } 203 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { this.setVisible(false); 206 this.dispose(); 207 } 209 210 private void exitForm(java.awt.event.WindowEvent evt) { System.exit(0); 212 } 214 217 public static void main(String args[]) { 218 new ExceptionViewer().show(); 219 } 220 221 222 private javax.swing.JLabel classLabelLabel; 224 private javax.swing.JPanel jPanel2; 225 private javax.swing.JPanel jPanel1; 226 private javax.swing.JButton jButton1; 227 private javax.swing.JScrollPane jScrollPane1; 228 private javax.swing.JLabel messageLabel; 229 private javax.swing.JLabel classLabel; 230 private javax.swing.JLabel errorIconLabel; 231 private javax.swing.JEditorPane jEditorPane1; 232 private javax.swing.JButton previousButton; 233 private javax.swing.JLabel messageLabelLabel; 234 private javax.swing.JButton nextButton; 235 237 } 238 | Popular Tags |