-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathAbstractHandle.java
More file actions
168 lines (126 loc) · 4.05 KB
/
AbstractHandle.java
File metadata and controls
168 lines (126 loc) · 4.05 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
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
package nodebox.handle;
import nodebox.client.Viewer;
import nodebox.graphics.*;
import nodebox.node.Node;
import java.awt.event.KeyEvent;
public abstract class AbstractHandle implements Handle {
public static final int HANDLE_SIZE = 6;
public static final int HALF_HANDLE_SIZE = HANDLE_SIZE / 2;
public static final Color HANDLE_COLOR = new Color(0.41, 0.39, 0.68);
public static final int SHIFT_DOWN = KeyEvent.SHIFT_DOWN_MASK;
public static final int CTRL_DOWN = KeyEvent.CTRL_DOWN_MASK;
public static final int ALT_DOWN = KeyEvent.ALT_DOWN_MASK;
public static final int META_DOWN = KeyEvent.META_DOWN_MASK;
private HandleDelegate delegate;
protected final Node node;
protected Viewer viewer;
private boolean visible = true;
private boolean combinesEdits = false;
protected AbstractHandle(Node node) {
this.node = node;
}
public Node getNode() {
return node;
}
public Viewer getViewer() {
return viewer;
}
public void setViewer(Viewer viewer) {
this.viewer = viewer;
}
public boolean isVisible() {
return visible;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
//// Stub implementations of event handling ////
public boolean mouseClicked(Point pt) {
return false;
}
public boolean mousePressed(Point pt) {
return false;
}
public boolean mouseReleased(Point pt) {
return false;
}
public boolean mouseEntered(Point pt) {
return false;
}
public boolean mouseExited(Point pt) {
return false;
}
public boolean mouseDragged(Point pt) {
return false;
}
public boolean mouseMoved(Point pt) {
return false;
}
public boolean keyTyped(int keyCode, int modifiers) {
return false;
}
public boolean keyPressed(int keyCode, int modifiers) {
return false;
}
public boolean keyReleased(int keyCode, int modifiers) {
return false;
}
//// Node events ////
// TODO Can be removed?
public void update() {
}
//// Node update methods ////
public void setValue(String parameterName, Object value) {
if (delegate != null)
delegate.setValue(node, parameterName, value);
}
public void silentSet(String parameterName, Object value) {
if (delegate != null)
delegate.silentSet(node, parameterName, value);
}
public void startCombiningEdits(String command) {
if (delegate != null && ! combinesEdits) {
delegate.startEdits(command);
combinesEdits = true;
}
}
public void stopCombiningEdits() {
if (delegate != null) {
combinesEdits = false;
delegate.stopEditing(node);
}
}
public void updateHandle() {
if (delegate != null)
delegate.updateHandle(node);
}
//// Handle delegate ////
public HandleDelegate getHandleDelegate() {
return delegate;
}
public void setHandleDelegate(HandleDelegate delegate) {
this.delegate = delegate;
}
//// Utility methods ////
protected void drawDot(GraphicsContext ctx, float x, float y) {
ctx.rectmode(GraphicsContext.RectMode.CENTER);
ctx.fill(HANDLE_COLOR);
ctx.rect(x, y, HANDLE_SIZE, HANDLE_SIZE);
}
protected void drawDot(Path p, float x, float y) {
p.rect(x, y, HANDLE_SIZE, HANDLE_SIZE);
}
/**
* Create a rectangle that can be used to test if a point is inside of it. (hit testing)
* The X and Y coordinates form the center of a rectangle that represents the handle size.
*
* @param x the center x position of the rectangle
* @param y the center y position of the rectangle
* @return a rectangle the size of the handle.
*/
protected Rect createHitRectangle(double x, double y) {
int ix = (int) x;
int iy = (int) y;
return new Rect(ix - HALF_HANDLE_SIZE, iy - HALF_HANDLE_SIZE, HANDLE_SIZE, HANDLE_SIZE);
}
}