Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JavaCL - Java API and utilities for OpenCL
   * http://javacl.googlecode.com/
   *
   * Copyright (c) 2009-2011, Olivier Chafik (http://ochafik.com/)
   * All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met:
  * 
  *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above copyright
  *       notice, this list of conditions and the following disclaimer in the
  *       documentation and/or other materials provided with the distribution.
  *     * Neither the name of Olivier Chafik nor the
  *       names of its contributors may be used to endorse or promote products
  *       derived from this software without specific prior written permission.
  * 
  * THIS SOFTWARE IS PROVIDED BY OLIVIER CHAFIK AND CONTRIBUTORS ``AS IS'' AND ANY
  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 package com.nativelibs4java.opencl.demos;
 
 import java.util.List;
 import  javax.media.opengl.GLCapabilities;
 import  javax.media.opengl.GLCapabilitiesChooser;
 import  javax.media.opengl.GLProfile;

Author(s):
ochafik
 
 public class JavaCLSettingsPanel extends javax.swing.JPanel {

    
 
 	private static final long serialVersionUID = -3840797355369910724L;
 
 	public void removeOpenGLComponents() {
         invalidate();
     }
    
    
Creates new form JavaCLSettingsPanel
 
     public JavaCLSettingsPanel() {
         initComponents();
 
         Border border = UIManager.getBorder"TitledBorder.aquaVariant" );
         if (border == null)
             border = new EtchedBorder();
         .setBorder(new TitledBorder(border"OpenCL & OpenGL Settings"));
         platformChanged(null);
         normalButtActionPerformed(null);
     }
 
     public boolean isDirectGLRendering() {
         return .isSelected();
     }
     public void setDirectGLRendering(boolean b) {
         .setSelected(b);
     }
 
     public CLDevice getDevice() {
         return (CLDevice).getSelectedItem();
     }
 
     public List<CLPlatformgetPlatforms() {
         CLPlatform[] platforms = JavaCL.listPlatforms();
         boolean hasSharing = false;
         plat: for (CLPlatform platform : platforms)
             if (platform.isGLSharingSupported())
                 for (CLDevice device : platform.listAllDevices(false)) 
                     if (device.isGLSharingSupported()) {
                        hasSharing = true;
                        break plat;
                    }
        .setEnabled(hasSharing);
        if (!hasSharing) {
            .setText(.getText() + " (unavailable option)");
            .setToolTipText("Did not find any OpenCL platform with OpenGL sharing support.");
        }
        
        return Arrays.asList(platforms);
    }
    public List<StringgetGLProfiles() {
        List<Stringlist = new ArrayList<String>();
        list.add(GLProfile.GL2);
        return list;
    }

    
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() {
         = new javax.swing.JPanel();
         = new javax.swing.JButton();
         = new javax.swing.JButton();
         = new javax.swing.JButton();
         = new javax.swing.JButton();
         = new javax.swing.JCheckBox();
         = new javax.swing.JCheckBox();
         = new javax.swing.JLabel();
         = new javax.swing.JComboBox();
         = new javax.swing.JLabel();
         = new javax.swing.JComboBox();
        .setText("Fastest (unstable)");
        .setToolTipText("Best performance, typically unstable.");
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fastestButtActionPerformed(evt);
            }
        });
        .setText("Safest (slow)");
        .setToolTipText("Choose this if you've experienced crashes or black screens with the other modes");
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                safestButtActionPerformed(evt);
            }
        });
        .setText("Normal (advised)");
        .setToolTipText("Usually the best compromise.");
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                normalButtActionPerformed(evt);
            }
        });
        .setText("Details");
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                detailsButtActionPerformed(evt);
            }
        });
        .setSelected(true);
        .setText("Direct OpenGL AWT Rendering (faster)");
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                awtRenderingCheckActionPerformed(evt);
            }
        });
        .setText("Configure from OpenGL context");
        .setToolTipText("Attempt to share data between OpenCL and OpenGL. \nThis is not well supported by existing graphic card drivers might crash the program.");
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                configFromGLChanged(evt);
            }
        });
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                configFromGLCheckActionPerformed(evt);
            }
        });
        .setText("Platform");
        .setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1""Item 2""Item 3""Item 4" }));
        .setMinimumSize(new java.awt.Dimension(16, 27));
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                platformChanged(evt);
            }
        });
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                platformComboActionPerformed(evt);
            }
        });
        .setText("Device");
        .setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1""Item 2""Item 3""Item 4" }));
        .setMinimumSize(new java.awt.Dimension(16, 27));
        org.jdesktop.layout.GroupLayout settingsPanelLayout = new org.jdesktop.layout.GroupLayout();
        .setLayout(settingsPanelLayout);
        settingsPanelLayout.setHorizontalGroup(
            settingsPanelLayout.createParallelGroup(....)
            .add(settingsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(settingsPanelLayout.createParallelGroup(....)
                    .add()
                    .add())
                .addPreferredGap(....)
                .add(settingsPanelLayout.createParallelGroup(....)
                    .add(settingsPanelLayout.createSequentialGroup()
                        .add()
                        .addPreferredGap(....)
                        .add(...., 170, .)
                        .addPreferredGap(....)
                    .add()
                    .add()
                    .add(....settingsPanelLayout.createSequentialGroup()
                        .add(, 0, 354, .)
                        .addPreferredGap(....)
                        .add())
                    .add(...., 0, 448, .))
                .addContainerGap())
        );
        settingsPanelLayout.setVerticalGroup(
            settingsPanelLayout.createParallelGroup(....)
            .add(....settingsPanelLayout.createSequentialGroup()
                .add(settingsPanelLayout.createParallelGroup(....)
                .addPreferredGap(....)
                .add()
                .addPreferredGap(....)
                .add(settingsPanelLayout.createParallelGroup(....)
                    .add()
                    .add())
                .addPreferredGap(....)
                .add(settingsPanelLayout.createParallelGroup(....)
                    .add())
                .addPreferredGap(....)
                .add())
        );
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
        );
        layout.setVerticalGroup(
        );
    }// </editor-fold>//GEN-END:initComponents
    private void configFromGLCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configFromGLCheckActionPerformed
        
    }//GEN-LAST:event_configFromGLCheckActionPerformed
    private void awtRenderingCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_awtRenderingCheckActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_awtRenderingCheckActionPerformed
    private void platformComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_platformComboActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_platformComboActionPerformed
    private void platformChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_platformChanged
        CLPlatform platform = (CLPlatform).getSelectedItem();
        if (platform != null) {
            CLDevice[] devices = platform.listAllDevices(true);
            .setModel(new DefaultComboBoxModel(devices));
            setDevice(platform.getBestDevice());
        } else {
            .setModel(new DefaultComboBoxModel(new Object[0]));
        }
    }//GEN-LAST:event_platformChanged
    private void fastestButtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fastestButtActionPerformed
        selectBestDevice();
        if (.isEnabled())
            .setSelected(true);
        if (.isEnabled())
            .setSelected(true);
    }//GEN-LAST:event_fastestButtActionPerformed
    private void normalButtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_normalButtActionPerformed
        selectBestDevice();
        if (.isEnabled())
            .setSelected(true);
        if (.isEnabled())
            .setSelected(false);
    }//GEN-LAST:event_normalButtActionPerformed
    private void safestButtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_safestButtActionPerformed
        selectBestDevice();
        if (.isEnabled())
            .setSelected(false);
        if (.isEnabled())
            .setSelected(false);
    }//GEN-LAST:event_safestButtActionPerformed
    private void configFromGLChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_configFromGLChanged
    }//GEN-LAST:event_configFromGLChanged
    private void detailsButtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detailsButtActionPerformed
        CLPlatform platform = (CLPlatform).getSelectedItem();
        if (platform != null) {
            JComponent c = HardwareReport.getHardwareReportComponent(platform);
            c.setMaximumSize(new Dimension(600, 600));
            c.setPreferredSize(new Dimension(600, 600));
            JOptionPane.showMessageDialog(thisc"HardwareReport for platform '" + platform.getName() + "'".);
        }
    }//GEN-LAST:event_detailsButtActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton detailsButt;
    private javax.swing.JComboBox deviceCombo;
    private javax.swing.JLabel deviceLab;
    private javax.swing.JButton fastestButt;
    private javax.swing.JButton normalButt;
    private javax.swing.JLabel platformLab;
    private javax.swing.JButton safestButt;
    private javax.swing.JPanel settingsPanel;
    // End of variables declaration//GEN-END:variables
    private void setDevice(CLDevice device) {
        if (device == null) {
            .setSelectedIndex(-1);
            return;
        }
        CLPlatform platform = device.getPlatform();
        if (!platform.equals(.getSelectedItem()))
            .setSelectedItem(platform);
        for (int i = 0, len = .getModel().getSize(); i < leni++) {
            CLDevice d = (CLDevice).getModel().getElementAt(i);
            if (device.equals(d)) {
                .setSelectedItem(d);
                break;
            }
        }
    }
    private void selectBestDevice() {
        setDevice(JavaCL.getBestDevice());
    }
    public boolean isGLSharingEnabled() {
    }
    public void setGLSharingEnabled(boolean b) {
        if (.isEnabled())
            .setSelected(b);
    }
New to GrepCode? Check out our FAQ X