[31] | 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 | * Created on Jul 16, 2005 |
---|
| 9 | * |
---|
| 10 | |
---|
| 11 | */ |
---|
| 12 | import java.util.Enumeration; |
---|
| 13 | import java.util.Vector; |
---|
| 14 | |
---|
| 15 | import javax.comm.CommPortIdentifier; |
---|
| 16 | import javax.swing.*; |
---|
| 17 | |
---|
| 18 | import vnsim.core.*; |
---|
| 19 | import vnsim.map.object.*; |
---|
| 20 | |
---|
| 21 | import java.awt.*; |
---|
| 22 | |
---|
| 23 | import java.awt.event.*; |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | /** |
---|
| 27 | * @author Victor-Radu |
---|
| 28 | * |
---|
| 29 | */ |
---|
| 30 | public class Main extends JFrame { |
---|
| 31 | |
---|
| 32 | /** |
---|
| 33 | * |
---|
| 34 | */ |
---|
[43] | 35 | |
---|
[31] | 36 | private static final long serialVersionUID = 1L; |
---|
| 37 | static final String maps[]={"NJ","Poli"}; |
---|
| 38 | JComboBox mapsCB = new JComboBox(maps); |
---|
| 39 | |
---|
| 40 | JTextField delayTF1 = new JTextField("5000"); |
---|
| 41 | JTextField periodTF1 = new JTextField("1000"); |
---|
| 42 | |
---|
| 43 | JTextField delayTF2 = new JTextField("10000"); |
---|
| 44 | JTextField periodTF2 = new JTextField("1000"); |
---|
| 45 | |
---|
| 46 | JTextField idTF = new JTextField("1000"); |
---|
| 47 | |
---|
| 48 | JRadioButton tracesRB, serialRB; |
---|
| 49 | JRadioButton net1RB, net2RB; |
---|
| 50 | |
---|
| 51 | JButton fileB=new JButton("File:"); |
---|
| 52 | JTextField fileTF = new JTextField(); |
---|
| 53 | |
---|
| 54 | JLabel deviceL=new JLabel("Device:"); |
---|
| 55 | Vector<String> devs = new Vector<String>(); |
---|
| 56 | JComboBox devsCB = null; |
---|
| 57 | |
---|
| 58 | JButton StartButton = new JButton("Start"); |
---|
| 59 | JButton ExitButton = new JButton("Exit"); |
---|
| 60 | |
---|
| 61 | public Main(){ |
---|
| 62 | super("TrafficView"); |
---|
| 63 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
---|
| 64 | setSize(600,400); |
---|
| 65 | setResizable(false); |
---|
| 66 | Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize(); |
---|
| 67 | setLocation(screenSize.width/2-200,screenSize.height/2-250); |
---|
| 68 | |
---|
| 69 | Container cp=getContentPane(); |
---|
| 70 | cp.setLayout(null); |
---|
| 71 | |
---|
| 72 | //select map |
---|
| 73 | JLabel map=new JLabel("Map:"); |
---|
| 74 | map.setBounds(20,20,30,20); |
---|
| 75 | cp.add(map); |
---|
| 76 | mapsCB.setBounds(100,20,100,20); |
---|
| 77 | cp.add(mapsCB); |
---|
| 78 | |
---|
| 79 | //set GPS input |
---|
| 80 | JLabel gpsL=new JLabel("GPS"); |
---|
| 81 | gpsL.setBounds(280,60,30,20); |
---|
| 82 | cp.add(gpsL); |
---|
| 83 | |
---|
| 84 | JLabel delayL1=new JLabel("delay"); |
---|
| 85 | delayL1.setBounds(20,125,50,20); |
---|
| 86 | cp.add(delayL1); |
---|
| 87 | delayTF1.setBounds(70,125,50,20); |
---|
| 88 | cp.add(delayTF1); |
---|
| 89 | |
---|
| 90 | JLabel periodL1=new JLabel("period"); |
---|
| 91 | periodL1.setBounds(140,125,50,20); |
---|
| 92 | cp.add(periodL1); |
---|
| 93 | periodTF1.setBounds(190,125,50,20); |
---|
| 94 | cp.add(periodTF1); |
---|
| 95 | |
---|
| 96 | Enumeration en = CommPortIdentifier.getPortIdentifiers(); |
---|
| 97 | while (en.hasMoreElements()){ |
---|
| 98 | CommPortIdentifier cpi = (CommPortIdentifier)en.nextElement(); |
---|
| 99 | devs.add(cpi.getName()); |
---|
| 100 | } |
---|
| 101 | deviceL.setBounds(410,100,50,20); |
---|
| 102 | cp.add(deviceL); |
---|
| 103 | devsCB = new JComboBox(devs); |
---|
| 104 | devsCB.setBounds(470,100,70,20); |
---|
| 105 | cp.add(devsCB); |
---|
| 106 | fileB.setBounds(410,140,60,25); |
---|
| 107 | cp.add(fileB); |
---|
| 108 | fileTF.setBounds(470,140,110,25); |
---|
| 109 | cp.add(fileTF); |
---|
| 110 | fileB.addActionListener(new ActionListener(){ |
---|
| 111 | public void actionPerformed(ActionEvent e){ |
---|
| 112 | JFileChooser selectTraceFile = new JFileChooser(); |
---|
| 113 | int returnVal = selectTraceFile.showOpenDialog((JFrame)((JButton)e.getSource()).getRootPane().getParent()); |
---|
| 114 | if(returnVal == JFileChooser.APPROVE_OPTION) { |
---|
| 115 | fileTF.setText(selectTraceFile.getSelectedFile().getName()); |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | }); |
---|
| 119 | fileB.setEnabled(true); |
---|
| 120 | fileTF.setEnabled(true); |
---|
| 121 | deviceL.setEnabled(false); |
---|
| 122 | devsCB.setEnabled(false); |
---|
| 123 | ButtonGroup group=new ButtonGroup(); |
---|
| 124 | tracesRB=new JRadioButton("Use GPS traces"); |
---|
| 125 | tracesRB.setSelected(true); |
---|
| 126 | serialRB=new JRadioButton("Use GPS device"); |
---|
| 127 | serialRB.addActionListener(new ActionListener(){ |
---|
| 128 | public void actionPerformed(ActionEvent e){ |
---|
| 129 | fileB.setEnabled(false); |
---|
| 130 | fileTF.setEnabled(false); |
---|
| 131 | deviceL.setEnabled(true); |
---|
| 132 | devsCB.setEnabled(true); |
---|
| 133 | } |
---|
| 134 | }); |
---|
| 135 | tracesRB.addActionListener(new ActionListener(){ |
---|
| 136 | public void actionPerformed(ActionEvent e){ |
---|
| 137 | fileB.setEnabled(true); |
---|
| 138 | fileTF.setEnabled(true); |
---|
| 139 | deviceL.setEnabled(false); |
---|
| 140 | devsCB.setEnabled(false); |
---|
| 141 | } |
---|
| 142 | }); |
---|
| 143 | group.add(tracesRB); |
---|
| 144 | group.add(serialRB); |
---|
| 145 | serialRB.setBounds(270,100,130,20); |
---|
| 146 | tracesRB.setBounds(270,140,130,20); |
---|
| 147 | cp.add(tracesRB); |
---|
| 148 | cp.add(serialRB); |
---|
| 149 | |
---|
| 150 | //set networking model |
---|
| 151 | JLabel netL=new JLabel("Networking model"); |
---|
| 152 | netL.setBounds(250,180,150,20); |
---|
| 153 | cp.add(netL); |
---|
| 154 | |
---|
| 155 | ButtonGroup group2 = new ButtonGroup(); |
---|
| 156 | net1RB = new JRadioButton("Simple text messages"); |
---|
| 157 | net2RB=new JRadioButton("Neighbor discovery"); |
---|
| 158 | net2RB.setSelected(true); |
---|
| 159 | group2.add(net1RB); |
---|
| 160 | group2.add(net2RB); |
---|
| 161 | net1RB.setBounds(20,220,180,20); |
---|
| 162 | net2RB.setBounds(20,260,180,20); |
---|
| 163 | cp.add(net1RB); |
---|
| 164 | cp.add(net2RB); |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | JLabel delayL2=new JLabel("delay"); |
---|
| 168 | delayL2.setBounds(300,240,50,20); |
---|
| 169 | cp.add(delayL2); |
---|
| 170 | delayTF2.setBounds(350,240,50,20); |
---|
| 171 | cp.add(delayTF2); |
---|
| 172 | |
---|
| 173 | JLabel periodL2=new JLabel("period"); |
---|
| 174 | periodL2.setBounds(420,240,50,20); |
---|
| 175 | cp.add(periodL2); |
---|
| 176 | periodTF2.setBounds(470,240,50,20); |
---|
| 177 | cp.add(periodTF2); |
---|
| 178 | |
---|
| 179 | JLabel idL=new JLabel("Vehicle ID:"); |
---|
| 180 | idL.setBounds(420,240,80,20); |
---|
| 181 | cp.add(idL); |
---|
| 182 | idTF.setBounds(500,240,50,20); |
---|
| 183 | cp.add(idTF); |
---|
| 184 | |
---|
| 185 | StartButton.setBounds(400,330,80,30); |
---|
| 186 | StartButton.addActionListener(new StartListener()); |
---|
| 187 | |
---|
| 188 | ExitButton.setBounds(500,330,80,30); |
---|
| 189 | ExitButton.addActionListener(new ExitListener()); |
---|
| 190 | |
---|
| 191 | cp.add(StartButton); |
---|
| 192 | cp.add(ExitButton); |
---|
| 193 | |
---|
| 194 | setVisible(true); |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | |
---|
| 198 | class StartListener implements ActionListener{ |
---|
| 199 | |
---|
| 200 | public void actionPerformed(ActionEvent e){ |
---|
| 201 | setVisible(false); |
---|
| 202 | fileTF.setEnabled(false); |
---|
| 203 | // new displayMain2( (JFrame)((JButton)e.getSource()).getRootPane().getParent()); |
---|
| 204 | } |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | class ExitListener implements ActionListener{ |
---|
| 208 | |
---|
| 209 | public void actionPerformed(ActionEvent e){ |
---|
| 210 | System.exit(0); |
---|
| 211 | } |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | public static void startGui() throws Exception { |
---|
| 216 | Globals.map.setLaneNoExtra(); |
---|
| 217 | Globals.engine=new Engine(true, true); |
---|
| 218 | Globals.engine.init(); |
---|
| 219 | Globals.demo = new Display(); |
---|
| 220 | Globals.demo.setVisible(true); |
---|
| 221 | System.out.println("Gata main"); |
---|
[43] | 222 | |
---|
| 223 | System.out.println(".........................aici end startGui........."); |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | |
---|
[31] | 227 | } |
---|
| 228 | |
---|
[43] | 229 | public static void someTests(Map map){ |
---|
[31] | 230 | Road r = (Road)map.roads.get(69); |
---|
| 231 | for (int i=0; i<r.crosses.size(); i++){ |
---|
| 232 | Cross c = (Cross)r.crosses.get(i); |
---|
[43] | 233 | System.out.println(".........................Intersectie la "+c.getPointIndex()+" cu "+c.getCrossRoadIndex() + " in "+c.getCrossPointIndex()); |
---|
[31] | 234 | } |
---|
[43] | 235 | /*for (int i=0; i<10; i++){ |
---|
[31] | 236 | PeanoKey pk = (PeanoKey)map.peanoKeys.get(i); |
---|
| 237 | r = (Road)map.roads.get(pk.getRoadIndex()); |
---|
| 238 | // Point p = (Point)r.points.get(pk.getPointIndex()); |
---|
| 239 | // System.out.println(new String( ((PeanoKey)map.peanoKeys.get(i)).getValue() ) + " ("+ p.getLongitude() + "," + p.getLatitude() +")" ); |
---|
| 240 | } |
---|
| 241 | if (Globals.map!= null) |
---|
| 242 | { |
---|
| 243 | System.out.println(map.roads.size() + " roads"); |
---|
| 244 | System.out.println(map.peanoKeys.size()+ " points"); |
---|
| 245 | for (int i=0; i<map.roads.size(); i++){ |
---|
| 246 | r = (Road)map.roads.get(i); |
---|
| 247 | if ( r.getName().trim().equals("Raritan") |
---|
| 248 | && new String(r.getType()).trim().equals("Ave")){ |
---|
| 249 | // System.out.println("Raritan road segment, id: "+r.getId()+ |
---|
| 250 | // ", length: " + ((Point)r.points.get(r.points.size()-1)).getDistance()+ |
---|
| 251 | // " km, points: " + r.points.size() + ", " + new String(r.getRoadinfo()) + ", connects to:"); |
---|
| 252 | for (int j=0;j<r.crosses.size();j++){ |
---|
| 253 | Cross c = (Cross)r.crosses.get(j); |
---|
| 254 | Road r2 = (Road)map.roads.get(c.getCrossRoadIndex()); |
---|
| 255 | System.out.println("\t" + r2.getName().trim() + " " + new String(r.getType()).trim() + |
---|
| 256 | ", id: " + r2.getId()); |
---|
| 257 | |
---|
| 258 | } |
---|
| 259 | } |
---|
| 260 | } |
---|
| 261 | }else |
---|
[43] | 262 | System.out.println("null");*/ |
---|
[31] | 263 | } |
---|
| 264 | } |
---|