Package bpntojava.view.View

Source Code of bpntojava.view.View.View

package bpntojava.view.View;

import bpntojava.controller.Constant;
import bpntojava.controller.Controller;
import bpntojava.model.stafftable.Usable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedList;
import javax.swing.*;

/**
* View.
*
* @author mschuessler
*/
public class View extends JFrame implements ActionListener {

    /**
     * Controller.
     */
    Controller controller;
    /**
     * Usables.
     */
    LinkedList<Usable> usables;
    /**
     * Hauptpanel.
     */
    private JPanel mainpanel;
    /**
     * Auswahlbox: Datum.
     */
    private JComboBox dates;
    /**
     * getTable-Button.
     */
    private JButton getTableButton;
    /**
     * GetDate-Button.
     */
    private JButton getDataButton;
    /**
     * Anzeigetabelle.
     */
    private JTable table;
    /**
     * Label für Informationen.
     */
    private JLabel info;

    /**
     * Konstruktor.
     *
     * @param controller Controller.
     */
    public View(Controller controller) {
        super(Constant.MAIN_TITLE);
        this.controller = controller;
        initMain();
        initPanel();
        initActionListener();
        this.setVisible(true);
    }

    /**
     * Initialisiert die ActionListener.
     */
    private void initActionListener() {
        getTableButton.addActionListener(this);
        getDataButton.addActionListener(this);
    }

    /**
     * Erstellt den MainFrame.
     */
    private void initMain() {
        //this.setResizable(false);
        this.setSize(Constant.MAIN_WIDTH, Constant.MAIN_HEIGHT);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    /**
     * Erstellt das panel und seine Bestandteile.
     */
    private void initPanel() {
        mainpanel = new JPanel();
        dates = new JComboBox();
        getTableButton = new JButton("Tabelle anzeigen");
        getDataButton = new JButton("Daten laden");
        info = new JLabel("Info");
        table = new JTable();
        mainpanel.add(dates);
        mainpanel.add(getTableButton);
        mainpanel.add(getDataButton);
        mainpanel.add(info);
        mainpanel.add(table);
        getContentPane().add(mainpanel);
    }

    /**
     * DatenAUswahl füllen.
     */
    public void fillDates() {
        usables = this.controller.getUsables();
        String[] tmp = fillBoxes(0);
        for (int i = 0; i < tmp.length; i++) {
            dates.addItem(tmp[i]);
        }
    }

    /**
     * Füllt die Auswahlbox mit ihren Usables.
     *
     * @param i Usablenummer
     * @return String-Array
     */
    private String[] fillBoxes(int i) {
        Usable usable = usables.get(i);
        String[] toReturn;
        toReturn = new String[usable.size()];
        for (int j = 0; j < usable.size(); j++) {
            toReturn[j] = usable.get(j);
        }
        return toReturn;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == getTableButton) {
            table.setModel(controller.getTable((String) dates.getSelectedItem()));
            table.getColumnModel().getColumn(0).setMinWidth(Constant.TABLE_MIN_FIRST);
            for (int i = 1; i < table.getColumnCount() - 1; i++) {
                table.getColumnModel().getColumn(i).setMaxWidth(Constant.TABLE_MAX_ROWWIDTH);
            }
        }
        if (e.getSource() == getDataButton) {
            info.setText("Daten werden geladen...");
            controller.getBPNData();
        }
    }

    /**
     * Button augrauen.
     *
     * @param usable true/false
     */
    public void setGetTableButtonUsable(boolean usable) {
        getTableButton.setEnabled(usable);
    }

    /**
     * Button augrauen.
     *
     * @param usable true/false
     */
    public void setGetDataButtonUsable(boolean usable) {
        getDataButton.setEnabled(usable);
    }

    /**
     * Verändert den Text des InfoLabels.
     *
     * @param value Text
     */
    public void setInfo(String value) {
        info.setText(value);
    }
}
TOP

Related Classes of bpntojava.view.View.View

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.