comparison java/src/uk/ac/qmul/eecs/ccmi/gui/HapticTrigger.java @ 0:78b7fc5391a2

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