1 24 25 package org.objectweb.cjdbc.console.gui.frames; 26 27 import java.awt.BorderLayout ; 28 import java.awt.Color ; 29 import java.awt.Dimension ; 30 import java.awt.GridLayout ; 31 import java.awt.event.ActionEvent ; 32 import java.awt.event.ActionListener ; 33 import java.io.IOException ; 34 import java.io.PrintWriter ; 35 36 import javax.swing.Icon ; 37 import javax.swing.JButton ; 38 import javax.swing.JDialog ; 39 import javax.swing.JFrame ; 40 import javax.swing.JLabel ; 41 import javax.swing.JPanel ; 42 import javax.swing.JScrollPane ; 43 import javax.swing.JTextArea ; 44 import javax.swing.JTextField ; 45 46 import org.objectweb.cjdbc.common.i18n.GuiTranslate; 47 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 48 import org.objectweb.cjdbc.console.gui.constants.GuiConstants; 49 import org.objectweb.cjdbc.console.gui.constants.GuiIcons; 50 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter; 51 52 58 public class GuiExceptionFrame extends JDialog implements ActionListener 59 { 60 JTextField errorMessage; 61 JTextField classMessage; 62 JTextArea traceMessage; 63 JTextAreaWriter writer; 64 PrintWriter printWriter; 65 JButton showMe; 66 static final int FRAME_WIDTH = 500; 67 static final int SHORT_HEIGHT = 200; 68 static final int LONG_HEIGHT = 400; 69 private JScrollPane scrollPane; 70 71 76 public GuiExceptionFrame(JFrame gui) 77 { 78 super(gui, true); 79 setTitle(GuiTranslate.get("frame.exception.title")); 80 81 82 GuiConstants.centerComponent(this,FRAME_WIDTH,SHORT_HEIGHT); 83 setVisible(false); 84 85 getContentPane().setLayout(new BorderLayout ()); 86 87 GridLayout layout = new GridLayout (6, 1); 88 JPanel messagePanel = new JPanel (layout); 89 messagePanel.add(new JLabel (GuiTranslate.get("frame.exception.error.type"))); 90 classMessage = new JTextField (0); 91 classMessage.setBackground(Color.white); 92 classMessage.setAlignmentX(CENTER_ALIGNMENT); 93 classMessage.setEditable(false); 94 messagePanel.add(classMessage); 95 96 messagePanel.add(new JLabel (GuiTranslate.get("frame.exception.error.message"))); 97 errorMessage = new JTextField (0); 98 errorMessage.setBackground(Color.white); 99 errorMessage.setAlignmentX(CENTER_ALIGNMENT); 100 errorMessage.setEditable(false); 101 messagePanel.add(errorMessage); 102 103 JLabel label = new JLabel (GuiTranslate.get("frame.exception.stack.trace")); 105 showMe = new JButton (); 107 showMe.addActionListener(this); 108 setShowMeToShow(); 109 110 messagePanel.add(label); 111 messagePanel.add(showMe); 112 113 traceMessage = new JTextArea (); 114 traceMessage.setVisible(false); 115 traceMessage.setAlignmentX(CENTER_ALIGNMENT); 116 traceMessage.setEditable(false); 117 traceMessage.setFont(GuiConstants.CENTER_PANE_FONT); 118 traceMessage.setPreferredSize(new Dimension (FRAME_WIDTH, LONG_HEIGHT / 2)); 119 writer = new JTextAreaWriter(traceMessage); 120 printWriter = new PrintWriter (writer); 121 scrollPane = new JScrollPane (); 122 scrollPane.getViewport().add(traceMessage); 123 scrollPane.setVisible(false); 124 125 JButton iconPane = new JButton (); 127 Icon icon = GuiIcons.FRAME_ERROR_ICON; 128 iconPane.setIcon(icon); 129 Dimension dime = new Dimension (icon.getIconWidth(), icon.getIconHeight()); 130 iconPane.setMaximumSize(dime); 131 iconPane.setPreferredSize(dime); 132 iconPane.setActionCommand(GuiCommands.COMMAND_HIDE_ERROR_FRAME); 133 iconPane.addActionListener(this); 134 getContentPane().add(iconPane, BorderLayout.EAST); 135 136 getContentPane().add(messagePanel, BorderLayout.CENTER); 138 139 getContentPane().add(scrollPane, BorderLayout.SOUTH); 141 142 setVisible(false); 143 setBackground(Color.white); 144 setDefaultCloseOperation(HIDE_ON_CLOSE); 145 validate(); 146 } 147 148 153 public void showException(Exception e) 154 { 155 errorMessage.setText(e.getMessage()); 156 classMessage.setText(e.getClass().getName()); 157 traceMessage.setText(""); 158 e.printStackTrace(printWriter); 159 try 160 { 161 writer.flush(); 162 } 163 catch (IOException e1) 164 { 165 } 167 setVisible(true); 168 } 169 170 private void setShowMeToShow() 171 { 172 showMe.setText(GuiTranslate.get("frame.exception.show.trace")); 173 showMe.setActionCommand(GuiCommands.COMMAND_SHOW_ERROR_TRACE); 174 showMe.validate(); 175 showMe.repaint(); 176 } 177 178 private void setShowMeToHide() 179 { 180 showMe.setText(GuiTranslate.get("frame.exception.hide.trace")); 181 showMe.setActionCommand(GuiCommands.COMMAND_HIDE_ERROR_TRACE); 182 showMe.validate(); 183 showMe.repaint(); 184 } 185 186 189 public void actionPerformed(ActionEvent e) 190 { 191 if (e.getActionCommand().equals(GuiCommands.COMMAND_HIDE_ERROR_FRAME)) 192 { 193 scrollPane.setVisible(false); 194 this.setVisible(false); 195 } 196 else if (e.getActionCommand().equals(GuiCommands.COMMAND_SHOW_ERROR_TRACE)) 197 { 198 setSize(FRAME_WIDTH, LONG_HEIGHT); 199 traceMessage.setVisible(true); 200 scrollPane.setVisible(true); 201 validate(); 202 repaint(); 203 scrollPane.repaint(); 204 setShowMeToHide(); 205 } 206 else if (e.getActionCommand().equals(GuiCommands.COMMAND_HIDE_ERROR_TRACE)) 207 { 208 setSize(FRAME_WIDTH, SHORT_HEIGHT); 209 traceMessage.setVisible(false); 210 scrollPane.setVisible(false); 211 validate(); 212 repaint(); 213 scrollPane.repaint(); 214 setShowMeToShow(); 215 } 216 } 217 } 218 | Popular Tags |