From f5c7b0fa69c72ed3c1e6cca466b0dfaeac36f15c Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 7 Sep 2010 23:32:37 +0200 Subject: initial import of GLInfo html demo. --- src/com/jogamp/opencl/demos/info/CLInfo.java | 108 +++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/com/jogamp/opencl/demos/info/CLInfo.java diff --git a/src/com/jogamp/opencl/demos/info/CLInfo.java b/src/com/jogamp/opencl/demos/info/CLInfo.java new file mode 100644 index 0000000..af7e30c --- /dev/null +++ b/src/com/jogamp/opencl/demos/info/CLInfo.java @@ -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(""); + CLPlatform[] platforms = CLPlatform.listCLPlatforms(); + + // platforms + List> platProps = new ArrayList>(); + List spans = new ArrayList(); + for (CLPlatform p : platforms) { + platProps.add(p.getProperties()); + spans.add(p.listCLDevices().length); + } + fillTable(platProps, spans, html); + + // devices + ArrayList> devProps = new ArrayList>(); + for (CLPlatform p : platforms) { + CLDevice[] devices = p.listCLDevices(); + for (CLDevice d : devices) { + devProps.add(d.getProperties()); + } + } + fillTable(devProps, html); + html.append("
"); + + return html.toString(); + } + + private static void fillTable(List> properties, StringBuilder sb) { + ArrayList spans = new ArrayList(properties.size()); + for (int i = 0; i < properties.size(); i++) { + spans.add(1); + } + fillTable(properties, spans, sb); + } + + private static void fillTable(List> properties, List spans, StringBuilder sb) { + boolean header = true; + for (String key : properties.get(0).keySet()) { + sb.append(""); + cell(sb, key); + int i = 0; + for (Map map : properties) { + cell(sb, spans.get(i), map.get(key), header); + i++; + } + sb.append(""); + header = false; + } + } + + private static void cell(StringBuilder sb, String value) { + sb.append("").append(value).append(""); + } + + private static void cell(StringBuilder sb, int span, String value, boolean header) { + if(header) { + sb.append("").append(value).append(""); + }else{ + sb.append("").append(value).append(""); + } + } +} -- cgit v1.2.3