forked from bsondermann/BlackboxSticksExporter3D
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUIComponent.pde
172 lines (130 loc) · 3.24 KB
/
GUIComponent.pde
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
170
171
172
import processing.event.*;
abstract class GUIComponent {
private int x, y, wid, hgt;
private String label;
// TODO Can I get rid of this?
protected boolean wasClicked = false;
protected Object listener;
protected IFLookAndFeel lookAndFeel;
protected GUIController controller;
//protected PFont meta;
// May not need this
protected int index;
public GUIComponent () {
}
public void setIndex(int i) {
index = i;
}
public int getIndex() {
return index;
}
public void update(int argX, int argY) {
}
public void show() {
}
public void setController (GUIController c) {
controller = c;
}
public GUIController getController() {
return controller;
}
public void initWithParent () {
}
public void setLookAndFeel(IFLookAndFeel lf) {
lookAndFeel = lf;
}
public IFLookAndFeel getLookAndFeel() {
return lookAndFeel;
}
public String getLabel() {
return label;
}
public void setLabel (String argLabel) {
label = argLabel;
}
public boolean canReceiveFocus() {
return true;
}
public int getWidth() {
return wid;
}
public void setWidth(int newWidth) {
if (newWidth > 0) wid = newWidth;
}
public int getHeight() {
return hgt;
}
public void setHeight(int newHeight) {
if (newHeight > 0) hgt = newHeight;
}
public void addActionListener (Object newListener) {
listener = newListener;
}
public void setSize(int newWidth, int newHeight) {
if (newHeight > 0 && newWidth > 0) {
hgt = newHeight;
wid = newWidth;
}
}
//public IFSize getSize() {
// return new IFRect(wid, hgt);
//}
public void setPosition(int newX, int newY) {
if (newX >= 0 && newY >= 0) {
x = newX;
y = newY;
}
}
//public IFPoint getPosition() {
// return new IFPoint(x, y);
//}
public void setX(int newX) {
if (newX >= 0) x = newX;
}
public int getX() {
return x;
}
public int getAbsoluteX() {
if (controller != null)
return controller.getAbsoluteX() + x;
else
return x;
}
public void setY(int newY) {
if (newY >= 0) y = newY;
}
public int getY() {
return y;
}
public int getAbsoluteY() {
if (controller != null)
return controller.getAbsoluteY() + y;
else
return y;
}
public void mouseEvent (MouseEvent e) {
if (e.getAction() == MouseEvent.PRESS) {
if (isMouseOver (e.getX(), e.getY())) {
wasClicked = true;
}
} else if (e.getAction() == MouseEvent.RELEASE) {
if (wasClicked && isMouseOver (e.getX(), e.getY())) {
fireEventNotification(this, "Clicked");
wasClicked = false;
}
}
}
public void keyEvent (KeyEvent e) {
}
public void actionPerformed (GUIEvent e) {
}
public void fireEventNotification (GUIComponent argComponent, String argMessage) {
if (listener == null)
return;
GUIEvent e = new GUIEvent(argComponent, argMessage);
IFDelegation.callDelegate(listener, "actionPerformed", new Object[] { e });
}
public boolean isMouseOver (int mouseX, int mouseY) {
return ((mouseX >= x) && (mouseY >= y) && (mouseX <= (x + wid)) && (mouseY <= (y + hgt)));
}
}