-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcell.java
More file actions
83 lines (63 loc) · 2.22 KB
/
cell.java
File metadata and controls
83 lines (63 loc) · 2.22 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
73
74
75
76
77
78
79
80
81
82
83
/*
This class implements the cell object.
It acts like a standard button, also you can set an image on it
change the image displayed during runtime od disable the button.
*/
import java.awt.*;
class cell extends Canvas {
Container pappy;
Image image;
Dimension minSize;
int w, h;
int DOWN=1,UP=0;
int buttonstatus=UP;
boolean enabled=true;
public cell(Image image, Container parent, int initialWidth, int initialHeight) {
this.image = image;
pappy = parent;
w = initialWidth;
h = initialHeight;
minSize = new Dimension(w,h);
}
public Dimension preferredSize() { return minSize; /* minimumSize();*/ }
public synchronized Dimension minimumSize() { return minSize; }
public void disableCell() { enabled=false; disable(); }
public void setImage(Image img){
this.image=img;
repaint();
}
// the mouse events only simulate the click on the button
public boolean mouseDown(Event evt,int x,int y){
if (evt.modifiers!=Event.META_MASK) { // il tasto sinistro
buttonstatus=DOWN;
repaint();
return false;
}
return false;
}
public boolean mouseUp(Event evt,int x,int y){
buttonstatus=UP;
repaint();
return false;
}
public void paint (Graphics g) {
if (enabled) {
if (buttonstatus==UP) {
g.drawRect(0,0,size().width-1,size().height-1);
g.setColor(getBackground());
g.draw3DRect(0,0,size().width-2,size().height-2,true);
} else {
g.drawRect(0,0,size().width-1,size().height-1);
g.setColor(getBackground());
g.fillRect(1,1,size().width,size().height);
}
if (image!=null) g.drawImage(image, (size().width-image.getWidth(this))/2, (size().height-image.getHeight(this))/2, this);
} else { /* not enabled */
g.setColor(Color.gray);
g.drawRect(0,0,size().width-1,size().height-1);
g.setColor(getBackground());
g.fillRect(1,1,size().width,size().height);
if (image!=null) g.drawImage(image, (size().width-image.getWidth(this))/2, (size().height-image.getHeight(this))/2, this);
}
}
} // end class cell