package org.simantics.district.network.ui.participants; import java.awt.geom.Point2D; import java.util.Set; import org.simantics.g2d.canvas.ICanvasContext; import org.simantics.g2d.canvas.ICanvasParticipant; import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor; import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo; import org.simantics.g2d.element.IElement; import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler; import org.simantics.scenegraph.g2d.events.KeyEvent; import org.simantics.scenegraph.g2d.events.KeyEvent.KeyReleasedEvent; public class DNPointerInteractor extends PointerInteractor { private RoutingMode routingMode; public DNPointerInteractor() { super(new DNPickSorter()); } @Override protected ICanvasParticipant createConnectTool(TerminalInfo ti, int mouseId, Point2D startCanvasPos) { return super.createConnectTool(ti, mouseId, startCanvasPos); } @Override protected ICanvasParticipant createTranslateTool(int mouseId, Point2D startCanvasPos, Point2D curCanvasPos, Set elementsToDrag) { return new DNTranslateMode(startCanvasPos, curCanvasPos, mouseId, elementsToDrag); } @EventHandler(priority = 1000) public boolean enterroutingMode(KeyEvent ke) { if (Character.toLowerCase(ke.character) == 't' && ke instanceof KeyReleasedEvent) { ICanvasContext canvasContext = getContext(); if (routingMode == null || routingMode.isRemoved()) { routingMode = new RoutingMode(0); canvasContext.add(routingMode); } } return false; } @Override public double getPickDistance() { return 4; } }