-
Notifications
You must be signed in to change notification settings - Fork 0
/
EdgeComponent.java
50 lines (41 loc) · 1.4 KB
/
EdgeComponent.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
package demo2;
import javax.swing.*;
import java.awt.*;
public class EdgeComponent extends JComponent {
private Color color = Color.WHITE;
private boolean free = true;
public EdgeComponent(int x, int y, int width, int height) {
super();
setLocation(x, y);
setSize(width, height);
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public boolean isFree() {
return free;
}
public void setFree(boolean free) {
this.free = free;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
boolean horizontal = getWidth() > getHeight();
int midValue = (horizontal ? getHeight() : getWidth()) / 2;
int alphaStep = free ? 255 / midValue : 0;
for (int i = 0; i < midValue; i++) {
g.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 255 - alphaStep * i));
if (horizontal) {
g.drawLine(0, midValue + i, getWidth(), midValue + i);
g.drawLine(0, midValue - i, getWidth(), midValue - i);
} else {
g.drawLine(midValue + i, 0, midValue + i, getHeight());
g.drawLine(midValue - i, 0, midValue - i, getHeight());
}
}
}
}