001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.modules.log;
019:
020: import java.awt.BorderLayout;
021: import java.lang.reflect.InvocationTargetException;
022: import java.util.logging.Level;
023: import java.util.logging.Logger;
024:
025: import javax.swing.JDialog;
026: import javax.swing.JOptionPane;
027: import javax.swing.JPanel;
028: import javax.swing.JScrollPane;
029: import javax.swing.JTextArea;
030: import javax.swing.SwingUtilities;
031:
032: import de.finix.contelligent.client.ContelligentClient;
033: import de.finix.contelligent.client.i18n.Resources;
034:
035: public class LogDetailDialog extends JOptionPane {
036:
037: private final static Logger logger = Logger
038: .getLogger(LogDetailDialog.class.getName());
039:
040: public final static void show(final String messageString) {
041: if (!SwingUtilities.isEventDispatchThread()) {
042: logger
043: .log(
044: Level.WARNING,
045: "Show was not called in AWT-Event-Thread even though it must - requeueing it now!");
046: try {
047: SwingUtilities.invokeAndWait(new Runnable() {
048: public void run() {
049: swingShow(messageString);
050: }
051: });
052: } catch (InterruptedException ie) {
053: logger.log(Level.WARNING,
054: "Interrupted while showing details", ie);
055: } catch (InvocationTargetException ite) {
056: logger
057: .log(Level.WARNING, "Could not show details",
058: ite);
059: }
060: } else {
061: swingShow(messageString);
062: }
063: }
064:
065: private final static void swingShow(String messageString) {
066: LogDetailDialog exceptionDialog = new LogDetailDialog(
067: messageString);
068: JDialog dialog = exceptionDialog.createDialog(
069: ContelligentClient.getActiveFrame(), Resources
070: .getLocalString("info"));
071: dialog.setVisible(true);
072: }
073:
074: public LogDetailDialog(String messageString) {
075:
076: JPanel messagePanel = new JPanel(new BorderLayout());
077:
078: JTextArea message = new JTextArea(messageString, 30, 120);
079: // message.setForeground(Color.red);
080: message.setEditable(false);
081: message.setOpaque(false);
082: message.setLineWrap(true);
083: // message.setWrapStyleWord(true);
084: JScrollPane messageScrollPane = new JScrollPane(message);
085: // messageScrollPane.setBorder(null);
086: messagePanel.add(messageScrollPane, BorderLayout.CENTER);
087:
088: /*
089: * StringWriter writer = new StringWriter(); PrintWriter printWriter =
090: * new PrintWriter(writer); throwable.printStackTrace(printWriter);
091: * JTextArea stack = new JTextArea(writer.toString(), 10, 50);
092: * stack.setEditable(false); stack.setOpaque(false); JScrollPane
093: * stackTrace = new JScrollPane(stack); messagePanel.add(stackTrace,
094: * BorderLayout.CENTER);
095: */
096:
097: Object[] array = { messagePanel };
098:
099: Object[] options = { Resources.getLocalString("ok") };
100:
101: setMessage(array);
102: setMessageType(JOptionPane.INFORMATION_MESSAGE);
103: setOptionType(JOptionPane.DEFAULT_OPTION);
104: setOptions(options);
105: setInitialValue(options[0]);
106: }
107: }
|