-
Notifications
You must be signed in to change notification settings - Fork 0
/
BlobIcon.java
111 lines (90 loc) · 1.98 KB
/
BlobIcon.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
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
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JComponent;
public class BlobIcon extends JComponent
implements BlobListener, MouseListener, MouseMotionListener
{
private static final int R=30;
private Blob p;
private int x0;
private int y0;
private boolean isSelected;
public BlobIcon(Blob p)
{
this.p= p;
isSelected= false;
this.addMouseMotionListener(this);
this.addMouseListener(this);
this.setBounds(p.getX()-R,p.getY()-R,2*R,2*R);
this.setVisible(true);
repaint();
}
public void setSelected(boolean b)
{
if( isSelected==b ){
return;
}
isSelected= b;
repaint();
}
public boolean isSelected()
{
return isSelected;
}
protected void paintComponent(Graphics gg)
{
System.out.println("BlobIcon.paintComponent");
super.paintComponent(gg);
Graphics2D g= (Graphics2D)gg;
g.setColor(Color.RED);
if( isSelected ){
g.fillArc(0,0,2*R,2*R,0,360);
}else{
g.drawArc(0,0,2*R,2*R,0,360);
}
}
//Bloblistener
public void blobChanged()
{
this.setLocation(p.getX()-R,p.getY()-R);
repaint();
}
//MouseListener
public void mouseEntered(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
public void mousePressed(MouseEvent me)
{
System.out.println("BlobIcon.mousePressed");
x0= me.getX();
y0= me.getY();
}
public void mouseReleased(MouseEvent me)
{
}
public void mouseClicked(MouseEvent me)
{
System.out.println("BlobIcon.mouseClicked");
isSelected= !isSelected;
repaint();
}
//MouseMotionListener
public void mouseDragged(MouseEvent me)
{
System.out.println("BlobIcon.mouseDragged");
int x= me.getX();
int y= me.getY();
p.moveBy(x-x0,y-y0);
}
public void mouseMoved(MouseEvent me)
{
}
}