source: proiecte/ptvs/src/vnsim/gui/Statistics.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 8.0 KB
Line 
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 ***********************************************************************************/
6package vnsim.gui;
7
8import javax.swing.JLabel;
9import javax.swing.JPanel;
10import javax.swing.JScrollPane;
11import javax.swing.JTextArea;
12import javax.swing.Spring;
13import javax.swing.SpringLayout;
14
15import vnsim.map.object.Globals;
16
17public class Statistics extends JPanel {
18
19        private SpringLayout layout;
20
21        private JLabel carsNoL, realTimeL, simTimeL, step, nrEvents, semTimeL,
22                        selection;
23
24        public JLabel dse, dsw, dne, dnw;
25
26        public JLabel cycle, phase1, phase2, phase3, phase4;
27
28        private JScrollPane details;
29
30        private JTextArea text;
31
32        private static final long serialVersionUID = 1L;
33
34        public Statistics(int w, int h) {
35                super();
36                layout = new SpringLayout();
37                realTimeL = new JLabel("Real time: ");
38                simTimeL = new JLabel("Sim. time: ");
39                semTimeL = new JLabel("");
40                selection = new JLabel("");
41                carsNoL = new JLabel("Cars no: ");
42                step = new JLabel("Step: ");
43                nrEvents = new JLabel("Events pending: ");
44                text = new JTextArea("No info yet!");
45                text.setEditable(false);
46                details = new JScrollPane(text);
47
48                dne = new JLabel();
49                dnw = new JLabel();
50                dse = new JLabel();
51                dsw = new JLabel();
52
53                cycle = new JLabel();
54                phase1 = new JLabel();
55                phase2 = new JLabel();
56                phase3 = new JLabel();
57                phase4 = new JLabel();
58
59                this.setSize(w - 1, h - 1);
60                this.setLayout(layout);
61                // adds the components to the frame
62                realTimeL.setSize(w, h / 8 - 1);
63                carsNoL.setSize(w, h / 8 - 1);
64                simTimeL.setSize(w, h / 8 - 1);
65                semTimeL.setSize(w, h / 8 - 1);
66                selection.setSize(w, h / 8 - 1);
67                step.setSize(w, h / 8 - 1);
68                nrEvents.setSize(w, h / 8 - 1);
69                details.setSize(w, h / 2 - 1);
70                details.setAutoscrolls(true);
71
72                dse.setSize(w, h / 8 - 1);
73                dsw.setSize(w, h / 8 - 1);
74                dne.setSize(w, h / 8 - 1);
75                dnw.setSize(w, h / 8 - 1);
76
77                cycle.setSize(w, h / 8 - 1);
78                phase1.setSize(w, h / 8 - 1);
79                phase2.setSize(w, h / 8 - 1);
80                phase3.setSize(w, h / 8 - 1);
81                phase4.setSize(w, h / 8 - 1);
82
83                SpringLayout.Constraints c1 = layout.getConstraints(realTimeL);
84                SpringLayout.Constraints c2 = layout.getConstraints(simTimeL);
85                SpringLayout.Constraints c3 = layout.getConstraints(step);
86                SpringLayout.Constraints c4 = layout.getConstraints(nrEvents);
87                SpringLayout.Constraints c5 = layout.getConstraints(details);
88                SpringLayout.Constraints c6 = layout.getConstraints(carsNoL);
89                SpringLayout.Constraints c11 = layout.getConstraints(semTimeL);
90                SpringLayout.Constraints c12 = layout.getConstraints(selection);
91
92                SpringLayout.Constraints c7 = layout.getConstraints(dse);
93                SpringLayout.Constraints c8 = layout.getConstraints(dsw);
94                SpringLayout.Constraints c9 = layout.getConstraints(dne);
95                SpringLayout.Constraints c10 = layout.getConstraints(dnw);
96
97                SpringLayout.Constraints c13 = layout.getConstraints(cycle);
98                SpringLayout.Constraints c14 = layout.getConstraints(phase1);
99                SpringLayout.Constraints c15 = layout.getConstraints(phase2);
100                SpringLayout.Constraints c16 = layout.getConstraints(phase3);
101                SpringLayout.Constraints c17 = layout.getConstraints(phase4);
102
103                c1.setX(Spring.constant(1));
104                c1.setY(Spring.constant(1));
105                // c3.setWidth(Spring.constant((screenSize.width * 6) / 7));
106                // c4.setHeight(Spring.constant((screenSize.height * 6) / 7));
107
108                c2.setX(Spring.constant(1));
109                c2.setY(Spring.constant(1 + h / 32));
110
111                c3.setX(Spring.constant(1));
112                c3.setY(Spring.constant(1 + 2 * h / 32));
113
114                c4.setX(Spring.constant(1));
115                c4.setY(Spring.constant(1 + 3 * h / 32));
116
117                c6.setX(Spring.constant(1));
118                c6.setY(Spring.constant(1 + 4 * h / 32));
119
120                c12.setX(Spring.constant(1));
121                c12.setY(Spring.constant(1 + 6 * h / 32));
122
123                c7.setX(Spring.constant(1));
124                c7.setY(Spring.constant(1 + 7 * h / 32));
125
126                c8.setX(Spring.constant(1));
127                c8.setY(Spring.constant(1 + 8 * h / 32));
128
129                c9.setX(Spring.constant(1));
130                c9.setY(Spring.constant(1 + 9 * h / 32));
131
132                c10.setX(Spring.constant(1));
133                c10.setY(Spring.constant(1 + 10 * h / 32));
134
135                c11.setX(Spring.constant(1));
136                c11.setY(Spring.constant(1 + 11 * h / 32));
137
138                c13.setX(Spring.constant(1));
139                c13.setY(Spring.constant(1 + 13 * h / 32));
140
141                c14.setX(Spring.constant(1));
142                c14.setY(Spring.constant(1 + 14 * h / 32));
143
144                c15.setX(Spring.constant(1));
145                c15.setY(Spring.constant(1 + 15 * h / 32));
146
147                c16.setX(Spring.constant(1));
148                c16.setY(Spring.constant(1 + 16 * h / 32));
149
150                c17.setX(Spring.constant(1));
151                c17.setY(Spring.constant(1 + 17 * h / 32));
152
153                c5.setX(Spring.constant(1));
154                c5.setY(Spring.constant(1 + 20 * h / 32));
155                c5.setWidth(Spring.constant(w));
156                c5.setHeight(Spring.constant(10 * h / 32));
157
158                this.add(carsNoL);
159                this.add(realTimeL);
160                this.add(simTimeL);
161                this.add(selection);
162                this.add(step);
163                this.add(semTimeL);
164                this.add(nrEvents);
165                this.add(details);
166
167                this.add(dse);
168                this.add(dsw);
169                this.add(dne);
170                this.add(dnw);
171
172                this.add(cycle);
173                this.add(phase1);
174                this.add(phase2);
175                this.add(phase3);
176                this.add(phase4);
177
178                this.setVisible(true);
179
180        }
181
182        public void resetLabels() {
183                Globals.demo.st.dsw.setText("");
184                Globals.demo.st.dnw.setText("");
185                Globals.demo.st.dse.setText("");
186                Globals.demo.st.dne.setText("");
187                Globals.demo.st.cycle.setText("");
188                Globals.demo.st.phase1.setText("");
189                Globals.demo.st.phase2.setText("");
190                Globals.demo.st.phase3.setText("");
191                Globals.demo.st.phase4.setText("");
192
193                Globals.demo.st.repaint();
194
195        }
196
197        public void setCurrentTime(long l) {
198                long ms = l % 1000;
199                l /= 1000;
200                long sec = l % 60;
201                l /= 60;
202                long min = l % 60;
203                l /= 60;
204                this.realTimeL.setText("Real time: " + l + ":" + min + ":" + sec + "."
205                                + ms);
206                this.repaint();
207        }
208
209        public void setSelection(String s) {
210                this.selection.setText(s);
211                this.repaint();
212        }
213
214        public void setSemTime(int color, int remaining) {
215                // long ms = l % 1000;
216                // l /= 1000;
217                // long sec = l % 60;
218                // l /= 60;
219                // long min = l % 60;
220                // l /= 60;
221                // this.semTimeL.setText("Lights time: " +l+":"+min+":"+ sec+"."+ ms);
222                if (color == -1) {
223                        this.semTimeL.setText(" ");
224                } else if (color == Globals.GREEN)
225                        this.semTimeL.setText("Green: " + remaining);
226                else if (remaining < 0)
227                        this.semTimeL.setText("Red: +- " + (-remaining));
228                else
229                        this.semTimeL.setText("Red: " + remaining);
230                this.repaint();
231        }
232
233        public void setCount(long l) {
234                this.step.setText("Step: " + l);
235                this.repaint();
236        }
237
238        public void setSimulationTime(float f) {
239                long time = (long) f;
240                long ms = time % 1000;
241                time /= 1000;
242                long sec = time % 60;
243                time /= 60;
244                long min = time % 60;
245                time /= 60;
246
247                this.simTimeL.setText("Sim. time: " + time + ":" + min + ":" + sec
248                                + "." + ms);
249                this.repaint();
250        }
251
252        public void addInfo(String s) {
253                this.text.append("\n" + s);
254                this.repaint();
255        }
256
257        public void clearInfo() {
258                this.text.setText("");
259                this.repaint();
260        }
261
262        public void setNrEvents(int n) {
263                this.nrEvents.setText("Events pending: " + n);
264                this.repaint();
265        }
266
267        public void setDemand(String seg, int n, int n2, boolean TL) {
268
269                if (TL) {
270                        if (seg.equals("sw"))
271                                this.dsw.setText("SW: " + n + "/" + n2 + " veh/h");
272                        if (seg.equals("se"))
273                                this.dse.setText("SE: " + n + "/" + n2 + " veh/h");
274                        if (seg.equals("ne"))
275                                this.dne.setText("NE: " + n + "/" + n2 + " veh/h");
276                        if (seg.equals("nw"))
277                                this.dnw.setText("NW: " + n + "/" + n2 + " veh/h");
278                } else {
279                        if (seg.equals("sw")) {
280                                this.dsw.setText("Queue size: " + n + " m");
281                        }
282                        if (seg.equals("ne"))
283                                this.dne.setText("Speed: " + n + " km/h");
284                        if (seg.equals("nw"))
285                                this.dnw.setText("Suggested: " + n + " km/h");
286                }
287
288                this.repaint();
289        }
290
291        public void setCarsNo(int n) {
292                this.carsNoL.setText("Cars no: " + n);
293                this.repaint();
294        }
295
296}
Note: See TracBrowser for help on using the repository browser.