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 | import java.awt.Color; |
---|
9 | import java.awt.GridLayout; |
---|
10 | import java.awt.event.ActionEvent; |
---|
11 | import java.awt.event.ActionListener; |
---|
12 | import java.awt.event.ComponentEvent; |
---|
13 | import java.awt.event.ComponentListener; |
---|
14 | import java.io.File; |
---|
15 | import java.io.FileInputStream; |
---|
16 | import java.io.FileOutputStream; |
---|
17 | import java.io.ObjectInputStream; |
---|
18 | import java.io.ObjectOutputStream; |
---|
19 | import java.io.RandomAccessFile; |
---|
20 | import java.util.Random; |
---|
21 | import java.util.StringTokenizer; |
---|
22 | import java.util.TreeSet; |
---|
23 | import java.util.Vector; |
---|
24 | import java.util.logging.Level; |
---|
25 | import java.util.logging.Logger; |
---|
26 | |
---|
27 | import javax.swing.ButtonGroup; |
---|
28 | import javax.swing.DefaultListModel; |
---|
29 | import javax.swing.JButton; |
---|
30 | import javax.swing.JCheckBox; |
---|
31 | import javax.swing.JFrame; |
---|
32 | import javax.swing.JLabel; |
---|
33 | import javax.swing.JList; |
---|
34 | import javax.swing.JOptionPane; |
---|
35 | import javax.swing.JPanel; |
---|
36 | import javax.swing.JRadioButton; |
---|
37 | import javax.swing.JScrollPane; |
---|
38 | import javax.swing.JTextField; |
---|
39 | import javax.swing.Spring; |
---|
40 | import javax.swing.SpringLayout; |
---|
41 | import javax.swing.plaf.basic.BasicBorders.RadioButtonBorder; |
---|
42 | |
---|
43 | import vnsim.applications.adaptiveTL.WirelessTrafficLight; |
---|
44 | import vnsim.applications.trafficview.SimulatedCarInfo; |
---|
45 | import vnsim.core.Engine; |
---|
46 | import vnsim.gui.Utils.ClassSystemView; |
---|
47 | import vnsim.gui.selector.StartRouteDesigner; |
---|
48 | import vnsim.gui.selector.StartScenarioDesigner; |
---|
49 | import vnsim.map.object.Globals; |
---|
50 | import vnsim.socialNet.GlobalNetwork; |
---|
51 | import vnsim.vehicular.routePlan.RoutingConstants; |
---|
52 | import vnsim.vehicular.scenarios.MainSMFCreator; |
---|
53 | |
---|
54 | public class MapLoader { |
---|
55 | |
---|
56 | /** Logger used by this class */ |
---|
57 | private static final transient Logger logger = Logger.getLogger("gui.MapLoader"); |
---|
58 | |
---|
59 | static void loadSerializedMap(String file) throws Exception { |
---|
60 | ObjectInputStream ois = new ObjectInputStream(new FileInputStream(mapsDir + file)); |
---|
61 | Globals.map = (vnsim.map.object.Map) ois.readObject(); |
---|
62 | } |
---|
63 | |
---|
64 | static void createMapFromRT1(String file) throws Exception { |
---|
65 | // file = "*.RT1" or "*.rt1" |
---|
66 | String file2 = null; |
---|
67 | if (file.endsWith(".rt1")) { |
---|
68 | file2 = file.substring(0, file.length() - 4) + ".rt2"; |
---|
69 | } else if (file.endsWith(".RT1")) { |
---|
70 | file2 = file.substring(0, file.length() - 4) + ".RT2"; |
---|
71 | } else { |
---|
72 | logger.severe("ERROR: file not rt1 or RT1:" + file); |
---|
73 | throw new Exception("ERROR: file not rt1 or RT1:" + file); |
---|
74 | |
---|
75 | } |
---|
76 | |
---|
77 | logger.info("PARAMS:" + rtDir + file + ";" + rtDir + file2); |
---|
78 | Globals.map = new vnsim.map.object.Map(rtDir + file, rtDir + file2); |
---|
79 | final String dir = System.getProperty("user.home") + File.separatorChar + "maps" + File.separatorChar + "map"; |
---|
80 | (new File(dir)).mkdirs(); |
---|
81 | ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(dir + File.separatorChar |
---|
82 | + file.substring(0, file.length() - 4) + ".map")); |
---|
83 | try { |
---|
84 | loadExtraInfo(file.substring(0, file.length() - 4) + ".rtx.txt"); |
---|
85 | } catch (Exception ex) { |
---|
86 | logger.log(Level.WARNING, "Extra info not loaded: check file: " + file.substring(0, file.length() - 4) |
---|
87 | + ".rtx.txt", ex); |
---|
88 | } |
---|
89 | Globals.map.createTrafficLights(new Random()); |
---|
90 | logger.info("Writing Map File..."); |
---|
91 | oos.writeObject(Globals.map); |
---|
92 | oos.close(); |
---|
93 | logger.info("Done writing map file"); |
---|
94 | } |
---|
95 | |
---|
96 | private final static String mapsDir = "/maps/map/"; |
---|
97 | |
---|
98 | private final static String rtDir = "/maps/rt/"; |
---|
99 | |
---|
100 | private final static String smfDir = "/maps/smf/"; |
---|
101 | |
---|
102 | private final static String fscDir = "/maps/fsc/"; |
---|
103 | |
---|
104 | static boolean startDesigner = false; |
---|
105 | |
---|
106 | static boolean startRouteDesign = false; |
---|
107 | |
---|
108 | static boolean startSimulation = false; |
---|
109 | |
---|
110 | static boolean socialNetwork = false; |
---|
111 | |
---|
112 | static String selectedScenario; |
---|
113 | |
---|
114 | public static JList listMap, listFsc, listSmf, list; |
---|
115 | |
---|
116 | private static JFrame frame; |
---|
117 | |
---|
118 | public static void show(boolean isShowing) { |
---|
119 | frame.setVisible(isShowing); |
---|
120 | if (isShowing) |
---|
121 | frame.getContentPane().repaint(); |
---|
122 | } |
---|
123 | |
---|
124 | public static String[] readSerializedMaps() { |
---|
125 | final ClassSystemView f1 = new ClassSystemView(mapsDir); |
---|
126 | String[] files1 = f1.list(); |
---|
127 | File f = (new File(System.getProperty("user.home") + File.separatorChar + "maps" + File.separatorChar + "map")); |
---|
128 | String[] files2 = null; |
---|
129 | if (f.exists() && f.isDirectory()) |
---|
130 | files2 = f.list(); |
---|
131 | // merge the two lists... |
---|
132 | final TreeSet<String> l = new TreeSet<String>(); |
---|
133 | if (files1 != null && files1.length != 0) |
---|
134 | for (int i = 0; i < files1.length; i++) |
---|
135 | if (!l.contains(files1[i])) |
---|
136 | l.add(files1[i]); |
---|
137 | if (files2 != null && files2.length != 0) |
---|
138 | for (int i = 0; i < files2.length; i++) |
---|
139 | if (!l.contains(files2[i])) |
---|
140 | l.add(files2[i]); |
---|
141 | files1 = new String[l.size()]; |
---|
142 | files1 = l.toArray(files1); |
---|
143 | return files1; |
---|
144 | } |
---|
145 | |
---|
146 | public static String[] readSMFs() { |
---|
147 | final ClassSystemView f1 = new ClassSystemView(smfDir); |
---|
148 | String[] files1 = f1.list(); |
---|
149 | File f = (new File(System.getProperty("user.home") + File.separatorChar + "maps" + File.separatorChar + "smf")); |
---|
150 | String[] files2 = null; |
---|
151 | if (f.exists() && f.isDirectory()) |
---|
152 | files2 = f.list(); |
---|
153 | // merge the two lists... |
---|
154 | final TreeSet<String> l = new TreeSet<String>(); |
---|
155 | if (files1 != null && files1.length != 0) |
---|
156 | for (int i = 0; i < files1.length; i++) |
---|
157 | if (!l.contains(files1[i])) |
---|
158 | l.add(files1[i]); |
---|
159 | if (files2 != null && files2.length != 0) |
---|
160 | for (int i = 0; i < files2.length; i++) |
---|
161 | if (!l.contains(files2[i])) |
---|
162 | l.add(files2[i]); |
---|
163 | files1 = new String[l.size()]; |
---|
164 | files1 = l.toArray(files1); |
---|
165 | return files1; |
---|
166 | } |
---|
167 | |
---|
168 | public static String[] readFSCs() { |
---|
169 | final ClassSystemView f1 = new ClassSystemView(fscDir); |
---|
170 | String[] files1 = f1.list(); |
---|
171 | File f = (new File(System.getProperty("user.home") + File.separatorChar + "maps" + File.separatorChar + "fsc")); |
---|
172 | String[] files2 = null; |
---|
173 | if (f.exists() && f.isDirectory()) |
---|
174 | files2 = f.list(); |
---|
175 | // merge the two lists... |
---|
176 | final TreeSet<String> l = new TreeSet<String>(); |
---|
177 | if (files1 != null && files1.length != 0) |
---|
178 | for (int i = 0; i < files1.length; i++) |
---|
179 | if (!l.contains(files1[i])) |
---|
180 | l.add(files1[i]); |
---|
181 | if (files2 != null && files2.length != 0) |
---|
182 | for (int i = 0; i < files2.length; i++) |
---|
183 | if (!l.contains(files2[i])) |
---|
184 | l.add(files2[i]); |
---|
185 | files1 = new String[l.size()]; |
---|
186 | files1 = l.toArray(files1); |
---|
187 | return files1; |
---|
188 | } |
---|
189 | |
---|
190 | /** |
---|
191 | * |
---|
192 | */ |
---|
193 | /** |
---|
194 | * |
---|
195 | */ |
---|
196 | public static void loadMap() { |
---|
197 | |
---|
198 | frame = new JFrame(); |
---|
199 | frame.addComponentListener(new MapLoaderComponentListener()); |
---|
200 | frame.setSize(810, 400); |
---|
201 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
202 | |
---|
203 | list = new JList(); |
---|
204 | listSmf = new JList(new DefaultListModel()); |
---|
205 | ((DefaultListModel) listSmf.getModel()).addElement("tt"); |
---|
206 | listFsc = new JList(); |
---|
207 | listMap = new JList(); |
---|
208 | |
---|
209 | final JButton buildMap = new JButton("Build Map"); |
---|
210 | final JButton smf = new JButton("Create Empty Scenarios"); |
---|
211 | final JButton scenario = new JButton("Scenario Designer"); |
---|
212 | final JButton startSim = new JButton("Simulate Scenario"); |
---|
213 | final JButton routeDesign = new JButton("Route Designer"); |
---|
214 | final JButton socialNet = new JButton("Social Network"); |
---|
215 | final JButton refresh = new JButton("Refresh"); |
---|
216 | |
---|
217 | JButton exit = new JButton("Exit"); |
---|
218 | final JLabel label1, label2, label3, label4; |
---|
219 | final JScrollPane scroll1, scroll2, scroll3, scroll4; |
---|
220 | scroll1 = new JScrollPane(); |
---|
221 | scroll2 = new JScrollPane(); |
---|
222 | scroll3 = new JScrollPane(); |
---|
223 | scroll4 = new JScrollPane(); |
---|
224 | |
---|
225 | label1 = new JLabel("Raw maps:"); |
---|
226 | label2 = new JLabel("Serialized maps:"); |
---|
227 | label3 = new JLabel("Empty Scenarios:"); |
---|
228 | label4 = new JLabel("Complete Scenarios:"); |
---|
229 | scroll1.setViewportView(list); |
---|
230 | scroll2.setViewportView(listMap); |
---|
231 | scroll3.setViewportView(listSmf); |
---|
232 | scroll4.setViewportView(listFsc); |
---|
233 | |
---|
234 | final ClassSystemView f1 = new ClassSystemView(rtDir); |
---|
235 | String[] files1 = f1.list(); |
---|
236 | String[] files2 = readSerializedMaps(); |
---|
237 | String[] files3 = readSMFs(); |
---|
238 | String[] files4 = readFSCs(); |
---|
239 | if (files1 == null) |
---|
240 | System.out.println("eroare 1"); |
---|
241 | if (files1 == null || files2 == null || files3 == null || files4 == null) { |
---|
242 | // System.out.println(files1.length); |
---|
243 | // System.out.println(files2.length); |
---|
244 | // System.out.println(files3.length); |
---|
245 | // System.out.println(files4.length); |
---|
246 | logger.severe("ERROR! Directories maps/map or maps/rt or maps/fsc or maps/smf not found!"); |
---|
247 | System.exit(0); |
---|
248 | } |
---|
249 | |
---|
250 | Vector<String> maps = new Vector<String>(); |
---|
251 | for (int i = 0; i < files1.length; i++) { |
---|
252 | if ((files1[i].endsWith(".RT1") || (files1[i].endsWith(".rt1")))) |
---|
253 | maps.addElement(files1[i]); |
---|
254 | } |
---|
255 | |
---|
256 | |
---|
257 | listSmf.setListData(files3); |
---|
258 | listFsc.setListData(files4); |
---|
259 | list.setListData(maps); |
---|
260 | listMap.setListData(files2); |
---|
261 | |
---|
262 | buildMap.addActionListener(new ActionListener() { |
---|
263 | public void actionPerformed(ActionEvent e) { |
---|
264 | String sel = (String) list.getSelectedValue(); |
---|
265 | if (sel == null) { |
---|
266 | JOptionPane.showMessageDialog(null, "Select a raw map first!"); |
---|
267 | return; |
---|
268 | } |
---|
269 | try { |
---|
270 | createMapFromRT1(sel); |
---|
271 | } catch (Exception ex) { |
---|
272 | logger.log(Level.WARNING, "Got exception creating map from rt1 file", ex); |
---|
273 | } |
---|
274 | listMap.setListData(readSerializedMaps()); |
---|
275 | } |
---|
276 | }); |
---|
277 | |
---|
278 | exit.addActionListener(new ActionListener() { |
---|
279 | public void actionPerformed(ActionEvent ev) { |
---|
280 | logger.info("Bye bye"); |
---|
281 | frame.dispose(); |
---|
282 | System.exit(0); |
---|
283 | } |
---|
284 | }); |
---|
285 | |
---|
286 | smf.addActionListener(new ActionListener() { |
---|
287 | public void actionPerformed(ActionEvent ev) { |
---|
288 | String sel = (String) listMap.getSelectedValue(); |
---|
289 | if (sel == null) { |
---|
290 | JOptionPane.showMessageDialog(null, "Select a map first!"); |
---|
291 | return; |
---|
292 | } |
---|
293 | try { |
---|
294 | MainSMFCreator.main(null); |
---|
295 | } catch (Exception e) { |
---|
296 | // return; |
---|
297 | } |
---|
298 | logger.info("SMF files created"); |
---|
299 | listSmf.setListData(readSMFs()); |
---|
300 | } |
---|
301 | }); |
---|
302 | |
---|
303 | scenario.addActionListener(new ActionListener() { |
---|
304 | public void actionPerformed(ActionEvent ev) { |
---|
305 | String sel = (String) listSmf.getSelectedValue(); |
---|
306 | if (sel == null) { |
---|
307 | JOptionPane.showMessageDialog(null, "Select an empty scenario first!"); |
---|
308 | return; |
---|
309 | } |
---|
310 | show(!StartScenarioDesigner.createWindow()); |
---|
311 | } |
---|
312 | }); |
---|
313 | |
---|
314 | routeDesign.addActionListener(new ActionListener() { |
---|
315 | public void actionPerformed(ActionEvent ev) { |
---|
316 | String sel = (String) listSmf.getSelectedValue(); |
---|
317 | if (sel == null) { |
---|
318 | JOptionPane.showMessageDialog(null, "Select an empty scenario first!"); |
---|
319 | return; |
---|
320 | } |
---|
321 | show(!StartRouteDesigner.createWindow()); |
---|
322 | } |
---|
323 | }); |
---|
324 | |
---|
325 | startSim.addActionListener(new ActionListener() { |
---|
326 | public void actionPerformed(ActionEvent ev) { |
---|
327 | selectedScenario = (String) listFsc.getSelectedValue(); |
---|
328 | if (selectedScenario == null) { |
---|
329 | JOptionPane.showMessageDialog(null, "Select a scenario to simulate!"); |
---|
330 | return; |
---|
331 | } |
---|
332 | try { |
---|
333 | String[] args = new String[1]; |
---|
334 | args[0] = selectedScenario; |
---|
335 | loadSimulationParameters(args, false); |
---|
336 | show(false); |
---|
337 | // vnsim.vehicular.scenarios.Main.main(args); |
---|
338 | } catch (Exception ex) { |
---|
339 | ex.printStackTrace(); |
---|
340 | // System.exit(0); |
---|
341 | show(true); |
---|
342 | } |
---|
343 | } |
---|
344 | }); |
---|
345 | |
---|
346 | refresh.addActionListener(new ActionListener() { |
---|
347 | public void actionPerformed(ActionEvent ev) { |
---|
348 | String[] files1 = f1.list(); |
---|
349 | String[] files2 = readSerializedMaps(); |
---|
350 | String[] files3 = readSMFs(); |
---|
351 | String[] files4 = readFSCs(); |
---|
352 | if (files1 == null || files2 == null || files3 == null || files4 == null) { |
---|
353 | logger.severe("ERROR! Directories maps/map or maps/rt or maps/fsc or maps/smf not found!"); |
---|
354 | return; |
---|
355 | } |
---|
356 | |
---|
357 | Vector<String> maps = new Vector<String>(); |
---|
358 | for (int i = 0; i < files1.length; i++) { |
---|
359 | if ((files1[i].endsWith(".RT1") || (files1[i].endsWith(".rt1")))) |
---|
360 | maps.addElement(files1[i]); |
---|
361 | } |
---|
362 | |
---|
363 | listSmf.setListData(files3); |
---|
364 | listFsc.setListData(files4); |
---|
365 | list.setListData(maps); |
---|
366 | listMap.setListData(files2); |
---|
367 | } |
---|
368 | }); |
---|
369 | |
---|
370 | socialNet.addActionListener(new ActionListener() { |
---|
371 | public void actionPerformed(ActionEvent ev) { |
---|
372 | selectedScenario = (String) listMap.getSelectedValue(); |
---|
373 | if (selectedScenario == null) { |
---|
374 | JOptionPane.showMessageDialog(null, "Select a map file!"); |
---|
375 | return; |
---|
376 | } |
---|
377 | try { |
---|
378 | String[] args = new String[1]; |
---|
379 | args[0] = selectedScenario; |
---|
380 | loadSocialNetworkParameters(args); |
---|
381 | show(false); |
---|
382 | } catch (Exception ex) { |
---|
383 | ex.printStackTrace(); |
---|
384 | // System.exit(0); |
---|
385 | socialNetwork = false; |
---|
386 | loadMap(); |
---|
387 | } |
---|
388 | } |
---|
389 | }); |
---|
390 | |
---|
391 | SpringLayout l = new SpringLayout(); |
---|
392 | frame.setLayout(l); |
---|
393 | SpringLayout.Constraints constraint; |
---|
394 | |
---|
395 | constraint = l.getConstraints(label1); |
---|
396 | constraint.setY(Spring.constant(1)); |
---|
397 | constraint.setX(Spring.constant(5)); |
---|
398 | constraint.setWidth(Spring.constant(190)); |
---|
399 | constraint.setHeight(Spring.constant(40)); |
---|
400 | |
---|
401 | constraint = l.getConstraints(label2); |
---|
402 | constraint.setY(Spring.constant(1)); |
---|
403 | constraint.setX(Spring.constant(200)); |
---|
404 | constraint.setWidth(Spring.constant(190)); |
---|
405 | constraint.setHeight(Spring.constant(40)); |
---|
406 | |
---|
407 | constraint = l.getConstraints(label3); |
---|
408 | constraint.setY(Spring.constant(1)); |
---|
409 | constraint.setX(Spring.constant(400)); |
---|
410 | constraint.setWidth(Spring.constant(190)); |
---|
411 | constraint.setHeight(Spring.constant(40)); |
---|
412 | |
---|
413 | constraint = l.getConstraints(label4); |
---|
414 | constraint.setY(Spring.constant(1)); |
---|
415 | constraint.setX(Spring.constant(600)); |
---|
416 | constraint.setWidth(Spring.constant(190)); |
---|
417 | constraint.setHeight(Spring.constant(40)); |
---|
418 | |
---|
419 | constraint = l.getConstraints(scroll1); |
---|
420 | constraint.setY(Spring.constant(50)); |
---|
421 | constraint.setX(Spring.constant(5)); |
---|
422 | constraint.setWidth(Spring.constant(190)); |
---|
423 | constraint.setHeight(Spring.constant(200)); |
---|
424 | |
---|
425 | constraint = l.getConstraints(scroll2); |
---|
426 | constraint.setY(Spring.constant(50)); |
---|
427 | constraint.setX(Spring.constant(200)); |
---|
428 | constraint.setWidth(Spring.constant(190)); |
---|
429 | constraint.setHeight(Spring.constant(200)); |
---|
430 | |
---|
431 | constraint = l.getConstraints(scroll3); |
---|
432 | constraint.setY(Spring.constant(50)); |
---|
433 | constraint.setX(Spring.constant(400)); |
---|
434 | constraint.setWidth(Spring.constant(190)); |
---|
435 | constraint.setHeight(Spring.constant(200)); |
---|
436 | |
---|
437 | constraint = l.getConstraints(scroll4); |
---|
438 | constraint.setX(Spring.constant(600)); |
---|
439 | constraint.setY(Spring.constant(50)); |
---|
440 | constraint.setWidth(Spring.constant(190)); |
---|
441 | constraint.setHeight(Spring.constant(200)); |
---|
442 | |
---|
443 | constraint = l.getConstraints(buildMap); |
---|
444 | constraint.setX(Spring.constant(1)); |
---|
445 | constraint.setY(Spring.constant(250)); |
---|
446 | constraint.setWidth(Spring.constant(190)); |
---|
447 | constraint.setHeight(Spring.constant(50)); |
---|
448 | |
---|
449 | constraint = l.getConstraints(routeDesign); |
---|
450 | constraint.setX(Spring.constant(400)); |
---|
451 | constraint.setY(Spring.constant(250)); |
---|
452 | constraint.setWidth(Spring.constant(190)); |
---|
453 | constraint.setHeight(Spring.constant(50)); |
---|
454 | |
---|
455 | constraint = l.getConstraints(refresh); |
---|
456 | constraint.setX(Spring.constant(1)); |
---|
457 | constraint.setY(Spring.constant(310)); |
---|
458 | constraint.setWidth(Spring.constant(190)); |
---|
459 | constraint.setHeight(Spring.constant(50)); |
---|
460 | |
---|
461 | constraint = l.getConstraints(socialNet); |
---|
462 | constraint.setX(Spring.constant(200)); |
---|
463 | constraint.setY(Spring.constant(310)); |
---|
464 | constraint.setWidth(Spring.constant(190)); |
---|
465 | constraint.setHeight(Spring.constant(50)); |
---|
466 | |
---|
467 | constraint = l.getConstraints(scenario); |
---|
468 | constraint.setX(Spring.constant(400)); |
---|
469 | constraint.setY(Spring.constant(310)); |
---|
470 | constraint.setWidth(Spring.constant(190)); |
---|
471 | constraint.setHeight(Spring.constant(50)); |
---|
472 | |
---|
473 | constraint = l.getConstraints(smf); |
---|
474 | constraint.setX(Spring.constant(200)); |
---|
475 | constraint.setY(Spring.constant(250)); |
---|
476 | constraint.setWidth(Spring.constant(190)); |
---|
477 | constraint.setHeight(Spring.constant(50)); |
---|
478 | |
---|
479 | constraint = l.getConstraints(startSim); |
---|
480 | constraint.setX(Spring.constant(600)); |
---|
481 | constraint.setY(Spring.constant(250)); |
---|
482 | constraint.setWidth(Spring.constant(190)); |
---|
483 | constraint.setHeight(Spring.constant(50)); |
---|
484 | |
---|
485 | constraint = l.getConstraints(exit); |
---|
486 | constraint.setX(Spring.constant(600)); |
---|
487 | constraint.setY(Spring.constant(310)); |
---|
488 | constraint.setWidth(Spring.constant(190)); |
---|
489 | constraint.setHeight(Spring.constant(50)); |
---|
490 | buildMap.setToolTipText("Builds a map using a RT1 file."); |
---|
491 | routeDesign.setToolTipText("Manages routes, entries and exits from a scenario."); |
---|
492 | smf.setToolTipText("Creates an empty scenario from a map file."); |
---|
493 | exit.setToolTipText("Closes the application."); |
---|
494 | refresh.setToolTipText("Refresh the lists."); |
---|
495 | startSim.setToolTipText("Start the simulation."); |
---|
496 | socialNet.setToolTipText("Starts a simulation using random entries and exits."); |
---|
497 | scenario.setToolTipText("Create a scenario that can be simulated."); |
---|
498 | |
---|
499 | frame.add(label1); |
---|
500 | frame.add(label2); |
---|
501 | frame.add(label3); |
---|
502 | frame.add(label4); |
---|
503 | frame.add(scroll1); |
---|
504 | frame.add(scroll2); |
---|
505 | frame.add(scroll3); |
---|
506 | frame.add(scroll4); |
---|
507 | frame.add(buildMap); |
---|
508 | frame.add(routeDesign); |
---|
509 | frame.add(socialNet); |
---|
510 | frame.add(smf); |
---|
511 | frame.add(scenario); |
---|
512 | frame.add(startSim); |
---|
513 | frame.add(exit); |
---|
514 | frame.add(refresh); |
---|
515 | frame.setVisible(true); |
---|
516 | frame.setResizable(false); |
---|
517 | } |
---|
518 | |
---|
519 | public static void refreshSMF() { |
---|
520 | String[] files3 = readSMFs(); |
---|
521 | if (files3 == null) { |
---|
522 | return; |
---|
523 | } |
---|
524 | listSmf.setListData(files3); |
---|
525 | } |
---|
526 | |
---|
527 | public static void loadSocialNetworkParameters(final String args[]) { |
---|
528 | |
---|
529 | final JFrame frame = new JFrame(); |
---|
530 | frame.setSize(800, 520); |
---|
531 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
532 | |
---|
533 | final JButton exit = new JButton("Cancel"); |
---|
534 | final JButton ok = new JButton("Ok"); |
---|
535 | |
---|
536 | final JPanel timePanel = new JPanel(new GridLayout(0, 1)); |
---|
537 | |
---|
538 | final JLabel vehicleCalm, vehicleAggresive, vehicleRegular, theshold, thesholdUnit; |
---|
539 | final JTextField vehicleCalmVal, vehicleAggresiveVal, vehicleRegularVal, thesholdVal; |
---|
540 | final JTextField confTimeVal, rewireVal, rowVal, columnVal, groupVal, seedVal; |
---|
541 | final JLabel rewire, rewireUnit, grid, row, column, group, seed; |
---|
542 | |
---|
543 | final ButtonGroup priorityButton, typeButton, routingButton; |
---|
544 | final JPanel priorityPanel = new JPanel(new GridLayout(0, 1)); |
---|
545 | final JPanel priority = new JPanel(new GridLayout(0, 1)); |
---|
546 | final JPanel routingPanel = new JPanel(new GridLayout(0, 1)); |
---|
547 | final JRadioButton randomPr, centerPr, edgePr, priorityTrue, priorityFalse, socialNetwork, shortestPath; |
---|
548 | |
---|
549 | JLabel confTimeLabel = new JLabel("Reconfiguration Interval (sec)"); |
---|
550 | vehicleCalm = new JLabel("Number of calm vehicles "); |
---|
551 | vehicleAggresive = new JLabel("Number of aggresive vehicles "); |
---|
552 | vehicleRegular = new JLabel("Number of regular vehicles "); |
---|
553 | theshold = new JLabel("Connection Theshold "); |
---|
554 | thesholdUnit = new JLabel(" /100"); |
---|
555 | rewire = new JLabel("Rewire Probability"); |
---|
556 | rewireUnit = new JLabel(" /100"); |
---|
557 | grid = new JLabel("Grid Properties"); |
---|
558 | row = new JLabel("Number of Rows"); |
---|
559 | column = new JLabel("Number of Columns"); |
---|
560 | group = new JLabel("Number of Groups"); |
---|
561 | seed = new JLabel("Seed generator"); |
---|
562 | |
---|
563 | vehicleCalmVal = new JTextField("10"); |
---|
564 | vehicleAggresiveVal = new JTextField("10"); |
---|
565 | vehicleRegularVal = new JTextField("20"); |
---|
566 | thesholdVal = new JTextField("10"); |
---|
567 | confTimeVal = new JTextField("100"); |
---|
568 | rewireVal = new JTextField("10"); |
---|
569 | rowVal = new JTextField("10"); |
---|
570 | columnVal = new JTextField("10"); |
---|
571 | groupVal = new JTextField("15"); |
---|
572 | seedVal = new JTextField("0"); |
---|
573 | |
---|
574 | typeButton = new ButtonGroup(); |
---|
575 | randomPr = new JRadioButton("Random Priority"); |
---|
576 | randomPr.setSelected(true); |
---|
577 | centerPr = new JRadioButton("Center - Edge"); |
---|
578 | edgePr = new JRadioButton("Edge - Edge"); |
---|
579 | typeButton.add(randomPr); |
---|
580 | typeButton.add(centerPr); |
---|
581 | typeButton.add(edgePr); |
---|
582 | priorityPanel.add(new JLabel("Priority Type")); |
---|
583 | priorityPanel.add(randomPr); |
---|
584 | priorityPanel.add(centerPr); |
---|
585 | priorityPanel.add(edgePr); |
---|
586 | priorityPanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
587 | |
---|
588 | priorityButton = new ButtonGroup(); |
---|
589 | priorityFalse = new JRadioButton("Without priority"); |
---|
590 | priorityFalse.setSelected(true); |
---|
591 | priorityTrue = new JRadioButton("With priority"); |
---|
592 | priorityButton.add(priorityFalse); |
---|
593 | priorityButton.add(priorityTrue); |
---|
594 | priority.add(new JLabel("Priority")); |
---|
595 | priority.add(priorityFalse); |
---|
596 | priority.add(priorityTrue); |
---|
597 | priority.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
598 | |
---|
599 | routingButton = new ButtonGroup(); |
---|
600 | socialNetwork = new JRadioButton("Social Network"); |
---|
601 | socialNetwork.setSelected(true); |
---|
602 | shortestPath = new JRadioButton("Shortest Path"); |
---|
603 | routingButton.add(socialNetwork); |
---|
604 | routingButton.add(shortestPath); |
---|
605 | routingPanel.add(new JLabel("Static Routing Type")); |
---|
606 | routingPanel.add(socialNetwork); |
---|
607 | routingPanel.add(shortestPath); |
---|
608 | routingPanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
609 | |
---|
610 | exit.addActionListener(new ActionListener() { |
---|
611 | public void actionPerformed(ActionEvent ev) { |
---|
612 | frame.dispose(); |
---|
613 | System.exit(0); |
---|
614 | } |
---|
615 | }); |
---|
616 | |
---|
617 | ok.addActionListener(new ActionListener() { |
---|
618 | public void actionPerformed(ActionEvent ev) { |
---|
619 | GlobalNetwork.CALM = (int) Integer.parseInt(vehicleCalmVal.getText()); |
---|
620 | GlobalNetwork.AGGRESIVE = (int) Integer.parseInt(vehicleAggresiveVal.getText()); |
---|
621 | GlobalNetwork.REGULAR = (int) Integer.parseInt(vehicleRegularVal.getText()); |
---|
622 | GlobalNetwork.THESHOLD = (double) Integer.parseInt(thesholdVal.getText()) / 100; |
---|
623 | GlobalNetwork.REWIRE = (double) Integer.parseInt(rewireVal.getText()) / 100; |
---|
624 | GlobalNetwork.CONFTIME = (double) Integer.parseInt(confTimeVal.getText()); |
---|
625 | GlobalNetwork.ROWS = (int) Integer.parseInt(rowVal.getText()); |
---|
626 | GlobalNetwork.COLUMNS = (int) Integer.parseInt(columnVal.getText()); |
---|
627 | GlobalNetwork.GROUPS = (double) Integer.parseInt(groupVal.getText()); |
---|
628 | GlobalNetwork.SEED = (double) Integer.parseInt(seedVal.getText()); |
---|
629 | |
---|
630 | if (priorityTrue.isSelected()) { |
---|
631 | GlobalNetwork.PRIORITY = true; |
---|
632 | } else { |
---|
633 | GlobalNetwork.PRIORITY = false; |
---|
634 | } |
---|
635 | GlobalNetwork.priorityType = -1; |
---|
636 | if (randomPr.isSelected()) { |
---|
637 | GlobalNetwork.priorityType = 0; |
---|
638 | } |
---|
639 | if (centerPr.isSelected()) { |
---|
640 | GlobalNetwork.priorityType = 1; |
---|
641 | } |
---|
642 | if (edgePr.isSelected()) { |
---|
643 | GlobalNetwork.priorityType = 2; |
---|
644 | } |
---|
645 | if (socialNetwork.isSelected()) { |
---|
646 | GlobalNetwork.routingType = 0; |
---|
647 | } |
---|
648 | if (shortestPath.isSelected()) { |
---|
649 | GlobalNetwork.routingType = 0; |
---|
650 | } |
---|
651 | |
---|
652 | frame.setVisible(false); |
---|
653 | frame.dispose(); |
---|
654 | try { |
---|
655 | Globals.SOCIALNETWORK = 1; |
---|
656 | MapLoader.loadSimulationParameters(args, true); |
---|
657 | // vnsim.socialNet.Main.main(args); |
---|
658 | } catch (Throwable t) { |
---|
659 | t.printStackTrace(); |
---|
660 | show(true); |
---|
661 | } |
---|
662 | } |
---|
663 | }); |
---|
664 | |
---|
665 | SpringLayout l = new SpringLayout(); |
---|
666 | frame.setLayout(l); |
---|
667 | SpringLayout.Constraints constraint; |
---|
668 | |
---|
669 | SpringLayout l2 = new SpringLayout(); |
---|
670 | timePanel.setLayout(l2); |
---|
671 | SpringLayout.Constraints cons; |
---|
672 | |
---|
673 | cons = l2.getConstraints(confTimeVal); |
---|
674 | cons.setX(Spring.constant(5)); |
---|
675 | cons.setY(Spring.constant(55)); |
---|
676 | cons.setWidth(Spring.constant(200)); |
---|
677 | cons.setHeight(Spring.constant(45)); |
---|
678 | |
---|
679 | cons = l2.getConstraints(confTimeLabel); |
---|
680 | cons.setX(Spring.constant(5)); |
---|
681 | cons.setY(Spring.constant(5)); |
---|
682 | cons.setWidth(Spring.constant(200)); |
---|
683 | cons.setHeight(Spring.constant(45)); |
---|
684 | |
---|
685 | timePanel.add(confTimeLabel); |
---|
686 | timePanel.add(confTimeVal); |
---|
687 | timePanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
688 | |
---|
689 | constraint = l.getConstraints(ok); |
---|
690 | constraint.setX(Spring.constant(350)); |
---|
691 | constraint.setY(Spring.constant(420)); |
---|
692 | constraint.setWidth(Spring.constant(100)); |
---|
693 | constraint.setHeight(Spring.constant(50)); |
---|
694 | |
---|
695 | constraint = l.getConstraints(exit); |
---|
696 | constraint.setX(Spring.constant(460)); |
---|
697 | constraint.setY(Spring.constant(420)); |
---|
698 | constraint.setWidth(Spring.constant(100)); |
---|
699 | constraint.setHeight(Spring.constant(50)); |
---|
700 | |
---|
701 | constraint = l.getConstraints(vehicleCalm); |
---|
702 | constraint.setX(Spring.constant(10)); |
---|
703 | constraint.setY(Spring.constant(10)); |
---|
704 | constraint.setWidth(Spring.constant(200)); |
---|
705 | constraint.setHeight(Spring.constant(45)); |
---|
706 | |
---|
707 | constraint = l.getConstraints(vehicleCalmVal); |
---|
708 | constraint.setX(Spring.constant(210)); |
---|
709 | constraint.setY(Spring.constant(10)); |
---|
710 | constraint.setWidth(Spring.constant(100)); |
---|
711 | constraint.setHeight(Spring.constant(45)); |
---|
712 | |
---|
713 | constraint = l.getConstraints(vehicleAggresive); |
---|
714 | constraint.setX(Spring.constant(10)); |
---|
715 | constraint.setY(Spring.constant(60)); |
---|
716 | constraint.setWidth(Spring.constant(200)); |
---|
717 | constraint.setHeight(Spring.constant(45)); |
---|
718 | |
---|
719 | constraint = l.getConstraints(vehicleAggresiveVal); |
---|
720 | constraint.setX(Spring.constant(210)); |
---|
721 | constraint.setY(Spring.constant(60)); |
---|
722 | constraint.setWidth(Spring.constant(100)); |
---|
723 | constraint.setHeight(Spring.constant(45)); |
---|
724 | |
---|
725 | constraint = l.getConstraints(vehicleRegular); |
---|
726 | constraint.setX(Spring.constant(10)); |
---|
727 | constraint.setY(Spring.constant(110)); |
---|
728 | constraint.setWidth(Spring.constant(200)); |
---|
729 | constraint.setHeight(Spring.constant(45)); |
---|
730 | |
---|
731 | constraint = l.getConstraints(vehicleRegularVal); |
---|
732 | constraint.setX(Spring.constant(210)); |
---|
733 | constraint.setY(Spring.constant(110)); |
---|
734 | constraint.setWidth(Spring.constant(100)); |
---|
735 | constraint.setHeight(Spring.constant(45)); |
---|
736 | |
---|
737 | constraint = l.getConstraints(theshold); |
---|
738 | constraint.setX(Spring.constant(10)); |
---|
739 | constraint.setY(Spring.constant(180)); |
---|
740 | constraint.setWidth(Spring.constant(200)); |
---|
741 | constraint.setHeight(Spring.constant(45)); |
---|
742 | |
---|
743 | constraint = l.getConstraints(thesholdVal); |
---|
744 | constraint.setX(Spring.constant(210)); |
---|
745 | constraint.setY(Spring.constant(180)); |
---|
746 | constraint.setWidth(Spring.constant(100)); |
---|
747 | constraint.setHeight(Spring.constant(45)); |
---|
748 | |
---|
749 | constraint = l.getConstraints(thesholdUnit); |
---|
750 | constraint.setX(Spring.constant(310)); |
---|
751 | constraint.setY(Spring.constant(180)); |
---|
752 | constraint.setWidth(Spring.constant(200)); |
---|
753 | constraint.setHeight(Spring.constant(45)); |
---|
754 | |
---|
755 | constraint = l.getConstraints(rewire); |
---|
756 | constraint.setX(Spring.constant(10)); |
---|
757 | constraint.setY(Spring.constant(230)); |
---|
758 | constraint.setWidth(Spring.constant(200)); |
---|
759 | constraint.setHeight(Spring.constant(45)); |
---|
760 | |
---|
761 | constraint = l.getConstraints(rewireVal); |
---|
762 | constraint.setX(Spring.constant(210)); |
---|
763 | constraint.setY(Spring.constant(230)); |
---|
764 | constraint.setWidth(Spring.constant(100)); |
---|
765 | constraint.setHeight(Spring.constant(45)); |
---|
766 | |
---|
767 | constraint = l.getConstraints(rewireUnit); |
---|
768 | constraint.setX(Spring.constant(310)); |
---|
769 | constraint.setY(Spring.constant(230)); |
---|
770 | constraint.setWidth(Spring.constant(200)); |
---|
771 | constraint.setHeight(Spring.constant(45)); |
---|
772 | |
---|
773 | constraint = l.getConstraints(timePanel); |
---|
774 | constraint.setX(Spring.constant(10)); |
---|
775 | constraint.setY(Spring.constant(290)); |
---|
776 | constraint.setWidth(Spring.constant(230)); |
---|
777 | constraint.setHeight(Spring.constant(110)); |
---|
778 | |
---|
779 | constraint = l.getConstraints(grid); |
---|
780 | constraint.setX(Spring.constant(550)); |
---|
781 | constraint.setY(Spring.constant(0)); |
---|
782 | constraint.setWidth(Spring.constant(200)); |
---|
783 | constraint.setHeight(Spring.constant(45)); |
---|
784 | |
---|
785 | constraint = l.getConstraints(row); |
---|
786 | constraint.setX(Spring.constant(450)); |
---|
787 | constraint.setY(Spring.constant(50)); |
---|
788 | constraint.setWidth(Spring.constant(150)); |
---|
789 | constraint.setHeight(Spring.constant(45)); |
---|
790 | |
---|
791 | constraint = l.getConstraints(rowVal); |
---|
792 | constraint.setX(Spring.constant(600)); |
---|
793 | constraint.setY(Spring.constant(50)); |
---|
794 | constraint.setWidth(Spring.constant(100)); |
---|
795 | constraint.setHeight(Spring.constant(45)); |
---|
796 | |
---|
797 | constraint = l.getConstraints(column); |
---|
798 | constraint.setX(Spring.constant(450)); |
---|
799 | constraint.setY(Spring.constant(100)); |
---|
800 | constraint.setWidth(Spring.constant(150)); |
---|
801 | constraint.setHeight(Spring.constant(45)); |
---|
802 | |
---|
803 | constraint = l.getConstraints(columnVal); |
---|
804 | constraint.setX(Spring.constant(600)); |
---|
805 | constraint.setY(Spring.constant(100)); |
---|
806 | constraint.setWidth(Spring.constant(100)); |
---|
807 | constraint.setHeight(Spring.constant(45)); |
---|
808 | |
---|
809 | constraint = l.getConstraints(group); |
---|
810 | constraint.setX(Spring.constant(450)); |
---|
811 | constraint.setY(Spring.constant(160)); |
---|
812 | constraint.setWidth(Spring.constant(150)); |
---|
813 | constraint.setHeight(Spring.constant(45)); |
---|
814 | |
---|
815 | constraint = l.getConstraints(groupVal); |
---|
816 | constraint.setX(Spring.constant(600)); |
---|
817 | constraint.setY(Spring.constant(160)); |
---|
818 | constraint.setWidth(Spring.constant(100)); |
---|
819 | constraint.setHeight(Spring.constant(45)); |
---|
820 | |
---|
821 | constraint = l.getConstraints(seed); |
---|
822 | constraint.setX(Spring.constant(450)); |
---|
823 | constraint.setY(Spring.constant(210)); |
---|
824 | constraint.setWidth(Spring.constant(100)); |
---|
825 | constraint.setHeight(Spring.constant(45)); |
---|
826 | |
---|
827 | constraint = l.getConstraints(seedVal); |
---|
828 | constraint.setX(Spring.constant(600)); |
---|
829 | constraint.setY(Spring.constant(210)); |
---|
830 | constraint.setWidth(Spring.constant(100)); |
---|
831 | constraint.setHeight(Spring.constant(45)); |
---|
832 | |
---|
833 | constraint = l.getConstraints(routingPanel); |
---|
834 | constraint.setX(Spring.constant(270)); |
---|
835 | constraint.setY(Spring.constant(290)); |
---|
836 | constraint.setWidth(Spring.constant(150)); |
---|
837 | constraint.setHeight(Spring.constant(110)); |
---|
838 | |
---|
839 | constraint = l.getConstraints(priority); |
---|
840 | constraint.setX(Spring.constant(450)); |
---|
841 | constraint.setY(Spring.constant(290)); |
---|
842 | constraint.setWidth(Spring.constant(150)); |
---|
843 | constraint.setHeight(Spring.constant(110)); |
---|
844 | |
---|
845 | constraint = l.getConstraints(priorityPanel); |
---|
846 | constraint.setX(Spring.constant(630)); |
---|
847 | constraint.setY(Spring.constant(290)); |
---|
848 | constraint.setWidth(Spring.constant(150)); |
---|
849 | constraint.setHeight(Spring.constant(110)); |
---|
850 | |
---|
851 | frame.add(vehicleRegular); |
---|
852 | frame.add(vehicleRegularVal); |
---|
853 | frame.add(vehicleAggresive); |
---|
854 | frame.add(vehicleAggresiveVal); |
---|
855 | frame.add(vehicleCalm); |
---|
856 | frame.add(vehicleCalmVal); |
---|
857 | frame.add(theshold); |
---|
858 | frame.add(thesholdVal); |
---|
859 | frame.add(thesholdUnit); |
---|
860 | frame.add(timePanel); |
---|
861 | frame.add(rewire); |
---|
862 | frame.add(rewireVal); |
---|
863 | frame.add(rewireUnit); |
---|
864 | |
---|
865 | frame.add(grid); |
---|
866 | frame.add(row); |
---|
867 | frame.add(rowVal); |
---|
868 | frame.add(column); |
---|
869 | frame.add(columnVal); |
---|
870 | frame.add(group); |
---|
871 | frame.add(groupVal); |
---|
872 | frame.add(seed); |
---|
873 | frame.add(seedVal); |
---|
874 | frame.add(priorityPanel); |
---|
875 | frame.add(priority); |
---|
876 | frame.add(routingPanel); |
---|
877 | frame.add(exit); |
---|
878 | frame.add(ok); |
---|
879 | frame.setVisible(true); |
---|
880 | } |
---|
881 | |
---|
882 | public static void loadSimulationParameters(final String[] args, final boolean socialNet) { |
---|
883 | final JFrame frame = new JFrame(); |
---|
884 | frame.setSize(1100, 550); |
---|
885 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
886 | |
---|
887 | final JButton ok = new JButton("Start Simulation"); |
---|
888 | |
---|
889 | JButton exit = new JButton("Cancel"); |
---|
890 | |
---|
891 | final ButtonGroup semaphoreType, routingType, applicationType, disseminationType; |
---|
892 | final JRadioButton fixSem, adaptiveSem, predefRoute, scftRoute, infrastructRoute; |
---|
893 | final JRadioButton noneApp, ezCab; |
---|
894 | final JRadioButton neighDisc, compForward, probabilistic; |
---|
895 | final JLabel vehicleWrange, infrastructWrange, mobilityFps, simFps, equiped, neigExp; |
---|
896 | final JTextField vehicleWrangeVal, infrastructWrangeVal, mobilityFpsVal, simFpsVal, equipedVal, neigExpVal; |
---|
897 | |
---|
898 | final JPanel semPanel = new JPanel(new GridLayout(0, 1)); |
---|
899 | final JPanel routingPanel = new JPanel(new GridLayout(0, 1)); |
---|
900 | final JPanel applicationPanel = new JPanel(new GridLayout(0, 1)); |
---|
901 | final JPanel dissemPanel = new JPanel(new GridLayout(0, 1)); |
---|
902 | final JPanel protocolPanel = new JPanel(new GridLayout(0, 1));/* Petroaca */ |
---|
903 | final JPanel propagationPanel = new JPanel(new GridLayout(0, 1));/* Petroaca */ |
---|
904 | final JPanel DSRCfunctions = new JPanel(new GridLayout(0, 1));/* Petroaca */ |
---|
905 | |
---|
906 | final ButtonGroup protocolType;/* Petroaca */ |
---|
907 | final ButtonGroup propagationType;/* Petroaca */ |
---|
908 | |
---|
909 | final JRadioButton p802p11, DSRC;/* |
---|
910 | * Petroaca - 2 communication protocol |
---|
911 | * types : 802.11 and DSRC |
---|
912 | */ |
---|
913 | final JRadioButton twoRay, shadow, ricean;/* |
---|
914 | * Petroaca - 2 radio |
---|
915 | * propagation models : two ray |
---|
916 | * and shadowing |
---|
917 | */ |
---|
918 | |
---|
919 | final JCheckBox phyParam, DiffCW, multiChannels;/* |
---|
920 | * Petroaca - 3 DSRC |
---|
921 | * functions |
---|
922 | */ |
---|
923 | |
---|
924 | // Petroaca - creates the radio button group from where the user can |
---|
925 | // select the communication protocol type |
---|
926 | protocolType = new ButtonGroup(); |
---|
927 | p802p11 = new JRadioButton("802.11"); |
---|
928 | p802p11.setSelected(true); |
---|
929 | DSRC = new JRadioButton("DSRC"); |
---|
930 | protocolType.add(p802p11); |
---|
931 | protocolType.add(DSRC); |
---|
932 | protocolPanel.add(new JLabel("Communication Protocol Type")); |
---|
933 | protocolPanel.add(p802p11); |
---|
934 | protocolPanel.add(DSRC); |
---|
935 | protocolPanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
936 | DSRC.setSelected(true); |
---|
937 | |
---|
938 | // Petroaca - creates the radio button group from where the user can |
---|
939 | // select the radio propagation model |
---|
940 | propagationType = new ButtonGroup(); |
---|
941 | twoRay = new JRadioButton("Two Ray"); |
---|
942 | twoRay.setSelected(true); |
---|
943 | shadow = new JRadioButton("Shadowing"); |
---|
944 | ricean = new JRadioButton("Ricean"); |
---|
945 | ricean.setSelected(true); |
---|
946 | propagationType.add(twoRay); |
---|
947 | propagationType.add(shadow); |
---|
948 | propagationType.add(ricean); |
---|
949 | propagationPanel.add(new JLabel("Radio Propagation Model")); |
---|
950 | propagationPanel.add(twoRay); |
---|
951 | propagationPanel.add(shadow); |
---|
952 | propagationPanel.add(ricean); |
---|
953 | propagationPanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
954 | shadow.setSelected(true); |
---|
955 | |
---|
956 | // Petroaca - creates the 3 DSRC functions - phy paramaters , diff CW , |
---|
957 | // multiple channels |
---|
958 | phyParam = new JCheckBox("DSRC Physical Parameters"); |
---|
959 | phyParam.setSelected(true); |
---|
960 | DiffCW = new JCheckBox("CSMA/CA Differential CW"); |
---|
961 | DiffCW.setSelected(true); |
---|
962 | multiChannels = new JCheckBox("DSRC Multiple Cahnnels"); |
---|
963 | multiChannels.setSelected(true); |
---|
964 | DSRCfunctions.add(new JLabel("DSRC functionalities")); |
---|
965 | DSRCfunctions.add(phyParam); |
---|
966 | DSRCfunctions.add(DiffCW); |
---|
967 | DSRCfunctions.add(multiChannels); |
---|
968 | DSRCfunctions.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
969 | |
---|
970 | semaphoreType = new ButtonGroup(); |
---|
971 | fixSem = new JRadioButton("Fixed Traffic Lights "); |
---|
972 | fixSem.setSelected(true); |
---|
973 | adaptiveSem = new JRadioButton("Adaptive Traffic Lights"); |
---|
974 | semaphoreType.add(fixSem); |
---|
975 | semaphoreType.add(adaptiveSem); |
---|
976 | semPanel.add(new JLabel("Traffic Lights Type")); |
---|
977 | semPanel.add(fixSem); |
---|
978 | semPanel.add(adaptiveSem); |
---|
979 | semPanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
980 | adaptiveSem.setSelected(true); |
---|
981 | |
---|
982 | routingType = new ButtonGroup(); |
---|
983 | predefRoute = new JRadioButton("Predefined Routes"); |
---|
984 | predefRoute.setSelected(true); |
---|
985 | scftRoute = new JRadioButton("SCFT Routing"); |
---|
986 | infrastructRoute = new JRadioButton("Infrastructure Routing"); |
---|
987 | routingType.add(predefRoute); |
---|
988 | routingType.add(scftRoute); |
---|
989 | routingType.add(infrastructRoute); |
---|
990 | routingPanel.add(new JLabel("Routing Type")); |
---|
991 | routingPanel.add(predefRoute); |
---|
992 | routingPanel.add(scftRoute); |
---|
993 | routingPanel.add(infrastructRoute); |
---|
994 | routingPanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
995 | |
---|
996 | applicationType = new ButtonGroup(); |
---|
997 | noneApp = new JRadioButton("None"); |
---|
998 | noneApp.setSelected(true); |
---|
999 | ezCab = new JRadioButton("EZCab"); |
---|
1000 | ezCab.setSelected(false); |
---|
1001 | applicationType.add(noneApp); |
---|
1002 | applicationType.add(ezCab); |
---|
1003 | applicationPanel.add(new JLabel("Application Type")); |
---|
1004 | applicationPanel.add(noneApp); |
---|
1005 | applicationPanel.add(ezCab); |
---|
1006 | applicationPanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
1007 | |
---|
1008 | |
---|
1009 | disseminationType = new ButtonGroup(); |
---|
1010 | neighDisc = new JRadioButton("Neighbor Discovery"); |
---|
1011 | neighDisc.setSelected(true); |
---|
1012 | compForward = new JRadioButton("Complete Forwarding"); |
---|
1013 | probabilistic = new JRadioButton("Probabilistic Forwarding"); |
---|
1014 | disseminationType.add(neighDisc); |
---|
1015 | disseminationType.add(compForward); |
---|
1016 | disseminationType.add(probabilistic); |
---|
1017 | dissemPanel.add(new JLabel("Dissemination Model")); |
---|
1018 | dissemPanel.add(neighDisc); |
---|
1019 | dissemPanel.add(compForward); |
---|
1020 | dissemPanel.add(probabilistic); |
---|
1021 | dissemPanel.setBorder(new RadioButtonBorder(Color.BLACK, Color.GRAY, Color.WHITE, Color.WHITE)); |
---|
1022 | probabilistic.setSelected(true); |
---|
1023 | |
---|
1024 | vehicleWrange = new JLabel("Vehicle's Wireless Range (m)"); |
---|
1025 | infrastructWrange = new JLabel("Infrastructure Wireless Range (m)"); |
---|
1026 | mobilityFps = new JLabel("Mobility FPS (frames/sec)"); |
---|
1027 | simFps = new JLabel("Simulation FPS (frames/sec)"); |
---|
1028 | equiped = new JLabel("Equiped Cars (%) "); |
---|
1029 | neigExp = new JLabel("Neighbour Expires (s)"); |
---|
1030 | |
---|
1031 | vehicleWrangeVal = new JTextField("200"); |
---|
1032 | infrastructWrangeVal = new JTextField("1000"); |
---|
1033 | mobilityFpsVal = new JTextField("10"); |
---|
1034 | simFpsVal = new JTextField("100"); |
---|
1035 | equipedVal = new JTextField("100"); |
---|
1036 | neigExpVal = new JTextField("2"); |
---|
1037 | |
---|
1038 | ok.addActionListener(new ActionListener() { |
---|
1039 | public void actionPerformed(ActionEvent e) { |
---|
1040 | try { |
---|
1041 | Globals.FPS = Integer.parseInt(mobilityFpsVal.getText()); |
---|
1042 | Globals.executionFPS = Integer.parseInt(simFpsVal.getText()); |
---|
1043 | Engine.WIRELESS_RANGE = (double) Integer.parseInt(vehicleWrangeVal.getText()) / 1000; |
---|
1044 | Engine.EXTENDED_WIRELESS_RANGE = (double) Integer.parseInt(infrastructWrangeVal.getText()) / 1000; |
---|
1045 | Globals.PERCENT_EQUIPPED_VEHICLES = Integer.parseInt(equipedVal.getText()); |
---|
1046 | Globals.NEIGHBOR_EXPIRES = Integer.parseInt(neigExpVal.getText()) * Globals.SECOND; |
---|
1047 | |
---|
1048 | if (neighDisc.isSelected()) { |
---|
1049 | SimulatedCarInfo.STANDARD_MESSAGE_ID = Globals.PROT_NEIGHBOR_DISCOVERY; |
---|
1050 | } |
---|
1051 | if (compForward.isSelected()) { |
---|
1052 | SimulatedCarInfo.STANDARD_MESSAGE_ID = Globals.PROT_SETOFCARS; |
---|
1053 | Globals.probabilisticModel = false; |
---|
1054 | } |
---|
1055 | if (probabilistic.isSelected()) { |
---|
1056 | SimulatedCarInfo.STANDARD_MESSAGE_ID = Globals.PROT_SETOFCARS; |
---|
1057 | Globals.probabilisticModel = true; |
---|
1058 | } |
---|
1059 | |
---|
1060 | if (fixSem.isSelected()) { |
---|
1061 | WirelessTrafficLight.adaptive = false; |
---|
1062 | } |
---|
1063 | if (adaptiveSem.isSelected()) { |
---|
1064 | WirelessTrafficLight.adaptive = true; |
---|
1065 | } |
---|
1066 | |
---|
1067 | if (predefRoute.isSelected()) { |
---|
1068 | Engine.simulationType = Globals.routePlanConstants.INITIALLY_PROVIDED_ROUTE; |
---|
1069 | } |
---|
1070 | if (scftRoute.isSelected()) { |
---|
1071 | // Engine.simulationType = Globals.routePlanConstants.DYNAMIC_SELF_ROUTE; |
---|
1072 | Engine.simulationType = RoutingConstants.ROUTING_SCFT; |
---|
1073 | } |
---|
1074 | if (ezCab.isSelected()) { |
---|
1075 | Engine.applicationType = Globals.PROT_EZCAB; |
---|
1076 | } else if (noneApp.isSelected()) { |
---|
1077 | Engine.applicationType = 0; |
---|
1078 | } |
---|
1079 | if (infrastructRoute.isSelected()) { |
---|
1080 | Engine.simulationType = Globals.routePlanConstants.DYNAMIC_INFRASTRUCTURE_ROUTE; |
---|
1081 | } |
---|
1082 | |
---|
1083 | // Petroaca - checks the selection of the protocol type |
---|
1084 | if (p802p11.isSelected()) { |
---|
1085 | Engine.simulationProtocol = Globals.PROTOCOL_80211; |
---|
1086 | } |
---|
1087 | |
---|
1088 | if (DSRC.isSelected()) { |
---|
1089 | Engine.simulationProtocol = Globals.PROTOCOL_DSRC; |
---|
1090 | } |
---|
1091 | |
---|
1092 | // Petroaca - checks the selection of the propagation model |
---|
1093 | if (twoRay.isSelected()) { |
---|
1094 | Engine.propagationModel = Globals.TWO_RAY_GROUND; |
---|
1095 | } |
---|
1096 | |
---|
1097 | if (shadow.isSelected()) { |
---|
1098 | Engine.propagationModel = Globals.SHADOWING; |
---|
1099 | } |
---|
1100 | |
---|
1101 | if (ricean.isSelected()) { |
---|
1102 | Engine.propagationModel = Globals.RICEAN; |
---|
1103 | } |
---|
1104 | |
---|
1105 | if (phyParam.isSelected()) { |
---|
1106 | Globals.TRANSMITTER_POWER = Globals.TRANSMITTER_POWER_DSRC; |
---|
1107 | Globals.SINRThresholdBPSK = Globals.SINRThresholdBPSK_DSRC; |
---|
1108 | } else { |
---|
1109 | Globals.TRANSMITTER_POWER = Globals.TRANSMITTER_POWER_80211; |
---|
1110 | Globals.SINRThresholdBPSK = Globals.SINRThresholdBPSK_80211; |
---|
1111 | } |
---|
1112 | |
---|
1113 | if (DiffCW.isSelected()) { |
---|
1114 | Globals.DIFFERENTIAL_CW = true; |
---|
1115 | } else |
---|
1116 | Globals.DIFFERENTIAL_CW = false; |
---|
1117 | |
---|
1118 | if (multiChannels.isSelected()) |
---|
1119 | Globals.MULTI_CHANNEL = true; |
---|
1120 | else |
---|
1121 | Globals.MULTI_CHANNEL = false; |
---|
1122 | } catch (Exception ex) { |
---|
1123 | ex.printStackTrace(); |
---|
1124 | return; |
---|
1125 | } |
---|
1126 | |
---|
1127 | frame.setVisible(false); |
---|
1128 | frame.dispose(); |
---|
1129 | try { |
---|
1130 | if (socialNet) |
---|
1131 | vnsim.socialNet.Main.main(args); |
---|
1132 | else |
---|
1133 | vnsim.vehicular.scenarios.Main.main(args); |
---|
1134 | } catch (Throwable t) { |
---|
1135 | t.printStackTrace(); |
---|
1136 | // System.exit(0); |
---|
1137 | show(true); |
---|
1138 | } |
---|
1139 | } |
---|
1140 | }); |
---|
1141 | |
---|
1142 | exit.addActionListener(new ActionListener() { |
---|
1143 | public void actionPerformed(ActionEvent ev) { |
---|
1144 | frame.dispose(); |
---|
1145 | System.exit(0); |
---|
1146 | } |
---|
1147 | }); |
---|
1148 | |
---|
1149 | SpringLayout l = new SpringLayout(); |
---|
1150 | frame.setLayout(l); |
---|
1151 | SpringLayout.Constraints constraint; |
---|
1152 | |
---|
1153 | constraint = l.getConstraints(mobilityFps); |
---|
1154 | constraint.setX(Spring.constant(10)); |
---|
1155 | constraint.setY(Spring.constant(5)); |
---|
1156 | constraint.setWidth(Spring.constant(200)); |
---|
1157 | constraint.setHeight(Spring.constant(45)); |
---|
1158 | |
---|
1159 | constraint = l.getConstraints(simFps); |
---|
1160 | constraint.setX(Spring.constant(10)); |
---|
1161 | constraint.setY(Spring.constant(50)); |
---|
1162 | constraint.setWidth(Spring.constant(200)); |
---|
1163 | constraint.setHeight(Spring.constant(45)); |
---|
1164 | |
---|
1165 | constraint = l.getConstraints(mobilityFpsVal); |
---|
1166 | constraint.setX(Spring.constant(210)); |
---|
1167 | constraint.setY(Spring.constant(5)); |
---|
1168 | constraint.setWidth(Spring.constant(100)); |
---|
1169 | constraint.setHeight(Spring.constant(45)); |
---|
1170 | |
---|
1171 | constraint = l.getConstraints(simFpsVal); |
---|
1172 | constraint.setX(Spring.constant(210)); |
---|
1173 | constraint.setY(Spring.constant(50)); |
---|
1174 | constraint.setWidth(Spring.constant(100)); |
---|
1175 | constraint.setHeight(Spring.constant(45)); |
---|
1176 | |
---|
1177 | constraint = l.getConstraints(semPanel); |
---|
1178 | constraint.setX(Spring.constant(10)); |
---|
1179 | constraint.setY(Spring.constant(120)); |
---|
1180 | constraint.setWidth(Spring.constant(145)); |
---|
1181 | constraint.setHeight(Spring.constant(100)); |
---|
1182 | |
---|
1183 | constraint = l.getConstraints(routingPanel); |
---|
1184 | constraint.setX(Spring.constant(160)); |
---|
1185 | constraint.setY(Spring.constant(120)); |
---|
1186 | constraint.setWidth(Spring.constant(145)); |
---|
1187 | constraint.setHeight(Spring.constant(100)); |
---|
1188 | |
---|
1189 | constraint = l.getConstraints(dissemPanel); |
---|
1190 | constraint.setX(Spring.constant(310)); |
---|
1191 | constraint.setY(Spring.constant(120)); |
---|
1192 | constraint.setWidth(Spring.constant(145)); |
---|
1193 | constraint.setHeight(Spring.constant(100)); |
---|
1194 | |
---|
1195 | constraint = l.getConstraints(applicationPanel); |
---|
1196 | constraint.setX(Spring.constant(340)); |
---|
1197 | constraint.setY(Spring.constant(5)); |
---|
1198 | constraint.setWidth(Spring.constant(145)); |
---|
1199 | constraint.setHeight(Spring.constant(100)); |
---|
1200 | |
---|
1201 | |
---|
1202 | // Petroaca - set position of protocol panel on frame |
---|
1203 | constraint = l.getConstraints(protocolPanel); |
---|
1204 | constraint.setX(Spring.constant(460)); |
---|
1205 | constraint.setY(Spring.constant(120)); |
---|
1206 | constraint.setWidth(Spring.constant(200)); |
---|
1207 | constraint.setHeight(Spring.constant(100)); |
---|
1208 | |
---|
1209 | // Petroaca - set position of propagation panel on frame |
---|
1210 | constraint = l.getConstraints(propagationPanel); |
---|
1211 | constraint.setX(Spring.constant(665)); |
---|
1212 | constraint.setY(Spring.constant(120)); |
---|
1213 | constraint.setWidth(Spring.constant(200)); |
---|
1214 | constraint.setHeight(Spring.constant(100)); |
---|
1215 | |
---|
1216 | // Petroaca - set positiion of DSRC functions panel |
---|
1217 | constraint = l.getConstraints(DSRCfunctions); |
---|
1218 | constraint.setX(Spring.constant(870)); |
---|
1219 | constraint.setY(Spring.constant(120)); |
---|
1220 | constraint.setWidth(Spring.constant(200)); |
---|
1221 | constraint.setHeight(Spring.constant(100)); |
---|
1222 | |
---|
1223 | constraint = l.getConstraints(vehicleWrange); |
---|
1224 | constraint.setX(Spring.constant(10)); |
---|
1225 | constraint.setY(Spring.constant(240)); |
---|
1226 | constraint.setWidth(Spring.constant(200)); |
---|
1227 | constraint.setHeight(Spring.constant(45)); |
---|
1228 | |
---|
1229 | constraint = l.getConstraints(infrastructWrange); |
---|
1230 | constraint.setX(Spring.constant(10)); |
---|
1231 | constraint.setY(Spring.constant(290)); |
---|
1232 | constraint.setWidth(Spring.constant(200)); |
---|
1233 | constraint.setHeight(Spring.constant(45)); |
---|
1234 | |
---|
1235 | constraint = l.getConstraints(equiped); |
---|
1236 | constraint.setX(Spring.constant(10)); |
---|
1237 | constraint.setY(Spring.constant(340)); |
---|
1238 | constraint.setWidth(Spring.constant(200)); |
---|
1239 | constraint.setHeight(Spring.constant(45)); |
---|
1240 | |
---|
1241 | constraint = l.getConstraints(neigExp); |
---|
1242 | constraint.setX(Spring.constant(10)); |
---|
1243 | constraint.setY(Spring.constant(390)); |
---|
1244 | constraint.setWidth(Spring.constant(200)); |
---|
1245 | constraint.setHeight(Spring.constant(45)); |
---|
1246 | |
---|
1247 | constraint = l.getConstraints(vehicleWrangeVal); |
---|
1248 | constraint.setX(Spring.constant(210)); |
---|
1249 | constraint.setY(Spring.constant(240)); |
---|
1250 | constraint.setWidth(Spring.constant(100)); |
---|
1251 | constraint.setHeight(Spring.constant(45)); |
---|
1252 | |
---|
1253 | constraint = l.getConstraints(infrastructWrangeVal); |
---|
1254 | constraint.setX(Spring.constant(210)); |
---|
1255 | constraint.setY(Spring.constant(290)); |
---|
1256 | constraint.setWidth(Spring.constant(100)); |
---|
1257 | constraint.setHeight(Spring.constant(45)); |
---|
1258 | |
---|
1259 | constraint = l.getConstraints(equipedVal); |
---|
1260 | constraint.setX(Spring.constant(210)); |
---|
1261 | constraint.setY(Spring.constant(340)); |
---|
1262 | constraint.setWidth(Spring.constant(100)); |
---|
1263 | constraint.setHeight(Spring.constant(45)); |
---|
1264 | |
---|
1265 | constraint = l.getConstraints(neigExpVal); |
---|
1266 | constraint.setX(Spring.constant(210)); |
---|
1267 | constraint.setY(Spring.constant(390)); |
---|
1268 | constraint.setWidth(Spring.constant(100)); |
---|
1269 | constraint.setHeight(Spring.constant(45)); |
---|
1270 | |
---|
1271 | constraint = l.getConstraints(ok); |
---|
1272 | constraint.setX(Spring.constant(10)); |
---|
1273 | constraint.setY(Spring.constant(440)); |
---|
1274 | constraint.setWidth(Spring.constant(200)); |
---|
1275 | constraint.setHeight(Spring.constant(50)); |
---|
1276 | |
---|
1277 | constraint = l.getConstraints(exit); |
---|
1278 | constraint.setX(Spring.constant(210)); |
---|
1279 | constraint.setY(Spring.constant(440)); |
---|
1280 | constraint.setWidth(Spring.constant(100)); |
---|
1281 | constraint.setHeight(Spring.constant(50)); |
---|
1282 | |
---|
1283 | frame.add(ok); |
---|
1284 | frame.add(exit); |
---|
1285 | frame.add(semPanel); |
---|
1286 | frame.add(routingPanel); |
---|
1287 | frame.add(applicationPanel); |
---|
1288 | frame.add(dissemPanel); |
---|
1289 | frame.add(protocolPanel);// Petroaca |
---|
1290 | frame.add(propagationPanel);// Petroaca |
---|
1291 | frame.add(DSRCfunctions);// Petroaca |
---|
1292 | frame.add(vehicleWrange); |
---|
1293 | frame.add(infrastructWrange); |
---|
1294 | frame.add(mobilityFps); |
---|
1295 | frame.add(simFps); |
---|
1296 | frame.add(equiped); |
---|
1297 | frame.add(neigExp); |
---|
1298 | frame.add(vehicleWrangeVal); |
---|
1299 | frame.add(infrastructWrangeVal); |
---|
1300 | frame.add(mobilityFpsVal); |
---|
1301 | frame.add(simFpsVal); |
---|
1302 | frame.add(equipedVal); |
---|
1303 | frame.add(neigExpVal); |
---|
1304 | frame.setVisible(true); |
---|
1305 | frame.setResizable(false); |
---|
1306 | } |
---|
1307 | |
---|
1308 | public static void loadExtraInfo(String filename) { |
---|
1309 | // 2 TYPES OF LINES: "R _ID_ _ONEWAY_" where _ONEWAY_=0,1 or 2 (like in |
---|
1310 | // the Road class) |
---|
1311 | // OR: "L _ID_ _NOLANES_" |
---|
1312 | |
---|
1313 | try { |
---|
1314 | RandomAccessFile f = new RandomAccessFile(rtDir + filename, "r"); |
---|
1315 | String line; |
---|
1316 | while (((line = f.readLine()) != null)) { |
---|
1317 | try { |
---|
1318 | if (line.startsWith("R")) { |
---|
1319 | StringTokenizer st = new StringTokenizer(line, " \t"); |
---|
1320 | st.nextToken(); |
---|
1321 | int id = new Integer(st.nextToken()); |
---|
1322 | int oneWay = new Integer(st.nextToken()); |
---|
1323 | Globals.map.roads.get(id).oneWay = oneWay; |
---|
1324 | } else if (line.startsWith("L")) { |
---|
1325 | StringTokenizer st = new StringTokenizer(line, " \t"); |
---|
1326 | st.nextToken(); |
---|
1327 | int id = new Integer(st.nextToken()); |
---|
1328 | int laneNo = new Integer(st.nextToken()); |
---|
1329 | Globals.map.roads.get(id).laneNo = laneNo; |
---|
1330 | } |
---|
1331 | } catch (Exception ex) { |
---|
1332 | // skipping line |
---|
1333 | } |
---|
1334 | } |
---|
1335 | } catch (Exception ex) { |
---|
1336 | logger.info("Additional map information could not be set"); |
---|
1337 | } |
---|
1338 | } |
---|
1339 | |
---|
1340 | private static class MapLoaderComponentListener implements ComponentListener { |
---|
1341 | |
---|
1342 | public void componentHidden(ComponentEvent e) { |
---|
1343 | } |
---|
1344 | |
---|
1345 | public void componentMoved(ComponentEvent e) { |
---|
1346 | } |
---|
1347 | |
---|
1348 | public void componentResized(ComponentEvent e) { |
---|
1349 | } |
---|
1350 | |
---|
1351 | public void componentShown(ComponentEvent e) { |
---|
1352 | } |
---|
1353 | |
---|
1354 | } |
---|
1355 | |
---|
1356 | public static void main(String args[]) { |
---|
1357 | loadMap(); |
---|
1358 | } |
---|
1359 | } |
---|