-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConsole.java
More file actions
542 lines (476 loc) · 18.2 KB
/
Console.java
File metadata and controls
542 lines (476 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
package com.masim.ui;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JToggleButton;
import javax.swing.table.DefaultTableModel;
import com.masim.core.CooperationStrategy;
import com.masim.utils.SimulationFramework;
import com.masim.utils.Source;
import com.masim.utils.DispersionEngine;
public class Console extends JFrame {
// private JTextArea txt= new JTextArea();
public static Console current;
public javax.swing.JTabbedPane tabPan;
public javax.swing.JPanel gridPanel;
public javax.swing.JPanel plotsPanel;
public javax.swing.JTextArea frmlogs;
public javax.swing.JTable tabshow;
public DefaultTableModel dtm;
public JPanel textAreaPanle;
public JSplitPane controlJsplitPanel;
// Variables declaration - do not modify
public javax.swing.JButton jButton1;
public javax.swing.JButton jButton2;
public javax.swing.JButton jButton3;
public javax.swing.JCheckBox jCheckBox1;
public javax.swing.JCheckBox jCheckBox2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSplitPane jSplitPane1;
public javax.swing.JTextArea txt;
private javax.swing.JToolBar jToolBar1;
public javax.swing.JToggleButton jToggleButton1;
private javax.swing.JToggleButton jToggleButton2;
public javax.swing.JButton btn_showEmissionSourcesStates;
public javax.swing.JCheckBox btn_useCumulatifPenalities;
// Variables declaration - do not modify
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenu jMenu4;
private javax.swing.JMenu jMenu5;
private javax.swing.JMenu modelMenu;
private javax.swing.JMenu dispersionMenu;
// private javax.swing.JMenu
private javax.swing.JMenuBar jMenuBar1;
public javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem10;
private javax.swing.JMenuItem jMenuItem11;
public javax.swing.JMenuItem jMenuItem2;
public javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
public javax.swing.JMenuItem jMenuItem5;
public javax.swing.JMenuItem jMenuItem6;
public javax.swing.JMenuItem addSourceMenuItem;
private javax.swing.JMenuItem jMenuItem8;
public javax.swing.JMenuItem jMenuItem9;
public javax.swing.JMenuItem buildModelMenuItem;
public javax.swing.JMenuItem buildO3ModelMenuItem;
public javax.swing.JMenuItem buildSOXModelMenuItem;
public javax.swing.JMenuItem buildNOXModelMenuItem;
public javax.swing.JMenuItem buildCOXModelMenuItem;
public javax.swing.JMenuItem buildAQModelMenuItem;
public javax.swing.JMenuItem showClimaticParams;
public JMenuItem showDispersionWindowsMenuItem;
public JMenuItem showPollutionParams;
public JMenuItem testModelPM10;
public JMenuItem configureDATA_PATH;
private javax.swing.JPopupMenu.Separator jSeparator1;
public JMenu confguration;
public JMenuItem confitgurationITM;
public JMenu aboutJM;
public JMenuItem aboutMASAP;
public JMenu cooperationStrategiesJM;
public JMenuItem defineCooperationStrategiesJMI;
public JMenuItem computeRMSQFORALLMODEL;
public JMenuItem selectAirQualityGoal;
// End of variables declaration
// End of variables declaration
public Console() throws HeadlessException {
this.initComponents();
}
private void initComponents() {
tabPan= new JTabbedPane();
gridPanel= new JPanel();
jToolBar1 = new javax.swing.JToolBar();
jToggleButton1 = new javax.swing.JToggleButton();
jToggleButton2 = new javax.swing.JToggleButton();
jSplitPane1 = new javax.swing.JSplitPane();
jScrollPane1 = new javax.swing.JScrollPane();
txt = new javax.swing.JTextArea();
frmlogs = new javax.swing.JTextArea();
jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jCheckBox1 = new javax.swing.JCheckBox();
jCheckBox2 = new javax.swing.JCheckBox();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem6 = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
jMenu2 = new javax.swing.JMenu();
jMenuItem3 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem5 = new javax.swing.JMenuItem();
jMenu4 = new javax.swing.JMenu();
jMenuItem8 = new javax.swing.JMenuItem();
jMenuItem9 = new javax.swing.JMenuItem();
jMenu5 = new javax.swing.JMenu();
jMenuItem10 = new javax.swing.JMenuItem();
jMenuItem11 = new javax.swing.JMenuItem();
jMenu3 = new javax.swing.JMenu();
addSourceMenuItem = new javax.swing.JMenuItem();
modelMenu = new javax.swing.JMenu();
showPollutionParams = new JMenuItem();
dispersionMenu = new JMenu();
showDispersionWindowsMenuItem = new JMenuItem();
testModelPM10 = new JMenuItem();
buildModelMenuItem = new javax.swing.JMenuItem();
aboutJM = new JMenu();
aboutMASAP = new JMenuItem("About MASAP");
cooperationStrategiesJM = new JMenu("Cooperation Strategies");
defineCooperationStrategiesJMI = new JMenuItem(
"Select a Cooperation Stratedy");
selectAirQualityGoal = new JMenuItem("Select Air Quality Index");
cooperationStrategiesJM.add(defineCooperationStrategiesJMI);
cooperationStrategiesJM.add(selectAirQualityGoal);
aboutJM.add(aboutMASAP);
buildO3ModelMenuItem = new javax.swing.JMenuItem(
"Build O3 Prediction Model");
buildSOXModelMenuItem = new javax.swing.JMenuItem(
"Build SOX Prediction Model");
buildNOXModelMenuItem = new javax.swing.JMenuItem(
"Build NOX Prediction Model");
buildCOXModelMenuItem = new javax.swing.JMenuItem(
"Build COX prediction Model");
modelMenu.add(buildO3ModelMenuItem);
modelMenu.add(buildSOXModelMenuItem);
modelMenu.add(buildNOXModelMenuItem);
modelMenu.add(buildCOXModelMenuItem);
buildAQModelMenuItem = new JMenuItem();
showClimaticParams = new javax.swing.JMenuItem();
configureDATA_PATH = new JMenuItem("Configure DATA_PATH and load Data");
confguration = new JMenu("Configuration");
confitgurationITM = new JMenuItem("Manage Configuration");
confguration.add(confitgurationITM);
computeRMSQFORALLMODEL = new JMenuItem(
"Compute performance of predictions models");
selectAirQualityGoal = new JMenuItem("Select Air Quality Index Goal");
tabshow = new JTable();
dtm = new DefaultTableModel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
modelMenu.setText("Models");
buildModelMenuItem.setText("Build PM10 prediction model");
buildAQModelMenuItem.setText("Build Air Quality prediction model");
testModelPM10.setText("Run Validation for prediction Models");
modelMenu.add(buildModelMenuItem);
modelMenu.add(buildAQModelMenuItem);
modelMenu.add(testModelPM10);
modelMenu.add(computeRMSQFORALLMODEL);
dispersionMenu.add(showDispersionWindowsMenuItem);
jMenu1.setText("File");
dispersionMenu.setText("Dispersion");
showDispersionWindowsMenuItem.setText("Show Dispersion window");
jMenuItem1.setText("Save");
jMenu1.add(jMenuItem1);
jMenuItem2.setText("Save As...");
jMenu1.add(jMenuItem2);
jMenuItem6.setText("Exit");
jMenu1.add(jMenuItem6);
jMenu1.add(jSeparator1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Simulation");
jMenuItem3.setText("Start Simulation");
jMenu2.add(jMenuItem3);
jMenuItem4.setText("Cancel Simulation");
jMenu2.add(jMenuItem4);
jMenuItem5.setText("Reaload System Parameters");
jMenu2.add(jMenuItem5);
jMenuBar1.add(jMenu2);
jMenu4.setText("Data");
jMenu4.add(configureDATA_PATH);
jMenuItem9.setText("Reload Environment Data");
jMenu4.add(jMenuItem9);
jMenuItem9.setText("Load Environment Data");
showClimaticParams
.setText("Plot climatic paramaters (Humidity, temperature and wind speed");
showPollutionParams
.setText("Plot pollution parameters (O3,SOx,COx,PM10 and NOx)");
jMenu4.add(showClimaticParams);
jMenu4.add(showPollutionParams);
jMenuItem8.setText("Export Simulation Result");
jMenu4.add(jMenuItem8);
jMenuBar1.add(jMenu4);
jMenuBar1.add(confguration);
jMenu5.setText("Profiling");
jMenuItem10.setText("Start Profiling");
jMenu5.add(jMenuItem10);
jMenuItem11.setText("Stop Profiling");
jMenu5.add(jMenuItem11);
jMenuBar1.add(jMenu5);
jMenu3.setText("Manage Emission Source");
addSourceMenuItem.setText("Add Point Source");
jMenu3.add(addSourceMenuItem);
jMenuBar1.add(cooperationStrategiesJM);
jMenuBar1.add(jMenu3);
jMenuBar1.add(modelMenu);
jMenuBar1.add(dispersionMenu);
aboutJM.setText("?");
jMenuBar1.add(aboutJM);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
gridPanel);
gridPanel.setLayout(layout);
layout.setHorizontalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 400,
Short.MAX_VALUE));
layout.setVerticalGroup(layout.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 279,
Short.MAX_VALUE));
jToolBar1.setRollover(true);
jToggleButton1.setText(" Select Predefined Simulation Scenario");
jToggleButton1.setFocusable(false);
jToggleButton1
.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jToggleButton1
.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToolBar1.add(jToggleButton1);
// -------
btn_showEmissionSourcesStates = new JButton();
btn_showEmissionSourcesStates.setText("Show Emission Sources Rate");
btn_showEmissionSourcesStates.setFocusable(false);
btn_showEmissionSourcesStates
.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btn_showEmissionSourcesStates
.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToolBar1.add(btn_showEmissionSourcesStates);
// btn_showEmissionSourcesStates
//btn_useCumulatifPenalities
btn_useCumulatifPenalities = new JCheckBox();
btn_useCumulatifPenalities.setText("Use cumulative penalty");
btn_useCumulatifPenalities.setFocusable(false);
btn_useCumulatifPenalities
.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
btn_useCumulatifPenalities
.setVerticalTextPosition(javax.swing.SwingConstants.CENTER);
jToolBar1.add(btn_useCumulatifPenalities);
//
jToggleButton2.setText("Clear Message LOG");
jToggleButton2.setFocusable(false);
jToggleButton2
.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jToggleButton2
.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton2ActionPerformed(evt);
}
});
jToolBar1.add(jToggleButton2);
controlJsplitPanel = new JSplitPane();
controlJsplitPanel.setOrientation(jSplitPane1.VERTICAL_SPLIT);
jSplitPane1.setDividerLocation(200);
jSplitPane1.setDividerSize(10);
txt.setColumns(20);
txt.setRows(5);
txt.setBackground(Color.white);
txt.setForeground(Color.BLACK);
txt.setAutoscrolls(true);
frmlogs.setAutoscrolls(true);
frmlogs.setMaximumSize(new Dimension(200, 200));
txt.setFont(new Font("Times", 1, 10));
frmlogs.setFont(new Font("Times", 1, 10));
jScrollPane1.setViewportView(tabshow);
jSplitPane1.setRightComponent(jScrollPane1);
jButton1.setText("Select Air Quality Index Goal.");
jButton1.setVisible(true);
jCheckBox1.setLabel("Use Gaussian Plume Dispersion Model");
jCheckBox1.setSelected(true);
jCheckBox2.setText("Use Penalities");
jCheckBox2.setVisible(true);
jCheckBox2.setSelected(true);
jButton2.setText("Stop Simulation and save Data");
jButton3.setText("Suspend Simulation");
jButton3.setVisible(false);
// frmlogs.setSize(200, 400);
frmlogs.setAutoscrolls(true);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout
.setHorizontalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addGroup(
jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jCheckBox2)
.addContainerGap())
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jCheckBox1)
.addContainerGap(
61,
Short.MAX_VALUE))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jButton1,
javax.swing.GroupLayout.PREFERRED_SIZE,
103,
Short.MAX_VALUE)
.addGap(93,
93,
93))
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addComponent(
jButton2)
.addContainerGap(
91,
Short.MAX_VALUE)))));
jPanel1Layout
.setVerticalGroup(jPanel1Layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
jPanel1Layout
.createSequentialGroup()
.addContainerGap()
.addComponent(jCheckBox1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jCheckBox2)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addContainerGap(141, Short.MAX_VALUE))
);
jSplitPane1.setLeftComponent(controlJsplitPanel);
JScrollPane panle = new JScrollPane();
panle.setAutoscrolls(true);
panle.setViewportView(frmlogs);
controlJsplitPanel.setBottomComponent(panle);
controlJsplitPanel.setTopComponent(jPanel1);
getContentPane().add(tabPan);
tabPan.addTab("Console", gridPanel);
tabPan.addTab("Plots", plotsPanel);
//getContentPane()
gridPanel.setLayout(layout);
layout.setHorizontalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE,
711, Short.MAX_VALUE)
.addGroup(
layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jSplitPane1,
javax.swing.GroupLayout.DEFAULT_SIZE,
691, Short.MAX_VALUE).addContainerGap()));
layout.setVerticalGroup(layout
.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout.createSequentialGroup()
.addComponent(jToolBar1,
javax.swing.GroupLayout.PREFERRED_SIZE,
25,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSplitPane1,
javax.swing.GroupLayout.DEFAULT_SIZE,
258, Short.MAX_VALUE).addContainerGap()));
//getContentPane().add(new DrawPanle());
pack();
}
public Console(GraphicsConfiguration gc) {
super(gc);
// TODO Auto-generated constructor stub
}
public Console(String title) throws HeadlessException {
super(title);
// TODO Auto-generated constructor stub
}
public Console(String title, GraphicsConfiguration gc) {
super(title, gc);
// TODO Auto-generated constructor stub
}
/**
* Put MSG into the text area of the Console.
*
* @param MSG
* the message to be displayed on the console
*/
public static void logMSG(String MSG) {
if (current == null) {
// current= new Console();
// current.setVisible(true);
// current.setTitle("MASAP (Multi-Agent Simulation of Air Pollution) v 0.1 beta");
// current.setState(MAXIMIZED_BOTH);
}
// current.txt.append("\n");
current.txtLog.append(MSG + "\n");
}
public static StringBuffer txtLog = new StringBuffer();
public static boolean first = true;
public static void logTab(Object[] obj) {
if (SimulationFramework.currentStrategy == CooperationStrategy.NEGOTIATION) {
if (first) {
Console.current.dtm.setColumnIdentifiers(new String[] {
"SimStep", "quotionC", "quotionCPM10", "quotionCCOx",
"quotionCSOx", "quotionCNOx", "PM10 Level",
"Cox Level", "NOX Level", "SOX level", "O3 level",
"Air Quality" });
Console.current.tabshow.setModel(Console.current.dtm);
first = false;
} else {
Console.current.dtm.addRow(obj);
}
} else {
if (first) {
Console.current.dtm.setColumnIdentifiers(new String[] {
"SimStep", "PM10", "SOX", "COX", "NOX", "O3", "AIRQ" });
Console.current.tabshow.setModel(Console.current.dtm);
first = false;
} else {
Console.current.dtm.addRow(obj);
}
}
}
public static void frmLogMSG(String MSG) {
if (current == null) {
current = new Console();
current.setVisible(true);
current.setTitle("MASAP (Multi-Agent Simulation of Air Pollution) v 0.1 beta");
current.setState(MAXIMIZED_BOTH);
}
current.frmlogs.append(MSG + "\n");
}
private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {
this.frmlogs.setText("");
}
}