Package gui.tabs

Source Code of gui.tabs.RadarTab

/*
* RadarTab.java
*
* Created on 25. Februar 2008, 19:29
*/
package gui.tabs;

import enums.PlaneStates;
import events.AirportEvent;
import events.ColorEvent;
import events.HeightEvent;
import events.NavaidEvent;
import framework.IATMCModel;
import framework.IATMClient;
import framework.IAirport;
import framework.IAirport.IRunway;
import framework.IAirport.ITower;
import framework.INavaidCoord;
import framework.IPlaneDataObject;
import framework.IRadarColor;
import framework.IRadarPlaneObject;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Point;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import logic.Airport;
import logic.Airport.Runway;
import logic.AirportXML;
import logic.DistanceCalculator;
import logic.NavaidCoord;
import logic.NavaidXML;
import messages.PlaneDataObject;
import messages.RadarPlaneObject;

/**
*
* @author  m0ng85
*/
public class RadarTab extends javax.swing.JPanel implements Observer {

    private IATMCModel atmcModel;
    private IATMClient atmClient;
    private float minX = 5;
    private float maxX = 11;
    private float minY = 45.885f;
    private float maxY = 48;
    private int resX = 800;
    private int resY = 600;
    private double asp = (double) resX / resY;
    private float zoomLevel = maxX - minX;
    private int historyLength = 10; //seconds
    private static final double REPAINT_TIMER = 1; //seconds
    private static final int BULLSHIT_FACTOR = 2000;
    private static final int OTHER_PLANE_MAX_ZOOM_NAMERENDER = 2;
    private static final int OWN_PLANE_MAX_ZOOM_NAMERENDER = 8;
    private static final int COLLISION_WARN_DISTANCE = 5;
    private static final Font AIRPLANE_NAME_FONT = new Font(Font.DIALOG, Font.PLAIN, 10);
    private Map<String, PlaneDataObject> lastPlanePosition =
            new TreeMap<String, PlaneDataObject>();
    private ShowEntitiesDialog showEntities;
    private Map<String, IAirport> airports = new HashMap<String, IAirport>();
    private Map<String, INavaidCoord> navaids = new TreeMap<String, INavaidCoord>();
    private Map<String, Boolean> allObjects = new TreeMap<String, Boolean>();
    private Map<String, IRadarColor> colors = new TreeMap<String, IRadarColor>();

    /** Creates new form RadarTab */
    public RadarTab(IATMClient atmc) {

        atmClient = atmc;
        atmcModel = atmc.getModel();
        atmcModel.addNewObserver(this);

        initComponents();
        refreshColors();
        refreshAirports();
        refreshHeights();
        refreshNavaids();

        historySizeButton.setText("History-Size: " + historyLength + " seconds");
       

        Timer drawTimer = new Timer();
        TimerTask drawTimerTask = new TimerTask() {

            @Override
            public void run() {
                atmcModel.setUpdates();
                repaint();
            }
        };
        drawTimer.schedule(drawTimerTask, (int) (REPAINT_TIMER * 1000), 1000);
        this.setPreferredSize(new Dimension(100, 100));
        this.validate();


    }

    private void drawNavaidsDetailed(Graphics2D g) {
        int navaidRadius = 36;
        Iterator it = navaids.values().iterator();

        int lineSize = navaidRadius / 10;
        int polyRadius = navaidRadius / 5;
        g.setColor(colors.get("NAVAIDS_DETAILED").getColor());
        while (it.hasNext()) {
            INavaidCoord tmp = (NavaidCoord) it.next();
            if (allObjects.get("Navaid: " + tmp.getName())) {

                g.drawOval(getX(tmp.getLon()) - navaidRadius, getY(tmp.getLat()) - navaidRadius, navaidRadius * 2, navaidRadius * 2);

                double xRaw = getX(tmp.getLon());
                double yRaw = getY(tmp.getLat());


                for (int i = 0; i < 36; i++) {
                    if (i != 0 && i % 3 != 0) {
                        g.drawLine(
                                (int) (xRaw + (Math.sin((Math.PI / 18) * i)) * (navaidRadius - lineSize)),
                                (int) (yRaw + (Math.cos((Math.PI / 18) * i)) * (navaidRadius - lineSize)),
                                (int) (xRaw + (Math.sin((Math.PI / 18) * i)) * navaidRadius),
                                (int) (yRaw + (Math.cos((Math.PI / 18) * i)) * navaidRadius));
                    }


                }


                for (int i = 0; i < 12; i++) {
                    g.drawLine(
                            (int) (xRaw + (Math.sin((Math.PI / 6) * i)) * (navaidRadius - lineSize * 2)),
                            (int) (yRaw + (Math.cos((Math.PI / 6) * i)) * (navaidRadius - lineSize * 2)),
                            (int) (xRaw + (Math.sin((Math.PI / 6) * i)) * navaidRadius),
                            (int) (yRaw + (Math.cos((Math.PI / 6) * i)) * navaidRadius));
                }


                int[] xPointsPoly = new int[6];
                int[] yPointsPoly = new int[6];




                for (int i = 0; i < 6; i++) {
                    xPointsPoly[i] = (int) (xRaw + (Math.sin((Math.PI / 3) * i) * polyRadius));
                    yPointsPoly[i] = (int) (yRaw + (Math.cos((Math.PI / 3) * i) * polyRadius));
                }


                g.fillRect((int) xRaw - 1, (int) yRaw - 1, 3, 3);
                g.drawPolygon(xPointsPoly, yPointsPoly, 6);
                g.drawString(tmp.getName(), (float) (xRaw), (float) (yRaw + navaidRadius + 20));
                g.drawString(tmp.getFrequency(), (float) (xRaw), (float) (yRaw + navaidRadius + 32));
            }
        }
    }

    private void drawNavaidsUndetailed(Graphics2D g) {
        g.setColor(colors.get("NAVAIDS_UNDETAILED").getColor());
        Iterator it = navaids.values().iterator();
        while (it.hasNext()) {
            INavaidCoord tmp = (NavaidCoord) it.next();
            if (allObjects.get("Navaid: " + tmp.getName())) {
                g.drawString(tmp.getID(), getX(tmp.getLon()) - 2, getY(tmp.getLat()) - 4);
                g.fillRect(getX(tmp.getLon()) - 2, getY(tmp.getLat()) - 2, 4, 4);
            }


        }
    }

    public void drawPlanes(final Graphics g) {
        Graphics2D g2 = (Graphics2D) g;

        Iterator<RadarPlaneObject> it = atmcModel.getRadarPlaneObjects().values().iterator();
        int planeCount = 0;
        while (it.hasNext()) {
            RadarPlaneObject current = it.next();
            Float cAltitude = 0f;
            try {
                cAltitude = current.getAltitude();
            } catch (NumberFormatException e) {
            }


            if (cAltitude > atmcModel.getMinHeight() && cAltitude < atmcModel.getMaxHeight()) {
                if (!lastPlanePosition.containsKey(current.getIp())) {
                    lastPlanePosition.put(current.getIp(), null);
                }
                PlaneDataObject lastPos = lastPlanePosition.get(current.getIp());
                PlaneDataObject currentPos = (PlaneDataObject) current.getCurrentPos();


                if (currentPos != null && !currentPos.equals(lastPlanePosition.get(current.getIp()))) {
                    lastPlanePosition.put(current.getIp(), currentPos);
                }

                if (currentPos != null) {
                    drawHistoryList(g2, current);
                    drawPlaneShape(g2, current);
                    planeCount++;
                }
            }
        }
    }

    private void drawHistoryList(Graphics g, RadarPlaneObject rpo) {
        LinkedList<PlaneDataObject> tmpList = new LinkedList<PlaneDataObject>(rpo.getPositions());
        if (tmpList.size() > 0) {
            if (tmpList.size() - historyLength - 1 < 0) {
                tmpList = new LinkedList<PlaneDataObject>(tmpList.subList(0, tmpList.size() - 1));
            } else {
                tmpList = new LinkedList<PlaneDataObject>(tmpList.subList(tmpList.size() - historyLength - 1, tmpList.size() - 1));
            }
        }
        Iterator it = tmpList.iterator();
        g.setColor(colors.get("PLANE_HISTORY_COLOR").getColor());
        while (it.hasNext()) {
            PlaneDataObject currentPos = (PlaneDataObject) it.next();
            g.drawRect(getX(currentPos.getLongitude()), getY(currentPos.getLatitude()), 1, 1);
        }
    }

    private boolean doCollisionTest(IRadarPlaneObject rpo) {
        String ps = rpo.getPlaneState();
        if (!(ps.equals(PlaneStates.Landed.toString()) || ps.equals(PlaneStates.Cold.toString()) || ps.equals(PlaneStates.Engine_Start.toString()) || ps.equals(PlaneStates.Push_Back.toString()) || ps.equals(PlaneStates.To_Runway.toString()) || ps.equals(PlaneStates.To_Gate.toString()) || ps.equals(PlaneStates.Shutdown.toString())) || rpo.getSpeed() < 100) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * Zeichnet einen Flugzeugumrisss auf den Radar.
     * Diese Methode verwendet das erste PlaneDataObject als Basis fuer das Flugzeug und das Zweite als Richtung.
     *
     * @param g Das Graphics Object.
     * @param base Das Zentrum des Umrisses.
     * @param dir Der Richtungspunkt.
     * @param rpobj Das RadarPlaneObject aus dem die Daten kommen.
     */
    private void drawPlaneShape(final Graphics2D g,
            final RadarPlaneObject rpobj) {

        IPlaneDataObject dir = rpobj.getCurrentPos();
        /*IPlaneDataObject base = null;
        if (rpobj.getPositions().size() > 1) {
        base = (IPlaneDataObject) rpobj.getPositions().get(rpobj.getPositions().size() - 2);
        }*/
        //Colisiontest just if not on ground and faster than 100
        int coll = 0;
        String ps = rpobj.getPlaneState();
        if (doCollisionTest(rpobj)) {
            coll = collisionTest((PlaneDataObject) rpobj.getCurrentPos());
        }
        g.setColor(colors.get("PLANE_NAME_COLOR").getColor());
        g.setFont(AIRPLANE_NAME_FONT);

        if (zoomLevel < OWN_PLANE_MAX_ZOOM_NAMERENDER && rpobj != null && rpobj.getActiveController() != null && rpobj.getActiveController().equals(atmcModel.getUser())) {
            g.drawString(rpobj.getFlightNumber(),
                    getXFloat(dir.getLongitude()) - 4,
                    getYFloat(dir.getLatitude()) - 4);
        }

        if (zoomLevel < OTHER_PLANE_MAX_ZOOM_NAMERENDER && rpobj != null && rpobj.getActiveController() != null && !rpobj.getActiveController().equals(atmcModel.getUser())) {
            g.drawString(rpobj.getFlightNumber(), getXFloat(dir.getLongitude()) - 4, getYFloat(dir.getLatitude()) - 4);
        }
        g.setColor(colors.get("PLANE_SHAPE_COLOR").getColor());
        double heading = -(rpobj.getHeading() + 190) * Math.PI / 180.0;
        double baseX = getXFloat(dir.getLongitude());
        double baseY = getYFloat(dir.getLatitude());
        double xFactor = 3 * Math.sin(heading);
        double yFactor = 3 * Math.cos(heading);
        Point fwdPt = new Point((int) (baseX + 4 * xFactor), (int) (baseY + 4 * yFactor));
        Point lwingbasePt = new Point((int) (baseX + yFactor), (int) (baseY - xFactor));
        Point rwingbasePt = new Point((int) (baseX - yFactor), (int) (baseY + xFactor));
        g.drawLine(fwdPt.x, fwdPt.y, lwingbasePt.x, lwingbasePt.y);
        g.drawLine(fwdPt.x, fwdPt.y, rwingbasePt.x, rwingbasePt.y);
        g.drawLine(lwingbasePt.x, lwingbasePt.y, rwingbasePt.x, rwingbasePt.y);
        if (coll == 1) {
            drawWarning(new Point((int) (baseX + 2 * xFactor), (int) (baseY + 2 * yFactor)), g);
        } else if (coll == 2) {
            drawAlert(new Point((int) (baseX + 2 * xFactor), (int) (baseY + 2 * yFactor)), g);
        }
    }

    /**
     * Zeichnet einen Warnungskreis um ein Flugzeug.
     * @param Zentrum um welches der Kreis gezeichnet wird.
     * @param g Das Graphics2D Objekt.
     */
    private void drawWarning(final Point center,
            final Graphics2D g) {
        g.setColor(colors.get("COLLISION_WARNING").getColor());
        g.drawOval(center.x - 8, center.y - 8, 16, 16);
    }

    /**
     * Zeichnet einen Warnungskreis um ein Flugzeug.
     * @param Zentrum um welches der Kreis gezeichnet wird.
     * @param g Das Graphics2D Objekt.
     */
    private void drawAlert(final Point center,
            final Graphics2D g) {
        g.setColor(colors.get("COLLISION_ALERT").getColor());
        g.drawOval(center.x - 8, center.y - 8, 16, 16);
    }

    private int collisionTest(final PlaneDataObject pdo) {
        int collisionIndicator = 0;
        Iterator<RadarPlaneObject> it = atmcModel.getRadarPlaneObjects().values().iterator();
        String thisIP = pdo.getIP();
        while (it.hasNext()) {
            IPlaneDataObject testPos = it.next().getCurrentPos();
            if (testPos != null && !testPos.getIP().equals(thisIP)) {
                if (DistanceCalculator.getDistance(testPos.getLatitude(), testPos.getLongitude(), pdo.getLatitude(), pdo.getLongitude()) < COLLISION_WARN_DISTANCE) {
                    return 2;
                } else if (DistanceCalculator.getDistance(testPos.getLatitude(), testPos.getLongitude(), pdo.getLatitude(), pdo.getLongitude()) < 2 * COLLISION_WARN_DISTANCE) {
                    collisionIndicator = 1;
                }
            }
        }
        return collisionIndicator;
    }

    private void drawAirports(final Graphics2D g) {
        if (zoomLevel > 30) {
            drawNoAirports(g);
        } else if (zoomLevel < 3) {
            drawAirportsDetailed(g);
        } else {
            drawAirportsUndetailed(g);
        }
    }

    private void drawNoAirports(final Graphics2D g) {
        g.setColor(colors.get("NO_AIRPORT_COLOR").getColor());
        g.fillRect(getX(7.5f) - 2, getY(46.91f) - 2, 4, 4);
        g.drawString("Schweiz", getX(7.5f) - 10, getY(46.91f) - 10);
    }

    private void drawAirportsUndetailed(final Graphics2D g) {
        g.setColor(colors.get("UNDETAILED_AIRPORT_COLOR").getColor());
        Iterator<IAirport> it = airports.values().iterator();
        while (it.hasNext()) {
            Airport cAirport = (Airport) it.next();
            if (allObjects.get("Airport: " + cAirport.getName())) {
                float upperLat = cAirport.getUpperLatBound();
                float lowerLon = cAirport.getLowerLonBound();
                g.drawString(cAirport.getID(), getX(lowerLon) - 2, getY(upperLat) - 4);
                g.fillRect(getX(lowerLon) - 2, getY(upperLat) - 2, 4, 4);
            }

        }
    }

    private void drawAirportsDetailed(final Graphics2D g) {
        Collection<IAirport> cAirports = airports.values();
        Iterator it = cAirports.iterator();
        while (it.hasNext()) {
            Airport current = (Airport) it.next();
            ITower cTower = current.getTower();
            Iterator<? extends IRunway> iRunways = current.getRunways();
            String aName = current.getName();

            //Draw the boundaries

            float upperLon = current.getUpperLonBound();
            float upperLat = current.getUpperLatBound();
            float lowerLon = current.getLowerLonBound();
            float lowerLat = current.getLowerLatBound();
            if (allObjects.get("Airport: " + aName)) {
                g.setColor(colors.get("DETAILED_AIRPORT_COLOR_BORDER").getColor());
                g.drawRect(getX(lowerLon) - 10, getY(upperLat) - 10, getX(upperLon) - getX(lowerLon) + 20, getY(lowerLat) - getY(upperLat) + 20);
                g.setColor(colors.get("DETAILED_AIRPORT_COLOR_NAME").getColor());
                g.drawString(current.getID() + " " + aName, getX(lowerLon) - 10, getY(upperLat) - 15);
            }


            //Draw the Tower
            if (cTower != null && allObjects.get("Tower: " + aName + " - " + cTower.getName())) {
                g.setColor(colors.get("DETAILED_AIRPORT_COLOR_TOWER").getColor());
                g.fillRect(getX(cTower.getLon()) - 3, getY(cTower.getLat()) - 3, 6, 6);
            }

            //Draw the Runways
            while (iRunways.hasNext()) {
                Runway cRunway = (Runway) iRunways.next();
                float x1 = getXFloat(cRunway.getStartLon());
                float y1 = getYFloat(cRunway.getStartLat());
                float x2 = getXFloat(cRunway.getEndLon());
                float y2 = getYFloat(cRunway.getEndLat());
                float width = cRunway.getWidth(); // feet

                if (allObjects.get("Runway: " + current.getName() + " - " + cRunway.getStartNum())) {
                    g.setColor(colors.get("DETAILED_AIRPORT_COLOR_RUNWAY").getColor());
                    if (width < BULLSHIT_FACTOR) {
                        float ref = DistanceCalculator.getDistance(minY, minX, minY, maxX);
                        ref = DistanceCalculator.milesToFeet(ref);
                        float fact = ref / width;
                        g.setStroke(new BasicStroke(width / fact));
                        g.drawLine((int) x1, (int) y1, (int) x2, (int) y2);
                    }

                }
                g.setStroke(new BasicStroke(1));


                //Draw the ILSPath - Start ILS
                double ILSTestLength = 9300.0; //feet

                double ILSTestLengthShort = ILSTestLength - 300;
                double offset = 0.03;

                if (cRunway.hasStartILS()) {
                    if (allObjects.get("ILS: " + aName + " - " + cRunway.getStartNum())) {

                        float ref = DistanceCalculator.milesToFeet(DistanceCalculator.getDistance(minY, minX, minY, maxX));

                        double fact = ref / ILSTestLength;
                        double factShort = ref / ILSTestLengthShort;

                        double angle = Math.atan2(x2 - x1, y2 - y1);
                        angle = angle - Math.PI;

                        //Calculate the edge points
                        int leftOffsetX = (int) (x2 + Math.sin(angle - offset) * (ILSTestLength / fact));
                        int leftOffsetY = (int) (y2 + Math.cos(angle - offset) * (ILSTestLength / fact));
                        int middleX = (int) (x2 + Math.sin(angle) * ((ILSTestLengthShort) / factShort));
                        int middleY = (int) (y2 + Math.cos(angle) * ((ILSTestLengthShort) / factShort));
                        int rightOffsetX = (int) (x2 + Math.sin(angle + offset) * (ILSTestLength / fact));
                        int rightOffsetY = (int) (y2 + Math.cos(angle + offset) * (ILSTestLength / fact));

                        //Draw the actual ILS
                        g.setColor(colors.get("DETAILED_AIRPORT_COLOR_ILS").getColor());
                        g.drawLine((int) x1, (int) y1, leftOffsetX, leftOffsetY);
                        g.drawLine((int) x1, (int) y1, middleX, middleY);
                        g.drawLine((int) x1, (int) y1, rightOffsetX, rightOffsetY);
                        g.drawLine(leftOffsetX, leftOffsetY, middleX, middleY);
                        g.drawLine(rightOffsetX, rightOffsetY, middleX, middleY);
                    }


                }
                //Draw the ILSPath - End ILS
                if (cRunway.hasEndILS()) {

                    if (allObjects.get("ILS: " + aName + " - " + cRunway.getEndNum())) {

                        float ref = DistanceCalculator.getDistance(minY, minX, minY, maxX);
                        ref = DistanceCalculator.milesToFeet(ref);


                        double fact = ref / ILSTestLength;
                        double factShort = ref / ILSTestLengthShort;

                        double angle = Math.atan2(x1 - x2, y1 - y2);
                        angle = angle - Math.PI;
                        //Calculate the edge points
                        int leftOffsetX = (int) (x1 + Math.sin(angle - offset) * (ILSTestLength / fact));
                        int leftOffsetY = (int) (y1 + Math.cos(angle - offset) * (ILSTestLength / fact));
                        int middleX = (int) (x1 + Math.sin(angle) * ((ILSTestLengthShort) / factShort));
                        int middleY = (int) (y1 + Math.cos(angle) * ((ILSTestLengthShort) / factShort));
                        int rightOffsetX = (int) (x1 + Math.sin(angle + offset) * (ILSTestLength / fact));
                        int rightOffsetY = (int) (y1 + Math.cos(angle + offset) * (ILSTestLength / fact));

                        //Draw the actual ILS
                        g.setColor(colors.get("DETAILED_AIRPORT_COLOR_ILS").getColor());
                        g.drawLine((int) x2, (int) y2, leftOffsetX, leftOffsetY);
                        g.drawLine((int) x2, (int) y2, middleX, middleY);
                        g.drawLine((int) x2, (int) y2, rightOffsetX, rightOffsetY);
                        g.drawLine(leftOffsetX, leftOffsetY, middleX, middleY);
                        g.drawLine(rightOffsetX, rightOffsetY, middleX, middleY);
                    }


                }

                //Draw the Runwayname

                if (zoomLevel < 0.1) {
                    if ((Boolean) (allObjects.get("Runway: " + current.getName() + " - " + cRunway.getStartNum())).booleanValue()) {
                        Font f = g.getFont();
                        int xoffset = 0;
                        int yoffset = 0;
                        if (x1 < x2) {
                            xoffset = -15;
                        } else {
                            xoffset = 15;
                        }

                        if (y1 < y2) {
                            yoffset = -15;
                        } else {
                            yoffset = 15;
                        }

                        g.setColor(Color.green.darker().darker());
                        g.setFont(AIRPLANE_NAME_FONT);
                        g.drawString(cRunway.getStartNum(), x1 + xoffset, y1 + yoffset);
                        g.drawString(cRunway.getEndNum(), x2 - xoffset, y2 - yoffset);
                        g.setFont(f);
                    }
                }
            }
        }
    }

    public void drawNavAids(Graphics2D g) {
        if (zoomLevel > 30) {
        } else if (zoomLevel < 3) {
            drawNavaidsDetailed(g);
        } else {
            drawNavaidsUndetailed(g);
        }
    }

    public JPanel getRadarScreen() {
        return this;
    }

    public void paintTest(Graphics g) {
        this.paint(g);
    }

    public void zoomIn() {
        if (zoomLevel > 0.1f) {
            float xdif = maxX - minX;
            xdif /=
                    40;
            float ydif = maxY - minY;
            ydif /=
                    40;
            minX +=
                    xdif;
            maxX -=
                    xdif;
            minY +=
                    ydif;
            maxY -=
                    ydif;
            repaint();
        }

    }

    public void zoomOut() {
        if (zoomLevel < 50) {
            float xdif = maxX - minX;
            xdif /=
                    20;
            float ydif = maxY - minY;
            ydif /=
                    20;
            minX -=
                    xdif;
            maxX +=
                    xdif;
            minY -=
                    ydif;
            maxY +=
                    ydif;
            repaint();
        }

    }

    public void clearPath() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    /**
     * Diese Funktion rechnet die X Bildschirmkoordinate basierend auf einem Laengengrad aus.
     * @param xpos Laengengrad des zu zeichnenden Objektes.
     * @return int Gibt die X Bildschirmkoordinate zurueck.
     */
    private int getX(final float xpos) {
        float diff = maxX - minX;
        float xstep = resX / diff;
        float x = xpos - minX;
        return (int) (x * xstep);
    }

    /**
     * Diese Funktion rechnet die Y Bildschirmkoordinate basierend auf einem Breitengrad aus.
     * @param ypos Breitengrad des zu zeichnenden Objektes.
     * @return int Gibt die Y Bildschirmkoordinate zurueck.
     */
    private int getY(final float ypos) {
        float diff = maxY - minY;
        float ystep = resY / diff;
        float y = ypos - minY;
        return (int) (resY - y * ystep) + 25;
    }

    /**
     * Diese Funktion rechnet die X Bildschirmkoordinate basierend auf einem Laengengrad aus.
     * Es wird ein Floatwert zurueckgegeben.
     * Wird von der PaintPlaneShape() Methode verwendet.
     * @param xpos Laengengrad des zu zeichnenden Objektes.
     * @return Gibt die X Bildschirmkoordinate zurueck.
     */
    private float getXFloat(final float xpos) {

        float diff = maxX - minX;
        float xstep = resX / diff;
        float x = xpos - minX;
        return (x * xstep);
    }

    /**
     * Diese Funktion rechnet die Y Bildschirmkoordinate basierend auf einem Breitengrad aus.
     * Es wird ein Floatwert zurueckgegeben.
     * Wird von der PaintPlaneShape() Methode verwendet.
     * @param ypos Breitengrad des zu zeichnenden Objektes.
     * @return Gibt die Y Bildschirmkoordinate zurueck.
     */
    private float getYFloat(final float ypos) {
        float diff = maxY - minY;
        float ystep = resY / diff;
        float y = ypos - minY;
        return (resY - y * ystep) + 25;
    }

    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        HistorySizeDialog = new javax.swing.JDialog();
        historySizeInput = new javax.swing.JTextField();
        historySizeText = new javax.swing.JLabel();
        historySizeAcceptButton = new javax.swing.JButton();
        MinHeightDialog = new javax.swing.JDialog();
        minHeightText = new javax.swing.JLabel();
        minHeightInput = new javax.swing.JTextField();
        minHeightAcceptButton = new javax.swing.JButton();
        MaxHeightDialog = new javax.swing.JDialog();
        maxHeightText = new javax.swing.JLabel();
        maxHeightInput = new javax.swing.JTextField();
        maxHeightAcceptButton = new javax.swing.JButton();
        toolBar = new javax.swing.JToolBar();
        clearButton = new javax.swing.JButton();
        sep1 = new javax.swing.JToolBar.Separator();
        zoomInButton = new javax.swing.JButton();
        zoomOutButton = new javax.swing.JButton();
        sep2 = new javax.swing.JToolBar.Separator();
        minHeightButton = new javax.swing.JButton();
        sep3 = new javax.swing.JToolBar.Separator();
        maxHeightButton = new javax.swing.JButton();
        sep4 = new javax.swing.JToolBar.Separator();
        historySizeButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        showButton = new javax.swing.JButton();
        radarPanel = new Radar(this);

        HistorySizeDialog.setTitle("History Length");
        HistorySizeDialog.setBounds(new java.awt.Rectangle(0, 0, 300, 70));
        HistorySizeDialog.setResizable(false);

        historySizeInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                historySizeInputActionPerformed(evt);
            }
        });

        historySizeText.setText("Size: ");

        historySizeAcceptButton.setText("Accept");
        historySizeAcceptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                historySizeAcceptButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout HistorySizeDialogLayout = new javax.swing.GroupLayout(HistorySizeDialog.getContentPane());
        HistorySizeDialog.getContentPane().setLayout(HistorySizeDialogLayout);
        HistorySizeDialogLayout.setHorizontalGroup(
            HistorySizeDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(HistorySizeDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(historySizeText)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(historySizeInput, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(historySizeAcceptButton)
                .addContainerGap(54, Short.MAX_VALUE))
        );
        HistorySizeDialogLayout.setVerticalGroup(
            HistorySizeDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(HistorySizeDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(HistorySizeDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(historySizeText)
                    .addComponent(historySizeInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(historySizeAcceptButton))
                .addContainerGap(56, Short.MAX_VALUE))
        );

        MinHeightDialog.setTitle("Minimum Flightlevel");
        MinHeightDialog.setBounds(new java.awt.Rectangle(0, 0, 300, 70));
        MinHeightDialog.setResizable(false);

        minHeightText.setText("MinHeight:");

        minHeightInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minHeightInputActionPerformed(evt);
            }
        });

        minHeightAcceptButton.setText("Accept");
        minHeightAcceptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minHeightAcceptButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout MinHeightDialogLayout = new javax.swing.GroupLayout(MinHeightDialog.getContentPane());
        MinHeightDialog.getContentPane().setLayout(MinHeightDialogLayout);
        MinHeightDialogLayout.setHorizontalGroup(
            MinHeightDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MinHeightDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(minHeightText)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(minHeightInput, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(minHeightAcceptButton)
                .addContainerGap(138, Short.MAX_VALUE))
        );
        MinHeightDialogLayout.setVerticalGroup(
            MinHeightDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MinHeightDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(MinHeightDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(minHeightText)
                    .addComponent(minHeightInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(minHeightAcceptButton))
                .addContainerGap(266, Short.MAX_VALUE))
        );

        MaxHeightDialog.setTitle("Maximum Flightlevel");
        MaxHeightDialog.setBounds(new java.awt.Rectangle(0, 0, 300, 70));
        MaxHeightDialog.setResizable(false);

        maxHeightText.setText("MaxHeight:");

        maxHeightInput.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maxHeightInputActionPerformed(evt);
            }
        });

        maxHeightAcceptButton.setText("Accept");
        maxHeightAcceptButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maxHeightAcceptButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout MaxHeightDialogLayout = new javax.swing.GroupLayout(MaxHeightDialog.getContentPane());
        MaxHeightDialog.getContentPane().setLayout(MaxHeightDialogLayout);
        MaxHeightDialogLayout.setHorizontalGroup(
            MaxHeightDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MaxHeightDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(maxHeightText)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(maxHeightInput, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(maxHeightAcceptButton)
                .addContainerGap(125, Short.MAX_VALUE))
        );
        MaxHeightDialogLayout.setVerticalGroup(
            MaxHeightDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(MaxHeightDialogLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(MaxHeightDialogLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(maxHeightText)
                    .addComponent(maxHeightInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(maxHeightAcceptButton))
                .addContainerGap(266, Short.MAX_VALUE))
        );

        setBackground(new java.awt.Color(0, 0, 0));
        addMouseWheelListener(new java.awt.event.MouseWheelListener() {
            public void mouseWheelMoved(java.awt.event.MouseWheelEvent evt) {
                formMouseWheelMoved(evt);
            }
        });
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
        });
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        toolBar.setFloatable(false);
        toolBar.setRollover(true);

        clearButton.setText("Clear");
        clearButton.setFocusable(false);
        clearButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        clearButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        toolBar.add(clearButton);
        toolBar.add(sep1);

        zoomInButton.setText("Zoom In");
        zoomInButton.setFocusable(false);
        zoomInButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        zoomInButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        zoomInButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zoomInButtonActionPerformed(evt);
            }
        });
        toolBar.add(zoomInButton);

        zoomOutButton.setText("Zoom out");
        zoomOutButton.setFocusable(false);
        zoomOutButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        zoomOutButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        zoomOutButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                zoomOutButtonActionPerformed(evt);
            }
        });
        toolBar.add(zoomOutButton);
        toolBar.add(sep2);

        minHeightButton.setText("minHeight: 0");
        minHeightButton.setFocusable(false);
        minHeightButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        minHeightButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        minHeightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                minHeightButtonActionPerformed(evt);
            }
        });
        toolBar.add(minHeightButton);
        toolBar.add(sep3);

        maxHeightButton.setText("maxHeight: 10000");
        maxHeightButton.setFocusable(false);
        maxHeightButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        maxHeightButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        maxHeightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maxHeightButtonActionPerformed(evt);
            }
        });
        toolBar.add(maxHeightButton);
        toolBar.add(sep4);

        historySizeButton.setText("History-Size: 10 seconds");
        historySizeButton.setFocusable(false);
        historySizeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        historySizeButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        historySizeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                historySizeButtonActionPerformed(evt);
            }
        });
        toolBar.add(historySizeButton);
        toolBar.add(jSeparator1);

        showButton.setText("Show");
        showButton.setFocusable(false);
        showButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        showButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        showButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showButtonActionPerformed(evt);
            }
        });
        toolBar.add(showButton);

        javax.swing.GroupLayout radarPanelLayout = new javax.swing.GroupLayout(radarPanel);
        radarPanel.setLayout(radarPanelLayout);
        radarPanelLayout.setHorizontalGroup(
            radarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 603, Short.MAX_VALUE)
        );
        radarPanelLayout.setVerticalGroup(
            radarPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 452, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(toolBar, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)
            .addComponent(radarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(toolBar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radarPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    private void formMouseWheelMoved(java.awt.event.MouseWheelEvent evt) {//GEN-FIRST:event_formMouseWheelMoved
        if (evt.getWheelRotation() == 1) {
            zoomIn();
        } else {
            zoomOut();
        }
    }//GEN-LAST:event_formMouseWheelMoved

    private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
        moveMap(evt.getX(), evt.getY());
    }//GEN-LAST:event_formMouseClicked

    private void moveMap(double x, double y) {
        int diffX = (int) (x - (int) (resX / 2));
        float subLon = 0;
        if (diffX != 0) {
            float diffLon = maxX - minX;
            float factorX = resX / diffX;
            subLon =
                    diffLon / factorX;
        }

        int diffY = (int) ((y - 25) - (int) (this.getHeight() / 2));
        float subLat = 0;
        if (diffY != 0) {
            float diffLat = maxY - minY;
            float factorY = this.getHeight() / diffY;
            subLat =
                    diffLat / factorY;
        }

        final float lonStep = subLon / 10;
        final float latStep = subLat / 10;
        final Timer moveTimer = new Timer();
        TimerTask moveTimerTask = new TimerTask() {

            private int count = 0;

            @Override
            public void run() {
                count++;
                minX +=
                        lonStep;
                maxX +=
                        lonStep;

                minY -=
                        latStep;
                maxY -=
                        latStep;
                repaint();
                if (count == 9) {
                    moveTimer.cancel();
                    count =
                            0;
                }

            }
        };
        moveTimer.schedule(moveTimerTask, 100, 100);
    }

    private void minHeightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minHeightButtonActionPerformed
        this.MinHeightDialog.setVisible(true);
}//GEN-LAST:event_minHeightButtonActionPerformed

    private void zoomInButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomInButtonActionPerformed
        zoomIn();
    }//GEN-LAST:event_zoomInButtonActionPerformed

    private void zoomOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomOutButtonActionPerformed
        zoomOut();
    }//GEN-LAST:event_zoomOutButtonActionPerformed

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed

        double moveStep = zoomLevel * 0.05;
        switch (evt.getKeyCode()) {
            case (81):
                zoomIn();
                break;
            case (69):
                zoomOut();
                break;
            case (65):
                minX -= moveStep;
                maxX -= moveStep;
                radarPanel.repaint();
                break;
            case (83):
                minY -= moveStep;
                maxY -= moveStep;
                radarPanel.repaint();
                break;
            case (68):
                minX += moveStep;
                maxX += moveStep;
                radarPanel.repaint();
                break;
            case (87):
                minY += moveStep;
                maxY += moveStep;
                radarPanel.repaint();
                break;
        }
    }//GEN-LAST:event_formKeyPressed

    private void showButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showButtonActionPerformed
        showEntities.setVisible(true);
    }//GEN-LAST:event_showButtonActionPerformed

    private void historySizeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_historySizeButtonActionPerformed
        this.HistorySizeDialog.setVisible(true);
        this.historySizeInput.setText(this.historyLength + "");
    }//GEN-LAST:event_historySizeButtonActionPerformed

    private void historySizeInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_historySizeInputActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_historySizeInputActionPerformed

    private void historySizeAcceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_historySizeAcceptButtonActionPerformed
        try {
            int size = Integer.parseInt(historySizeInput.getText());
            if (size > 60) {
                size = 60;
            } else if (size <= 0) {
                size = 1;
            }

            historyLength = size;
            historySizeButton.setText("History-Size: " + size + " seconds");
            this.atmClient.addStatusMessage("History Length Changed (" + size + ")");
        } catch (NumberFormatException e) {
            this.atmClient.addStatusMessage("Invalid History Length Input (" + historySizeInput.getText() + ")");
        }

}//GEN-LAST:event_historySizeAcceptButtonActionPerformed

    private void maxHeightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maxHeightButtonActionPerformed
        this.MaxHeightDialog.setVisible(true);
    }//GEN-LAST:event_maxHeightButtonActionPerformed

    private void minHeightAcceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minHeightAcceptButtonActionPerformed
        try {
            int height = Integer.parseInt(minHeightInput.getText());
            atmcModel.setMinHeight(height);
        } catch (NumberFormatException e) {
            atmClient.addStatusMessage("Invalid Minimum Height (" + minHeightInput.getText() + ")");
        }
    }//GEN-LAST:event_minHeightAcceptButtonActionPerformed

    private void minHeightInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minHeightInputActionPerformed
    // TODO add your handling code here:
    }//GEN-LAST:event_minHeightInputActionPerformed

    private void maxHeightInputActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maxHeightInputActionPerformed
    // TODO add your handling code here:
}//GEN-LAST:event_maxHeightInputActionPerformed

    private void maxHeightAcceptButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maxHeightAcceptButtonActionPerformed
        try {
            int height = Integer.parseInt(maxHeightInput.getText());
            atmcModel.setMaxHeight(height);
        } catch (NumberFormatException e) {
            atmClient.addStatusMessage("Invalid Maximum Height (" + minHeightInput.getText() + ")");
        }
    }//GEN-LAST:event_maxHeightAcceptButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog HistorySizeDialog;
    private javax.swing.JDialog MaxHeightDialog;
    private javax.swing.JDialog MinHeightDialog;
    private javax.swing.JButton clearButton;
    private javax.swing.JButton historySizeAcceptButton;
    private javax.swing.JButton historySizeButton;
    private javax.swing.JTextField historySizeInput;
    private javax.swing.JLabel historySizeText;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JButton maxHeightAcceptButton;
    private javax.swing.JButton maxHeightButton;
    private javax.swing.JTextField maxHeightInput;
    private javax.swing.JLabel maxHeightText;
    private javax.swing.JButton minHeightAcceptButton;
    private javax.swing.JButton minHeightButton;
    private javax.swing.JTextField minHeightInput;
    private javax.swing.JLabel minHeightText;
    private javax.swing.JPanel radarPanel;
    private javax.swing.JToolBar.Separator sep1;
    private javax.swing.JToolBar.Separator sep2;
    private javax.swing.JToolBar.Separator sep3;
    private javax.swing.JToolBar.Separator sep4;
    private javax.swing.JButton showButton;
    private javax.swing.JToolBar toolBar;
    private javax.swing.JButton zoomInButton;
    private javax.swing.JButton zoomOutButton;
    // End of variables declaration//GEN-END:variables
    public class ShowEntitiesDialog extends JDialog {

        public ShowEntitiesDialog() {
            super();
            this.setTitle("Entities");
            this.setBounds(100, 100, 300, 500);
            JScrollPane sPane = new JScrollPane();
            JPanel sPanel = new JPanel();
            sPane.setViewportView(sPanel);

            GridBagLayout grid = new GridBagLayout();
            sPanel.setLayout(grid);

            this.setContentPane(sPane);

            int i = 0;
            JLabel airportLabel = new JLabel("Airports");
            airportLabel.setHorizontalAlignment(SwingConstants.CENTER);
            airportLabel.setOpaque(true);
            airportLabel.setBackground(Color.black);
            airportLabel.setForeground(Color.white);
            airportLabel.setPreferredSize(new Dimension(274, 20));
            GridBagConstraints gAirportLabel = new GridBagConstraints();
            gAirportLabel.gridx = 0;
            gAirportLabel.gridy = i;
            gAirportLabel.fill = GridBagConstraints.REMAINDER;
            grid.setConstraints(airportLabel, gAirportLabel);
            sPanel.add(airportLabel);
            i++;


            for (String s : allObjects.keySet()) {
                if (s.contains("Airport: ")) {
                    final String name = s;
                    JCheckBoxMenuItem tmp = new JCheckBoxMenuItem(name.substring(9),
                            allObjects.get(name));


                    tmp.addItemListener(new ItemListener() {

                        public void itemStateChanged(ItemEvent e) {
                            if (e.getStateChange() == e.DESELECTED) {
                                allObjects.put(name, false);
                                radarPanel.repaint();
                            } else {
                                allObjects.put(name, true);
                                radarPanel.repaint();
                            }
                        }
                    });

                    GridBagConstraints tmpConstraints = new GridBagConstraints();
                    tmpConstraints.gridx = 0;
                    tmpConstraints.gridy = i;
                    grid.setConstraints(tmp, tmpConstraints);
                    sPanel.add(tmp);
                    i++;
                }
            }

            JLabel towerLabel = new JLabel("Towers");
            towerLabel.setHorizontalAlignment(SwingConstants.CENTER);
            towerLabel.setOpaque(true);
            towerLabel.setBackground(Color.black);
            towerLabel.setForeground(Color.white);
            GridBagConstraints gtowerLabel = new GridBagConstraints();
            gtowerLabel.gridx = 0;
            gtowerLabel.gridy = i;
            gtowerLabel.fill = GridBagConstraints.HORIZONTAL;
            grid.setConstraints(towerLabel, gtowerLabel);
            sPanel.add(towerLabel);
            i++;

            for (String s : allObjects.keySet()) {
                if (s.contains("Tower: ")) {
                    final String name = s;
                    JCheckBoxMenuItem tmp = new JCheckBoxMenuItem(name.substring(7),
                            allObjects.get(name));


                    tmp.addItemListener(new ItemListener() {

                        public void itemStateChanged(ItemEvent e) {
                            if (e.getStateChange() == e.DESELECTED) {
                                allObjects.put(name, false);
                                radarPanel.repaint();
                            } else {
                                allObjects.put(name, true);
                                radarPanel.repaint();
                            }
                        }
                    });

                    GridBagConstraints tmpConstraints = new GridBagConstraints();
                    tmpConstraints.gridx = 0;
                    tmpConstraints.gridy = i;
                    grid.setConstraints(tmp, tmpConstraints);
                    sPanel.add(tmp);
                    i++;
                }
            }

            JLabel runwayLabel = new JLabel("Runways");
            runwayLabel.setHorizontalAlignment(SwingConstants.CENTER);
            runwayLabel.setOpaque(true);
            runwayLabel.setBackground(Color.black);
            runwayLabel.setForeground(Color.white);
            GridBagConstraints grunwayLabel = new GridBagConstraints();
            grunwayLabel.gridx = 0;
            grunwayLabel.gridy = i;
            grunwayLabel.fill = GridBagConstraints.HORIZONTAL;
            grid.setConstraints(runwayLabel, grunwayLabel);
            sPanel.add(runwayLabel);
            i++;

            for (String s : allObjects.keySet()) {
                if (s.contains("Runway: ")) {
                    final String name = s;
                    JCheckBoxMenuItem tmp = new JCheckBoxMenuItem(name.substring(8),
                            allObjects.get(name));


                    tmp.addItemListener(new ItemListener() {

                        public void itemStateChanged(ItemEvent e) {
                            if (e.getStateChange() == e.DESELECTED) {
                                allObjects.put(name, false);
                                radarPanel.repaint();
                            } else {
                                allObjects.put(name, true);
                                radarPanel.repaint();
                            }
                        }
                    });

                    GridBagConstraints tmpConstraints = new GridBagConstraints();
                    tmpConstraints.gridx = 0;
                    tmpConstraints.gridy = i;
                    grid.setConstraints(tmp, tmpConstraints);
                    sPanel.add(tmp);
                    i++;
                }
            }

            JLabel ilsLabel = new JLabel("ILSs");
            ilsLabel.setHorizontalAlignment(SwingConstants.CENTER);
            ilsLabel.setOpaque(true);
            ilsLabel.setBackground(Color.black);
            ilsLabel.setForeground(Color.white);
            GridBagConstraints gilsLabel = new GridBagConstraints();
            gilsLabel.gridx = 0;
            gilsLabel.gridy = i;
            gilsLabel.fill = GridBagConstraints.HORIZONTAL;
            grid.setConstraints(ilsLabel, gilsLabel);
            sPanel.add(ilsLabel);
            i++;

            for (String s : allObjects.keySet()) {
                if (s.contains("ILS: ")) {
                    final String name = s;
                    JCheckBoxMenuItem tmp = new JCheckBoxMenuItem(name.substring(5),
                            allObjects.get(name));


                    tmp.addItemListener(new ItemListener() {

                        public void itemStateChanged(ItemEvent e) {
                            if (e.getStateChange() == e.DESELECTED) {
                                allObjects.put(name, false);
                                radarPanel.repaint();
                            } else {
                                allObjects.put(name, true);
                                radarPanel.repaint();
                            }
                        }
                    });

                    GridBagConstraints tmpConstraints = new GridBagConstraints();
                    tmpConstraints.gridx = 0;
                    tmpConstraints.gridy = i;
                    grid.setConstraints(tmp, tmpConstraints);
                    sPanel.add(tmp);
                    i++;
                }
            }

            JLabel navaidLabel = new JLabel("Navaids");
            navaidLabel.setHorizontalAlignment(SwingConstants.CENTER);
            navaidLabel.setOpaque(true);
            navaidLabel.setBackground(Color.black);
            navaidLabel.setForeground(Color.white);
            GridBagConstraints gnavaidLabel = new GridBagConstraints();
            gnavaidLabel.gridx = 0;
            gnavaidLabel.gridy = i;
            gnavaidLabel.fill = GridBagConstraints.HORIZONTAL;
            grid.setConstraints(navaidLabel, gnavaidLabel);
            sPanel.add(navaidLabel);
            i++;

            for (String s : allObjects.keySet()) {
                if (s.contains("Navaid: ")) {
                    final String name = s;
                    JCheckBoxMenuItem tmp = new JCheckBoxMenuItem(name.substring(8),
                            allObjects.get(name));


                    tmp.addItemListener(new ItemListener() {

                        public void itemStateChanged(ItemEvent e) {
                            if (e.getStateChange() == e.DESELECTED) {
                                allObjects.put(name, false);
                                radarPanel.repaint();
                            } else {
                                allObjects.put(name, true);
                                radarPanel.repaint();
                            }
                        }
                    });

                    GridBagConstraints tmpConstraints = new GridBagConstraints();
                    tmpConstraints.gridx = 0;
                    tmpConstraints.gridy = i;
                    grid.setConstraints(tmp, tmpConstraints);
                    sPanel.add(tmp);
                    i++;
                }
            }
            JLabel tmpLabel = new JLabel();
            GridBagConstraints tmpConstraints = new GridBagConstraints();
            tmpConstraints.gridx = 0;
            tmpConstraints.gridy = i;
            tmpConstraints.weighty = 2.0;
            tmpConstraints.fill = GridBagConstraints.BOTH;
            grid.setConstraints(tmpLabel, tmpConstraints);
            sPanel.add(tmpLabel);

            this.validate();
        }
    }

    public class Radar extends JPanel {

        public RadarTab tab;

        public Radar() {
        }

        public Radar(RadarTab rTab) {
            super();
            tab = rTab;
        }

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);

            resX = tab.getWidth();
            resY = (int) (resX / asp); //DO NOT! CHANGE

            g.setColor(colors.get("BGCOLOR").getColor());

            zoomLevel =
                    maxX - minX;

            g.fillRect(0, 0, resX, this.getHeight());

            drawAirports((Graphics2D) g);
            drawNavAids((Graphics2D) g);
            drawPlanes(g);
        }
    }

    private void refreshNavaids() {
        navaids = atmcModel.getNavaids();
        refreshObjects();
    }

    private void refreshAirports() {
        airports = atmcModel.getAirports();
        refreshObjects();
    }

    private void refreshHeights() {
        String minHeight = atmcModel.getMinHeight()+"";
        String maxHeight = atmcModel.getMaxHeight()+"";
        minHeightButton.setText("minHeight: " + minHeight);
        maxHeightButton.setText("maxHeight: " + maxHeight);
        minHeightInput.setText(minHeight);
        maxHeightInput.setText(maxHeight);
        repaint();
    }

    private void refreshColors() {
        colors = atmcModel.getRadarColors();
        setBackground(colors.get("BGCOLOR").getColor());
        repaint();
    }

    private void refreshObjects() {
        allObjects.clear();

        Iterator it = navaids.values().iterator();
        while (it.hasNext()) {
            NavaidCoord nav = (NavaidCoord) it.next();
            allObjects.put("Navaid: " + nav.getName(), new Boolean(true));
        }
        it = airports.values().iterator();
        while (it.hasNext()) {
            Airport air = (Airport) it.next();
            allObjects.put("Airport: " + air.getName(), true);
            if (air.hasTower()) {
                allObjects.put("Tower: " + air.getName() + " - " + air.getTower().getName(), new Boolean(true));
            }
            Iterator rIt = air.getRunways();
            while (rIt.hasNext()) {
                Runway run = (Runway) rIt.next();
                allObjects.put("Runway: " + air.getName() + " - " + run.getStartNum(), new Boolean(true));
                if (run.hasStartILS()) {
                    allObjects.put("ILS: " + air.getName() + " - " + run.getStartNum(), true);
                }
                if (run.hasEndILS()) {
                    allObjects.put("ILS: " + air.getName() + " - " + run.getEndNum(), true);
                }
            }
        }
        showEntities = new ShowEntitiesDialog();
        repaint();
    }

    public void update(Observable o, Object arg) {
        if (arg instanceof ColorEvent) {
            refreshColors();
        } else if (arg instanceof AirportEvent) {
            refreshAirports();
        } else if (arg instanceof HeightEvent) {
            refreshHeights();
        } else if (arg instanceof NavaidEvent) {
            refreshNavaids();
        }
    }
}
TOP

Related Classes of gui.tabs.RadarTab

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.