Warning: Can't use blame annotator:
svn blame failed on trunk/src/scriptbuilder/structures/events/CHPRadioEvent.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator-scriptbuilder/trunk/src/scriptbuilder/structures/events/CHPRadioEvent.java @ 175

Revision 175, 2.9 KB checked in by sdanthin, 6 years ago (diff)

CHPRadioEvent.java added an overriding function to remove a corresponding audioEvent from the data model when its sister CHPRadioEvent is removed as well.

RevLine 
1/*
2 * To change this license header, choose License Headers in Project Properties.
3 * To change this template file, choose Tools | Templates
4 * and open the template in the editor.
5 */
6package scriptbuilder.structures.events;
7
8import java.util.ArrayList;
9import scriptbuilder.structures.ELEMENT;
10import scriptbuilder.structures.I_XML_Writable;
11import scriptbuilder.structures.ScriptEvent;
12import scriptbuilder.structures.XMLWriter;
13
14/**
15 * Data model for a CHP radio event. A CHP radio transmission has a
16 * conversation, with dialog between a field unit and a dispatch center. It also
17 * has an audio file which has that conversation acted out.
18 *
19 * @author Bryan McGuffin
20 */
21public class CHPRadioEvent extends ScriptEvent implements I_XML_Writable, I_AudioEvent
22{
23
24    /**
25     * Constructor.
26     */
27    public CHPRadioEvent()
28    {
29        super(ScriptEventType.CHP_RADIO_EVENT);
30    }
31
32    /**
33     * List of the lines of dialog in this event.
34     */
35    public ArrayList<String> lines = new ArrayList<String>();
36
37    /**
38     * List of the corresponding roles for each line of dialog.
39     */
40    public ArrayList<String> roles = new ArrayList<String>();
41
42    /**
43     * Path for the audio file to be played during this event.
44     */
45    public String radioFile = "";
46   
47    /**
48     * ID
49     */
50    public String id = "";
51   
52   
53    /**
54     * Returns the contents of the CHPRadioEvent to make recording easier.
55     * @return a string with the script to be said
56     */
57    public String toScriptFile()
58    {
59        String fileContents = "";
60        for(int lineIndex=0;lineIndex<lines.size();lineIndex++)
61        {
62            fileContents += roles.get(lineIndex) + " " + lines.get(lineIndex) + "\n";
63        }
64        return fileContents;
65    }
66   
67    @Override
68    public String getFileName()
69    {
70        return radioFile;
71    }
72   
73    @Override
74    public String getID()
75    {
76        return id;
77    }
78   
79    @Override
80    public void setID(String id)
81    {
82        this.id = id;
83    }
84   
85    @Override
86    public void setFileName(String s)
87    {
88        radioFile = s;
89    }
90   
91    @Override
92    public void removeThis()
93    {
94        this.slice.events.remove(this);
95        //removes the correct AudioEvent when this CHPRadioEvent is removed
96        this.slice.removeCorrespondingAudioEvent(this);
97        this.slice.checkEmpty();
98    }
99   
100    @Override
101    public String toXML()
102    {
103        String output = XMLWriter.openTag(ELEMENT.CHP_RADIO.tag + " RadioFile=\"" + radioFile + "\"");
104        output += XMLWriter.openTag(ELEMENT.DIALOG.tag);
105
106        for (int i = 0; i < lines.size(); i++)
107        {
108            output += XMLWriter.openTag(ELEMENT.LINE.tag + " Role=\"" + roles.get(i) + "\"");
109            output += lines.get(i);
110            output += XMLWriter.closeTag(ELEMENT.LINE.tag);
111        }
112
113        output += XMLWriter.closeTag(ELEMENT.DIALOG.tag);
114        output += XMLWriter.closeTag(ELEMENT.CHP_RADIO.tag);
115
116        return output;
117    }
118}
Note: See TracBrowser for help on using the repository browser.