MdlEvent.java
12.7 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
543
544
545
546
547
548
549
550
551
552
553
package org.emercit.model;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.ImageIcon;
import java.awt.Color;
import java.awt.Image;
public class MdlEvent {
private long id;
private int id_agk;
private String river;
private String datetime;
private String value;
private int id_status; // 0-norm, 1-nj-2, oj;
private boolean repair; // true -repair; false- no repair
private boolean opendoor; // true - open; false-close
private boolean veracirty; // veracity -true, no veracity -false;
private String imgstatus;
private String imgrepair;
private String imgdoor;
private String imgveracity;
private String titleagk;
private String titlestatus;
private String titlerepair;
private String titleopendoor;
private String titleveracity;
private String titlestatusconfirm;
private ImageIcon IconStatusSmall;
private ImageIcon IconRepairSmall;
private ImageIcon IconOpenDoorSmall;
private ImageIcon IconVeracitySmall;
private ImageIcon IconStatusLarge;
private ImageIcon IconRepairLarge;
private ImageIcon IconOpenDoorLarge;
private ImageIcon IconVeracityLarge;
private Color ColorStatus;
private Color ColorRepair;
private Color ColorOpenDoor;
private Color ColorVeracity;
private Color ColorLogPanel;
private int countsecanimate = 0;
private int countsecsound = 0;
private boolean sound = false; // false -no sound
private boolean siren = false; // false- no siren
public MdlEvent(long id, int id_agk, String river, String datetime,
String value, int id_status, boolean repair, boolean opendoor,
boolean veracity) {
this.setId(id);
this.setIdAgk(id_agk);
this.setRiver(river);
this.setDateTime(datetime);
this.setValue(value);
this.setIdStatus(id_status);
this.setRepair(repair);
this.setOpenDoor(opendoor);
this.setVeracity(veracity);
if (this.repair || this.opendoor || !this.veracirty) {
SetStrategy(0);
}
if (this.id_status == 0)
SetStrategy(0);
else if (this.id_status == 1)
SetStrategy(1);
else
SetStrategy(2);
}
public Color getColorLogPanel() {
return this.ColorLogPanel;
}
private void setId(long id) {
this.id = id;
}
public long getId() {
return id;
}
public int getCoundAnimate() {
return this.countsecanimate;
}
public int getCountSound() {
return this.countsecsound;
}
public boolean getSound() {
return this.sound;
}
public boolean getSiren() {
return this.siren;
}
public void setCountAnimate(int countanimate) {
this.countsecanimate = countanimate;
}
public void setCountSound(int countsecsound) {
this.countsecsound = countsecsound;
}
public void setSiren(boolean siren) {
this.siren = siren;
}
private void setSound(boolean sound) {
this.sound = sound;
}
private void setIdAgk(int id_agk) {
this.id_agk = id_agk;
this.titleagk = "АГК-" + id_agk;
}
public String getTitleAgk() {
return titleagk;
}
public int getIdAgk() {
return id_agk;
}
private void setRiver(String river) {
this.river = river;
}
public String getTitleRiver() {
return river;
}
public ImageIcon getIconRiver() {
ImageIcon icon = new ImageIcon(getClass().getResource("/river.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
return icon = new ImageIcon(newimg);
}
public ImageIcon getIconRiverSmall() {
ImageIcon icon = new ImageIcon(getClass().getResource("/river.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(15, 15,
java.awt.Image.SCALE_SMOOTH);
return icon = new ImageIcon(newimg);
}
public void setDateTime(String datetime) {
this.datetime = datetime;
}
public String getDateTime() {
return datetime;
}
public ImageIcon getIconDateTime() {
ImageIcon icon = new ImageIcon(getClass().getResource("/clock.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
return icon = new ImageIcon(newimg);
}
public ImageIcon getIconDateTimeSmall() {
ImageIcon icon = new ImageIcon(getClass().getResource("/clock.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(15, 15,
java.awt.Image.SCALE_SMOOTH);
return icon = new ImageIcon(newimg);
}
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return value;
}
private void setIdStatus(int id_status) {
this.id_status = id_status;
if (id_status == 0) {
this.titlestatus = "В НОРМЕ";
this.titlestatusconfirm = "Уровень реки в норме";
this.imgstatus = "green.png";
ImageIcon icon = new ImageIcon(getClass().getResource("/green.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconStatusLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconStatusSmall = icon;
this.ColorStatus = Color.BLUE;
this.ColorLogPanel = new Color(102, 255, 204);
} else if (id_status == 1) {
this.titlestatus = "НЯ";
this.titlestatusconfirm = "Неблагоприятное явление";
this.imgstatus = "yellow.png";
ImageIcon icon = new ImageIcon(getClass()
.getResource("/yellow.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconStatusLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconStatusSmall = icon;
this.ColorStatus = Color.RED;
this.ColorLogPanel = new Color(255, 255, 153);
} else {
this.titlestatus = "ОЯ";
this.titlestatusconfirm = "Опасное явление";
this.imgstatus = "red.png";
ImageIcon icon = new ImageIcon(getClass().getResource("/red.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconStatusLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconStatusSmall = icon;
this.ColorStatus = Color.RED;
this.ColorLogPanel = new Color(255, 153, 204);
}
}
public String getTitleStatus() {
return titlestatus;
}
public String getTitleStatusForConfirm() {
return "БСВ:" + String.valueOf(this.value) + " м. "
+ this.titlestatusconfirm;
}
public String getStrImgStatus() {
return imgstatus;
}
public int getIdStatus() {
return id_status;
}
public ImageIcon getIconStatusSmall() {
return this.IconStatusSmall;
}
public ImageIcon getIconStatusLarge() {
return this.IconStatusLarge;
}
private void setRepair(boolean repair) {
this.repair = repair;
if (repair) {
this.titlerepair = "Станция неисправна";
this.imgrepair = "repair.png";
ImageIcon icon = new ImageIcon(getClass()
.getResource("/repair.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconRepairLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconRepairSmall = icon;
this.ColorRepair = Color.RED;
} else {
this.titlerepair = "Станция исправна";
this.imgrepair = "good.png";
ImageIcon icon = new ImageIcon(getClass().getResource("/good.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconRepairLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconRepairSmall = icon;
this.ColorRepair = Color.BLUE;
}
}
public boolean getRepair() {
return repair;
}
public String getTitleRepair() {
return titlerepair;
}
public String getImgRepair() {
return imgrepair;
}
public ImageIcon getIconRepairSmall() {
return this.IconRepairSmall;
}
public ImageIcon getIconRepairLarge() {
return this.IconRepairLarge;
}
private void setOpenDoor(boolean opendoor) {
this.opendoor = opendoor;
if (opendoor) {
this.titleopendoor = "Контейнер открыт";
this.imgdoor = "opendoor.png";
ImageIcon icon = new ImageIcon(getClass().getResource(
"/opendoor.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconOpenDoorLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconOpenDoorSmall = icon;
this.ColorOpenDoor = Color.RED;
} else {
this.titleopendoor = "Контейнер закрыт";
this.imgdoor = "closedoor.png";
ImageIcon icon = new ImageIcon(getClass().getResource(
"/closedoor.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconOpenDoorLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconOpenDoorSmall = icon;
this.ColorOpenDoor = Color.BLUE;
}
}
public boolean getOpenDorr() {
return opendoor;
}
public String getTitleOpenDorr() {
return titleopendoor;
}
public String getImgOpenDoor() {
return imgdoor;
}
public ImageIcon getIconOpenDoorLarge() {
return this.IconOpenDoorLarge;
}
public ImageIcon getIconOpenDoorSmall() {
return this.IconOpenDoorSmall;
}
public void setVeracity(boolean veracity) {
this.veracirty = veracity;
if (veracity) {
this.titleveracity = "Данные достоверны";
this.imgveracity = "varacitytrue.png";
ImageIcon icon = new ImageIcon(getClass().getResource(
"/veracitytrue.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconVeracityLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconVeracitySmall = icon;
this.ColorVeracity = Color.BLUE;
} else {
this.titleveracity = "Данные недостоверны";
this.imgveracity = "varacityfalse.png";
ImageIcon icon = new ImageIcon(getClass().getResource(
"/veracityfalse.png"));
Image img = icon.getImage();
Image newimg = img.getScaledInstance(30, 30,
java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconVeracityLarge = icon;
img = icon.getImage();
newimg = img.getScaledInstance(15, 15, java.awt.Image.SCALE_SMOOTH);
icon = new ImageIcon(newimg);
this.IconVeracitySmall = icon;
this.ColorVeracity = Color.RED;
}
}
public String getTitleVeracity() {
return this.titleveracity;
}
public boolean getVeracity() {
return this.veracirty;
}
public ImageIcon getIconVeracityLarge() {
return this.IconVeracityLarge;
}
public ImageIcon getIconVeracitySmall() {
return this.IconVeracitySmall;
}
public Color getColorStatus() {
return this.ColorStatus;
}
public Color getColorRepair() {
return this.ColorRepair;
}
public Color getColorOpenDoor() {
return this.ColorOpenDoor;
}
public Color getColorVeracity() {
return this.ColorVeracity;
}
public boolean IsOld() {
boolean old = false;
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
Date dt1 = new Date();
Date dt2 = new Date();
try {
dt1 = dateFormat.parse(datetime);
// add -24
Calendar cal2 = Calendar.getInstance();
cal2.add(Calendar.MINUTE, -1);
dt2 = cal2.getTime();
if (dt1.before(dt2)) {
old = true;
}
} catch (Exception e) {
}
} catch (Exception e) {
}
return old;
}
// Устанавливаем стратегию оповещения для события
// 0 -animate 30+ sound ( repair, open door and status river is norm)
// 1- animate 20 + sound 25+siren // nj
// 2- animate 10 + sound 10+ siren // oj
private void SetStrategy(int type) {
switch (type) {
case 0:
this.setCountAnimate(30);
this.setSound(true);
break;
case 1:
this.setCountAnimate(20);
this.setCountSound(25);
this.setSound(true);
this.setSiren(true);
break;
default:
this.setCountAnimate(10);
this.setCountSound(10);
this.setSound(true);
this.setSiren(true);
}
}
}