com.tcay.slalom.UI.LeaderBoard.java Source code

Java tutorial

Introduction

Here is the source code for com.tcay.slalom.UI.LeaderBoard.java

Source

/*
 * This file is part of SlalomApp.
 *
 *     SlalomApp is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     SlalomApp 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 for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with SlalomApp.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * This file is part of SlalomApp.
 *
 *     SlalomApp is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     SlalomApp 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 for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with SlalomApp.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * This file is part of SlalomApp.
 *
 *     SlalomApp is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     SlalomApp 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 for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with SlalomApp.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.tcay.slalom.UI;

///import com.PrintUIWindow;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
import com.tcay.slalom.Race;
import com.tcay.slalom.UI.tables.ResultsTable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterException;

/**
 * ${PROJECT_NAME}
 * <p/>
 * Teton Cay Group Inc. ${YEAR}
 * <p/>
 * <p/>
 * User: allen
 * Date: 9/28/13
 * Time: 6:28 PM
 */
public class LeaderBoard {
    private JPanel panel1;
    private JScrollPane leaderScrollPane;
    private JTable table;
    private JButton printButton;
    private ResultsTable resultsTable;

    public LeaderBoard(ResultsTable resultsTable, JFrame frame) {
        this.resultsTable = resultsTable;
        $$$setupUI$$$();
        //        table = resultsTable.createTable();

        printButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                try {
                    table.print();
                } catch (PrinterException e) {
                    e.printStackTrace();
                }
            }
        });

    }

    //public LeaderBoard() {
    //}

    private void createUIComponents() {
        // TODO: place custom component creation code here
        //        resultsTable  = new JBTable();
        if (resultsTable == null) {
            resultsTable = new ResultsTable();
        }

        table = resultsTable.createTable();
        leaderScrollPane = //new JScrollPane();

                new JScrollPane(table) {
                    {
                        setOpaque(false);
                        getViewport().setOpaque(false);
                    }

                    @Override //tod drawimage if null .getImage() here throws exception 20151121
                    protected void paintComponent(Graphics g) {
                        //g.drawImage(Race.getInstance().getSlalomBackgroundII().getImage(), 0, 0, getWidth(), getHeight(), this);

                        g.drawImage(Race.getInstance().getBackgroundImage().getImage(), 0, 0, getWidth(),
                                getHeight(), this);
                        super.paintComponent(g);
                    }

                };
        table.setOpaque(false);

        Race.getInstance().updateResults(false); // TODO REALLY NEEDED ???   2016 Why is this needed here ?

    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        createUIComponents();
        panel1 = new JPanel();
        panel1.setLayout(new FormLayout("fill:d:grow", "center:max(d;4px):noGrow,top:3dlu:noGrow,center:d:grow"));
        leaderScrollPane.setPreferredSize(new Dimension(800, 600));
        CellConstraints cc = new CellConstraints();
        panel1.add(leaderScrollPane, cc.xy(1, 3, CellConstraints.FILL, CellConstraints.FILL));
        leaderScrollPane.setViewportView(table);
        printButton = new JButton();
        printButton.setText("Print");
        panel1.add(printButton, cc.xy(1, 1));
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return panel1;
    }
}