When studying the implementation of the GEF palette, I found a SWT control that I have never used before, probably because I rarelyProgramTo handle the mouse movement and other events. This good thing is tracker. I very much hope to call it a Shadow Warrior, because tracker often works with mouse clicks and movement events to dynamically display the changes in the position and size of the operated components, in a sense, tracker is very like GEF handle in SWT;
The following briefly introduces the basic usage of this tool. (In the GEF palette implementation, tracker is mainly used in the sash drag and the dock process of the palette)
Tracker directly inherits from Widgets. Like other widgets, constructor requires parent and style. parent is the control we need to track, so we will not go into details here. Tracker is called a Shadow Warrior mainly because tracker can display a rectangle in a shadow mode, which can be implemented through the setrectangles method, with this method name, we can see that a tracker can specify multiple rectangles. To tell the truth, I don't quite understand where to set multiple rectangles. At least I haven't touched them yet.
Of course, it is not the most important thing to set a rectangle. If you set a rectangle, the user will not feel very well. Therefore, there is another method: setstippled (Boolean) is used to specify whether to draw points in tracker, you can give it a try. It is generally nice to set to true;
In addition, the above settings are only the basic parameter settings, so how does trcker itself work? We need to mention another method of open, which only calls it, tracker will be displayed, and the movement of the mouse will be shown by our shadow warrior;
Of course, to better represent our moving direction, we 'd better set the tracker's cursor by: setcursor;
To sum up the usage of Tracker:
1. Define the mouse click and move event processor;
2. Define tracker as the tracker of a component;
3. Define the cursor and rectangle of the tracker;
4. Open tracker, that is, call method open;