Package eclc

Source Code of eclc.Winners

/*
* @(#)Winners.java   13/08/25
*
* Copyright (c) 2013 DieHard Development
*
* All rights reserved.
Released under the FreeBSD  license
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.
2. 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.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT OWNER OR 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.

The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*
*
*
*/


package eclc;

//~--- non-JDK imports --------------------------------------------------------

import com.xzq.osc.JocTable;

//~--- JDK imports ------------------------------------------------------------

import java.awt.Dimension;
import java.awt.Font;
import java.awt.HeadlessException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.WindowConstants;
import javax.swing.border.EmptyBorder;

/**
*
* @author tony
*/
public class Winners {
    private String wGroup = "";
    private javax.persistence.EntityManager entityManager;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    private javax.persistence.Query entryQuery;
    private java.util.List<eclc.Entry> entryList;
    private javax.swing.JScrollPane js;
    private JLabel lblClass;

    /**
     * Method description
     *
     *
     * @param group
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public void showWinners(String group) {
        JocTable jt = new JocTable();

        wGroup = group;
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();
        entityManager = java.beans.Beans.isDesignTime()
                        ? null
                        : javax.persistence.Persistence.createEntityManagerFactory("ShowManager").createEntityManager();
        entryQuery = java.beans.Beans.isDesignTime()
                     ? null
                     : entityManager.createQuery(
                         "SELECT e FROM Entry e WHERE e.truckclass =:truckclass ORDER BY e.votes DESC");
        entryQuery.setParameter("truckclass", group);
        entryList = java.beans.Beans.isDesignTime()
                    ? java.util.Collections.emptyList()
                    : entryQuery.getResultList();

        org.jdesktop.swingbinding.JTableBinding jTableBinding =
            org.jdesktop.swingbinding.SwingBindings.createJTableBinding(
                org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, entryList, jt);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding =
            jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${truckid}"));

        columnBinding.setColumnName("Truck ID");
        columnBinding.setColumnClass(Integer.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${truckowner}"));
        columnBinding.setColumnName("Truck Owner");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${truckmake}"));
        columnBinding.setColumnName("Truck Make");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${truckclass}"));
        columnBinding.setColumnName("Truck Class");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${votes}"));
        columnBinding.setColumnName("Votes");
        columnBinding.setColumnClass(Integer.class);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        js = new JScrollPane();
        jt.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jt.getColumnModel().getColumn(0).setMinWidth(70);
        jt.getColumnModel().getColumn(0).setPreferredWidth(70);
        jt.getColumnModel().getColumn(0).setMaxWidth(70);
        jt.getColumnModel().getColumn(1).setMinWidth(150);
        jt.getColumnModel().getColumn(1).setPreferredWidth(150);
        jt.getColumnModel().getColumn(1).setMaxWidth(150);
        jt.getColumnModel().getColumn(2).setMinWidth(80);
        jt.getColumnModel().getColumn(2).setPreferredWidth(80);
        jt.getColumnModel().getColumn(2).setMaxWidth(80);
        jt.getColumnModel().getColumn(3).setMinWidth(80);
        jt.getColumnModel().getColumn(3).setPreferredWidth(80);
        jt.getColumnModel().getColumn(3).setMaxWidth(80);
        jt.getColumnModel().getColumn(4).setMinWidth(70);
        jt.getColumnModel().getColumn(4).setPreferredWidth(70);
        jt.getColumnModel().getColumn(4).setMaxWidth(70);
        jt.setEditable(false);
        js.setViewportView(jt);
        lblClass = new JLabel("Class Winners for: " + wGroup);
        lblClass.setFont(new Font("SansSerif", Font.BOLD, 22));
        lblClass.setHorizontalAlignment(SwingConstants.CENTER);
        lblClass.setBounds(50, 300, 400, 30);
        buildGui(jt);
    }

    private void buildGui(JTable jt) throws HeadlessException {
        JFrame jf;

        jf = new JFrame();

        JPanel contentPane = new JPanel();

        jf.setContentPane(contentPane);
        contentPane.setBorder(new EmptyBorder(1, 1, 1, 1));
        contentPane.setLayout(null);
        js.setBounds(5, 20, 507, 220);
        contentPane.add(js);
        contentPane.add(lblClass);
        jf.setPreferredSize(new Dimension(513, 420));
        jf.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        jf.setLocationRelativeTo(null);
        jf.setResizable(false);
        jf.setTitle("ECLC Class Winners : " + wGroup);
        jf.pack();
        jf.setVisible(true);
    }
}


//~ Formatted in DD Std on 13/08/25
TOP

Related Classes of eclc.Winners

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.