Jogamp
initial import of GLInfo html demo.
authorMichael Bien <mbien@fh-landshut.de>
Tue, 7 Sep 2010 21:32:37 +0000 (23:32 +0200)
committerMichael Bien <mbien@fh-landshut.de>
Tue, 7 Sep 2010 21:32:37 +0000 (23:32 +0200)
src/com/jogamp/opencl/demos/info/CLInfo.java [new file with mode: 0644]

diff --git a/src/com/jogamp/opencl/demos/info/CLInfo.java b/src/com/jogamp/opencl/demos/info/CLInfo.java
new file mode 100644 (file)
index 0000000..af7e30c
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * Created on Tuesday, September 07 2010 21:33
+ */
+
+package com.jogamp.opencl.demos.info;
+
+import com.jogamp.opencl.CLDevice;
+import com.jogamp.opencl.CLPlatform;
+import java.awt.Container;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import javax.swing.JEditorPane;
+import javax.swing.JFrame;
+import javax.swing.JScrollPane;
+
+/**
+ *
+ * @author Michael Bien
+ */
+public class CLInfo {
+
+    public static void main(String[] args) {
+
+        JFrame frame = new JFrame("OpenCL Info");
+        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+        Container contentPane = frame.getContentPane();
+
+        JEditorPane area = new JEditorPane();
+        area.setContentType("text/html");
+        area.setEditable(false);
+
+        contentPane.add(new JScrollPane(area));
+
+        String html = createOpenCLInfoHTML();
+
+        area.setText(html.toString());
+
+        frame.setSize(800, 600);
+        frame.setVisible(true);
+
+    }
+
+    private static String createOpenCLInfoHTML() {
+
+        StringBuilder html = new StringBuilder();
+
+        html.append("<table border=\"1\">");
+        CLPlatform[] platforms = CLPlatform.listCLPlatforms();
+
+        // platforms
+        List<Map<String, String>> platProps = new ArrayList<Map<String, String>>();
+        List<Integer> spans = new ArrayList<Integer>();
+        for (CLPlatform p : platforms) {
+            platProps.add(p.getProperties());
+            spans.add(p.listCLDevices().length);
+        }
+        fillTable(platProps, spans, html);
+
+        // devices
+        ArrayList<Map<String, String>> devProps = new ArrayList<Map<String, String>>();
+        for (CLPlatform p : platforms) {
+            CLDevice[] devices = p.listCLDevices();
+            for (CLDevice d : devices) {
+                devProps.add(d.getProperties());
+            }
+        }
+        fillTable(devProps, html);
+        html.append("</table>");
+
+        return html.toString();
+    }
+
+    private static void fillTable(List<Map<String, String>> properties, StringBuilder sb) {
+        ArrayList<Integer> spans = new ArrayList<Integer>(properties.size());
+        for (int i = 0; i < properties.size(); i++) {
+            spans.add(1);
+        }
+        fillTable(properties, spans, sb);
+    }
+
+    private static void fillTable(List<Map<String, String>> properties, List<Integer> spans, StringBuilder sb) {
+        boolean header = true;
+        for (String key : properties.get(0).keySet()) {
+            sb.append("<tr>");
+                cell(sb, key);
+                int i = 0;
+                for (Map<String, String> map : properties) {
+                    cell(sb, spans.get(i), map.get(key), header);
+                    i++;
+                }
+            sb.append("</tr>");
+            header = false;
+        }
+    }
+
+    private static void cell(StringBuilder sb, String value) {
+        sb.append("<td>").append(value).append("</td>");
+    }
+
+    private static void cell(StringBuilder sb, int span, String value, boolean header) {
+        if(header) {
+            sb.append("<th colspan=\"").append(span).append("\">").append(value).append("</th>");
+        }else{
+            sb.append("<td colspan=\"").append(span).append("\">").append(value).append("</td>");
+        }
+    }
+}
http://JogAmp.org git info: FAQ, tutorial and man pages.