1 | /************************************************************************************ |
---|
2 | * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University |
---|
3 | * All rights reserved. |
---|
4 | * Refer to LICENSE for terms and conditions of use. |
---|
5 | ***********************************************************************************/ |
---|
6 | package vnsim.gui; |
---|
7 | |
---|
8 | |
---|
9 | import java.awt.Dimension; |
---|
10 | import java.awt.Toolkit; |
---|
11 | import java.awt.Frame; |
---|
12 | import javax.swing.*; |
---|
13 | |
---|
14 | import vnsim.applications.trafficview.SimulatedCarInfo; |
---|
15 | import vnsim.map.object.*; |
---|
16 | |
---|
17 | public class Display extends JFrame { |
---|
18 | |
---|
19 | private Control ct; // Controls |
---|
20 | |
---|
21 | public MapView mv; // The map |
---|
22 | |
---|
23 | public DriverView nv; |
---|
24 | |
---|
25 | public Statistics st; |
---|
26 | |
---|
27 | private SpringLayout layout; |
---|
28 | |
---|
29 | static final long serialVersionUID = 1; |
---|
30 | |
---|
31 | public Display() { |
---|
32 | super("TrafficSimulator"); |
---|
33 | |
---|
34 | getMinAndMaxPoint(); |
---|
35 | // Set the frames's properties |
---|
36 | setDefaultLookAndFeelDecorated(true); |
---|
37 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
38 | |
---|
39 | layout = new SpringLayout(); |
---|
40 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();// get's |
---|
41 | screenSize.height = screenSize.height - 60; |
---|
42 | |
---|
43 | ct = new Control(((screenSize.width * 6) / 7), (screenSize.height / 7)); |
---|
44 | st = new Statistics((screenSize.width / 7), screenSize.height); |
---|
45 | mv = new MapView(st, ((screenSize.width * 6) / 7), |
---|
46 | ((screenSize.height * 6) / 7)); |
---|
47 | nv = new DriverView(((screenSize.width * 6) / 7), |
---|
48 | ((screenSize.height * 6) / 7)); |
---|
49 | this.setSize(screenSize.width, screenSize.height); |
---|
50 | this.setLocation(0, 0);// places the main window starting from the |
---|
51 | // upper left corner of the screen |
---|
52 | this.getContentPane().setLayout(layout); |
---|
53 | // places each component at it's position in the Frame |
---|
54 | SpringLayout.Constraints mvConstraint = layout.getConstraints(mv); |
---|
55 | SpringLayout.Constraints ctConstraint = layout.getConstraints(ct); |
---|
56 | SpringLayout.Constraints stConstraint = layout.getConstraints(st); |
---|
57 | SpringLayout.Constraints nvConstraint = layout.getConstraints(nv); |
---|
58 | |
---|
59 | mvConstraint.setX(Spring.constant(0)); |
---|
60 | mvConstraint.setY(Spring.constant(0)); |
---|
61 | mvConstraint.setWidth(Spring.constant((screenSize.width * 6) / 7)); |
---|
62 | mvConstraint.setHeight(Spring.constant((screenSize.height * 6) / 7)); |
---|
63 | |
---|
64 | nvConstraint.setX(Spring.constant(0)); |
---|
65 | nvConstraint.setY(Spring.constant(0)); |
---|
66 | nvConstraint.setWidth(Spring.constant((screenSize.width * 6) / 7)); |
---|
67 | nvConstraint.setHeight(Spring.constant((screenSize.height * 6) / 7)); |
---|
68 | |
---|
69 | ctConstraint.setX(Spring.constant(0)); |
---|
70 | ctConstraint.setY(Spring.constant((screenSize.height * 6) / 7)); |
---|
71 | ctConstraint.setWidth(Spring.constant((screenSize.width * 6) / 7)); |
---|
72 | ctConstraint.setHeight(Spring.constant(screenSize.height / 7)); |
---|
73 | |
---|
74 | stConstraint.setX(Spring.constant((screenSize.width * 6) / 7)); |
---|
75 | stConstraint.setY(Spring.constant(0)); |
---|
76 | stConstraint.setWidth(Spring.constant(screenSize.width / 7)); |
---|
77 | stConstraint.setHeight(Spring.constant(screenSize.height)); |
---|
78 | |
---|
79 | // adds the components to the frame |
---|
80 | this.getContentPane().add(mv); |
---|
81 | this.getContentPane().add(st); |
---|
82 | this.getContentPane().add(ct); |
---|
83 | |
---|
84 | setVisible(true); |
---|
85 | this.setExtendedState(Frame.MAXIMIZED_BOTH); |
---|
86 | |
---|
87 | } |
---|
88 | |
---|
89 | // Get the minimum&maximum latitude and minimum&maximum longitude on the Map |
---|
90 | public void getMinAndMaxPoint() { |
---|
91 | |
---|
92 | // sets the Globals.minPoint and Globals.maxPoint |
---|
93 | // with the determined values |
---|
94 | Map currentMap; |
---|
95 | Point tmpPoint, minPoint, maxPoint; |
---|
96 | Road tmpRoad; |
---|
97 | int i, j; |
---|
98 | i = 0; |
---|
99 | currentMap = Globals.map; |
---|
100 | |
---|
101 | minPoint = new Point((double) 180, (double) 90); |
---|
102 | maxPoint = new Point((double) -180, (double) -90); |
---|
103 | while (i < currentMap.roads.size()) { |
---|
104 | tmpRoad = (Road) currentMap.roads.get(i); |
---|
105 | j = 0; |
---|
106 | while (j < tmpRoad.points.size()) { |
---|
107 | tmpPoint = (Point) tmpRoad.points.get(j); |
---|
108 | if (tmpPoint.getLatitude() < minPoint.getLatitude()) { |
---|
109 | minPoint.setLatitude(tmpPoint.getLatitude()); |
---|
110 | } |
---|
111 | if (tmpPoint.getLongitude() < minPoint.getLongitude()) { |
---|
112 | minPoint.setLongitude(tmpPoint.getLongitude()); |
---|
113 | } |
---|
114 | |
---|
115 | if (tmpPoint.getLatitude() > maxPoint.getLatitude()) { |
---|
116 | maxPoint.setLatitude(tmpPoint.getLatitude()); |
---|
117 | } |
---|
118 | if (tmpPoint.getLongitude() > maxPoint.getLongitude()) { |
---|
119 | maxPoint.setLongitude(tmpPoint.getLongitude()); |
---|
120 | } |
---|
121 | |
---|
122 | j++; |
---|
123 | } |
---|
124 | i++; |
---|
125 | } |
---|
126 | Globals.minPoint = minPoint; |
---|
127 | Globals.maxPoint = maxPoint; |
---|
128 | |
---|
129 | } |
---|
130 | |
---|
131 | public void zoomIn() { |
---|
132 | this.mv.zoomIn(); |
---|
133 | } |
---|
134 | |
---|
135 | public void zoomOut() { |
---|
136 | this.mv.zoomOut(); |
---|
137 | } |
---|
138 | |
---|
139 | public void setCurrentCar(SimulatedCarInfo s) { |
---|
140 | this.mv.currentCar = s; |
---|
141 | } |
---|
142 | |
---|
143 | public void setDriverView() { |
---|
144 | |
---|
145 | this.getContentPane().remove(mv); |
---|
146 | this.getContentPane().add(nv); |
---|
147 | this.repaint(); |
---|
148 | } |
---|
149 | |
---|
150 | public void unsetDriverView() { |
---|
151 | this.getContentPane().remove(nv); |
---|
152 | this.getContentPane().add(mv); |
---|
153 | this.repaint(); |
---|
154 | } |
---|
155 | } |
---|