view.FramePrincipal.java Source code

Java tutorial

Introduction

Here is the source code for view.FramePrincipal.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import control.DadosEstatisticos;
import control.JGeraGraficos;
import control.JOCLRenderizador;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import util.JLabelImagem;

/**
 *
 * @author Lavinia
 */
public class FramePrincipal extends javax.swing.JFrame {

    public FramePrincipal() {
        initComponents();
        initKernels();

    }

    /**
     * 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() {

        jRbtGroupAction = new javax.swing.ButtonGroup();
        jPanelImagem1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jPanelSecundario = new javax.swing.JPanel();
        jPanelParciais = new javax.swing.JPanel();
        JbtnGrafico = new javax.swing.JButton();
        jrbtJava = new javax.swing.JRadioButton();
        jRbtJavaThread = new javax.swing.JRadioButton();
        jRbtOpenCl = new javax.swing.JRadioButton();
        jBtnExecutar = new javax.swing.JButton();
        jPanellInfo = new javax.swing.JPanel();
        jPanelImagem2 = new javax.swing.JPanel();
        JlabelInfo = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JOCL Renderizador de Imagem");
        setBounds(new java.awt.Rectangle(50, 80, 1248, 600));
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jPanelImagem1
                .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanelImagem1.setPreferredSize(new java.awt.Dimension(479, 532));

        jLabel2.setText("Imagem Principal");

        javax.swing.GroupLayout jPanelImagem1Layout = new javax.swing.GroupLayout(jPanelImagem1);
        jPanelImagem1.setLayout(jPanelImagem1Layout);
        jPanelImagem1Layout.setHorizontalGroup(
                jPanelImagem1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanelImagem1Layout.createSequentialGroup().addContainerGap()
                                .addComponent(jLabel2).addContainerGap(385, Short.MAX_VALUE)));
        jPanelImagem1Layout.setVerticalGroup(jPanelImagem1Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(jPanelImagem1Layout
                        .createSequentialGroup().addComponent(jLabel2).addGap(0, 0, Short.MAX_VALUE)));

        jPanelSecundario
                .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
        jPanelSecundario.setPreferredSize(new java.awt.Dimension(479, 532));

        jPanelParciais
                .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        JbtnGrafico.setIcon(new javax.swing.ImageIcon(getClass().getResource("/util/3d_bar_chart.png"))); // NOI18N
        JbtnGrafico.setLabel("  Estatistica");
        JbtnGrafico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JbtnGraficoActionPerformed(evt);
            }
        });

        jRbtGroupAction.add(jrbtJava);
        jrbtJava.setSelected(true);
        jrbtJava.setText("Java");
        jrbtJava.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jrbtJava.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbtJavaActionPerformed(evt);
            }
        });

        jRbtGroupAction.add(jRbtJavaThread);
        jRbtJavaThread.setText("Thread Java");
        jRbtJavaThread.setBorder(javax.swing.BorderFactory.createCompoundBorder());

        jRbtGroupAction.add(jRbtOpenCl);
        jRbtOpenCl.setText("Api OpenCL");
        jRbtOpenCl.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jBtnExecutar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/util/execute.jpg"))); // NOI18N
        jBtnExecutar.setText("  Executar");
        jBtnExecutar.setPreferredSize(new java.awt.Dimension(113, 33));
        jBtnExecutar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnExecutarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelParciaisLayout = new javax.swing.GroupLayout(jPanelParciais);
        jPanelParciais.setLayout(jPanelParciaisLayout);
        jPanelParciaisLayout.setHorizontalGroup(jPanelParciaisLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelParciaisLayout.createSequentialGroup()
                        .addGap(54, 54, 54).addComponent(jrbtJava).addGap(70, 70, 70).addComponent(jRbtJavaThread)
                        .addGap(54, 54, 54).addComponent(jRbtOpenCl).addGap(38, 38, 38)
                        .addComponent(jBtnExecutar, javax.swing.GroupLayout.PREFERRED_SIZE, 138,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                        .addComponent(JbtnGrafico, javax.swing.GroupLayout.PREFERRED_SIZE, 142,
                                javax.swing.GroupLayout.PREFERRED_SIZE)));
        jPanelParciaisLayout.setVerticalGroup(jPanelParciaisLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelParciaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(JbtnGrafico, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jrbtJava).addComponent(jRbtJavaThread).addComponent(jRbtOpenCl)
                        .addComponent(jBtnExecutar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)));

        jPanellInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Parciais",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION));

        javax.swing.GroupLayout jPanellInfoLayout = new javax.swing.GroupLayout(jPanellInfo);
        jPanellInfo.setLayout(jPanellInfoLayout);
        jPanellInfoLayout.setHorizontalGroup(jPanellInfoLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 182, Short.MAX_VALUE));
        jPanellInfoLayout.setVerticalGroup(jPanellInfoLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 469, Short.MAX_VALUE));

        javax.swing.GroupLayout jPanelImagem2Layout = new javax.swing.GroupLayout(jPanelImagem2);
        jPanelImagem2.setLayout(jPanelImagem2Layout);
        jPanelImagem2Layout.setHorizontalGroup(jPanelImagem2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 519, Short.MAX_VALUE));
        jPanelImagem2Layout.setVerticalGroup(jPanelImagem2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 492, Short.MAX_VALUE));

        javax.swing.GroupLayout jPanelSecundarioLayout = new javax.swing.GroupLayout(jPanelSecundario);
        jPanelSecundario.setLayout(jPanelSecundarioLayout);
        jPanelSecundarioLayout.setHorizontalGroup(jPanelSecundarioLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelSecundarioLayout.createSequentialGroup().addContainerGap()
                        .addComponent(jPanelImagem2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanellInfo, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addComponent(jPanelParciais, javax.swing.GroupLayout.DEFAULT_SIZE,
                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
        jPanelSecundarioLayout.setVerticalGroup(
                jPanelSecundarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                        javax.swing.GroupLayout.Alignment.TRAILING,
                        jPanelSecundarioLayout.createSequentialGroup()
                                .addGroup(jPanelSecundarioLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jPanellInfo, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jPanelImagem2, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanelParciais, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)));

        JlabelInfo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        JlabelInfo.setForeground(java.awt.Color.red);
        JlabelInfo.setText("    ");

        jMenuBar1.setName("jMenuFile"); // NOI18N

        jMenu1.setText("Menu");

        jMenuItem2.setText("Inserir Imagem");
        jMenuItem2.setName("jMenuItemImagem"); // NOI18N
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuItem1.setText("Exemplo Secundario");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup().addContainerGap()
                        .addComponent(jPanelImagem1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(JlabelInfo).addComponent(jPanelSecundario,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, 733,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(20, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jPanelSecundario, javax.swing.GroupLayout.DEFAULT_SIZE, 539,
                                        Short.MAX_VALUE)
                                .addComponent(jPanelImagem1, javax.swing.GroupLayout.DEFAULT_SIZE, 539,
                                        Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JlabelInfo).addGap(0, 10, Short.MAX_VALUE)));
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem2ActionPerformed(ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        setaImagensPrincipais();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jrbtJavaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtJavaActionPerformed

    }//GEN-LAST:event_jrbtJavaActionPerformed

    private void jBtnExecutarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnExecutarActionPerformed
        if ("".equals(dirImagemPrincipal)) {
            JOptionPane.showMessageDialog(this, "Selecione uma Imagem Principal a ser Trabalhada ", "Aviso",
                    JOptionPane.INFORMATION_MESSAGE);
            setaImagensPrincipais();
        } else {
            ExecutarProcesso();
        }
    }//GEN-LAST:event_jBtnExecutarActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

    }//GEN-LAST:event_formWindowOpened

    private void JbtnGraficoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbtnGraficoActionPerformed
        if ("".equals(dirImagemPrincipal)) {
            JOptionPane.showMessageDialog(this, "Selecione uma Imagem Principal a ser Trabalhada ", "Aviso",
                    JOptionPane.INFORMATION_MESSAGE);
            setaImagensPrincipais();
        } else {
            GerarGraficoEstatistico();

            System.out.println("Java");
            for (DadosEstatisticos d : listaDadosEstatisticosJava) {
                System.out.println(d.toString());
            }
            System.out.println("Opencl");
            for (DadosEstatisticos d : listaDadosEstatisticosOPENCL) {
                System.out.println(d.toString());
            }

        }

    }//GEN-LAST:event_JbtnGraficoActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        JFrameSegExemplo frame = new JFrameSegExemplo();
        frame.setBounds(50, 80, 210, 450);
        frame.setVisible(true); // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException
                | javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FramePrincipal.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new FramePrincipal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JbtnGrafico;
    private javax.swing.JLabel JlabelInfo;
    private javax.swing.JButton jBtnExecutar;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanelImagem1;
    private javax.swing.JPanel jPanelImagem2;
    private javax.swing.JPanel jPanelParciais;
    private javax.swing.JPanel jPanelSecundario;
    private javax.swing.JPanel jPanellInfo;
    private javax.swing.ButtonGroup jRbtGroupAction;
    private javax.swing.JRadioButton jRbtJavaThread;
    private javax.swing.JRadioButton jRbtOpenCl;
    private javax.swing.JRadioButton jrbtJava;
    // End of variables declaration//GEN-END:variables

    // Variaveis      
    public String dirImagemPrincipal = "";

    private BufferedImage inputImage, outputImage, infoImage;
    private List<Kernel> kernels = null;
    private List<String> kernelNames = null;
    private List<DadosEstatisticos> listaDadosEstatisticosJava = null;
    private List<DadosEstatisticos> listaDadosEstatisticosOPENCL = null;
    private List<DadosEstatisticos> listaDadosEstatisticosJavaTHREAD = null;

    // Metodos 
    public static String truncate(String value, int length) {
        if (value != null && value.length() > length) {
            value = value.substring(0, length);
        }
        return value;
    }

    private static BufferedImage createBufferedImage(String fileName) {
        BufferedImage image = null;
        try {
            image = ImageIO.read(new File(fileName));
        } catch (IOException e) {
            return null;
        }

        int sizeX = image.getWidth();
        int sizeY = image.getHeight();

        BufferedImage result = new BufferedImage(sizeX, sizeY, BufferedImage.TYPE_INT_RGB);
        Graphics g = result.createGraphics();
        g.drawImage(image, 0, 0, null);
        g.dispose();
        return result;
    }

    public String retornaDiretorioArquivo(String[] TipoArquivo) {
        String dir = "";
        JFileChooser _fileChooser = new JFileChooser();

        int retval = _fileChooser.showOpenDialog(this);
        final String[] okFileExtensions = TipoArquivo;
        File file;
        if (retval == JFileChooser.APPROVE_OPTION) {
            file = _fileChooser.getSelectedFile();
            Boolean flag = false;

            for (String extension : okFileExtensions) {
                if (file.getName().toLowerCase().endsWith(extension)) {
                    flag = true;
                }
            }
            if (!flag) {
                JOptionPane.showMessageDialog(this,
                        "Selecione um Arquivo do tipo " + java.util.Arrays.toString(TipoArquivo), "Erro",
                        JOptionPane.ERROR_MESSAGE);
                retornaDiretorioArquivo(TipoArquivo);
            }

            if (_fileChooser.getSelectedFile().exists()) {
                dir = _fileChooser.getSelectedFile().toString();
            }
            LimpaPanels();
        }
        return dir;
    }

    private void setaImagensPrincipais() {
        String aux = "";
        String tipoImgs[] = { "png", "jpg", "jpeg" };
        aux = retornaDiretorioArquivo(tipoImgs);
        if (!"".equals(aux)) {
            dirImagemPrincipal = aux;

            inputImage = createBufferedImage(dirImagemPrincipal);
            JLabelImagem lblInput = new JLabelImagem(inputImage);
            lblInput.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            jPanelImagem1.setBounds(3, 5, 479, 532);
            lblInput.setBounds(jPanelImagem1.getBounds());
            jPanelImagem1.add(lblInput, BorderLayout.BEFORE_LINE_BEGINS);
        }
    }

    private void LimpaPanels() {
        jPanelImagem1.removeAll();
        jPanelImagem2.removeAll();
        jPanellInfo.removeAll();
        jPanelImagem1.revalidate();
        jPanelImagem1.repaint();
        jPanelImagem2.revalidate();
        jPanelImagem2.repaint();
        jPanellInfo.revalidate();
        jPanellInfo.repaint();
        JlabelInfo.setText("");
    }

    private void LimpaPanelsPreExecucao() {
        jPanelImagem2.removeAll();
        jPanellInfo.removeAll();
        jPanelImagem2.revalidate();
        jPanelImagem2.repaint();
        jPanellInfo.revalidate();
        jPanellInfo.repaint();
        JlabelInfo.setText("");
    }

    private void LimpaTela() {
        dirImagemPrincipal = "";
        LimpaPanels();
    }

    private void ExecutarProcesso() {
        LimpaPanelsPreExecucao();
        int sizeX = inputImage.getWidth();
        int sizeY = inputImage.getHeight();

        outputImage = new BufferedImage(sizeX, sizeY, BufferedImage.TYPE_INT_RGB);

        if (jrbtJava.isSelected()) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    listaDadosEstatisticosJava.clear();
                    for (int i = 0; i < kernels.size(); i++) {
                        Kernel kernel = kernels.get(i);
                        applyKernelJava(kernel, kernelNames.get(i));
                        jPanelImagem2.removeAll();
                        JLabelImagem lblOutput = new JLabelImagem(outputImage);
                        jPanelImagem2.setBounds(2, 3, 530, 488);
                        lblOutput.setBounds(jPanelImagem2.getBounds());
                        jPanelImagem2.add(lblOutput, BorderLayout.BEFORE_LINE_BEGINS);
                        jPanelImagem2.revalidate();
                        jPanelImagem2.repaint();

                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }

                    ImprimePainelGraficoParcial();
                }
            }).start();

        } else if (jRbtOpenCl.isSelected()) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    listaDadosEstatisticosOPENCL.clear();
                    for (int i = 0; i < kernels.size(); i++) {
                        Kernel kernel = kernels.get(i);
                        applyKernelOpenCl(kernel, kernelNames.get(i));
                        jPanelImagem2.removeAll();
                        JLabelImagem lblOutput = new JLabelImagem(outputImage);
                        jPanelImagem2.setBounds(2, 3, 530, 488);
                        lblOutput.setBounds(jPanelImagem2.getBounds());
                        jPanelImagem2.add(lblOutput, BorderLayout.BEFORE_LINE_BEGINS);
                        jPanelImagem2.revalidate();
                        jPanelImagem2.repaint();
                        try {
                            Thread.sleep(3000);
                        } catch (InterruptedException ex) {
                            Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }

                    ImprimePainelGraficoParcial();
                }
            }).start();

        } else if (jRbtJavaThread.isSelected()) {
            new Thread(new Runnable() {
                @Override
                public void run() {

                    synchronized (this) {
                        listaDadosEstatisticosJavaTHREAD.clear();
                        for (int i = 0; i < kernels.size(); i++) {
                            Kernel kernel = kernels.get(i);
                            applyKernelJavaThread(kernel, kernelNames.get(i));
                            jPanelImagem2.removeAll();
                            JLabelImagem lblOutput = new JLabelImagem(outputImage);
                            jPanelImagem2.setBounds(2, 3, 530, 488);
                            lblOutput.setBounds(jPanelImagem2.getBounds());
                            jPanelImagem2.add(lblOutput, BorderLayout.BEFORE_LINE_BEGINS);
                            jPanelImagem2.revalidate();
                            jPanelImagem2.repaint();

                            try {
                                Thread.sleep(3000);
                            } catch (InterruptedException ex) {
                                Logger.getLogger(FramePrincipal.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                        ImprimePainelGraficoParcial();
                    }
                }
            }).start();
        }
    }

    private void initRedimencionarKernel(int kernelSize) {
        int kernelSizeX = kernelSize;
        int kernelSizeY = kernelSize;
        int size = kernelSizeX * kernelSizeY;
        float value = 1.0f / size;
        float kernelData[] = new float[size];
        for (int i = 0; i < size; i++) {
            kernelData[i] = value;
        }
        kernels.add(new Kernel(kernelSizeX, kernelSizeY, kernelData));
        kernelNames.add("Redimencionar Pixel - " + kernelSizeX + "x" + kernelSizeY);
    }

    @SuppressWarnings("Convert2Diamond")
    private void initKernels() {
        kernels = new ArrayList<Kernel>();
        kernelNames = new ArrayList<String>();
        listaDadosEstatisticosJava = new ArrayList<DadosEstatisticos>();
        listaDadosEstatisticosOPENCL = new ArrayList<DadosEstatisticos>();
        listaDadosEstatisticosJavaTHREAD = new ArrayList<DadosEstatisticos>();

        int kernelSizeX = 0;
        int kernelSizeY = 0;
        float kernelData[] = null;

        // Edge detection
        kernelSizeX = 3;
        kernelSizeY = 3;
        kernelData = new float[] { -1, 0, -1, 0, 4, 0, -1, 0, -1 };
        kernels.add(new Kernel(kernelSizeX, kernelSizeY, kernelData));
        kernelNames.add("Negativar");

        // Sharpen
        kernelSizeX = 3;
        kernelSizeY = 3;
        kernelData = new float[] { -1, 0, -1, 0, 5, 0, -1, 0, -1 };
        kernels.add(new Kernel(kernelSizeX, kernelSizeY, kernelData));
        kernelNames.add("Desbotar");

        // Blur
        for (int i = 3; i <= 21; i += 2) {
            initRedimencionarKernel(i);
        }
    }

    private void applyKernelJava(Kernel kernel, String DescricaoKernel) {
        long before = 0;
        long after = 0;
        double durationMS = 0;
        String message = null;

        BufferedImageOp bop = new ConvolveOp(kernel);
        before = System.nanoTime();
        outputImage = bop.filter(inputImage, outputImage);
        after = System.nanoTime();
        durationMS = (after - before) / 1e6;
        message = "Java: " + String.format("%.2f", durationMS) + " ms" + " Descrio : "
                + truncate(DescricaoKernel, 13);
        DadosEstatisticos dadosEstatisticos = new DadosEstatisticos(truncate(DescricaoKernel, 13),
                kernel.getWidth(), kernel.getHeight(), (float) durationMS);
        listaDadosEstatisticosJava.add(dadosEstatisticos);
        setInfoProcesso(dadosEstatisticos);
        System.out.println(message);

    }

    private void applyKernelOpenCl(Kernel kernel, String DescricaoKernel) {
        long before = 0;
        long after = 0;
        double durationMS = 0;

        String message = null;

        JOCLRenderizador jop = JOCLRenderizador.create(kernel);
        before = System.nanoTime();
        outputImage = jop.filter(inputImage, outputImage);
        after = System.nanoTime();
        durationMS = (after - before) / 1e6;
        message = "JOCL: " + String.format("%.2f", durationMS) + " ms" + " Descrio : "
                + truncate(DescricaoKernel, 13);
        System.out.println(message);
        DadosEstatisticos dadosEstatisticos = new DadosEstatisticos(truncate(DescricaoKernel, 13),
                kernel.getWidth(), kernel.getHeight(), (float) durationMS);
        listaDadosEstatisticosOPENCL.add(dadosEstatisticos);
        setInfoProcesso(dadosEstatisticos);
        jop.shutdown();

    }

    private void applyKernelJavaThread(final Kernel kernel, final String DescricaoKernel) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                long before = 0;
                long after = 0;
                double durationMS = 0;
                String message = null;

                BufferedImageOp bop = new ConvolveOp(kernel);
                before = System.nanoTime();
                outputImage = bop.filter(inputImage, outputImage);
                after = System.nanoTime();
                durationMS = (after - before) / 1e6;
                message = "Java ThRead: " + String.format("%.2f", durationMS) + " ms" + " Descrio : "
                        + truncate(DescricaoKernel, 13);
                DadosEstatisticos dadosEstatisticos = new DadosEstatisticos(truncate(DescricaoKernel, 13),
                        kernel.getWidth(), kernel.getHeight(), (float) durationMS);
                listaDadosEstatisticosJavaTHREAD.add(dadosEstatisticos);
                setInfoProcesso(dadosEstatisticos);
                System.out.println(message);

            }
        }).start();

    }

    private void ImprimePainelGraficoParcial() {
        if (jrbtJava.isSelected()) {
            GerarGraficoInfoParcial((ArrayList<DadosEstatisticos>) listaDadosEstatisticosJava, "JAVA");
        } else if (jRbtOpenCl.isSelected()) {
            GerarGraficoInfoParcial((ArrayList<DadosEstatisticos>) listaDadosEstatisticosOPENCL, "OPENCL");
        }
        if (jRbtJavaThread.isSelected()) {
            GerarGraficoInfoParcial((ArrayList<DadosEstatisticos>) listaDadosEstatisticosJavaTHREAD, "JAVA THREAD");
        }
    }

    private void GerarGraficoInfoParcial(ArrayList<DadosEstatisticos> lista, String Titulo) {
        JlabelInfo.setText("Processo " + Titulo + " Finalizado.");
        JGeraGraficos grafico = new JGeraGraficos();
        jPanellInfo.add(grafico.GetGraficoParcial(lista, Titulo), BorderLayout.CENTER);
        jPanellInfo.revalidate();
        jPanellInfo.repaint();
    }

    private void GerarGraficoEstatistico() {
        JGeraGraficos g = new JGeraGraficos((ArrayList<DadosEstatisticos>) listaDadosEstatisticosJava,
                (ArrayList<DadosEstatisticos>) listaDadosEstatisticosJavaTHREAD,
                (ArrayList<DadosEstatisticos>) listaDadosEstatisticosOPENCL);
    }

    private void setInfoProcesso(DadosEstatisticos Info) {
        JlabelInfo.setText(Info.getInfoDetalhada());
    }
    //new Thread(
    //  new Runnable() {
    //   public void run() {
    //      panel.shuffle ();
    //   }
    //  }
    //).start();

}