-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCraftsMovementDisplay.java
More file actions
72 lines (57 loc) · 1.72 KB
/
CraftsMovementDisplay.java
File metadata and controls
72 lines (57 loc) · 1.72 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
package cas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.util.List;;
import java.lang.Math;
import java.awt.BasicStroke;
import Ertsys.*;
public class CraftsMovementDisplay extends JPanel {
private List<Aircraft> _aircrafts;
private static final double scale = 1.4;
public CraftsMovementDisplay(List<Aircraft> aircrafts)
{
_aircrafts = aircrafts;
setLayout(null);
}
public void updateAircrafts(List<Aircraft> aircrafts)
{
_aircrafts = aircrafts;
this.repaint();
}
public void paintComponent(Graphics g)
{
setBackground(Color.black);
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
for (Aircraft aircraft : _aircrafts)
{
//Set conflict colour
if (aircraft.conflictStatus == ConflictStatus.Conflicted)
g2d.setColor(Color.red);
else if(aircraft.conflictStatus == ConflictStatus.PotentialFutureConflict)
g2d.setColor(Color.yellow);
else
g2d.setColor(Color.green);
int x = (int)(aircraft.position.x/scale);
int y = (int)(aircraft.position.y/scale);
//Draw aircraft
g2d.setStroke(new BasicStroke(1.5f));
g2d.drawLine(x, y, x, y);
//Draw id
String id = aircraft.identification.toString();
String sId = id.substring(4, id.length()-1).replaceAll(",", "");
g2d.drawString(sId, x-1, y-1);
//Draw boundary
g2d.setStroke(new BasicStroke(1f));
int cx = (int)(x - (aircraft.boundaryRadius/2.0));
int cy = (int)(y - (aircraft.boundaryRadius/2.0));
g2d.drawOval(cx, cy, (int)aircraft.boundaryRadius, (int)aircraft.boundaryRadius);
}
}
}