GraphicsNodeMouseEvent mevt = null;
if (evt instanceof GraphicsNodeMouseEvent) {
mevt = (GraphicsNodeMouseEvent) evt;
}
GraphicsNode source = evt.getGraphicsNode();
if (isDeselectGesture(evt)) {
if (selectionNode != null) {
selectionNodeRoot.removeTreeGraphicsNodeChangeListener(this);
}
clearSelection();
} else if (mevt != null) {
Point2D p = new Point2D.Double(mevt.getX(), mevt.getY());
AffineTransform t = source.getGlobalTransform();
if (t == null) {
t = new AffineTransform();
}
else {
try {
t = t.createInverse();
} catch (NoninvertibleTransformException ni) {
}
}
p = t.transform(p, null);
if ((source instanceof Selectable) &&
(isSelectStartGesture(evt))) {
if (selectionNode != source) {
if (selectionNode != null) {
selectionNodeRoot
.removeTreeGraphicsNodeChangeListener(this);
}
selectionNode = source;
if (source != null) {
selectionNodeRoot = source.getRoot();
selectionNodeRoot
.addTreeGraphicsNodeChangeListener(this);
}
}
((Selectable) source).selectAt(p.getX(), p.getY());
dispatchSelectionEvent(
new SelectionEvent(null,
SelectionEvent.SELECTION_STARTED,
null));
} else if (isSelectEndGesture(evt)) {
if (selectionNode == source) {
((Selectable) source).selectTo(p.getX(), p.getY());
}
Object oldSelection = getSelection();
if (selectionNode != null) {
Shape newShape;
newShape = ((Selectable)selectionNode).getHighlightShape();
dispatchSelectionEvent
(new SelectionEvent(oldSelection,
SelectionEvent.SELECTION_DONE,
newShape));
}
} else if (isSelectContinueGesture(evt)) {
if (selectionNode == source) {
boolean result = ((Selectable) source).selectTo(p.getX(),
p.getY());
if (result) {
Shape newShape =
((Selectable) selectionNode).getHighlightShape();
dispatchSelectionEvent(
new SelectionEvent(null,
SelectionEvent.SELECTION_CHANGED,
newShape));
}
}
} else if ((source instanceof Selectable) &&
(isSelectAllGesture(evt))) {
if (selectionNode != source) {
if (selectionNode != null) {
selectionNodeRoot
.removeTreeGraphicsNodeChangeListener(this);
}
selectionNode = source;
if (source != null) {
selectionNodeRoot = source.getRoot();
selectionNodeRoot
.addTreeGraphicsNodeChangeListener(this);
}
}
((Selectable) source).selectAll(p.getX(), p.getY());