fiore@3: /*
fiore@3: CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
fiore@3:
fiore@3: Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
fiore@3:
fiore@3: This program is free software: you can redistribute it and/or modify
fiore@3: it under the terms of the GNU General Public License as published by
fiore@3: the Free Software Foundation, either version 3 of the License, or
fiore@3: (at your option) any later version.
fiore@3:
fiore@3: This program is distributed in the hope that it will be useful,
fiore@3: but WITHOUT ANY WARRANTY; without even the implied warranty of
fiore@3: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fiore@3: GNU General Public License for more details.
fiore@3:
fiore@3: You should have received a copy of the GNU General Public License
fiore@3: along with this program. If not, see .
fiore@3: */
fiore@3: package uk.ac.qmul.eecs.ccmi.gui;
fiore@3:
fiore@3: import java.text.MessageFormat;
fiore@3: import java.util.ResourceBundle;
fiore@3:
fiore@3: import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionEvent;
fiore@3: import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionListener;
fiore@3: import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramElement;
fiore@3: import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramTreeNodeListener;
fiore@3: import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramTreeNodeEvent;
fiore@3: import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent;
fiore@3: import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent.PropertyChangeArgs;
fiore@3: import uk.ac.qmul.eecs.ccmi.sound.PlayerListener;
fiore@3: import uk.ac.qmul.eecs.ccmi.sound.SoundEvent;
fiore@3: import uk.ac.qmul.eecs.ccmi.sound.SoundFactory;
fiore@3: import uk.ac.qmul.eecs.ccmi.speech.NarratorFactory;
fiore@3:
fiore@3: /**
fiore@3: * This class is a listener providing audio (speech + sound) feedback to changes on the
fiore@3: * model (e.g. node added, node removed, node name changed etc.) operated only on the local (so not from
fiore@3: * a tree of another user sharing the same diagram)
fiore@3: * tree it is linked to. If the source of the events is different from the local tree , then no action
fiore@3: * is performed.
fiore@3: */
fiore@3: public class AudioFeedback implements CollectionListener, DiagramTreeNodeListener {
fiore@3:
fiore@3: /**
fiore@3: * Construct an {@code AudioFeedback} object linked to a {@code DiagramTree}.
fiore@3: *
fiore@3: * @param tree the tree this instance is going to be linked to
fiore@3: */
fiore@3: AudioFeedback(DiagramTree tree){
fiore@3: resources = ResourceBundle.getBundle(EditorFrame.class.getName());
fiore@3: this.tree = tree;
fiore@3: }
fiore@3:
fiore@3: @Override
fiore@3: public void elementInserted(CollectionEvent e) {
fiore@3: DiagramEventSource source = (DiagramEventSource)e.getSource();
fiore@3: if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){
fiore@3: final DiagramElement diagramElement = e.getDiagramElement();
fiore@3: boolean isNode = diagramElement instanceof Node;
fiore@3: if(isNode){
fiore@3: SoundFactory.getInstance().play( SoundEvent.OK ,new PlayerListener(){
fiore@3: @Override
fiore@3: public void playEnded() {
fiore@3: NarratorFactory.getInstance().speak(MessageFormat.format(resources.getString("speech.input.node.ack"),diagramElement.spokenText()));
fiore@3: }
fiore@3: });
fiore@3: }else{
fiore@3: Edge edge = (Edge)diagramElement;
fiore@3: final StringBuilder builder = new StringBuilder();
fiore@3: for(int i=0; i