1 package org.splat.simer;
3 import java.util.Iterator;
4 import java.util.Vector;
6 import org.splat.som.Scenario;
7 import org.splat.som.Step;
8 import org.splat.som.Study;
9 import org.splat.wapp.MenuItem;
10 import org.splat.wapp.SlidMenu;
13 public class NewScenarioMenu extends SlidMenu {
16 private Scenario scopen; // Currently "open" scenario
17 private Step stopen; // Currently selected step
19 // ==============================================================================================================================
21 // ==============================================================================================================================
23 public NewScenarioMenu (Study context) {
24 // -----------------------------------
25 super("scenarii", "study");
30 // ==============================================================================================================================
32 // ==============================================================================================================================
34 public void selects (String name) {
35 // ---------------------------------
36 String[] parse = name.split("\\x2E");
37 Scenario[] scenes = study.getScenarii();
38 Scenario scenew = scopen;
42 if (scenew == null && scenes.length == 1) scenew = scenes[0];
44 int askdex = Integer.valueOf(parse[0]);
46 while (askid < scenes.length) {
47 if (scenes[askid].getIndex() == askdex) break;
50 scenew = scenes[askid]; // Throws an exception if the scenario does not exist (that is, if name is not correct)
52 } catch (Exception error) {
57 // Study with several scenarii, non of them open
59 // Collection of steps to be displayed
60 Vector<Step> steps = new Vector<Step>();
61 Step[] newstep = scenes[0].getSteps(); // All scenarii have the same steps
63 for (int i=0; i<scenes.length; i++) steps.add(scenes[i].getFirstStep());
64 newstep = study.getSteps();
65 stopen = newstep[0]; // Default selected step
67 // Creation of the menu
68 for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
70 int number = step.getNumber();
71 Scenario group = (Scenario)step.getOwner(); // The menu includes first scenario steps only
72 int index = group.getIndex();
73 String value = index + "." + number;
75 if (group.isEmpty()) icon = "icon.empty.png";
76 // else if (group.isFinished()) icon = "icon.checked.png";
77 else icon = "icon.done.png";
78 addGroup(value, group.getTitle(), icon, "select-step?selection=" + value + "&title=%{title}");
81 if (scopen == null || !scenew.equals(scopen)) {
85 // Collection of steps to be displayed
86 Vector<Step> steps = new Vector<Step>();
87 Step[] newstep = scenew.getSteps();
89 for (int i=0; i<newstep.length; i++) {
90 steps.add(newstep[i]);
92 for (int i=askid-1; i>-1; i--) steps.add(0, scenes[i].getFirstStep());
93 newstep = study.getSteps();
94 for (int i=askid+1; i<scenes.length; i++) steps.add(scenes[i].getFirstStep());
96 // Creation of the menu
97 boolean first = true; // For differentiating the first scenario step
98 int askdex = Integer.valueOf(parse[1]);
99 for (Iterator<Step> i=steps.iterator(); i.hasNext(); ) {
100 Step step = i.next();
101 int number = step.getNumber();
103 if (!step.isStarted()) icon = "icon.empty.png";
104 else if (step.isFinished()) icon = "icon.checked.png";
105 else icon = "icon.done.png";
106 if (number == askdex) stopen = step;
107 Scenario group = (Scenario)step.getOwner();
108 int index = group.getIndex();
109 String value = index + "." + number;
110 if (index != scenew.getIndex()) {
111 if (group.isEmpty()) icon = "icon.empty.png";
112 // else if (group.isFinished()) icon = "icon.checked.png";
113 else icon = "icon.done.png";
114 addGroup(value, group.getTitle(), icon, "select-step?selection=" + value + "&title=%{title}");
116 addGroup(value, scenew.getTitle(), icon, "select-step?selection=" + value + "&title=%{title}");
119 addSubItem(value, "menu.step." + number, icon, "select-step?selection=" + value + "&title=%{title}");
127 public void refreshSelectedItem () {
128 // ----------------------------------
129 MenuItem item = this.getSelectedItem();
131 if (!stopen.isStarted()) icon = "icon.empty.png";
132 else if (stopen.isFinished()) icon = "icon.checked.png";
133 else icon = "icon.done.png";