Changeset 9 in tmcsimulator-scriptbuilder for trunk/src/scriptbuilder/structures/SimulationScript.java


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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} 
Note: See TracChangeset for help on using the changeset viewer.