fiore@0: /* fiore@0: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool fiore@0: fiore@0: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) fiore@0: fiore@0: This program is free software: you can redistribute it and/or modify fiore@0: it under the terms of the GNU General Public License as published by fiore@0: the Free Software Foundation, either version 3 of the License, or fiore@0: (at your option) any later version. fiore@0: fiore@0: This program is distributed in the hope that it will be useful, fiore@0: but WITHOUT ANY WARRANTY; without even the implied warranty of fiore@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the fiore@0: GNU General Public License for more details. fiore@0: fiore@0: You should have received a copy of the GNU General Public License fiore@0: along with this program. If not, see . fiore@0: */ fiore@0: package uk.ac.qmul.eecs.ccmi.gui; fiore@0: fiore@0: import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionEvent; fiore@0: import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionListener; fiore@0: import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent; fiore@0: import uk.ac.qmul.eecs.ccmi.haptics.HapticsFactory; fiore@0: fiore@0: /** fiore@0: * A CollectionListener that updates the haptic scene upon insertion deletion and fiore@0: * movement of nodes and edges in the diagram. fiore@0: * fiore@0: * fiore@0: */ fiore@0: public class HapticTrigger implements CollectionListener { fiore@0: fiore@0: @Override fiore@0: public void elementInserted(CollectionEvent evt) { fiore@3: DiagramEventSource source = (DiagramEventSource)evt.getSource(); fiore@0: if(evt.getDiagramElement() instanceof Node){ fiore@0: Node n = (Node)evt.getDiagramElement(); fiore@3: HapticsFactory.getInstance().addNode(n.getBounds().getCenterX(), n.getBounds().getCenterY(), System.identityHashCode(n),source.getDiagramName()); fiore@0: }else{//edge fiore@0: Edge e = (Edge)evt.getDiagramElement(); fiore@0: Edge.PointRepresentation pr = e.getPointRepresentation(); fiore@3: HapticsFactory.getInstance().addEdge(System.identityHashCode(e),pr.xs,pr.ys,pr.adjMatrix,pr.nodeStart,e.getStipplePattern(),e.getNameLine(),source.getDiagramName()); fiore@0: } fiore@0: } fiore@0: fiore@0: @Override fiore@0: public void elementTakenOut(CollectionEvent evt) { fiore@3: DiagramEventSource source = (DiagramEventSource)evt.getSource(); fiore@0: if(evt.getDiagramElement() instanceof Node){ fiore@0: Node n = (Node)evt.getDiagramElement(); fiore@3: HapticsFactory.getInstance().removeNode(System.identityHashCode(n),source.getDiagramName()); fiore@0: }else{//edge fiore@0: Edge e = (Edge)evt.getDiagramElement(); fiore@3: HapticsFactory.getInstance().removeEdge(System.identityHashCode(e),source.getDiagramName()); fiore@0: } fiore@0: } fiore@0: fiore@0: @Override fiore@0: public void elementChanged(ElementChangedEvent evt) { fiore@3: DiagramEventSource source = (DiagramEventSource)evt.getSource(); fiore@4: if("stop_move".equals(evt.getChangeType()) || "remove_node".equals(evt.getChangeType())){ fiore@0: if(evt.getDiagramElement() instanceof Edge){ fiore@0: Edge e = (Edge)evt.getDiagramElement(); fiore@0: Edge.PointRepresentation pr = e.getPointRepresentation(); fiore@3: HapticsFactory.getInstance().updateEdge( fiore@3: System.identityHashCode(e), fiore@3: pr.xs, fiore@3: pr.ys, fiore@3: pr.adjMatrix, fiore@3: pr.nodeStart, fiore@3: e.getNameLine(), fiore@3: source.getDiagramName()); fiore@0: }else{ fiore@0: Node n = (Node)evt.getDiagramElement(); fiore@0: HapticsFactory.getInstance().moveNode( fiore@0: n.getBounds().getCenterX(), fiore@0: n.getBounds().getCenterY(), fiore@3: System.identityHashCode(n), fiore@3: source.getDiagramName() fiore@0: ); fiore@0: } fiore@0: } fiore@0: } fiore@0: fiore@0: }