Changeset 9 in tmcsimulator-scriptbuilder for trunk


Ignore:
Timestamp:
07/25/2017 02:59:09 PM (9 years ago)
Author:
bmcguffin
Message:

Decoupled ScriptIncident? from the observer-observable pattern. SimulationScript? no longer implements Observer; instead, ScriptIncident? calls methods in SimulationScript? which notify the script's observers of a change.

Also: TimeSlice? now contains a stub method, toXML(), which returns the contents of the timeslice in XML text format.

Location:
trunk/src/scriptbuilder/structures
Files:
3 edited

Legend:

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

    r7 r9  
    1919 * @version 2017/06/29 
    2020 */ 
    21 public class ScriptIncident extends Observable 
     21public class ScriptIncident 
    2222{ 
    2323 
     
    6666     */ 
    6767    private int latestStart = 0; 
     68 
     69    SimulationScript script; 
    6870 
    6971    /** 
     
    8284        this.name = name; 
    8385        this.description = description; 
    84         this.addObserver(script); 
     86        this.script = script; 
    8587        slices = new TreeMap<Integer, TimeSlice>(); 
    8688    } 
     
    102104        this.name = name; 
    103105        this.description = description; 
    104         this.addObserver(script); 
     106        this.script = script; 
    105107        slices = new TreeMap<Integer, TimeSlice>(); 
    106108    } 
     
    124126        this.name = name; 
    125127        this.description = description; 
    126         this.addObserver(script); 
     128        this.script = script; 
    127129        slices = new TreeMap<Integer, TimeSlice>(); 
    128130        this.setOffset(offset); 
     
    137139    { 
    138140        this.collapsed = collapsed; 
    139         setChanged(); 
    140         notifyObservers(); 
     141        script.update(); 
    141142    } 
    142143 
     
    150151    { 
    151152        this.offset = offset; 
    152         setChanged(); 
    153         notifyObservers(); 
     153        script.update(); 
    154154    } 
    155155 
     
    253253        if (this.slices.get(i) != null) 
    254254        { 
    255             setChanged(); 
    256             notifyObservers(new SliceChangedEvent(this.slices.get(i))); 
     255            script.broadcastEvent(new SliceChangedEvent(this.slices.get(i))); 
    257256        } 
    258257    } 
     
    277276    public void setIncidentActive() 
    278277    { 
    279         setChanged(); 
    280         notifyObservers(new IncidentFocusedEvent(this)); 
     278        script.broadcastEvent(new IncidentFocusedEvent(this)); 
    281279    } 
    282280 
  • trunk/src/scriptbuilder/structures/SimulationScript.java

    r1 r9  
    2626 * @version 2017/06/22 
    2727 */ 
    28 public class SimulationScript extends Observable implements Observer 
     28public class SimulationScript extends Observable 
    2929{ 
    3030 
     
    155155 
    156156    /** 
    157      * Pass incident focus events on to observers, if applicable. 
    158      * 
    159      * @param o The observable object sending the update 
    160      * @param arg Argument parameter of update 
    161      */ 
    162     @Override 
    163     public void update(Observable o, Object arg) 
    164     { 
    165         if (arg instanceof SliceChangedEvent) 
    166         { 
    167             // The slice focus has changed; pass the message 
    168             setChanged(); 
    169             notifyObservers(arg); 
    170         } 
    171         else if (arg instanceof IncidentFocusedEvent) 
    172         { 
    173             // The slice focus has changed; pass the message 
    174             setChanged(); 
    175             notifyObservers(arg); 
    176         } 
    177         else 
    178         { 
    179             // The script has changed, notify observers 
    180             setChanged(); 
    181             notifyObservers(this); 
    182         } 
     157     * Update the script's observers. 
     158     * 
     159     */ 
     160    public void update() 
     161    { 
     162        // The script has changed, notify observers 
     163        setChanged(); 
     164        notifyObservers(this); 
     165    } 
     166 
     167    /** 
     168     * Tell this script's observers that there is a new slice event. 
     169     * 
     170     * @param e the slice focus event 
     171     */ 
     172    public void broadcastEvent(SliceChangedEvent e) 
     173    { 
     174        // The slice focus has changed; pass the message 
     175        setChanged(); 
     176        notifyObservers(e); 
     177    } 
     178 
     179    /** 
     180     * Tell this script's observers that there is a new slice event. 
     181     * 
     182     * @param e the incident focus event 
     183     */ 
     184    public void broadcastEvent(IncidentFocusedEvent e) 
     185    { 
     186        // The slice focus has changed; pass the message 
     187        setChanged(); 
     188        notifyObservers(e); 
    183189    } 
    184190 
     
    210216            ex.printStackTrace(); 
    211217        } 
    212         update(this, this); 
     218        this.update(); 
    213219    } 
    214220} 
  • trunk/src/scriptbuilder/structures/TimeSlice.java

    r7 r9  
    185185 
    186186    } 
     187 
     188    /** 
     189     * Stub method. Converts the contents of this timeslice to a correctly 
     190     * formatted <ScriptEvent> XML element. 
     191     * 
     192     * @return XML conversion of this timeslice. 
     193     */ 
     194    public String toXML() 
     195    { 
     196        return "STUB"; 
     197    } 
    187198} 
Note: See TracChangeset for help on using the changeset viewer.