package org.bdgp.MMSlide;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import static org.bdgp.MMSlide.Util.map;

public class Main {
    public static Map<String,String> getConfig() {
        return map("server.port","9001");
    }
    public static void main(String[] args) throws InvocationTargetException, InterruptedException {
        // try to set look and feel on Linux OS
        if (System.getProperty("os.name").equals("Linux")) {
            try { UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Exception e) {}
            try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); } catch (Exception e) {}
        }
        
        // open the slide workflow dialog
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                final WorkflowDialog dialog = new WorkflowDialog();
                dialog.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                dialog.pack();
                dialog.setVisible(true);
                
                Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                    public void uncaughtException(Thread t, Throwable e) {
                        StringWriter sw = new StringWriter();
                        PrintWriter pw = new PrintWriter(sw);
                        e.printStackTrace(pw);
                        System.err.println(sw.toString());
                        
                        JTextArea text = new JTextArea(sw.toString());
                        text.setEditable(false);
                        JOptionPane.showMessageDialog(dialog, text);
                        dialog.dispose();
                    }
                });
            }
        });
    }
}

@@ -20,16 +20,43 @@
 Slide;%0A%0A
+import java.awt.Dimension;%0A
 import j
@@ -67,32 +67,32 @@
 io.PrintWriter;%0A
-
 import java.io.S
@@ -238,16 +238,48 @@
 onPane;%0A
+import javax.swing.JScrollPane;%0A
 import j
@@ -1330,32 +1330,166 @@
                %0A
+                // Handle uncaught exceptions by print to stderr and displaying a GUI%0A                // window with the stack trace.%0A
                 
@@ -1566,24 +1566,54 @@
 Handler() %7B%0A
+                    @Override%0A
             
@@ -2046,24 +2046,288 @@
 ble(false);%0A
+                        JScrollPane textScrollPane = new JScrollPane(text);%0A                        textScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);%0A                        textScrollPane.setPreferredSize(new Dimension(800, 600));%0A
             
@@ -2376,24 +2376,34 @@
 dialog, text
+ScrollPane
 );%0A         

make the stacktrace message scrollable