fiore@0
|
1 /*
|
fiore@0
|
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
|
fiore@0
|
3
|
fiore@0
|
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
|
fiore@0
|
5
|
fiore@0
|
6 This program is free software: you can redistribute it and/or modify
|
fiore@0
|
7 it under the terms of the GNU General Public License as published by
|
fiore@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
fiore@0
|
9 (at your option) any later version.
|
fiore@0
|
10
|
fiore@0
|
11 This program is distributed in the hope that it will be useful,
|
fiore@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
fiore@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
fiore@0
|
14 GNU General Public License for more details.
|
fiore@0
|
15
|
fiore@0
|
16 You should have received a copy of the GNU General Public License
|
fiore@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
fiore@0
|
18 */
|
fiore@0
|
19 package uk.ac.qmul.eecs.ccmi.gui;
|
fiore@0
|
20
|
fiore@0
|
21 import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionEvent;
|
fiore@0
|
22 import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionListener;
|
fiore@0
|
23 import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent;
|
fiore@0
|
24 import uk.ac.qmul.eecs.ccmi.haptics.HapticsFactory;
|
fiore@0
|
25
|
fiore@0
|
26 /**
|
fiore@0
|
27 * A CollectionListener that updates the haptic scene upon insertion deletion and
|
fiore@0
|
28 * movement of nodes and edges in the diagram.
|
fiore@0
|
29 *
|
fiore@0
|
30 *
|
fiore@0
|
31 */
|
fiore@0
|
32 public class HapticTrigger implements CollectionListener {
|
fiore@0
|
33
|
fiore@0
|
34 @Override
|
fiore@0
|
35 public void elementInserted(CollectionEvent evt) {
|
fiore@3
|
36 DiagramEventSource source = (DiagramEventSource)evt.getSource();
|
fiore@0
|
37 if(evt.getDiagramElement() instanceof Node){
|
fiore@0
|
38 Node n = (Node)evt.getDiagramElement();
|
fiore@3
|
39 HapticsFactory.getInstance().addNode(n.getBounds().getCenterX(), n.getBounds().getCenterY(), System.identityHashCode(n),source.getDiagramName());
|
fiore@0
|
40 }else{//edge
|
fiore@0
|
41 Edge e = (Edge)evt.getDiagramElement();
|
fiore@0
|
42 Edge.PointRepresentation pr = e.getPointRepresentation();
|
fiore@3
|
43 HapticsFactory.getInstance().addEdge(System.identityHashCode(e),pr.xs,pr.ys,pr.adjMatrix,pr.nodeStart,e.getStipplePattern(),e.getNameLine(),source.getDiagramName());
|
fiore@0
|
44 }
|
fiore@0
|
45 }
|
fiore@0
|
46
|
fiore@0
|
47 @Override
|
fiore@0
|
48 public void elementTakenOut(CollectionEvent evt) {
|
fiore@3
|
49 DiagramEventSource source = (DiagramEventSource)evt.getSource();
|
fiore@0
|
50 if(evt.getDiagramElement() instanceof Node){
|
fiore@0
|
51 Node n = (Node)evt.getDiagramElement();
|
fiore@3
|
52 HapticsFactory.getInstance().removeNode(System.identityHashCode(n),source.getDiagramName());
|
fiore@0
|
53 }else{//edge
|
fiore@0
|
54 Edge e = (Edge)evt.getDiagramElement();
|
fiore@3
|
55 HapticsFactory.getInstance().removeEdge(System.identityHashCode(e),source.getDiagramName());
|
fiore@0
|
56 }
|
fiore@0
|
57 }
|
fiore@0
|
58
|
fiore@0
|
59 @Override
|
fiore@0
|
60 public void elementChanged(ElementChangedEvent evt) {
|
fiore@3
|
61 DiagramEventSource source = (DiagramEventSource)evt.getSource();
|
fiore@4
|
62 if("stop_move".equals(evt.getChangeType()) || "remove_node".equals(evt.getChangeType())){
|
fiore@0
|
63 if(evt.getDiagramElement() instanceof Edge){
|
fiore@0
|
64 Edge e = (Edge)evt.getDiagramElement();
|
fiore@0
|
65 Edge.PointRepresentation pr = e.getPointRepresentation();
|
fiore@3
|
66 HapticsFactory.getInstance().updateEdge(
|
fiore@3
|
67 System.identityHashCode(e),
|
fiore@3
|
68 pr.xs,
|
fiore@3
|
69 pr.ys,
|
fiore@3
|
70 pr.adjMatrix,
|
fiore@3
|
71 pr.nodeStart,
|
fiore@3
|
72 e.getNameLine(),
|
fiore@3
|
73 source.getDiagramName());
|
fiore@0
|
74 }else{
|
fiore@0
|
75 Node n = (Node)evt.getDiagramElement();
|
fiore@0
|
76 HapticsFactory.getInstance().moveNode(
|
fiore@0
|
77 n.getBounds().getCenterX(),
|
fiore@0
|
78 n.getBounds().getCenterY(),
|
fiore@3
|
79 System.identityHashCode(n),
|
fiore@3
|
80 source.getDiagramName()
|
fiore@0
|
81 );
|
fiore@0
|
82 }
|
fiore@0
|
83 }
|
fiore@0
|
84 }
|
fiore@0
|
85
|
fiore@0
|
86 }
|