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.vehicular.scenarios; |
---|
7 | |
---|
8 | |
---|
9 | |
---|
10 | import java.io.*; |
---|
11 | import javax.swing.*; |
---|
12 | import java.util.logging.*; |
---|
13 | |
---|
14 | import vnsim.vehicular.generator.Mobility; |
---|
15 | import vnsim.gui.*; |
---|
16 | import vnsim.map.object.*; |
---|
17 | |
---|
18 | |
---|
19 | public class Main { |
---|
20 | |
---|
21 | /*public static void main(String args[]) throws Exception { |
---|
22 | ObjectInputStream ois=new ObjectInputStream(new FileInputStream(".//maps//fsc//"+args[0])); |
---|
23 | Scenario sc=null; |
---|
24 | try { |
---|
25 | sc=(Scenario)ois.readObject(); |
---|
26 | System.out.println("Sc name="+sc.name); |
---|
27 | } catch (Exception ex) { |
---|
28 | JOptionPane.showMessageDialog(null, "<html>ERROR! Scenario could not be read!<br> Try rebuilding the map " + args[0] +"!</html>"); |
---|
29 | throw ex; |
---|
30 | } |
---|
31 | |
---|
32 | int ret=JOptionPane.showConfirmDialog(null, "Do you want to specify a flow variations file?"); |
---|
33 | |
---|
34 | if(ret==JOptionPane.OK_OPTION) { |
---|
35 | JFileChooser fc=new JFileChooser(".//maps//variations//"); |
---|
36 | fc.setDialogTitle("Choose the file specifying the flow variations"); |
---|
37 | int retVal=fc.showOpenDialog(null); |
---|
38 | if(retVal==JFileChooser.APPROVE_OPTION) { |
---|
39 | vnsim.map.object.Globals.variationsFile=fc.getSelectedFile().getName(); |
---|
40 | } else { |
---|
41 | vnsim.map.object.Globals.variationsFile=null; |
---|
42 | } |
---|
43 | } else { |
---|
44 | vnsim.map.object.Globals.variationsFile=null; |
---|
45 | } |
---|
46 | try { |
---|
47 | Mobility.loadScenario(sc); |
---|
48 | } catch (Exception ex) { |
---|
49 | JOptionPane.showMessageDialog(null, "<html>ERROR! Map structure has been modified<br> Try rebuilding the map " + sc.mapFileName +"!</html>"); |
---|
50 | throw ex; |
---|
51 | } |
---|
52 | System.out.println("Scenario loaded..."); |
---|
53 | vnsim.gui.Main.startGui(); |
---|
54 | } |
---|
55 | }*/ |
---|
56 | /** Logger used by this class */ |
---|
57 | private static final transient Logger logger = Logger.getLogger("scenarios.Main"); |
---|
58 | |
---|
59 | public static void main(String args[]) throws Exception { |
---|
60 | Scenario sc=null; |
---|
61 | try { |
---|
62 | ObjectInputStream ois = null; |
---|
63 | File f = new File(System.getProperty("user.home")+File.separatorChar+"maps"+File.separatorChar+"fsc"+File.separatorChar+args[0]); |
---|
64 | if (f.exists() && f.isFile() && f.canRead()) { |
---|
65 | ois = new ObjectInputStream(new FileInputStream(f)); |
---|
66 | } else { |
---|
67 | ois = new ObjectInputStream(Utils.getInstance().openStream("maps/fsc/"+args[0])); |
---|
68 | } |
---|
69 | sc=(Scenario)ois.readObject(); |
---|
70 | logger.info("Sc name="+sc.name); |
---|
71 | ois.close(); |
---|
72 | } catch (Exception ex) { |
---|
73 | JOptionPane.showMessageDialog(null, "<html>ERROR! Scenario could not be read!<br> Try rebuilding the map " + args[0] +"!</html>"); |
---|
74 | throw ex; |
---|
75 | } |
---|
76 | int ret=JOptionPane.showConfirmDialog(null, "Do you want to specify a flow variations file?"); |
---|
77 | if(ret==JOptionPane.OK_OPTION) { |
---|
78 | JFileChooser fc=new JFileChooser("/maps/variations/", Utils.getInstance().getSystemView("/maps/variations")); |
---|
79 | fc.setDialogTitle("Choose the file specifying the flow variations"); |
---|
80 | int retVal=fc.showOpenDialog(null); |
---|
81 | if(retVal==JFileChooser.APPROVE_OPTION) { |
---|
82 | Globals.variationsFile=fc.getSelectedFile().getName(); |
---|
83 | } else { |
---|
84 | Globals.variationsFile = null; |
---|
85 | } |
---|
86 | } else { |
---|
87 | Globals.variationsFile = null; |
---|
88 | } |
---|
89 | try { |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | Mobility.loadScenario(sc); |
---|
94 | } catch (Exception ex) { |
---|
95 | JOptionPane.showMessageDialog(null, "<html>ERROR! Map structure has been modified<br> Try rebuilding the map " + sc.mapFileName +"!</html>"); |
---|
96 | throw ex; |
---|
97 | } |
---|
98 | logger.info("Scenario loaded..."); |
---|
99 | vnsim.gui.Main.startGui(); |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|