1 package org.opentrafficsim.demo.carFollowing;
2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.GridLayout;
6 import java.awt.LayoutManager;
7 import java.awt.event.ActionEvent;
8 import java.awt.event.ActionListener;
9 import java.awt.geom.Rectangle2D;
10 import java.rmi.RemoteException;
11 import java.text.DecimalFormat;
12 import java.util.ArrayList;
13
14 import javax.swing.BoxLayout;
15 import javax.swing.ButtonGroup;
16 import javax.swing.GroupLayout;
17 import javax.swing.GroupLayout.Alignment;
18 import javax.swing.JButton;
19 import javax.swing.JCheckBox;
20 import javax.swing.JFrame;
21 import javax.swing.JLabel;
22 import javax.swing.JMenu;
23 import javax.swing.JMenuBar;
24 import javax.swing.JMenuItem;
25 import javax.swing.JOptionPane;
26 import javax.swing.JPanel;
27 import javax.swing.JRadioButton;
28 import javax.swing.JSpinner;
29 import javax.swing.SpinnerNumberModel;
30 import javax.swing.SwingUtilities;
31 import javax.swing.border.EtchedBorder;
32 import javax.swing.border.TitledBorder;
33
34 import nl.tudelft.simulation.dsol.SimRuntimeException;
35 import nl.tudelft.simulation.dsol.gui.swing.TablePanel;
36
37
38
39
40
41
42
43 import org.opentrafficsim.core.dsol.OTSSimTimeDouble;
44 import org.opentrafficsim.core.unit.TimeUnit;
45 import org.opentrafficsim.core.value.vdouble.scalar.DoubleScalar;
46 import org.opentrafficsim.graphs.AccelerationContourPlot;
47 import org.opentrafficsim.graphs.ContourPlot;
48 import org.opentrafficsim.graphs.DensityContourPlot;
49 import org.opentrafficsim.graphs.FlowContourPlot;
50 import org.opentrafficsim.graphs.SpeedContourPlot;
51 import org.opentrafficsim.graphs.TrajectoryPlot;
52 import org.opentrafficsim.simulationengine.AbstractProperty;
53 import org.opentrafficsim.simulationengine.SimpleSimulator;
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 class VerticalMenuBar extends JMenuBar
69 {
70 private static final LayoutManager grid = new GridLayout(0, 1);
71
72 public VerticalMenuBar()
73 {
74 setLayout(grid);
75 }
76 }
77
78 public class newGUI
79 {
80
81 JFrame f = new JFrame("OpenTrafficSim GUI");
82
83 JPanel networkPanel = new JPanel();
84
85 JPanel modelPanel = new JPanel();
86
87 JPanel inputPanel = new JPanel();
88
89 JPanel outputPanel = new JPanel();
90
91 JPanel settingPanel = new JPanel();
92
93 JPanel simPanel = new JPanel();
94
95 JPanel statPanel = new JPanel();
96
97 JLabel networkLabel = new JLabel();
98
99 JLabel modelLabel = new JLabel();
100
101 JLabel networkDescriptor = new JLabel();
102
103 ButtonGroup networkButtonGroup = new ButtonGroup();
104
105
106 ButtonGroup circularLaneBtnGroup = new ButtonGroup();
107
108 ButtonGroup circularRoadBtnGroup = new ButtonGroup();
109
110 ButtonGroup directLaneBtnGroup = new ButtonGroup();
111
112 private JMenuBar mb_network = new JMenuBar();
113
114 private JMenuBar mb_model = new JMenuBar();
115
116 JMenu network = new JMenu("Network Settings");
117
118 JMenu model = new JMenu("Model Settings");
119
120 JMenuItem circularLane = new JMenuItem("Circular Lane");
121
122 JMenuItem circularRoad = new JMenuItem("Circular Road");
123
124 JMenuItem directLane = new JMenuItem("Direct Lane");
125
126 JMenuItem customorize = new JMenuItem("Customorize");
127
128 JMenu micro = new JMenu("Micro");
129
130 JMenu macro = new JMenu("Macro");
131
132 JMenuItem meta = new JMenuItem("Meta");
133
134 JMenu CF = new JMenu("CF");
135
136 JMenu LC = new JMenu("LC");
137
138 JMenuItem IDM = new JMenuItem("IDM");
139
140 JMenuItem Mobil = new JMenuItem("Mobil");
141
142 JSpinner spinner1 = new JSpinner();
143
144 JSpinner spinner2 = new JSpinner();
145
146 JSpinner spinner3 = new JSpinner();
147
148 JSpinner spinner4 = new JSpinner();
149
150 JSpinner spinner5 = new JSpinner();
151
152 private void settingPanel_conf()
153 {
154 networkPanel_conf();
155 modelPanel_conf();
156
157 this.settingPanel.setLayout(new BorderLayout());
158 this.settingPanel.add(this.networkPanel, BorderLayout.NORTH);
159 this.settingPanel.add(this.modelPanel, BorderLayout.CENTER);
160 this.settingPanel.add(this.outputPanel, BorderLayout.SOUTH);
161 }
162
163 private void networkPanel_conf()
164 {
165 this.network.add(this.circularLane);
166 this.network.addSeparator();
167 this.network.add(this.circularRoad);
168 this.network.addSeparator();
169 this.network.add(this.directLane);
170 this.network.addSeparator();
171 this.network.add(this.customorize);
172
173 this.networkLabel.setPreferredSize(new Dimension(40, 30));
174
175 this.circularLane.addActionListener(new ActionListener()
176 {
177 public void actionPerformed(ActionEvent event)
178 {
179 newGUI.this.networkLabel.setText("Circular Lane Chosen");
180 newGUI.this.networkDescriptor.setText("<html>" + "The description of Circular Lane Network" + "</html>");
181 outputPanel_conf("circularLane");
182 }
183 });
184
185 this.circularRoad.addActionListener(new ActionListener()
186 {
187 public void actionPerformed(ActionEvent event)
188 {
189 newGUI.this.networkLabel.setText("Circular Road Chosen");
190 newGUI.this.networkDescriptor.setText("<html>" + "The description of Circular Road Network" + "</html>");
191 outputPanel_conf("circularRoad");
192 }
193 });
194
195 this.directLane.addActionListener(new ActionListener()
196 {
197 public void actionPerformed(ActionEvent event)
198 {
199 newGUI.this.networkLabel.setText("Direct Lane Chosen");
200 newGUI.this.networkDescriptor.setText("<html>"
201 + "The default Network using the Internal ContourPlots Model for simulation and contour plots"
202 + "</html>");
203 outputPanel_conf("DirectRoad");
204 }
205 });
206
207 this.customorize.addActionListener(new ActionListener()
208 {
209 public void actionPerformed(ActionEvent event)
210 {
211 newGUI.this.networkLabel.setText("Not Available Currently");
212 }
213 });
214
215 this.mb_network.add(this.network);
216
217 this.networkPanel.setLayout(new BorderLayout());
218 this.networkPanel.add(this.mb_network, BorderLayout.NORTH);
219 this.networkPanel.add(this.networkLabel, BorderLayout.CENTER);
220
221 this.networkDescriptor.setPreferredSize(new Dimension(40, 80));
222 this.networkPanel.add(this.networkDescriptor, BorderLayout.SOUTH);
223 }
224
225 private void modelPanel_conf()
226 {
227 this.model.add(this.micro);
228 this.model.addSeparator();
229 this.model.add(this.macro);
230 this.model.addSeparator();
231 this.model.add(this.meta);
232
233 this.IDM.addActionListener(new ActionListener()
234 {
235 public void actionPerformed(ActionEvent event)
236 {
237 inputPanel_conf("IDM");
238 newGUI.this.modelLabel.setText("IDM");
239 }
240 });
241
242 this.Mobil.addActionListener(new ActionListener()
243 {
244 public void actionPerformed(ActionEvent event)
245 {
246 inputPanel_conf("Mobil");
247 newGUI.this.modelLabel.setText("Mobil");
248 }
249 });
250
251 this.CF.add(this.IDM);
252 this.LC.add(this.Mobil);
253 this.micro.add(this.CF);
254 this.micro.add(this.LC);
255
256 this.mb_model.add(this.model);
257
258 this.modelPanel.setLayout(new BorderLayout());
259
260 this.modelPanel.add(this.mb_model, BorderLayout.NORTH);
261
262 this.modelPanel.add(this.inputPanel, BorderLayout.CENTER);
263 }
264
265 private void inputPanel_conf(String model)
266 {
267 if (model.equals("IDM"))
268 {
269 this.inputPanel.removeAll();
270
271 this.inputPanel.setBorder(new TitledBorder(new EtchedBorder(), "IDM Parameters"));
272 setParameters("IDM a", "IDM b", "IDM S0", "IDM tSafe", "IDM delta");
273
274 }
275 else if (model.equals("Mobil"))
276 {
277 this.inputPanel.removeAll();
278 this.inputPanel.setBorder(new TitledBorder(new EtchedBorder(), "Mobil Parameters"));
279 setParameters("mobil a", "mobil b", "mobil S0", "mobil tSate", "mobil delta");
280
281 }
282 else
283 {
284 this.inputPanel.removeAll();
285 }
286 }
287
288 private void setParameters(String first, String second, String third, String fourth, String fifth)
289 {
290
291 GroupLayout layout = new GroupLayout(this.inputPanel);
292 this.inputPanel.setLayout(layout);
293
294
295 layout.setAutoCreateGaps(true);
296
297
298
299 layout.setAutoCreateContainerGaps(true);
300
301
302
303 GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
304
305
306
307
308
309
310
311 JLabel label1 = new JLabel(first);
312 JLabel label2 = new JLabel(second);
313 JLabel label3 = new JLabel(third);
314 JLabel label4 = new JLabel(fourth);
315 JLabel label5 = new JLabel(fifth);
316
317
318 SpinnerNumberModel spinnerModel1 = new SpinnerNumberModel(1.0, -10.0, 10.0, 0.1);
319 SpinnerNumberModel spinnerModel2 = new SpinnerNumberModel(1.5, -10.0, 10.0, 0.1);
320 SpinnerNumberModel spinnerModel3 = new SpinnerNumberModel(2.0, -10.0, 10.0, 0.1);
321 SpinnerNumberModel spinnerModel4 = new SpinnerNumberModel(1.0, -10.0, 10.0, 0.1);
322 SpinnerNumberModel spinnerModel5 = new SpinnerNumberModel(1.00, -10.0, 10.0, 0.01);
323
324
325 this.spinner1.setModel(spinnerModel1);
326 this.spinner2.setModel(spinnerModel2);
327 this.spinner3.setModel(spinnerModel3);
328 this.spinner4.setModel(spinnerModel4);
329 this.spinner5.setModel(spinnerModel5);
330
331 JSpinner.NumberEditor editor2 = (JSpinner.NumberEditor) this.spinner2.getEditor();
332 DecimalFormat format2 = editor2.getFormat();
333 format2.setMinimumFractionDigits(2);
334
335 JSpinner.NumberEditor editor3 = (JSpinner.NumberEditor) this.spinner3.getEditor();
336 DecimalFormat format3 = editor3.getFormat();
337 format3.setMinimumFractionDigits(2);
338
339 JSpinner.NumberEditor editor4 = (JSpinner.NumberEditor) this.spinner4.getEditor();
340 DecimalFormat format4 = editor4.getFormat();
341 format4.setMinimumFractionDigits(2);
342
343 JSpinner.NumberEditor editor5 = (JSpinner.NumberEditor) this.spinner5.getEditor();
344 DecimalFormat format5 = editor5.getFormat();
345 format5.setMinimumFractionDigits(3);
346
347
348 this.spinner1.setValue(new Double(1.0));
349 this.spinner2.setValue(new Double(1.5));
350 this.spinner3.setValue(new Double(2.0));
351 this.spinner4.setValue(new Double(1.0));
352 this.spinner5.setValue(new Double(1.0));
353
354
355 hGroup.addGroup(layout.createParallelGroup().addComponent(label1).addComponent(label2).addComponent(label3)
356 .addComponent(label4).addComponent(label5));
357 hGroup.addGroup(layout.createParallelGroup().addComponent(this.spinner1).addComponent(this.spinner2).addComponent(
358 this.spinner3).addComponent(this.spinner4).addComponent(this.spinner5));
359 layout.setHorizontalGroup(hGroup);
360
361
362 GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
363
364
365
366
367
368
369 vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(label1).addComponent(this.spinner1));
370 vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(label2).addComponent(this.spinner2));
371 vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(label3).addComponent(this.spinner3));
372 vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(label4).addComponent(this.spinner4));
373 vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(label5).addComponent(this.spinner5));
374 layout.setVerticalGroup(vGroup);
375 }
376
377
378 JCheckBox showNewFrame = new JCheckBox("Show All Statistis in New Frame ");
379
380 private void outputPanel_conf(String network)
381 {
382
383 this.outputPanel.setLayout(new BoxLayout(this.outputPanel, BoxLayout.Y_AXIS));
384
385 this.outputPanel.removeAll();
386
387 switch (network)
388 {
389 case "circularLane":
390 addOutputButton("Statistics in 2D", network);
391 addOutputButton("Statistics in 3D", network);
392 this.outputPanel.add(this.showNewFrame, network);
393 break;
394 case "circularRoad":
395 addOutputButton("Statistics for Lane 1 in 2D", network);
396 addOutputButton("Statistics for Lane 2 in 2D", network);
397 addOutputButton("Statistics for Lane 1 in 3D", network);
398 addOutputButton("Statistics for Lane 2 in 3D", network);
399 this.outputPanel.add(this.showNewFrame);
400 break;
401 case "directRoad":
402 addOutputButton("Statistics in 2D", network);
403 addOutputButton("Statistics in 3D", network);
404 this.outputPanel.add(this.showNewFrame);
405 break;
406 case "customorize":
407 break;
408 default:
409 break;
410
411 }
412
413 JButton done_Btn = new JButton("Done");
414 this.outputPanel.add(done_Btn);
415 done_Btn.addActionListener(new ActionListener()
416 {
417 public void actionPerformed(ActionEvent event)
418 {
419 if ((!newGUI.this.networkLabel.getText().equals("")) && (!newGUI.this.modelLabel.getText().equals("")))
420 {
421 try
422 {
423 simPanel_conf(newGUI.this.networkLabel.getText());
424 }
425 catch (RemoteException | SimRuntimeException exception)
426 {
427 exception.printStackTrace();
428 }
429
430 }
431 else
432 {
433 JOptionPane.showMessageDialog(newGUI.this.f, "The setting is not compeleted");
434
435 }
436 }
437 });
438
439 }
440
441 void simPanel_conf(String network) throws RemoteException, SimRuntimeException
442 {
443 this.simPanel.setLayout(new BorderLayout());
444 this.simPanel.removeAll();
445 this.statPanel.removeAll();
446
447 if (network.equals("Circular Lane Chosen"))
448 {
449 LaneSimulationModel model = new LaneSimulationModel(new ArrayList<AbstractProperty<?>>());
450 SimpleSimulator simSimulator =
451 new SimpleSimulator(new OTSSimTimeDouble(new DoubleScalar.Abs<TimeUnit>(0.0, TimeUnit.SECOND)),
452 new DoubleScalar.Rel<TimeUnit>(0.0, TimeUnit.SECOND), new DoubleScalar.Rel<TimeUnit>(3600.0,
453 TimeUnit.SECOND), model, new Rectangle2D.Double(-1000, -1000, 1000, 1000));
454 this.simPanel.add(simSimulator.getPanel(), BorderLayout.CENTER);
455
456 ContourPlot cp;
457
458 cp =
459 new DensityContourPlot("DensityPlot " + model.carFollowingModelCars.getLongName(), model
460 .getMinimumDistance(), model.lane1.getLength());
461 cp.setTitle("Density Contour Graph");
462
463 model.getPlots().add(cp);
464 this.statPanel.add(cp.getContentPane());
465
466 cp =
467 new SpeedContourPlot("SpeedPlot " + model.carFollowingModelCars.getLongName(), model.getMinimumDistance(),
468 model.lane1.getLength());
469 cp.setTitle("Speed Contour Graph");
470 model.getPlots().add(cp);
471 this.statPanel.add(cp.getContentPane());
472
473 cp =
474 new FlowContourPlot("FlowPlot " + model.carFollowingModelCars.getLongName(), model.getMinimumDistance(),
475 model.lane1.getLength());
476 cp.setTitle("FLow Contour Graph");
477 model.getPlots().add(cp);
478 this.statPanel.add(cp.getContentPane());
479
480 cp =
481 new AccelerationContourPlot("AccelerationPlot " + model.carFollowingModelCars.getLongName(), model
482 .getMinimumDistance(), model.lane1.getLength());
483 cp.setTitle("Acceleration Contour Graph");
484 model.getPlots().add(cp);
485 this.statPanel.add(cp.getContentPane());
486
487 TrajectoryPlot trajectoryPlot =
488 new TrajectoryPlot("TrajectoryPlot " + model.carFollowingModelCars.getLongName(),
489 new DoubleScalar.Rel<TimeUnit>(0.5, TimeUnit.SECOND), model.getMinimumDistance(), model.lane1.getLength());
490 trajectoryPlot.setTitle("Trajectories");
491 this.statPanel.add(trajectoryPlot.getContentPane());
492 model.getTrajectoryPlots().add(trajectoryPlot);
493
494 if (this.showNewFrame.isSelected())
495 {
496 createCircularLaneFrame(model);
497 }
498 }
499 else if (network.equals("Circular Road Chosen"))
500 {
501 RoadSimulationModel model = new RoadSimulationModel(new ArrayList<AbstractProperty<?>>());
502 SimpleSimulator simSimulator =
503 new SimpleSimulator(new OTSSimTimeDouble(new DoubleScalar.Abs<TimeUnit>(0.0, TimeUnit.SECOND)),
504 new DoubleScalar.Rel<TimeUnit>(0.0, TimeUnit.SECOND), new DoubleScalar.Rel<TimeUnit>(3600.0,
505 TimeUnit.SECOND), model, new Rectangle2D.Double(-1000, -1000, 1000, 1000));
506 this.simPanel.add(simSimulator.getPanel(), BorderLayout.CENTER);
507
508 ContourPlot cp;
509
510 for (int laneIndex = 0; laneIndex <= 0; laneIndex++)
511 {
512 final String laneName = String.format(" lane %d", laneIndex + 1);
513 cp =
514 new DensityContourPlot(
515 "DensityPlot " + model.carFollowingModelCars.getLongName() + " lane " + laneIndex, model
516 .getMinimumDistance(), model.lanes[laneIndex].getLength());
517 cp.setTitle("Density Contour Graph");
518
519 model.getPlots().get(laneIndex).add(cp);
520 this.statPanel.add(cp.getContentPane());
521
522 cp =
523 new SpeedContourPlot("SpeedPlot " + model.carFollowingModelCars.getLongName() + laneName, model
524 .getMinimumDistance(), model.lanes[laneIndex].getLength());
525 cp.setTitle("Speed Contour Graph");
526 model.getPlots().get(laneIndex).add(cp);
527 this.statPanel.add(cp.getContentPane());
528
529 cp =
530 new FlowContourPlot("FlowPlot " + model.carFollowingModelCars.getLongName() + laneName, model
531 .getMinimumDistance(), model.lanes[laneIndex].getLength());
532 cp.setTitle("FLow Contour Graph");
533 model.getPlots().get(laneIndex).add(cp);
534 this.statPanel.add(cp.getContentPane());
535
536 cp =
537 new AccelerationContourPlot("AccelerationPlot " + model.carFollowingModelCars.getLongName() + laneName,
538 model.getMinimumDistance(), model.lanes[laneIndex].getLength());
539 cp.setTitle("Acceleration Contour Graph");
540 model.getPlots().get(laneIndex).add(cp);
541 this.statPanel.add(cp.getContentPane());
542
543 TrajectoryPlot trajectoryPlot =
544 new TrajectoryPlot("TrajectoryPlot " + model.carFollowingModelCars.getLongName() + laneName,
545 new DoubleScalar.Rel<TimeUnit>(0.5, TimeUnit.SECOND), model.getMinimumDistance(),
546 model.lanes[laneIndex].getLength());
547 trajectoryPlot.setTitle("Trajectories");
548 this.statPanel.add(trajectoryPlot.getContentPane());
549 model.getPlots().get(laneIndex).add(trajectoryPlot);
550 }
551
552 if (this.showNewFrame.isSelected())
553 {
554 createCircularRoadFrame(model);
555 }
556
557 }
558 else if (network.equals("Direct Lane Chosen"))
559 {
560 StraightModel model = new StraightModel(new ArrayList<AbstractProperty<?>>());
561 SimpleSimulator simSimulator =
562 new SimpleSimulator(new OTSSimTimeDouble(new DoubleScalar.Abs<TimeUnit>(0.0, TimeUnit.SECOND)),
563 new DoubleScalar.Rel<TimeUnit>(0.0, TimeUnit.SECOND), new DoubleScalar.Rel<TimeUnit>(1800.0,
564 TimeUnit.SECOND), model, new Rectangle2D.Double(0, -100, 5000, 200));
565 this.simPanel.add(simSimulator.getPanel(), BorderLayout.CENTER);
566
567 ContourPlot cp;
568
569 cp = new DensityContourPlot("DensityPlot", model.getMinimumDistance(), model.getMaximumDistance());
570 cp.setTitle("Density Contour Graph");
571
572 model.getPlots().add(cp);
573 this.statPanel.add(cp.getContentPane());
574
575 cp = new SpeedContourPlot("SpeedPlot", model.getMinimumDistance(), model.getMaximumDistance());
576 cp.setTitle("Speed Contour Graph");
577 model.getPlots().add(cp);
578 this.statPanel.add(cp.getContentPane());
579
580 cp = new FlowContourPlot("FlowPlot", model.getMinimumDistance(), model.getMaximumDistance());
581 cp.setTitle("FLow Contour Graph");
582 model.getPlots().add(cp);
583 this.statPanel.add(cp.getContentPane());
584
585 cp = new AccelerationContourPlot("AccelerationPlot", model.getMinimumDistance(), model.getMaximumDistance());
586 cp.setTitle("Acceleration Contour Graph");
587 model.getPlots().add(cp);
588 this.statPanel.add(cp.getContentPane());
589
590 if (this.showNewFrame.isSelected())
591 {
592 createDirectLaneFrame(model);
593 }
594 }
595 SwingUtilities.updateComponentTreeUI(this.f);
596 }
597
598
599
600 private void addOutputButton(String label, String network)
601 {
602 this.outputPanel.setBorder(new TitledBorder(new EtchedBorder(), "Set the Output Mode"));
603 JRadioButton button = new JRadioButton(label);
604 this.outputPanel.add(button);
605 switch (network)
606 {
607 case "circularLane":
608 this.circularLaneBtnGroup.add(button);
609
610 if (this.circularLaneBtnGroup.getButtonCount() == 0)
611 button.setSelected(true);
612 break;
613 case "circularRoad":
614 this.circularRoadBtnGroup.add(button);
615 if (this.circularRoadBtnGroup.getButtonCount() == 0)
616 button.setSelected(true);
617 break;
618 case "directLane":
619 this.directLaneBtnGroup.add(button);
620 if (this.directLaneBtnGroup.getButtonCount() == 0)
621 button.setSelected(true);
622 break;
623 default:
624 break;
625 }
626
627 }
628
629 JFrame separateFrame;
630
631 private void createCircularLaneFrame(LaneSimulationModel model)
632 {
633
634 if (this.separateFrame == null)
635 {
636 this.separateFrame = new JFrame("Statistics Plots");
637 this.separateFrame.setSize(800, 600);
638 }
639 else
640 {
641
642 this.separateFrame.setVisible(false);
643 this.separateFrame.dispose();
644
645 this.separateFrame = new JFrame("Statistics Plots");
646 this.separateFrame.setSize(800, 600);
647 }
648
649 TablePanel charts = new TablePanel(3, 2);
650
651
652 ContourPlot cp;
653
654 cp =
655 new DensityContourPlot("DensityPlot " + model.carFollowingModelCars.getLongName(), model.getMinimumDistance(),
656 model.lane1.getLength());
657 cp.setTitle("Density Contour Graph");
658
659 model.getPlots().add(cp);
660 charts.setCell(cp.getContentPane(), 0, 0);
661
662 cp =
663 new SpeedContourPlot("SpeedPlot " + model.carFollowingModelCars.getLongName(), model.getMinimumDistance(),
664 model.lane1.getLength());
665 cp.setTitle("Speed Contour Graph");
666 model.getPlots().add(cp);
667 charts.setCell(cp.getContentPane(), 1, 0);
668
669 cp =
670 new FlowContourPlot("FlowPlot " + model.carFollowingModelCars.getLongName(), model.getMinimumDistance(),
671 model.lane1.getLength());
672 cp.setTitle("FLow Contour Graph");
673 model.getPlots().add(cp);
674 charts.setCell(cp.getContentPane(), 0, 1);
675
676 cp =
677 new AccelerationContourPlot("AccelerationPlot " + model.carFollowingModelCars.getLongName(), model
678 .getMinimumDistance(), model.lane1.getLength());
679 cp.setTitle("Acceleration Contour Graph");
680 model.getPlots().add(cp);
681 charts.setCell(cp.getContentPane(), 1, 1);
682
683 TrajectoryPlot trajectoryPlot =
684 new TrajectoryPlot("TrajectoryPlot " + model.carFollowingModelCars.getLongName(),
685 new DoubleScalar.Rel<TimeUnit>(0.5, TimeUnit.SECOND), model.getMinimumDistance(), model.lane1.getLength());
686 trajectoryPlot.setTitle("Trajectories");
687 charts.setCell(trajectoryPlot.getContentPane(), 2, 0);
688 model.getTrajectoryPlots().add(trajectoryPlot);
689
690 this.separateFrame.add(charts);
691 this.separateFrame.setVisible(true);
692 this.separateFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
693 }
694
695 private void createCircularRoadFrame(RoadSimulationModel model)
696 {
697 if (this.separateFrame == null)
698 {
699 this.separateFrame = new JFrame("Statistics Plots");
700 this.separateFrame.setSize(800, 600);
701 }
702 else
703 {
704
705 this.separateFrame.setVisible(false);
706 this.separateFrame.dispose();
707
708 this.separateFrame = new JFrame("Statistics Plots");
709 this.separateFrame.setSize(800, 600);
710 }
711
712 TablePanel charts = new TablePanel(4, 3);
713 ContourPlot cp;
714
715 for (int laneIndex = 0; laneIndex <= 1; laneIndex++)
716 {
717 final String laneName = String.format(" lane %d", laneIndex + 1);
718 cp =
719 new DensityContourPlot("DensityPlot " + model.carFollowingModelCars.getLongName() + " lane " + laneIndex,
720 model.getMinimumDistance(), model.lanes[laneIndex].getLength());
721 cp.setTitle("Density Contour Graph");
722
723 model.getPlots().get(laneIndex).add(cp);
724 charts.setCell(cp.getContentPane(), 2 * laneIndex, 0);
725
726 cp =
727 new SpeedContourPlot("SpeedPlot " + model.carFollowingModelCars.getLongName() + laneName, model
728 .getMinimumDistance(), model.lanes[laneIndex].getLength());
729 cp.setTitle("Speed Contour Graph");
730 model.getPlots().get(laneIndex).add(cp);
731 charts.setCell(cp.getContentPane(), 2 * laneIndex + 1, 0);
732
733 cp =
734 new FlowContourPlot("FlowPlot " + model.carFollowingModelCars.getLongName() + laneName, model
735 .getMinimumDistance(), model.lanes[laneIndex].getLength());
736 cp.setTitle("FLow Contour Graph");
737 model.getPlots().get(laneIndex).add(cp);
738 charts.setCell(cp.getContentPane(), 2 * laneIndex, 1);
739
740 cp =
741 new AccelerationContourPlot("AccelerationPlot " + model.carFollowingModelCars.getLongName() + laneName,
742 model.getMinimumDistance(), model.lanes[laneIndex].getLength());
743 cp.setTitle("Acceleration Contour Graph");
744 model.getPlots().get(laneIndex).add(cp);
745 charts.setCell(cp.getContentPane(), 2 * laneIndex + 1, 1);
746
747 TrajectoryPlot trajectoryPlot =
748 new TrajectoryPlot("TrajectoryPlot " + model.carFollowingModelCars.getLongName() + laneName,
749 new DoubleScalar.Rel<TimeUnit>(0.5, TimeUnit.SECOND), model.getMinimumDistance(), model.lanes[laneIndex]
750 .getLength());
751 trajectoryPlot.setTitle("Trajectories");
752 charts.setCell(trajectoryPlot.getContentPane(), 1 + laneIndex, 2);
753 model.getPlots().get(laneIndex).add(trajectoryPlot);
754 }
755 this.separateFrame.add(charts);
756 this.separateFrame.setVisible(true);
757 this.separateFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
758 }
759
760 private void createDirectLaneFrame(StraightModel model)
761 {
762 if (this.separateFrame == null)
763 {
764 this.separateFrame = new JFrame("Statistics Plots");
765 this.separateFrame.setSize(800, 600);
766 }
767 else
768 {
769
770 this.separateFrame.setVisible(false);
771 this.separateFrame.dispose();
772
773 this.separateFrame = new JFrame("Statistics Plots");
774 this.separateFrame.setSize(800, 600);
775 }
776
777 TablePanel charts = new TablePanel(2, 2);
778
779
780 ContourPlot cp;
781
782 cp = new DensityContourPlot("DensityPlot", model.getMinimumDistance(), model.getMaximumDistance());
783 cp.setTitle("Density Contour Graph");
784
785 model.getPlots().add(cp);
786 charts.setCell(cp.getContentPane(), 0, 0);
787
788 cp = new SpeedContourPlot("SpeedPlot", model.getMinimumDistance(), model.getMaximumDistance());
789 cp.setTitle("Speed Contour Graph");
790 model.getPlots().add(cp);
791 charts.setCell(cp.getContentPane(), 1, 0);
792
793 cp = new FlowContourPlot("FlowPlot", model.getMinimumDistance(), model.getMaximumDistance());
794 cp.setTitle("FLow Contour Graph");
795 model.getPlots().add(cp);
796 charts.setCell(cp.getContentPane(), 0, 1);
797
798 cp = new AccelerationContourPlot("AccelerationPlot", model.getMinimumDistance(), model.getMaximumDistance());
799 cp.setTitle("Acceleration Contour Graph");
800 model.getPlots().add(cp);
801 charts.setCell(cp.getContentPane(), 1, 1);
802 this.separateFrame.setVisible(true);
803 this.separateFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
804 }
805
806 public void init() throws RemoteException, SimRuntimeException
807 {
808
809 settingPanel_conf();
810 this.f.add(this.settingPanel, BorderLayout.WEST);
811 this.simPanel.setPreferredSize(new Dimension(400, 800));
812 this.f.add(this.simPanel, BorderLayout.CENTER);
813 this.statPanel.setLayout(new GridLayout(2, 2, 3, 3));
814 this.statPanel.setPreferredSize(new Dimension(500, 800));
815
816 this.f.add(this.statPanel, BorderLayout.EAST);
817
818 this.f.setSize(1000, 800);
819 this.f.setVisible(true);
820 this.f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
821 }
822
823 public static void main(String[] args) throws RemoteException, SimRuntimeException
824 {
825
826 SwingUtilities.invokeLater(new Runnable()
827 {
828 @Override
829 public void run()
830 {
831 try
832 {
833 new newGUI().init();
834 }
835 catch (RemoteException | SimRuntimeException exception)
836 {
837 exception.printStackTrace();
838 }
839 }
840 });
841 }
842 }