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