src/org/objectweb/cjdbc/console/gui/frames/GuiExceptionFrame.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.console.gui.frames; 00026 00027 import java.awt.BorderLayout; 00028 import java.awt.Color; 00029 import java.awt.Dimension; 00030 import java.awt.GridLayout; 00031 import java.awt.Toolkit; 00032 import java.awt.event.ActionEvent; 00033 import java.awt.event.ActionListener; 00034 import java.io.IOException; 00035 import java.io.PrintWriter; 00036 00037 import javax.swing.Icon; 00038 import javax.swing.JButton; 00039 import javax.swing.JDialog; 00040 import javax.swing.JFrame; 00041 import javax.swing.JLabel; 00042 import javax.swing.JPanel; 00043 import javax.swing.JScrollPane; 00044 import javax.swing.JTextArea; 00045 import javax.swing.JTextField; 00046 00047 import org.objectweb.cjdbc.common.i18n.GuiTranslate; 00048 import org.objectweb.cjdbc.console.gui.constants.GuiCommands; 00049 import org.objectweb.cjdbc.console.gui.constants.GuiConstants; 00050 import org.objectweb.cjdbc.console.gui.constants.GuiIcons; 00051 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter; 00052 00059 public class GuiExceptionFrame extends JDialog implements ActionListener 00060 { 00061 JTextField errorMessage; 00062 JTextField classMessage; 00063 JTextArea traceMessage; 00064 JTextAreaWriter writer; 00065 PrintWriter printWriter; 00066 JButton showMe; 00067 static final int FRAME_WIDTH = 500; 00068 static final int SHORT_HEIGHT = 200; 00069 static final int LONG_HEIGHT = 400; 00070 private JScrollPane scrollPane; 00071 00077 public GuiExceptionFrame(JFrame gui) 00078 { 00079 super(gui, true); 00080 setTitle(GuiTranslate.get("frame.exception.title")); 00081 00082 Toolkit toolkit = Toolkit.getDefaultToolkit(); 00083 Dimension dim = toolkit.getScreenSize(); 00084 int screenHeight = dim.height; 00085 int screenWidth = dim.width; 00086 int frameWidth = FRAME_WIDTH; 00087 int frameHeight = SHORT_HEIGHT; 00088 setBounds((screenWidth - frameWidth) / 2, (screenHeight - frameHeight) / 2, 00089 frameWidth, frameHeight); 00090 validate(); 00091 setVisible(false); 00092 00093 getContentPane().setLayout(new BorderLayout()); 00094 00095 GridLayout layout = new GridLayout(6, 1); 00096 JPanel messagePanel = new JPanel(layout); 00097 messagePanel.add(new JLabel(GuiTranslate.get("frame.exception.error.type"))); 00098 classMessage = new JTextField(0); 00099 classMessage.setBackground(Color.white); 00100 classMessage.setAlignmentX(CENTER_ALIGNMENT); 00101 classMessage.setEditable(false); 00102 messagePanel.add(classMessage); 00103 00104 messagePanel.add(new JLabel(GuiTranslate.get("frame.exception.error.message"))); 00105 errorMessage = new JTextField(0); 00106 errorMessage.setBackground(Color.white); 00107 errorMessage.setAlignmentX(CENTER_ALIGNMENT); 00108 errorMessage.setEditable(false); 00109 messagePanel.add(errorMessage); 00110 00111 // Trace 00112 JLabel label = new JLabel(GuiTranslate.get("frame.exception.stack.trace")); 00113 // Show/hide trace 00114 showMe = new JButton(); 00115 showMe.addActionListener(this); 00116 setShowMeToShow(); 00117 00118 messagePanel.add(label); 00119 messagePanel.add(showMe); 00120 00121 traceMessage = new JTextArea(); 00122 traceMessage.setVisible(false); 00123 traceMessage.setAlignmentX(CENTER_ALIGNMENT); 00124 traceMessage.setEditable(false); 00125 traceMessage.setFont(GuiConstants.CENTER_PANE_FONT); 00126 traceMessage.setPreferredSize(new Dimension(FRAME_WIDTH, LONG_HEIGHT / 2)); 00127 writer = new JTextAreaWriter(traceMessage); 00128 printWriter = new PrintWriter(writer); 00129 scrollPane = new JScrollPane(); 00130 scrollPane.getViewport().add(traceMessage); 00131 scrollPane.setVisible(false); 00132 00133 // on the left 00134 JButton iconPane = new JButton(); 00135 Icon icon = GuiIcons.FRAME_ERROR_ICON; 00136 iconPane.setIcon(icon); 00137 Dimension dime = new Dimension(icon.getIconWidth(), icon.getIconHeight()); 00138 iconPane.setMaximumSize(dime); 00139 iconPane.setPreferredSize(dime); 00140 iconPane.setActionCommand(GuiCommands.COMMAND_HIDE_ERROR_FRAME); 00141 iconPane.addActionListener(this); 00142 getContentPane().add(iconPane, BorderLayout.EAST); 00143 00144 // on the center 00145 getContentPane().add(messagePanel, BorderLayout.CENTER); 00146 00147 // on the right 00148 getContentPane().add(scrollPane, BorderLayout.SOUTH); 00149 00150 setVisible(false); 00151 setBackground(Color.white); 00152 setDefaultCloseOperation(HIDE_ON_CLOSE); 00153 validate(); 00154 } 00155 00161 public void showException(Exception e) 00162 { 00163 errorMessage.setText(e.getMessage()); 00164 classMessage.setText(e.getClass().getName()); 00165 traceMessage.setText(""); 00166 e.printStackTrace(printWriter); 00167 try 00168 { 00169 writer.flush(); 00170 } 00171 catch (IOException e1) 00172 { 00173 // can't show, do not show 00174 } 00175 setVisible(true); 00176 } 00177 00178 private void setShowMeToShow() 00179 { 00180 showMe.setText(GuiTranslate.get("frame.exception.show.trace")); 00181 showMe.setActionCommand(GuiCommands.COMMAND_SHOW_ERROR_TRACE); 00182 showMe.validate(); 00183 showMe.repaint(); 00184 } 00185 00186 private void setShowMeToHide() 00187 { 00188 showMe.setText(GuiTranslate.get("frame.exception.hide.trace")); 00189 showMe.setActionCommand(GuiCommands.COMMAND_HIDE_ERROR_TRACE); 00190 showMe.validate(); 00191 showMe.repaint(); 00192 } 00193 00197 public void actionPerformed(ActionEvent e) 00198 { 00199 if (e.getActionCommand().equals(GuiCommands.COMMAND_HIDE_ERROR_FRAME)) 00200 { 00201 scrollPane.setVisible(false); 00202 this.setVisible(false); 00203 } 00204 else if (e.getActionCommand().equals(GuiCommands.COMMAND_SHOW_ERROR_TRACE)) 00205 { 00206 setSize(FRAME_WIDTH, LONG_HEIGHT); 00207 traceMessage.setVisible(true); 00208 scrollPane.setVisible(true); 00209 validate(); 00210 repaint(); 00211 scrollPane.repaint(); 00212 setShowMeToHide(); 00213 } 00214 else if (e.getActionCommand().equals(GuiCommands.COMMAND_HIDE_ERROR_TRACE)) 00215 { 00216 setSize(FRAME_WIDTH, SHORT_HEIGHT); 00217 traceMessage.setVisible(false); 00218 scrollPane.setVisible(false); 00219 validate(); 00220 repaint(); 00221 scrollPane.repaint(); 00222 setShowMeToShow(); 00223 } 00224 } 00225 }

CJDBCversion1.0.4に対してTue Oct 12 15:15:58 2004に生成されました。 doxygen 1.3.8