From fbe5e85e6017d757ae97a897690b31e897242b38 Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Fri, 10 Sep 2010 22:03:49 +0200 Subject: exception reporter for CLInfo. --- src/com/jogamp/opencl/demos/info/CLInfo.java | 21 ++- src/com/jogamp/opencl/util/64_35.png | Bin 0 -> 8705 bytes src/com/jogamp/opencl/util/ExceptionReporter.form | 129 +++++++++++++++++ src/com/jogamp/opencl/util/ExceptionReporter.java | 165 ++++++++++++++++++++++ 4 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 src/com/jogamp/opencl/util/64_35.png create mode 100644 src/com/jogamp/opencl/util/ExceptionReporter.form create mode 100644 src/com/jogamp/opencl/util/ExceptionReporter.java (limited to 'src') diff --git a/src/com/jogamp/opencl/demos/info/CLInfo.java b/src/com/jogamp/opencl/demos/info/CLInfo.java index af7e30c..0975f7b 100644 --- a/src/com/jogamp/opencl/demos/info/CLInfo.java +++ b/src/com/jogamp/opencl/demos/info/CLInfo.java @@ -4,24 +4,43 @@ package com.jogamp.opencl.demos.info; +import com.jogamp.common.JogampRuntimeException; import com.jogamp.opencl.CLDevice; import com.jogamp.opencl.CLPlatform; +import com.jogamp.opencl.util.ExceptionReporter; import java.awt.Container; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane; +import javax.swing.UIManager; /** - * + * Displays OpenCL information in a table. * @author Michael Bien */ public class CLInfo { public static void main(String[] args) { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (Exception ex) { + Logger.getLogger(CLInfo.class.getName()).log(Level.INFO, null, ex); + } + + try{ + CLPlatform.initialize(); + }catch(JogampRuntimeException ex) { + Logger.getLogger(CLInfo.class.getName()).log(Level.SEVERE, null, ex); + ExceptionReporter.appear("I tried hard but I really can't initialize JOCL. Is OpenCL properly set up?", ex); + return; + } + JFrame frame = new JFrame("OpenCL Info"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Container contentPane = frame.getContentPane(); diff --git a/src/com/jogamp/opencl/util/64_35.png b/src/com/jogamp/opencl/util/64_35.png new file mode 100644 index 0000000..507fdb5 Binary files /dev/null and b/src/com/jogamp/opencl/util/64_35.png differ diff --git a/src/com/jogamp/opencl/util/ExceptionReporter.form b/src/com/jogamp/opencl/util/ExceptionReporter.form new file mode 100644 index 0000000..d492479 --- /dev/null +++ b/src/com/jogamp/opencl/util/ExceptionReporter.form @@ -0,0 +1,129 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/jogamp/opencl/util/ExceptionReporter.java b/src/com/jogamp/opencl/util/ExceptionReporter.java new file mode 100644 index 0000000..17b92cc --- /dev/null +++ b/src/com/jogamp/opencl/util/ExceptionReporter.java @@ -0,0 +1,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("
").append(result.toString()).append("
"); + 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") + // //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(); + }// //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 + +} -- cgit v1.2.3