summaryrefslogtreecommitdiffstats
path: root/src/com/jogamp/opencl/util/ExceptionReporter.java
blob: 17b92cc3315a97a2bde142ac533df4d09ce992f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Created on Sep 10, 2010, 6:12:26 PM
 */

package com.jogamp.opencl.util;

import com.jogamp.common.JogampRuntimeException;
import java.awt.Component;
import java.awt.Desktop;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;

/*
 * Icon used in the dialog is from http://lazycrazy.deviantart.com/ released under the CC attibution license.
 */

/**
 *
 * @author Michael Bien
 */
public class ExceptionReporter extends JDialog {

    public ExceptionReporter(Frame parent, boolean modal) {
        super(parent, "Something went wrong", modal);
        initComponents();
    }

    public static void appear(String string, JogampRuntimeException ex) {
        ExceptionReporter reporter = new ExceptionReporter(null, true);
        reporter.setLocationRelativeTo(null);
        reporter.description.setText(string);

        StringBuilder sb = new StringBuilder();
        final Writer result = new StringWriter();
        ex.printStackTrace(new PrintWriter(result));

        sb.append("<pre>").append(result.toString()).append("</pre>");
        reporter.messagePane.setText(sb.toString());
        reporter.setVisible(true);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        JLabel icon = new JLabel();
        JButton reportButton = new JButton();
        JButton okButton = new JButton();
        JScrollPane jScrollPane1 = new JScrollPane();
        messagePane = new JEditorPane();
        JScrollPane jScrollPane2 = new JScrollPane();
        description = new JTextPane();

        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

        icon.setIcon(new ImageIcon(getClass().getResource("/com/jogamp/opencl/util/64_35.png"))); // NOI18N

        reportButton.setText("not at all. I file a bug!");
        reportButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                reportButtonActionPerformed(evt);
            }
        });

        okButton.setText("understood");
        okButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        messagePane.setContentType("text/html");
        messagePane.setEditable(false);
        jScrollPane1.setViewportView(messagePane);

        description.setEditable(false);
        description.setFocusable(false);
        jScrollPane2.setViewportView(description);

        GroupLayout layout = new GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(icon)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(Alignment.LEADING)
                            .addComponent(jScrollPane2, GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
                            .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)))
                    .addGroup(Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(okButton)
                        .addPreferredGap(ComponentPlacement.UNRELATED)
                        .addComponent(reportButton)))
                .addContainerGap())
        );

        layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {okButton, reportButton});

        layout.setVerticalGroup(
            layout.createParallelGroup(Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(Alignment.LEADING)
                    .addComponent(icon)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)))
                .addPreferredGap(ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(Alignment.BASELINE)
                    .addComponent(reportButton)
                    .addComponent(okButton))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void reportButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_reportButtonActionPerformed
        try {
            Desktop.getDesktop().browse(URI.create("http://www.jogamp.org/bugzilla/"));
        } catch (IOException ex) {
            Logger.getLogger(ExceptionReporter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_reportButtonActionPerformed

    private void okButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
        dispose();
    }//GEN-LAST:event_okButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private JTextPane description;
    private JEditorPane messagePane;
    // End of variables declaration//GEN-END:variables

}