/************************************************************************************ * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University * All rights reserved. * Refer to LICENSE for terms and conditions of use. ***********************************************************************************/ package vnsim.gui; import java.awt.Dimension; import java.awt.Toolkit; import java.awt.Frame; import javax.swing.*; import vnsim.applications.trafficview.SimulatedCarInfo; import vnsim.map.object.*; public class Display extends JFrame { private Control ct; // Controls public MapView mv; // The map public DriverView nv; public Statistics st; private SpringLayout layout; static final long serialVersionUID = 1; public Display() { super("TrafficSimulator"); getMinAndMaxPoint(); // Set the frames's properties setDefaultLookAndFeelDecorated(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); layout = new SpringLayout(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();// get's screenSize.height = screenSize.height - 60; ct = new Control(((screenSize.width * 6) / 7), (screenSize.height / 7)); st = new Statistics((screenSize.width / 7), screenSize.height); mv = new MapView(st, ((screenSize.width * 6) / 7), ((screenSize.height * 6) / 7)); nv = new DriverView(((screenSize.width * 6) / 7), ((screenSize.height * 6) / 7)); this.setSize(screenSize.width, screenSize.height); this.setLocation(0, 0);// places the main window starting from the // upper left corner of the screen this.getContentPane().setLayout(layout); // places each component at it's position in the Frame SpringLayout.Constraints mvConstraint = layout.getConstraints(mv); SpringLayout.Constraints ctConstraint = layout.getConstraints(ct); SpringLayout.Constraints stConstraint = layout.getConstraints(st); SpringLayout.Constraints nvConstraint = layout.getConstraints(nv); mvConstraint.setX(Spring.constant(0)); mvConstraint.setY(Spring.constant(0)); mvConstraint.setWidth(Spring.constant((screenSize.width * 6) / 7)); mvConstraint.setHeight(Spring.constant((screenSize.height * 6) / 7)); nvConstraint.setX(Spring.constant(0)); nvConstraint.setY(Spring.constant(0)); nvConstraint.setWidth(Spring.constant((screenSize.width * 6) / 7)); nvConstraint.setHeight(Spring.constant((screenSize.height * 6) / 7)); ctConstraint.setX(Spring.constant(0)); ctConstraint.setY(Spring.constant((screenSize.height * 6) / 7)); ctConstraint.setWidth(Spring.constant((screenSize.width * 6) / 7)); ctConstraint.setHeight(Spring.constant(screenSize.height / 7)); stConstraint.setX(Spring.constant((screenSize.width * 6) / 7)); stConstraint.setY(Spring.constant(0)); stConstraint.setWidth(Spring.constant(screenSize.width / 7)); stConstraint.setHeight(Spring.constant(screenSize.height)); // adds the components to the frame this.getContentPane().add(mv); this.getContentPane().add(st); this.getContentPane().add(ct); setVisible(true); this.setExtendedState(Frame.MAXIMIZED_BOTH); } // Get the minimum&maximum latitude and minimum&maximum longitude on the Map public void getMinAndMaxPoint() { // sets the Globals.minPoint and Globals.maxPoint // with the determined values Map currentMap; Point tmpPoint, minPoint, maxPoint; Road tmpRoad; int i, j; i = 0; currentMap = Globals.map; minPoint = new Point((double) 180, (double) 90); maxPoint = new Point((double) -180, (double) -90); while (i < currentMap.roads.size()) { tmpRoad = (Road) currentMap.roads.get(i); j = 0; while (j < tmpRoad.points.size()) { tmpPoint = (Point) tmpRoad.points.get(j); if (tmpPoint.getLatitude() < minPoint.getLatitude()) { minPoint.setLatitude(tmpPoint.getLatitude()); } if (tmpPoint.getLongitude() < minPoint.getLongitude()) { minPoint.setLongitude(tmpPoint.getLongitude()); } if (tmpPoint.getLatitude() > maxPoint.getLatitude()) { maxPoint.setLatitude(tmpPoint.getLatitude()); } if (tmpPoint.getLongitude() > maxPoint.getLongitude()) { maxPoint.setLongitude(tmpPoint.getLongitude()); } j++; } i++; } Globals.minPoint = minPoint; Globals.maxPoint = maxPoint; } public void zoomIn() { this.mv.zoomIn(); } public void zoomOut() { this.mv.zoomOut(); } public void setCurrentCar(SimulatedCarInfo s) { this.mv.currentCar = s; } public void setDriverView() { this.getContentPane().remove(mv); this.getContentPane().add(nv); this.repaint(); } public void unsetDriverView() { this.getContentPane().remove(nv); this.getContentPane().add(mv); this.repaint(); } }