This repository has been archived by the owner on Jul 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLegend.java
62 lines (49 loc) · 1.78 KB
/
Legend.java
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
import java.awt.*;
/**
* A box describing what each of the color of dots mean.
*/
class Legend {
private int x, y, markerSize;
private Font fondLegend = new Font("Arial", Font.PLAIN, 14);
Legend(int x, int y) {
this.x = x;
this.y = y;
}
void setMarkerSize(int markerSize) {
this.markerSize = markerSize;
}
void draw(Graphics2D g) {
final int WIDTH = 200, HEIGHT = 320;
//white background with black box
g.setColor(Color.white);
g.fillRect(x, y, WIDTH, HEIGHT);
g.setColor(Color.black);
g.drawRect(x, y, WIDTH, HEIGHT);
g.setFont(fondLegend);
// draw carbon legend
Carbon[] carbons = Carbon.values(); // returns the constants of this enum type, in the order they're declared
Carbon currCarb;
Shape shapeToDraw;
int theY;
for (int i = 0; i < carbons.length; i++) {
currCarb = carbons[i];
theY = y + (i * 30) + 10;
shapeToDraw = currCarb.getShape(x + 10, theY, markerSize);
g.setColor(Color.black);
g.draw(shapeToDraw);
g.drawString(currCarb.description, x + 20 + markerSize, theY + (markerSize / 2) + 4);
}
// draw groupset legend
Groupset[] groupsets = Groupset.getRanked();
final int barHeight = 25, barWidth = 40;
Groupset currGroup;
for (int i = 0; i < groupsets.length; i++) {
currGroup = groupsets[i];
g.setColor(currGroup.getColor());
theY = y + 100 + i * (barHeight + 2);
g.fillRect(x + 10, theY, barWidth, barHeight);
g.setColor(Color.black);
g.drawString(currGroup.name, x + barWidth + 20, theY + barHeight / 2 + 3);
}
}
}