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 java.text.MessageFormat;
f@0: import java.util.ResourceBundle;
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.DiagramElement;
f@0: import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramTreeNodeListener;
f@0: import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramTreeNodeEvent;
f@0: import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent;
f@0: import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent.PropertyChangeArgs;
f@0: import uk.ac.qmul.eecs.ccmi.sound.PlayerListener;
f@0: import uk.ac.qmul.eecs.ccmi.sound.SoundEvent;
f@0: import uk.ac.qmul.eecs.ccmi.sound.SoundFactory;
f@0: import uk.ac.qmul.eecs.ccmi.speech.NarratorFactory;
f@0:
f@0: /**
f@0: * This class is a listener providing audio (speech + sound) feedback to changes on the
f@0: * model (e.g. node added, node removed, node name changed etc.) operated only on the local (so not from
f@0: * a tree of another user sharing the same diagram)
f@0: * tree it is linked to. If the source of the events is different from the local tree , then no action
f@0: * is performed.
f@0: */
f@0: public class AudioFeedback implements CollectionListener, DiagramTreeNodeListener {
f@0:
f@0: /**
f@0: * Construct an {@code AudioFeedback} object linked to a {@code DiagramTree}.
f@0: *
f@0: * @param tree the tree this instance is going to be linked to
f@0: */
f@0: AudioFeedback(DiagramTree tree){
f@0: resources = ResourceBundle.getBundle(EditorFrame.class.getName());
f@0: this.tree = tree;
f@0: }
f@0:
f@0: @Override
f@0: public void elementInserted(CollectionEvent e) {
f@0: DiagramEventSource source = (DiagramEventSource)e.getSource();
f@0: if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){
f@0: final DiagramElement diagramElement = e.getDiagramElement();
f@0: boolean isNode = diagramElement instanceof Node;
f@0: if(isNode){
f@0: SoundFactory.getInstance().play( SoundEvent.OK ,new PlayerListener(){
f@0: @Override
f@0: public void playEnded() {
f@0: NarratorFactory.getInstance().speak(MessageFormat.format(resources.getString("speech.input.node.ack"),diagramElement.spokenText()));
f@0: }
f@0: });
f@0: }else{
f@0: Edge edge = (Edge)diagramElement;
f@0: final StringBuilder builder = new StringBuilder();
f@0: for(int i=0; i