]> gerrit.simantics Code Review - simantics/district.git/blob
acb0acacba55246f739a174c9d3d850de4835201
[simantics/district.git] /
1 package org.simantics.district.network.ui.participants;
2
3 import java.awt.geom.Point2D;
4 import java.util.Collections;
5 import java.util.List;
6 import java.util.Set;
7
8 import org.simantics.district.network.ui.adapters.DistrictNetworkEdgeElement;
9 import org.simantics.district.network.ui.adapters.DistrictNetworkVertexElement;
10 import org.simantics.g2d.canvas.ICanvasParticipant;
11 import org.simantics.g2d.diagram.handler.PickRequest.PickSorter;
12 import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;
13 import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;
14 import org.simantics.g2d.element.IElement;
15 import org.simantics.scenegraph.g2d.G2DNode;
16
17 public class DNPointerInteractor extends PointerInteractor {
18
19     private static class DNPickSorter implements PickSorter {
20
21         @Override
22         public void sort(List<IElement> elements) {
23             Collections.sort(elements, (e1, e2) -> {
24                 G2DNode e1node = getNode(e1);
25                 G2DNode e2node = getNode(e2);
26                 if (e1node.getZIndex() < e2node.getZIndex())
27                     return -1;
28                 else if (e1node.getZIndex() > e2node.getZIndex())
29                     return 1;
30                 return 0;
31             });
32         }
33
34         private static G2DNode getNode(IElement element) {
35             G2DNode node = element.getHint(DistrictNetworkEdgeElement.KEY_DN_EDGE_NODE);
36             if (node == null)
37                 node = element.getHint(DistrictNetworkVertexElement.KEY_DN_VERTEX_NODE);
38             return node;
39         }
40     }
41
42     public DNPointerInteractor() {
43         super(new DNPickSorter());
44     }
45
46     @Override
47     protected ICanvasParticipant createConnectTool(TerminalInfo ti, int mouseId, Point2D startCanvasPos) {
48         return super.createConnectTool(ti, mouseId, startCanvasPos);
49     }
50
51     @Override
52     protected ICanvasParticipant createTranslateTool(int mouseId, Point2D startCanvasPos, Point2D curCanvasPos,
53             Set<IElement> elementsToDrag) {
54         return new DNTranslateMode(startCanvasPos, curCanvasPos, mouseId, elementsToDrag);
55     }
56 }