Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
*
* The different states are handled by different tracker objects: the
* SimpleSelectAreaTracker, the SimpleDragTracker and
* the SimpleHandleTracker.
*
* A Figure can be selected by clicking at it. Holding the alt key or the ctrl
* key down, selects the Figure behind it.
*
* Holding down the shift key on mouse pressed, enforces the area selection
* function.
*
* @author Werner Randelshofer
*/
public class SelectionTool extends AbstractTool {
public static final String ID = "tool.selectFigure";
// ---
// Property names
// ---
public static final String SELECT_BEHIND_ENABLED = "selectBehindEnabled";
// ---
// Fields
// ---
/**
* The tracker encapsulates the current state of the SelectionTool.
*/
private @Nullable Tracker tracker;
/**
* The tracker encapsulates the current state of the SelectionTool.
*/
private HandleTracker handleTracker;
/**
* The tracker encapsulates the current state of the SelectionTool.
*/
private SelectAreaTracker selectAreaTracker;
/**
* The tracker encapsulates the current state of the SelectionTool.
*/
private DragTracker dragTracker;
/**
* Whether to update the cursor on mouse movements.
*/
private final boolean updateCursor = true;
private final BooleanProperty selectBehindEnabled = new SimpleBooleanProperty(this, SELECT_BEHIND_ENABLED, true);
private boolean mouseDragged;
private @Nullable Figure pressedFigure;
private final HandleType handleType;
private HandleType leadHandleType;
private HandleType anchorHandleType;
// ---
// Constructors
// ---
public SelectionTool() {
this("tool.selectFigure", HandleType.RESIZE, ApplicationLabels.getResources());
}
public SelectionTool(String name, Resources rsrc) {
this(name, HandleType.RESIZE, rsrc);
}
public SelectionTool(String name, HandleType handleType, Resources rsrc) {
super(name, rsrc);
this.handleType = handleType;
}
public SelectionTool(String name, HandleType handleType, HandleType anchorHandleType, HandleType leadHandleType, Resources rsrc) {
super(name, rsrc);
this.handleType = handleType;
this.anchorHandleType = anchorHandleType;
this.leadHandleType = leadHandleType;
}
// ---
// Properties
// ---
public BooleanProperty selectBehindEnabledProperty() {
return selectBehindEnabled;
}
// ---
// Behaviors
// ---
@Override
protected void stopEditing() {
setTracker(null);
}
@Override
protected void onMousePressed(MouseEvent event, DrawingView view) {
requestFocus();
mouseDragged = false;
double vx = event.getX();
double vy = event.getY();
// HandleTracker may capture mouse event!
Handle h = view.findHandle(vx, vy);
if (h != null) {
if (updateCursor) {
node.setCursor(h.getCursor());
}
setTracker(getHandleTracker(h));
} else {
if (updateCursor) {
node.setCursor(Cursor.DEFAULT);
}
tracker = null;
}
if (tracker == null) {
// Mouse event not captured by handle tracker => Process mouse event on our own.
if (event.isControlDown()) {
SelectAreaTracker t = getSelectAreaTracker();
setTracker(t);
} else {
// "alt" modifier finds a figure behind the current selection.
if (isSelectBehindEnabled() && event.isAltDown()) {
// Select a figure behind the current selection
pressedFigure = null;
Figure firstFigure = null;
boolean selectionFound = false;
for (Map.Entry