Changeset 21 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures/TimeSlice.java


Ignore:
Timestamp:
07/28/2017 04:37:57 PM (9 years ago)
Author:
bmcguffin
Message:

Filled out toXML() method of TimeSlice? class; method now generates a string containing DTD-compliant XML data and calls the same method on its held objects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/structures/TimeSlice.java

    r16 r21  
    11package scriptbuilder.structures; 
    22 
     3import java.text.SimpleDateFormat; 
    34import java.util.ArrayList; 
    45import java.util.Collections; 
     6import java.util.Date; 
    57import java.util.List; 
     8import java.util.TimeZone; 
    69import scriptbuilder.gui.ScriptBuilderGuiConstants; 
    710import scriptbuilder.structures.events.I_ScriptEvent; 
     
    1619 * @version 2017/06/30 
    1720 */ 
    18 public class TimeSlice implements Comparable 
     21public class TimeSlice implements Comparable, I_XML_Writable 
    1922{ 
    2023 
    21     //Events which occur at this instance 
     24    /** 
     25     * Reference to the incident which contains this timeslice. 
     26     */ 
     27    private ScriptIncident thisIncident; 
     28 
    2229    /** 
    2330     * List of Script Events which begin at this instance. 
     
    3340     * that this timeslice occurs 
    3441     */ 
    35     public TimeSlice(int seconds) 
     42    public TimeSlice(int seconds, ScriptIncident inc) 
    3643    { 
    3744        this.seconds = seconds; 
    3845        events = new ArrayList<I_ScriptEvent>(); 
     46        thisIncident = inc; 
    3947    } 
    4048 
     
    183191            return 0; 
    184192        } 
    185  
    186     } 
    187  
    188     /** 
    189      * Stub method. Converts the contents of this timeslice to a correctly 
     193    } 
     194 
     195    /** 
     196     * Converts the contents of this timeslice to a correctly 
    190197     * formatted <ScriptEvent> XML element. 
    191198     * 
    192199     * @return XML conversion of this timeslice. 
    193200     */ 
     201    @Override 
    194202    public String toXML() 
    195203    { 
    196         // stub 
    197         return "<EVENT GROUP>STUB</EVENT GROUP>"; 
     204        System.out.println("Seconds:: " + seconds); 
     205        String output = openTag(ELEMENT.SCRIPT_EVENT.tag); 
     206        SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss"); 
     207        df.setTimeZone(TimeZone.getTimeZone("GMT")); 
     208        output += openTag(ELEMENT.TIME_INDEX.tag) + df.format(new Date(seconds * 1000)) 
     209                + closeTag(ELEMENT.TIME_INDEX.tag); 
     210 
     211        output += openTag(ELEMENT.INCIDENT.tag + " LogNum=\"" + thisIncident.number + "\""); 
     212        output += thisIncident.name + closeTag(ELEMENT.INCIDENT.tag); 
     213 
     214        for (I_ScriptEvent ev : events) 
     215        { 
     216            if (ev instanceof I_XML_Writable) 
     217            { 
     218                I_XML_Writable ex = (I_XML_Writable) ev; 
     219                output += ex.toXML(); 
     220            } 
     221        } 
     222        output += closeTag(ELEMENT.SCRIPT_EVENT.tag); 
     223        System.out.println(output); 
     224        return output; 
     225    } 
     226 
     227    @Override 
     228    public String openTag(String s) 
     229    { 
     230        return "<" + s + ">\n"; 
     231    } 
     232 
     233    @Override 
     234    public String closeTag(String s) 
     235    { 
     236        return "</" + s + ">\n"; 
     237    } 
     238 
     239    @Override 
     240    public String emptyTag(String s) 
     241    { 
     242        return "<" + s + "/>\n"; 
    198243    } 
    199244} 
Note: See TracChangeset for help on using the changeset viewer.