f@0
|
1 /*
|
f@0
|
2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
|
f@0
|
3
|
f@0
|
4 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
|
f@0
|
5
|
f@0
|
6 This program is free software: you can redistribute it and/or modify
|
f@0
|
7 it under the terms of the GNU General Public License as published by
|
f@0
|
8 the Free Software Foundation, either version 3 of the License, or
|
f@0
|
9 (at your option) any later version.
|
f@0
|
10
|
f@0
|
11 This program is distributed in the hope that it will be useful,
|
f@0
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
f@0
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
f@0
|
14 GNU General Public License for more details.
|
f@0
|
15
|
f@0
|
16 You should have received a copy of the GNU General Public License
|
f@0
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
f@0
|
18 */
|
f@0
|
19 package uk.ac.qmul.eecs.ccmi.gui;
|
f@0
|
20
|
f@0
|
21 import java.text.MessageFormat;
|
f@0
|
22 import java.util.ResourceBundle;
|
f@0
|
23
|
f@0
|
24 import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionEvent;
|
f@0
|
25 import uk.ac.qmul.eecs.ccmi.diagrammodel.CollectionListener;
|
f@0
|
26 import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramElement;
|
f@0
|
27 import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramTreeNodeListener;
|
f@0
|
28 import uk.ac.qmul.eecs.ccmi.diagrammodel.DiagramTreeNodeEvent;
|
f@0
|
29 import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent;
|
f@0
|
30 import uk.ac.qmul.eecs.ccmi.diagrammodel.ElementChangedEvent.PropertyChangeArgs;
|
f@0
|
31 import uk.ac.qmul.eecs.ccmi.sound.PlayerListener;
|
f@0
|
32 import uk.ac.qmul.eecs.ccmi.sound.SoundEvent;
|
f@0
|
33 import uk.ac.qmul.eecs.ccmi.sound.SoundFactory;
|
f@0
|
34 import uk.ac.qmul.eecs.ccmi.speech.NarratorFactory;
|
f@0
|
35
|
f@0
|
36 /**
|
f@0
|
37 * This class is a listener providing audio (speech + sound) feedback to changes on the
|
f@0
|
38 * model (e.g. node added, node removed, node name changed etc.) operated only on the local (so not from
|
f@0
|
39 * a tree of another user sharing the same diagram)
|
f@0
|
40 * tree it is linked to. If the source of the events is different from the local tree , then no action
|
f@0
|
41 * is performed.
|
f@0
|
42 */
|
f@0
|
43 public class AudioFeedback implements CollectionListener, DiagramTreeNodeListener {
|
f@0
|
44
|
f@0
|
45 /**
|
f@0
|
46 * Construct an {@code AudioFeedback} object linked to a {@code DiagramTree}.
|
f@0
|
47 *
|
f@0
|
48 * @param tree the tree this instance is going to be linked to
|
f@0
|
49 */
|
f@0
|
50 AudioFeedback(DiagramTree tree){
|
f@0
|
51 resources = ResourceBundle.getBundle(EditorFrame.class.getName());
|
f@0
|
52 this.tree = tree;
|
f@0
|
53 }
|
f@0
|
54
|
f@0
|
55 @Override
|
f@0
|
56 public void elementInserted(CollectionEvent e) {
|
f@0
|
57 DiagramEventSource source = (DiagramEventSource)e.getSource();
|
f@0
|
58 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){
|
f@0
|
59 final DiagramElement diagramElement = e.getDiagramElement();
|
f@0
|
60 boolean isNode = diagramElement instanceof Node;
|
f@0
|
61 if(isNode){
|
f@0
|
62 SoundFactory.getInstance().play( SoundEvent.OK ,new PlayerListener(){
|
f@0
|
63 @Override
|
f@0
|
64 public void playEnded() {
|
f@0
|
65 NarratorFactory.getInstance().speak(MessageFormat.format(resources.getString("speech.input.node.ack"),diagramElement.spokenText()));
|
f@0
|
66 }
|
f@0
|
67 });
|
f@0
|
68 }else{
|
f@0
|
69 Edge edge = (Edge)diagramElement;
|
f@0
|
70 final StringBuilder builder = new StringBuilder();
|
f@0
|
71 for(int i=0; i<edge.getNodesNum();i++){
|
f@0
|
72 if(i == edge.getNodesNum()-1)
|
f@0
|
73 builder.append(edge.getNodeAt(i)+resources.getString("speech.input.edge.ack"));
|
f@0
|
74 else
|
f@0
|
75 builder.append(edge.getNodeAt(i)+ resources.getString("speech.input.edge.ack2"));
|
f@0
|
76 }
|
f@0
|
77 SoundFactory.getInstance().play( SoundEvent.OK, new PlayerListener(){
|
f@0
|
78 @Override
|
f@0
|
79 public void playEnded() {
|
f@0
|
80 NarratorFactory.getInstance().speak(builder.toString());
|
f@0
|
81 }
|
f@0
|
82 });
|
f@0
|
83 }
|
f@0
|
84 }
|
f@0
|
85 }
|
f@0
|
86
|
f@0
|
87 @Override
|
f@0
|
88 public void elementTakenOut(CollectionEvent e) {
|
f@0
|
89 DiagramEventSource source = (DiagramEventSource)e.getSource();
|
f@0
|
90 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){
|
f@0
|
91 final DiagramElement element = e.getDiagramElement();
|
f@0
|
92 SoundFactory.getInstance().play(SoundEvent.OK, new PlayerListener(){
|
f@0
|
93 @Override
|
f@0
|
94 public void playEnded() {
|
f@0
|
95 NarratorFactory.getInstance().speak(MessageFormat.format(resources.getString("speech.delete.element.ack"),element.spokenText(),tree.currentPathSpeech()));
|
f@0
|
96 }
|
f@0
|
97 });
|
f@0
|
98 }
|
f@0
|
99 }
|
f@0
|
100
|
f@0
|
101 @Override
|
f@0
|
102 public void elementChanged(ElementChangedEvent e) {
|
f@0
|
103 DiagramEventSource source = (DiagramEventSource)e.getSource();
|
f@0
|
104 if(!source.isLocal() || source.type != DiagramEventSource.Type.TREE)
|
f@0
|
105 return;
|
f@0
|
106 String change = e.getChangeType();
|
f@0
|
107 if("name".equals(change)){
|
f@0
|
108 playOK(tree.currentPathSpeech());
|
f@0
|
109 }else if ("property.add".equals(change)){
|
f@0
|
110 PropertyChangeArgs args = (PropertyChangeArgs)e.getArguments();
|
f@0
|
111 String propertyValue = ((Node)e.getDiagramElement()).getProperties().getValues(args.getPropertyType()).get(args.getPropertyIndex());
|
f@0
|
112 playOK(MessageFormat.format(resources.getString("speech.input.property.ack"),propertyValue));
|
f@0
|
113 }else if("property.set".equals(change)){
|
f@0
|
114 playOK(tree.currentPathSpeech());
|
f@0
|
115 }else if("property.remove".equals(change)){
|
f@0
|
116 PropertyChangeArgs args = (PropertyChangeArgs)e.getArguments();
|
f@0
|
117 playOK(MessageFormat.format(resources.getString("speech.deleted.property.ack"),args.getOldValue(),tree.currentPathSpeech()));
|
f@0
|
118 }else if("property.modifiers".equals(change)){
|
f@0
|
119 playOK(tree.currentPathSpeech());
|
f@0
|
120 }else if("arrowHead".equals(change)||"endLabel".equals(change)){
|
f@0
|
121 playOK(tree.currentPathSpeech());
|
f@0
|
122 }
|
f@0
|
123 }
|
f@0
|
124
|
f@0
|
125 @Override
|
f@0
|
126 public void bookmarkAdded(DiagramTreeNodeEvent evt) {
|
f@0
|
127 DiagramEventSource source = (DiagramEventSource)evt.getSource();
|
f@0
|
128 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){
|
f@0
|
129 playOK(tree.currentPathSpeech());
|
f@0
|
130 }
|
f@0
|
131 }
|
f@0
|
132
|
f@0
|
133 @Override
|
f@0
|
134 public void bookmarkRemoved(DiagramTreeNodeEvent evt) {
|
f@0
|
135 DiagramEventSource source = (DiagramEventSource)evt.getSource();
|
f@0
|
136 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){
|
f@0
|
137 playOK(MessageFormat.format(
|
f@0
|
138 resources.getString("speech.delete.bookmark.ack"),
|
f@0
|
139 evt.getValue(),
|
f@0
|
140 tree.currentPathSpeech()));
|
f@0
|
141 }
|
f@0
|
142 }
|
f@0
|
143
|
f@0
|
144 @Override
|
f@0
|
145 public void notesChanged(DiagramTreeNodeEvent evt) {
|
f@0
|
146 DiagramEventSource source = (DiagramEventSource)evt.getSource();
|
f@0
|
147 if(source.isLocal() && source.type == DiagramEventSource.Type.TREE){
|
f@0
|
148 playOK(tree.currentPathSpeech());
|
f@0
|
149 }
|
f@0
|
150 }
|
f@0
|
151
|
f@0
|
152 private void playOK(final String speech){
|
f@0
|
153 SoundFactory.getInstance().play(SoundEvent.OK, new PlayerListener(){
|
f@0
|
154 @Override
|
f@0
|
155 public void playEnded() {
|
f@0
|
156 NarratorFactory.getInstance().speak(speech);
|
f@0
|
157 }
|
f@0
|
158 });
|
f@0
|
159 }
|
f@0
|
160
|
f@0
|
161 private ResourceBundle resources;
|
f@0
|
162 private DiagramTree tree;
|
f@0
|
163 }
|