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 package org.ximtec.igesture.io.wacomclient;
28
29 import java.awt.Point;
30 import java.util.ArrayList;
31 import java.util.HashSet;
32 import java.util.List;
33 import java.util.logging.Logger;
34
35 import org.sigtec.graphix.Orientation;
36 import org.sigtec.ink.input.CompleteLocation;
37 import org.sigtec.ink.input.Location;
38 import org.sigtec.input.AbstractInputDevice;
39 import org.sigtec.input.InputDeviceEvent;
40 import org.sigtec.util.Constant;
41 import org.ximtec.igesture.io.button.ButtonDeviceEventListener;
42 import org.ximtec.igesture.io.button.ButtonDeviceHandler;
43 import org.ximtec.igesture.io.wacom.WacomCallback;
44 import org.ximtec.igesture.io.wacom.WacomUtils;
45 import org.ximtec.igesture.io.wacom.Wintab32.ORIENTATION;
46 import org.ximtec.igesture.io.wacom.Wintab32.ROTATION;
47
48
49
50
51
52
53
54
55
56 public class WacomReader extends AbstractInputDevice implements ButtonDeviceEventListener,
57 WacomCallback {
58
59 private static final Logger LOGGER = Logger.getLogger(WacomReader.class.getName());
60
61 private boolean lastKeyState = false;
62 private WacomUtils wacomUtils;
63
64 private int BUTTON_0 = 0;
65 private int BUTTON_5 = 5;
66
67 private HashSet<ButtonDeviceHandler> buttonUpEvents;
68
69
70 public WacomReader() {
71 init();
72 buttonUpEvents = new HashSet<ButtonDeviceHandler>();
73 }
74
75
76
77
78
79
80 public void init() {
81
82 init_callback();
83 }
84
85
86 void init_callback() {
87
88 wacomUtils = new WacomUtils(this);
89 wacomUtils.start();
90 }
91
92
93 public void callbackFunction(int x, int y, int z, int pkstatus, int npress,
94 int tpress, long timeStamp, ORIENTATION orientation, ROTATION rotation,
95 int button) {
96
97 if (button == BUTTON_5) {
98 Location location = new Location("screen", 1, new Point(x, y));
99 CompleteLocation tbl = null;
100 tbl = new CompleteLocation(location, timeStamp, npress,
101 Constant.NOT_AVAILABLE, new Orientation(rotation.roYaw,
102 rotation.roPitch, rotation.roRoll));
103 WacomReader.this.fireInputDeviceEvent(new WacomReaderEvent(tbl));
104 lastKeyState = true;
105
106 }
107 else {
108
109 if (lastKeyState) {
110 WacomReader.this.fireTabletButtonEvent(new InputDeviceEvent() {
111
112 public long getTimestamp() {
113 return System.currentTimeMillis();
114 }
115 });
116
117 lastKeyState = false;
118 }
119 }
120
121 }
122
123
124
125
126
127
128
129 public static List<WacomReader> createTablet() {
130 final List<WacomReader> list = new ArrayList<WacomReader>();
131 list.add(new WacomReader());
132 return list;
133 }
134
135
136 public void addButtonDeviceEventListener(ButtonDeviceHandler listener) {
137 buttonUpEvents.add(listener);
138 }
139
140
141 public void removeButtonDeviceEventListener(ButtonDeviceHandler listener) {
142 buttonUpEvents.remove(listener);
143 }
144
145
146 private void fireTabletButtonEvent(InputDeviceEvent event) {
147 for (final ButtonDeviceHandler listener : buttonUpEvents) {
148 listener.handleButtonPressedEvent(event);
149 }
150
151 }
152
153 }