protected boolean mouseDragged(MouseDragBegin e) {
if (isHovering()
&& (isControlDown(e) || isShiftDown(e))
- && e.context instanceof NodeEventHandler
&& (dataRVI != null || text != null))
{
List<Transferable> trs = new ArrayList<>(2);
import java.awt.Cursor;
import java.awt.Graphics;
import java.awt.Graphics2D;
+import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.image.VolatileImage;
import java.lang.reflect.Method;
import org.simantics.g2d.dnd.DragInteractor;
import org.simantics.g2d.dnd.DropInteractor;
import org.simantics.g2d.internal.DebugPolicy;
+import org.simantics.g2d.participant.TransformUtil;
import org.simantics.scenegraph.g2d.G2DRenderingHints;
import org.simantics.scenegraph.g2d.events.Event;
import org.simantics.scenegraph.g2d.events.IEventQueue;
holder.addMouseMotionListener(mouseAdapter);
holder.addMouseWheelListener(mouseAdapter);
holder.addFocusListener(focusAdapter);
+
+ TransformUtil util = canvasContext.getAtMostOneItemOfClass(TransformUtil.class);
+ if (util != null) {
+ mouseAdapter.initDragGestureListener(holder, (control) -> util.controlToCanvas(control, null));
+ }
+
}
};
if (AWTThread.getThreadAccess().currentThreadAccess())
if (deltaDistance > 0)
mi.addDistanceForButtons(deltaDistance);
- // Send mouse drag events.
- for (ButtonInfo bi : mi.buttonPressInfo.values()) {
- if (!bi.down)
- continue;
- if (bi.deltaMotion <= profile.movementTolerance)
- continue;
- if (bi.drag)
- continue;
- bi.drag = true;
- MouseDragBegin db = new MouseDragBegin(this, e.time, e.mouseId, e.buttons, e.stateMask, bi.button,
- bi.canvasPosition, bi.controlPosition, e.controlPosition, e.screenPosition);
- getContext().getEventQueue().queueFirst(db);
- }
-
} else if (e instanceof MouseButtonPressedEvent) {
Point2D canvasPosition = util.controlToCanvas(e.controlPosition, null);
MouseButtonPressedEvent me = (MouseButtonPressedEvent) e;
if (deltaDistance>0)
mi.addDistanceForButtons(deltaDistance);
- // Send mouse drag events.
- for (ButtonInfo bi : mi.buttonPressInfo.values())
- {
- if (!bi.down) continue;
- if (bi.deltaMotion<=profile.movementTolerance) continue;
- if (bi.drag) continue;
- bi.drag = true;
- MouseDragBegin db = new MouseDragBegin(
- this, e.time, e.mouseId, e.buttons, e.stateMask, bi.button,
- bi.canvasPosition, bi.controlPosition,
- e.controlPosition, e.screenPosition
- );
- getContext().getEventQueue().queueFirst(db);
- }
-
} else
if (e instanceof MouseButtonPressedEvent)
{
RepaintManager.setCurrentManager(repaintManager);
}
this.rootPane = rootPane;
- eventHandler.setRootPane(rootPane);
}
private RepaintManager findProperRepaintManager(RepaintManager old) {
*******************************************************************************/
package org.simantics.scenegraph.g2d.events;
-import java.awt.Component;
-import java.awt.GraphicsEnvironment;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DragGestureEvent;
-import java.awt.dnd.DragGestureListener;
-import java.awt.dnd.DragSource;
-import java.awt.dnd.DragSourceDragEvent;
-import java.awt.dnd.DragSourceDropEvent;
-import java.awt.dnd.DragSourceEvent;
-import java.awt.dnd.DragSourceListener;
-import java.awt.event.InputEvent;
-import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import org.simantics.scenegraph.g2d.IG2DNode;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;
-import org.simantics.scenegraph.g2d.events.adapter.AWTMouseEventAdapter;
import org.simantics.scenegraph.g2d.events.command.CommandEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return sort;
}
- public void setRootPane(Component rootPane) {
- if (GraphicsEnvironment.isHeadless()) {
- LOGGER.info("Disabling DragSource in headless environments");
- return;
- }
- final DragSource ds = new DragSource();
- final DragSourceListener dsl = new DragSourceListener() {
- @Override
- public void dropActionChanged(DragSourceDragEvent dsde) {
- }
- @Override
- public void dragOver(DragSourceDragEvent dsde) {
- }
- @Override
- public void dragExit(DragSourceEvent dse) {
- }
- @Override
- public void dragEnter(DragSourceDragEvent dsde) {
- }
- @Override
- public void dragDropEnd(DragSourceDropEvent dsde) {
- }
- };
- DragGestureListener dgl = new DragGestureListener() {
- @Override
- public void dragGestureRecognized(DragGestureEvent dge) {
- InputEvent ie = dge.getTriggerEvent();
- if (ie instanceof java.awt.event.MouseEvent) {
- java.awt.event.MouseEvent e = (java.awt.event.MouseEvent) ie;
- Point2D controlPos = AWTMouseEventAdapter.getControlPosition(e);
- MouseDragBegin event = new MouseDragBegin(NodeEventHandler.this,
- e.getWhen(), 0,
- AWTMouseEventAdapter.getButtonStatus(e),
- AWTMouseEventAdapter.getStateMask(e),
- AWTMouseEventAdapter.getMouseButton(e),
- // TODO: fix canvas position if necessary
- new Point2D.Double(),
- controlPos,
- controlPos,
- AWTMouseEventAdapter.getScreenPosition(e));
-
- // Send MouseDragBegin to the scenegraph and see
- // if anyone sets event.transferable to start DnD.
- handleMouseDragBeginEvent(event, EventTypes.MouseDragBegin);
- if (event.transferable != null) {
- ds.startDrag(dge, null, event.transferable, dsl);
- if (DEBUG_EVENTS)
- debug("dragGestureRecognized: startDrag " + event.transferable);
- }
- }
- }
- };
- ds.createDefaultDragGestureRecognizer(
- rootPane,
- DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
- dgl);
- ds.addDragSourceListener(dsl);
- }
-
public boolean mousePressed(MouseButtonPressedEvent event) {
G2DFocusManager.INSTANCE.clearFocus();
try {
*/
package org.simantics.scenegraph.g2d.events.adapter;
+import java.awt.Component;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragSource;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.awt.geom.Point2D;
+import java.util.function.UnaryOperator;
import org.simantics.scenegraph.g2d.events.EventDebugPolicy;
import org.simantics.scenegraph.g2d.events.IEventHandler;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseEnterEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
System.out.println("AWT mouse clicked: " + e);
}
+ public void initDragGestureListener(Component rootPane, UnaryOperator<Point2D> controlToCanvas) {
+ final DragSource ds = new DragSource();
+ DragGestureListener dgl = new DragGestureListener() {
+ @Override
+ public void dragGestureRecognized(DragGestureEvent dge) {
+ InputEvent ie = dge.getTriggerEvent();
+ if (ie instanceof java.awt.event.MouseEvent) {
+ java.awt.event.MouseEvent e = (java.awt.event.MouseEvent) ie;
+ Point2D controlPos = getControlPosition(e);
+ Point2D canvasPos = controlToCanvas.apply(controlPos);
+
+ MouseDragBegin event = new MouseDragBegin(this,
+ e.getWhen(), 0,
+ getButtonStatus(e),
+ getStateMask(e),
+ getMouseButton(e),
+ canvasPos,
+ controlPos,
+ controlPos,
+ getScreenPosition(e));
+
+ handleEvent(event);
+
+ if (event.transferable != null) {
+ ds.startDrag(dge, null, event.transferable, null);
+ }
+ }
+ }
+ };
+ ds.createDefaultDragGestureRecognizer(
+ rootPane,
+ DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
+ dgl);
+ }
}