Package logic

Source Code of logic.FlightListRenderer

/*
* To change this template, choose Tools | Templates
* and open the template in the Squawkor.
*/

package logic;

import framework.IRadarPlaneObject;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.TableCellRenderer;
import gui.windows.FlightList;

/**
*
* @author m0ng
*/
public class FlightListRenderer extends JTable implements TableCellRenderer{
   
        private FlightList flightList;
   
        private GridBagLayout layout = new GridBagLayout();

        private JLabel planeName                    = new JLabel("");
        private JLabel planeAlt                     = new JLabel("");
        private JLabel planeSpeed                   = new JLabel("");
        private JLabel planeState                   = new JLabel("");
        private JLabel planeControllers             = new JLabel("");
        private JLabel planeSquawk                    = new JLabel("");
       
        private JLabel planeNameDesc                = new JLabel("Flightnumber");
        private JLabel planeAltDesc                 = new JLabel("Altitude");
        private JLabel planeSpeedDesc               = new JLabel("MPH");
        private JLabel planeStateDesc               = new JLabel("State");
        private JLabel planeControllersDesc         = new JLabel("Controller");
        private JLabel planeSquawkDesc                = new JLabel("Squawk");
      
        private GridBagConstraints gbcPlaneName     = new GridBagConstraints();
        private GridBagConstraints gbcPlaneAlt      = new GridBagConstraints();
        private GridBagConstraints gbcPlaneSpeed    = new GridBagConstraints();
        private GridBagConstraints gbcPlaneState    = new GridBagConstraints();
        private GridBagConstraints gbcPlaneControllers = new GridBagConstraints();
        private GridBagConstraints gbcPlaneSquawk     = new GridBagConstraints();

        private GridBagConstraints gbcPlaneNameDesc  = new GridBagConstraints();
        private GridBagConstraints gbcPlaneAltDesc   = new GridBagConstraints();
        private GridBagConstraints gbcPlaneSpeedDesc = new GridBagConstraints();
        private GridBagConstraints gbcPlaneStateDesc  = new GridBagConstraints();
        private GridBagConstraints gbcPlaneControllersDesc = new GridBagConstraints();
        private GridBagConstraints gbcPlaneSquawkDesc   = new GridBagConstraints();

        /**
         * Default Konstruktor
         */
        public FlightListRenderer(FlightList fl) {
           
            flightList = fl;

            planeNameDesc.setHorizontalAlignment(SwingConstants.CENTER);
            planeNameDesc.setPreferredSize(new Dimension(102, 25));
            planeNameDesc.setFont(new Font(Font.DIALOG, Font.BOLD, 10));
            gbcPlaneNameDesc.gridx = 0; gbcPlaneNameDesc.gridy = 0;
            gbcPlaneNameDesc.weightx = 1; gbcPlaneNameDesc.weighty = 1;
            gbcPlaneNameDesc.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeNameDesc, gbcPlaneNameDesc);

            planeAltDesc.setHorizontalAlignment(SwingConstants.CENTER);
            planeAltDesc.setPreferredSize(new Dimension(80, 25));
            planeAltDesc.setFont(new Font(Font.DIALOG, Font.BOLD, 10));
            gbcPlaneAltDesc.gridx = 1; gbcPlaneAltDesc.gridy = 0;
            gbcPlaneAltDesc.weightx = 1; gbcPlaneAltDesc.weighty = 1;
            gbcPlaneAltDesc.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeAltDesc, gbcPlaneAltDesc);

            planeSpeedDesc.setHorizontalAlignment(SwingConstants.CENTER);
            planeSpeedDesc.setPreferredSize(new Dimension(80, 25));
            planeSpeedDesc.setFont(new Font(Font.DIALOG, Font.BOLD, 10));
            gbcPlaneSpeedDesc.gridx = 2; gbcPlaneSpeedDesc.gridy = 0;
            gbcPlaneSpeedDesc.weightx = 1; gbcPlaneSpeedDesc.weighty = 1;
            gbcPlaneSpeedDesc.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeSpeedDesc, gbcPlaneSpeedDesc);

            planeName.setHorizontalAlignment(SwingConstants.CENTER);
            planeName.setPreferredSize(new Dimension(102, 25));
            gbcPlaneName.gridx = 0; gbcPlaneName.gridy = 1;
            gbcPlaneName.weightx = 1; gbcPlaneName.weighty = 1;
            gbcPlaneName.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeName, gbcPlaneName);

            planeAlt.setHorizontalAlignment(SwingConstants.CENTER);
            planeAlt.setPreferredSize(new Dimension(80, 25));
            gbcPlaneAlt.gridx = 1; gbcPlaneAlt.gridy = 1;
            gbcPlaneAlt.weightx = 1; gbcPlaneAlt.weighty = 1;
            gbcPlaneAlt.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeAlt, gbcPlaneAlt);

            planeSpeed.setHorizontalAlignment(SwingConstants.CENTER);
            planeSpeed.setPreferredSize(new Dimension(80, 25));
            gbcPlaneSpeed.gridx = 2; gbcPlaneSpeed.gridy = 1;
            gbcPlaneSpeed.weightx = 1; gbcPlaneSpeed.weighty = 1;
            gbcPlaneSpeedDesc.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeSpeed, gbcPlaneSpeed);

            planeStateDesc.setHorizontalAlignment(SwingConstants.CENTER);
            planeStateDesc.setPreferredSize(new Dimension(102, 25));
            planeStateDesc.setFont(new Font(Font.DIALOG, Font.BOLD, 10));
            gbcPlaneStateDesc.gridx = 0; gbcPlaneStateDesc.gridy = 2;
            gbcPlaneStateDesc.weightx = 1; gbcPlaneStateDesc.weighty = 1;
            gbcPlaneStateDesc.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeStateDesc, gbcPlaneStateDesc);

            planeControllersDesc.setHorizontalAlignment(SwingConstants.CENTER);
            planeControllersDesc.setPreferredSize(new Dimension(80, 25));
            planeControllersDesc.setFont(new Font(Font.DIALOG, Font.BOLD, 10));
            gbcPlaneControllersDesc.gridx = 1; gbcPlaneControllersDesc.gridy = 2;
            gbcPlaneControllersDesc.weightx = 1; gbcPlaneControllersDesc.weighty = 1;
            gbcPlaneControllersDesc.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeControllersDesc, gbcPlaneControllersDesc);

            planeSquawkDesc.setHorizontalAlignment(SwingConstants.CENTER);
            planeSquawkDesc.setPreferredSize(new Dimension(80, 25));
            planeSquawkDesc.setFont(new Font(Font.DIALOG, Font.BOLD, 10));
            gbcPlaneSquawkDesc.gridx = 2; gbcPlaneSquawkDesc.gridy = 2;
            gbcPlaneSquawkDesc.weightx = 1; gbcPlaneSquawkDesc.weighty = 1;
            gbcPlaneSquawkDesc.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeSquawkDesc, gbcPlaneSquawkDesc);

            planeState.setHorizontalAlignment(SwingConstants.CENTER);
            planeState.setPreferredSize(new Dimension(102, 25));
            gbcPlaneState.gridx = 0; gbcPlaneState.gridy = 3;
            gbcPlaneState.weightx = 1; gbcPlaneState.weighty = 1;
            gbcPlaneState.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeState, gbcPlaneState);

            planeControllers.setHorizontalAlignment(SwingConstants.CENTER);
            planeControllers.setPreferredSize(new Dimension(80, 25));
            gbcPlaneControllers.gridx = 1; gbcPlaneControllers.gridy = 3;
            gbcPlaneControllers.weightx = 1; gbcPlaneControllers.weighty = 1;
            gbcPlaneControllers.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeControllers, gbcPlaneControllers);

            planeSquawk.setHorizontalAlignment(SwingConstants.CENTER);
            planeSquawk.setPreferredSize(new Dimension(80, 25));
            gbcPlaneSquawk.gridx = 2; gbcPlaneSquawk.gridy = 3;
            gbcPlaneSquawk.weightx = 1; gbcPlaneSquawk.weighty = 1;
            gbcPlaneSquawk.fill = GridBagConstraints.HORIZONTAL;
            layout.setConstraints(planeSquawk, gbcPlaneSquawk);


            this.setPreferredSize(new Dimension(306, 100));
            this.setLayout(layout);
            this.add(planeNameDesc);
            this.add(planeAltDesc);
            this.add(planeSpeedDesc);
            this.add(planeName);
            this.add(planeAlt);
            this.add(planeSpeed);
            this.add(planeStateDesc);
            this.add(planeControllersDesc);
            this.add(planeSquawkDesc);
            this.add(planeState);
            this.add(planeControllers);
            this.add(planeSquawk);
            validate();
        }

        public Component getTableCellRendererComponent(JTable table,
                Object value, boolean isSelected, boolean hasFocus,
                int row, int column) {

            IRadarPlaneObject tempValue = (IRadarPlaneObject) value;
           
            if (tempValue != null) {
                if(tempValue.equals(flightList.getSelectedPlane())){
                    this.setBackground(new Color(100, 120, 200, 130));
                } else {
                 this.setBackground(tempValue.getPlaneColor(flightList.getFunction()));
                }
                planeControllers.setText(tempValue.getActiveController());
                planeName.setText(tempValue.getFlightNumber());
                planeAlt.setText(tempValue.getAltitude()+"");
                planeSpeed.setText(tempValue.getSpeed()+"");
                planeState.setText(tempValue.getPlaneState());
                planeSquawk.setText(tempValue.getSquawk());
            }
           
            return this;
    }
}
TOP

Related Classes of logic.FlightListRenderer

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.