Mercurial > hg > accesspd
comparison java/src/uk/ac/qmul/eecs/ccmi/gui/AudioFeedback.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 java.text.MessageFormat; | |
22 import java.util.ResourceBundle; | |
23 | |
24 import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionEvent; | |
25 import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionListener; | |
26 import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramElement; | |
27 import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramTreeNodeListener; | |
28 import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramTreeNodeEvent; | |
29 import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent; | |
30 import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent.PropertyChangeArgs; | |
31 import uk.ac.qmul.eecs.ccmi.sound.PlayerListener; | |
32 import uk.ac.qmul.eecs.ccmi.sound.SoundEvent; | |
33 import uk.ac.qmul.eecs.ccmi.sound.SoundFactory; | |
34 import uk.ac.qmul.eecs.ccmi.speech.NarratorFactory; | |
35 | |
36 /** | |
37 * This class is a listener providing audio (speech + sound) feedback to changes on the | |
38 * model (e.g. node added, node removed, node name changed etc.) operated only on the local (so not from | |
39 * a tree of another user sharing the same diagram) | |
40 * tree it is linked to. If the source of the events is different from the local tree , then no action | |
41 * is performed. | |
42 */ | |
43 public class AudioFeedback implements CollectionListener, DiagramTreeNodeListener { | |
44 | |
45 /** | |
46 * Construct an {@code AudioFeedback} object linked to a {@code DiagramTree}. | |
47 * | |
48 * @param tree the tree this instance is going to be linked to | |
49 */ | |
50 AudioFeedback(DiagramTree tree){ | |
51 resources = ResourceBundle.getBundle(EditorFrame.class.getName()); | |
52 this.tree = tree; | |
53 } | |
54 | |
55 @Override | |
56 public void elementInserted(CollectionEvent e) { | |
57 DiagramEventSource source = (DiagramEventSource)e.getSource(); | |
58 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){ | |
59 final DiagramElement diagramElement = e.getDiagramElement(); | |
60 boolean isNode = diagramElement instanceof Node; | |
61 if(isNode){ | |
62 SoundFactory.getInstance().play( SoundEvent.OK ,new PlayerListener(){ | |
63 @Override | |
64 public void playEnded() { | |
65 NarratorFactory.getInstance().speak(MessageFormat.format(resources.getString("speech.input.node.ack"),diagramElement.spokenText())); | |
66 } | |
67 }); | |
68 }else{ | |
69 Edge edge = (Edge)diagramElement; | |
70 final StringBuilder builder = new StringBuilder(); | |
71 for(int i=0; i<edge.getNodesNum();i++){ | |
72 if(i == edge.getNodesNum()-1) | |
73 builder.append(edge.getNodeAt(i)+resources.getString("speech.input.edge.ack")); | |
74 else | |
75 builder.append(edge.getNodeAt(i)+ resources.getString("speech.input.edge.ack2")); | |
76 } | |
77 SoundFactory.getInstance().play( SoundEvent.OK, new PlayerListener(){ | |
78 @Override | |
79 public void playEnded() { | |
80 NarratorFactory.getInstance().speak(builder.toString()); | |
81 } | |
82 }); | |
83 } | |
84 } | |
85 } | |
86 | |
87 @Override | |
88 public void elementTakenOut(CollectionEvent e) { | |
89 DiagramEventSource source = (DiagramEventSource)e.getSource(); | |
90 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){ | |
91 final DiagramElement element = e.getDiagramElement(); | |
92 SoundFactory.getInstance().play(SoundEvent.OK, new PlayerListener(){ | |
93 @Override | |
94 public void playEnded() { | |
95 NarratorFactory.getInstance().speak(MessageFormat.format(resources.getString("speech.delete.element.ack"),element.spokenText(),tree.currentPathSpeech())); | |
96 } | |
97 }); | |
98 } | |
99 } | |
100 | |
101 @Override | |
102 public void elementChanged(ElementChangedEvent e) { | |
103 DiagramEventSource source = (DiagramEventSource)e.getSource(); | |
104 if(!source.isLocal() || source.type != DiagramEventSource.Type.TREE) | |
105 return; | |
106 String change = e.getChangeType(); | |
107 if("name".equals(change)){ | |
108 playOK(tree.currentPathSpeech()); | |
109 }else if ("property.add".equals(change)){ | |
110 PropertyChangeArgs args = (PropertyChangeArgs)e.getArguments(); | |
111 String propertyValue = ((Node)e.getDiagramElement()).getProperties().getValues(args.getPropertyType()).get(args.getPropertyIndex()); | |
112 playOK(MessageFormat.format(resources.getString("speech.input.property.ack"),propertyValue)); | |
113 }else if("property.set".equals(change)){ | |
114 playOK(tree.currentPathSpeech()); | |
115 }else if("property.remove".equals(change)){ | |
116 PropertyChangeArgs args = (PropertyChangeArgs)e.getArguments(); | |
117 playOK(MessageFormat.format(resources.getString("speech.deleted.property.ack"),args.getOldValue(),tree.currentPathSpeech())); | |
118 }else if("property.modifiers".equals(change)){ | |
119 playOK(tree.currentPathSpeech()); | |
120 }else if("arrowHead".equals(change)||"endLabel".equals(change)){ | |
121 playOK(tree.currentPathSpeech()); | |
122 } | |
123 } | |
124 | |
125 @Override | |
126 public void bookmarkAdded(DiagramTreeNodeEvent evt) { | |
127 DiagramEventSource source = (DiagramEventSource)evt.getSource(); | |
128 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){ | |
129 playOK(tree.currentPathSpeech()); | |
130 } | |
131 } | |
132 | |
133 @Override | |
134 public void bookmarkRemoved(DiagramTreeNodeEvent evt) { | |
135 DiagramEventSource source = (DiagramEventSource)evt.getSource(); | |
136 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){ | |
137 playOK(MessageFormat.format( | |
138 resources.getString("speech.delete.bookmark.ack"), | |
139 evt.getValue(), | |
140 tree.currentPathSpeech())); | |
141 } | |
142 } | |
143 | |
144 @Override | |
145 public void notesChanged(DiagramTreeNodeEvent evt) { | |
146 DiagramEventSource source = (DiagramEventSource)evt.getSource(); | |
147 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){ | |
148 playOK(tree.currentPathSpeech()); | |
149 } | |
150 } | |
151 | |
152 private void playOK(final String speech){ | |
153 SoundFactory.getInstance().play(SoundEvent.OK, new PlayerListener(){ | |
154 @Override | |
155 public void playEnded() { | |
156 NarratorFactory.getInstance().speak(speech); | |
157 } | |
158 }); | |
159 } | |
160 | |
161 private ResourceBundle resources; | |
162 private DiagramTree tree; | |
163 } |