/
Widget.java
169 lines (134 loc) · 3.75 KB
/
Widget.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import java.util.LinkedList;
import java.util.List;
import de.rwth.hci.Graphics.GraphicsEventSystem;
public class Widget {
protected int width;
protected int height;
protected int positionX;
protected int positionY;
protected String tittle;
protected boolean isFocused;
protected List<MouseEventHandler> listeners;
public void AddActionListeners(MouseEventHandler mouseClickDelegate) {
listeners.add(mouseClickDelegate);
}
List<Widget> widgets;
public Widget(){
isFocused = false;
widgets = new LinkedList<Widget>();
listeners = new LinkedList<MouseEventHandler>();
}
public void AddWidget(Widget w){
widgets.add(w);
}
public String getTittle(){
return tittle ;
}
public void setTittle(String tittle){
this.tittle = tittle ;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public int getPositionX() {
return positionX;
}
public void setPositionX(int positionX) {
this.positionX = positionX;
}
public int getPositionY() {
return positionY;
}
public void setPositionY(int positionY) {
this.positionY = positionY;
}
public void HandlePaint(GraphicsEventSystem ges){
// print this and the child
for(int i = 0; i < widgets.size() ; i++){
Widget w = widgets.get(i);
w.HandlePaint(ges);
}
}
public boolean checkCollision(int x, int y){
if( x >= positionX && x <= positionX + width && y >= positionY && y <= positionY + height + Constants.OS_title_bar_height){
return true;
}
return false;
}
public void handleMouseClicked(EventArgs e){
{
for(int i = 0; i < widgets.size(); i++){
Widget w = widgets.get(i);
w.handleMouseClicked(e);
}
if(checkCollision(e.getPosition().getX(), e.getPosition().getY())) {
for (MouseEventHandler hl : listeners){
// call callback
hl.OnClick(this, e);
}
}
}
}
public void handleMousePressed(EventArgs e) {
for(int i = 0; i < widgets.size(); i++){
Widget w = widgets.get(i);
w.handleMousePressed(e);
}
if(checkCollision(e.getPosition().getX(), e.getPosition().getY()))
{
isFocused = true;
for (MouseEventHandler hl : listeners){
// call callback
hl.OnMousePressed(this, e);
}
}
}
public void handleMouseReleased(EventArgs e) {
for(int i = 0; i < widgets.size(); i++){
Widget w = widgets.get(i);
w.handleMouseReleased(e);
}
if(isFocused)
{
for (MouseEventHandler hl : listeners){
// call callback
hl.OnMouseReleased(this, e);
}
}
}
public void handleMouseMoved(EventArgs e) {
for(int i = 0; i < widgets.size(); i++){
Widget w = widgets.get(i);
w.handleMouseMoved(e);
}
for (MouseEventHandler hl : listeners){
// call callback
hl.OnMouseMoved(this, e);
}
}
public void handleMouseDragged(EventArgs e) {
for(int i = 0; i < widgets.size(); i++){
Widget w = widgets.get(i);
w.handleMouseDragged(e);
}
if(isFocused)
{
for (MouseEventHandler hl : listeners){
// call callback
hl.OnMouseDragged(this, e);
}
}
}
public void OnWindowDragged(int deltaX, int deltaY) {
// TODO Auto-generated method stub
}
}