-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockEvent.java
More file actions
59 lines (51 loc) · 2.01 KB
/
Copy pathClockEvent.java
File metadata and controls
59 lines (51 loc) · 2.01 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
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.JPanel;
public class ClockEvent extends JPanel {
protected String label;
protected int process;
protected ClockEvent nextPtr = null; // next event on process
protected ClockEvent prevPtr = null; // previous event on process
protected ClockEvent toPtr =
null; // event receiving message from this event
protected ClockEvent fromPtr =
null; // event that sent a message to this event
protected int lamportTime = 0;
protected ArrayList<Integer> vectorTime;
protected boolean drawOutline = false;
public ClockEvent(int labelInt, int processNum, int totalProcesses) {
this.label = Utils.convertNumberToLabel(labelInt);
this.process = processNum;
this.vectorTime =
new ArrayList<Integer>(Collections.nCopies(totalProcesses, 0));
}
public void setDrawOutline(boolean drawOutline) {
this.drawOutline = drawOutline;
}
public boolean getDrawOutline() { return drawOutline; }
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
int x = (getWidth() - VisualArea.DIAMETER) / 2;
int y = (getHeight() - VisualArea.DIAMETER) / 2;
g.fillOval(x, y, VisualArea.DIAMETER, VisualArea.DIAMETER);
if (drawOutline) {
int outlineDistance = VisualArea.DIAMETER / 20;
g.setColor(Color.RED);
Graphics2D g2 = (Graphics2D)g;
g2.setStroke(new BasicStroke(VisualArea.DIAMETER / 8));
g2.drawOval(x - outlineDistance, y - outlineDistance,
VisualArea.DIAMETER + 2 * outlineDistance,
VisualArea.DIAMETER + 2 * outlineDistance);
}
}
public String toString() {
String retString = "(" + label;
retString += ":" + String.valueOf(lamportTime);
return retString + ")";
}
}