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