| 1 | package scriptbuilder.structures; |
|---|
| 2 | |
|---|
| 3 | import java.awt.Color; |
|---|
| 4 | import java.util.ArrayList; |
|---|
| 5 | import java.util.List; |
|---|
| 6 | import java.util.Observable; |
|---|
| 7 | |
|---|
| 8 | /** |
|---|
| 9 | * |
|---|
| 10 | * @author Greg Eddington <geddingt@calpoly.edu> |
|---|
| 11 | */ |
|---|
| 12 | public class ScriptIncident extends Observable |
|---|
| 13 | { |
|---|
| 14 | public List<TimeSlice> slices; |
|---|
| 15 | |
|---|
| 16 | public Color color; |
|---|
| 17 | public int number; |
|---|
| 18 | public String name; |
|---|
| 19 | public String description; |
|---|
| 20 | public int length; |
|---|
| 21 | public boolean collapsed = false; |
|---|
| 22 | public int offset = 0; |
|---|
| 23 | |
|---|
| 24 | public void setCollapsed(boolean collapsed) |
|---|
| 25 | { |
|---|
| 26 | this.collapsed = collapsed; |
|---|
| 27 | setChanged(); |
|---|
| 28 | notifyObservers(); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public void setOffset(int offset) |
|---|
| 32 | { |
|---|
| 33 | int shift = offset - this.offset; |
|---|
| 34 | |
|---|
| 35 | this.offset = offset; |
|---|
| 36 | |
|---|
| 37 | for (TimeSlice slice : slices) |
|---|
| 38 | { |
|---|
| 39 | slice.shift(shift); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | setChanged(); |
|---|
| 43 | notifyObservers(); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public ScriptIncident(int number, String name, String description, |
|---|
| 47 | int length, SimulationScript script) |
|---|
| 48 | { |
|---|
| 49 | color = Color.BLACK; |
|---|
| 50 | this.number = number; |
|---|
| 51 | this.name = name; |
|---|
| 52 | this.description = description; |
|---|
| 53 | this.length = length; |
|---|
| 54 | |
|---|
| 55 | this.addObserver(script); |
|---|
| 56 | |
|---|
| 57 | slices = new ArrayList<TimeSlice>(); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | public ScriptIncident(Color color, int number, String name, |
|---|
| 61 | String description, int length, SimulationScript script) |
|---|
| 62 | { |
|---|
| 63 | this.color = color; |
|---|
| 64 | this.number = number; |
|---|
| 65 | this.name = name; |
|---|
| 66 | this.description = description; |
|---|
| 67 | this.length = length; |
|---|
| 68 | |
|---|
| 69 | this.addObserver(script); |
|---|
| 70 | |
|---|
| 71 | slices = new ArrayList<TimeSlice>(); |
|---|
| 72 | for (int i = 0; i < length; i += 60) |
|---|
| 73 | { |
|---|
| 74 | slices.add(new TimeSlice(i)); |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | public ScriptIncident(Color color, int number, String name, |
|---|
| 79 | String description, int length, SimulationScript script, |
|---|
| 80 | int offset) |
|---|
| 81 | { |
|---|
| 82 | this.color = color; |
|---|
| 83 | this.number = number; |
|---|
| 84 | this.name = name; |
|---|
| 85 | this.description = description; |
|---|
| 86 | this.length = length; |
|---|
| 87 | |
|---|
| 88 | this.addObserver(script); |
|---|
| 89 | |
|---|
| 90 | slices = new ArrayList<TimeSlice>(); |
|---|
| 91 | for (int i = 0; i < length; i += 60) |
|---|
| 92 | { |
|---|
| 93 | slices.add(new TimeSlice(i)); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | this.setOffset(offset); |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | public static class SliceChangedEvent |
|---|
| 100 | { |
|---|
| 101 | public TimeSlice slice; |
|---|
| 102 | |
|---|
| 103 | SliceChangedEvent(TimeSlice slice) |
|---|
| 104 | { |
|---|
| 105 | this.slice = slice; |
|---|
| 106 | } |
|---|
| 107 | } |
|---|
| 108 | |
|---|
| 109 | public void setSliceActive(int i) |
|---|
| 110 | { |
|---|
| 111 | setChanged(); |
|---|
| 112 | notifyObservers(new SliceChangedEvent(this.slices.get(i))); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | public static class IncidentFocusedEvent |
|---|
| 116 | { |
|---|
| 117 | public ScriptIncident incident; |
|---|
| 118 | |
|---|
| 119 | IncidentFocusedEvent(ScriptIncident i) |
|---|
| 120 | { |
|---|
| 121 | incident = i; |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | public void setIncidentActive() |
|---|
| 126 | { |
|---|
| 127 | setChanged(); |
|---|
| 128 | notifyObservers(new IncidentFocusedEvent(this)); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | @Override |
|---|
| 132 | public String toString() |
|---|
| 133 | { |
|---|
| 134 | return this.number + " - " + this.name; |
|---|
| 135 | } |
|---|
| 136 | } |
|---|