Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

GuiExceptionFrame.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk
00022  * Contributor(s): ______________________.
00023  */
00024 
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.event.ActionEvent;
00032 import java.awt.event.ActionListener;
00033 import java.io.IOException;
00034 import java.io.PrintWriter;
00035 
00036 import javax.swing.Icon;
00037 import javax.swing.JButton;
00038 import javax.swing.JDialog;
00039 import javax.swing.JFrame;
00040 import javax.swing.JLabel;
00041 import javax.swing.JPanel;
00042 import javax.swing.JScrollPane;
00043 import javax.swing.JTextArea;
00044 import javax.swing.JTextField;
00045 
00046 import org.objectweb.cjdbc.common.i18n.GuiTranslate;
00047 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00048 import org.objectweb.cjdbc.console.gui.constants.GuiConstants;
00049 import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
00050 import org.objectweb.cjdbc.console.gui.jtools.JTextAreaWriter;
00051 
00052 /**
00053  * This class defines a GuiExceptionFrame
00054  * 
00055  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00056  * @version 1.0
00057  */
00058 public class GuiExceptionFrame extends JDialog implements ActionListener
00059 {
00060   JTextField       errorMessage;
00061   JTextField       classMessage;
00062   JTextArea        traceMessage;
00063   JTextAreaWriter  writer;
00064   PrintWriter      printWriter;
00065   JButton          showMe;
00066   static final int FRAME_WIDTH  = 500;
00067   static final int SHORT_HEIGHT = 200;
00068   static final int LONG_HEIGHT  = 400;
00069   private JScrollPane scrollPane;
00070 
00071   /**
00072    * Creates a new <code>GuiExceptionFrame.java</code> object
00073    * 
00074    * @param gui the parent frame
00075    */
00076   public GuiExceptionFrame(JFrame gui)
00077   {
00078     super(gui, true);
00079     setTitle(GuiTranslate.get("frame.exception.title"));
00080 
00081     
00082     GuiConstants.centerComponent(this,FRAME_WIDTH,SHORT_HEIGHT);
00083     setVisible(false);
00084 
00085     getContentPane().setLayout(new BorderLayout());
00086 
00087     GridLayout layout = new GridLayout(6, 1);
00088     JPanel messagePanel = new JPanel(layout);
00089     messagePanel.add(new JLabel(GuiTranslate.get("frame.exception.error.type")));
00090     classMessage = new JTextField(0);
00091     classMessage.setBackground(Color.white);
00092     classMessage.setAlignmentX(CENTER_ALIGNMENT);
00093     classMessage.setEditable(false);
00094     messagePanel.add(classMessage);
00095 
00096     messagePanel.add(new JLabel(GuiTranslate.get("frame.exception.error.message")));
00097     errorMessage = new JTextField(0);
00098     errorMessage.setBackground(Color.white);
00099     errorMessage.setAlignmentX(CENTER_ALIGNMENT);
00100     errorMessage.setEditable(false);
00101     messagePanel.add(errorMessage);
00102 
00103     // Trace
00104     JLabel label = new JLabel(GuiTranslate.get("frame.exception.stack.trace"));
00105     // Show/hide trace
00106     showMe = new JButton();
00107     showMe.addActionListener(this);
00108     setShowMeToShow();
00109 
00110     messagePanel.add(label);
00111     messagePanel.add(showMe);
00112 
00113     traceMessage = new JTextArea();
00114     traceMessage.setVisible(false);
00115     traceMessage.setAlignmentX(CENTER_ALIGNMENT);
00116     traceMessage.setEditable(false);
00117     traceMessage.setFont(GuiConstants.CENTER_PANE_FONT);
00118     traceMessage.setPreferredSize(new Dimension(FRAME_WIDTH, LONG_HEIGHT / 2));
00119     writer = new JTextAreaWriter(traceMessage);
00120     printWriter = new PrintWriter(writer);
00121     scrollPane = new JScrollPane();
00122     scrollPane.getViewport().add(traceMessage);
00123     scrollPane.setVisible(false);
00124 
00125     // on the left
00126     JButton iconPane = new JButton();
00127     Icon icon = GuiIcons.FRAME_ERROR_ICON;
00128     iconPane.setIcon(icon);
00129     Dimension dime = new Dimension(icon.getIconWidth(), icon.getIconHeight());
00130     iconPane.setMaximumSize(dime);
00131     iconPane.setPreferredSize(dime);
00132     iconPane.setActionCommand(GuiCommands.COMMAND_HIDE_ERROR_FRAME);
00133     iconPane.addActionListener(this);
00134     getContentPane().add(iconPane, BorderLayout.EAST);
00135 
00136     // on the center
00137     getContentPane().add(messagePanel, BorderLayout.CENTER);
00138     
00139     // on the right
00140     getContentPane().add(scrollPane, BorderLayout.SOUTH);
00141 
00142     setVisible(false);
00143     setBackground(Color.white);
00144     setDefaultCloseOperation(HIDE_ON_CLOSE);
00145     validate();
00146   }
00147 
00148   /**
00149    * Show the exception in a dialog box
00150    * 
00151    * @param e the exception
00152    */
00153   public void showException(Exception e)
00154   {
00155     errorMessage.setText(e.getMessage());
00156     classMessage.setText(e.getClass().getName());
00157     traceMessage.setText("");
00158     e.printStackTrace(printWriter);
00159     try
00160     {
00161       writer.flush();
00162     }
00163     catch (IOException e1)
00164     {
00165       // can't show, do not show
00166     }
00167     setVisible(true);
00168   }
00169 
00170   private void setShowMeToShow()
00171   {
00172     showMe.setText(GuiTranslate.get("frame.exception.show.trace"));
00173     showMe.setActionCommand(GuiCommands.COMMAND_SHOW_ERROR_TRACE);
00174     showMe.validate();
00175     showMe.repaint();
00176   }
00177 
00178   private void setShowMeToHide()
00179   {
00180     showMe.setText(GuiTranslate.get("frame.exception.hide.trace"));
00181     showMe.setActionCommand(GuiCommands.COMMAND_HIDE_ERROR_TRACE);
00182     showMe.validate();
00183     showMe.repaint();
00184   }
00185 
00186   /**
00187    * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
00188    */
00189   public void actionPerformed(ActionEvent e)
00190   {
00191     if (e.getActionCommand().equals(GuiCommands.COMMAND_HIDE_ERROR_FRAME))
00192     {
00193       scrollPane.setVisible(false);
00194       this.setVisible(false);
00195     }
00196     else if (e.getActionCommand().equals(GuiCommands.COMMAND_SHOW_ERROR_TRACE))
00197     {
00198       setSize(FRAME_WIDTH, LONG_HEIGHT);
00199       traceMessage.setVisible(true);
00200       scrollPane.setVisible(true);
00201       validate();
00202       repaint();
00203       scrollPane.repaint();
00204       setShowMeToHide();
00205     }
00206     else if (e.getActionCommand().equals(GuiCommands.COMMAND_HIDE_ERROR_TRACE))
00207     {
00208       setSize(FRAME_WIDTH, SHORT_HEIGHT);
00209       traceMessage.setVisible(false);
00210       scrollPane.setVisible(false);
00211       validate();
00212       repaint();
00213       scrollPane.repaint();
00214       setShowMeToShow();
00215     }
00216   }
00217 }

Generated on Mon Apr 11 22:01:32 2005 for C-JDBC by  doxygen 1.3.9.1