All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codename1.designer.BenchmarkResults Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Oracle designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Oracle in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores
 * CA 94065 USA or visit www.oracle.com if you need additional information or
 * have any questions.
 */

package com.codename1.designer;

import java.util.Collections;
import java.util.Map;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;

/**
 *  Shows the result of a benchmark run in the theme editor
 *
 * @author Shai Almog
 */
public class BenchmarkResults extends javax.swing.JDialog {

    /** Creates new form BenchmarkResults */
    public BenchmarkResults(java.awt.Component parent, String ram, String layout, String drawing,
            Map paintTimes, Map layoutTimes) {
        super((java.awt.Frame)SwingUtilities.windowForComponent(parent), true);
        initComponents();
        this.ram.setText(ram);
        this.drawing.setText(drawing);
        this.layoutSpeed.setText(layout);
        paintTimesTable.setModel(mapToModel(paintTimes));
        layoutTimesTable.setModel(mapToModel(layoutTimes));
        setLocationRelativeTo(parent);
        setVisible(true);
    }

    private DefaultTableModel mapToModel(Map map) {
        DefaultTableModel model = new DefaultTableModel(new Object[] {"Name", "Time"}, map.size());
        int offset = 0;
        for(String key : map.keySet()) {
            long val = map.get(key);
            model.setValueAt(key, offset, 0);
            model.setValueAt(val + " (" + (val / 1000000) + "ms)", offset, 1);
            offset++;
        }
        return model;
    }

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

        ok = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        ram = new javax.swing.JTextField();
        drawing = new javax.swing.JTextField();
        layoutSpeed = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        layoutTimesTable = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        paintTimesTable = new javax.swing.JTable();

        FormListener formListener = new FormListener();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Benchmark");

        ok.setText("OK");
        ok.setName("ok"); // NOI18N
        ok.addActionListener(formListener);

        jLabel1.setText("RAM Overhead (bytes)");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Drawing Speed (nano)");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("Layout Speed (nano)");
        jLabel3.setName("jLabel3"); // NOI18N

        ram.setColumns(10);
        ram.setEditable(false);
        ram.setName("ram"); // NOI18N

        drawing.setColumns(10);
        drawing.setEditable(false);
        drawing.setName("drawing"); // NOI18N

        layoutSpeed.setColumns(10);
        layoutSpeed.setEditable(false);
        layoutSpeed.setName("layoutSpeed"); // NOI18N

        jLabel4.setText("Layout Times");
        jLabel4.setName("jLabel4"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        layoutTimesTable.setName("layoutTimesTable"); // NOI18N
        jScrollPane1.setViewportView(layoutTimesTable);

        jLabel5.setText("Paint Times");
        jLabel5.setName("jLabel5"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        paintTimesTable.setName("paintTimesTable"); // NOI18N
        jScrollPane2.setViewportView(paintTimesTable);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel1)
                            .add(jLabel2)
                            .add(jLabel3)
                            .add(jLabel4)
                            .add(jLabel5))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                            .add(jScrollPane1, 0, 274, Short.MAX_VALUE)
                            .add(ram, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                            .add(drawing, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
                            .add(layoutSpeed, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, ok))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(ram, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(drawing, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(layoutSpeed, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel4)
                        .add(141, 141, 141)
                        .add(jLabel5))
                    .add(layout.createSequentialGroup()
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 147, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(ok)
                .addContainerGap())
        );

        pack();
    }

    // Code for dispatching events from components to event handlers.

    private class FormListener implements java.awt.event.ActionListener {
        FormListener() {}
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            if (evt.getSource() == ok) {
                BenchmarkResults.this.okActionPerformed(evt);
            }
        }
    }// //GEN-END:initComponents

    private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
        dispose();
}//GEN-LAST:event_okActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField drawing;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField layoutSpeed;
    private javax.swing.JTable layoutTimesTable;
    private javax.swing.JButton ok;
    private javax.swing.JTable paintTimesTable;
    private javax.swing.JTextField ram;
    // End of variables declaration//GEN-END:variables

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy