added contact information in 'about' box
[iDMC.git] / src / java / org / tsho / dmc2 / ui / coweb / CowebSM.java
blob09bef27432714c9edf28d059ea1a2cf1d7d9aa29
1 /*
2 * iDMC the interactive Dynamical Model Calculator simulates and performs
3 * graphical and numerical analysis of systems of differential and
4 * difference equations.
6 * Copyright (C) 2004 Marji Lines and Alfredo Medio.
8 * Written by Daniele Pizzoni <auouo@tin.it>.
11 * The software program was developed within a research project financed
12 * by the Italian Ministry of Universities, the Universities of Udine and
13 * Ca'Foscari of Venice, the Friuli-Venezia Giulia Region.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or any
18 * later version.
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.
25 package org.tsho.dmc2.ui.coweb;
27 import org.tsho.dmc2.managers.CowebManager;
28 import org.tsho.dmc2.sm.ComponentStateMachine;
29 import org.tsho.dmc2.sm.Condition;
30 import org.tsho.dmc2.sm.Input;
31 import org.tsho.dmc2.sm.ManagerError;
32 import org.tsho.dmc2.sm.ManagerInput;
33 import org.tsho.dmc2.sm.State;
34 import org.tsho.dmc2.sm.Transition;
35 import org.tsho.dmc2.sm.UserActionInput;
38 class CowebSM extends ComponentStateMachine {
40 private final CowebSMItf frame;
42 private static final State initS = new State("init"); // initial state
44 private static final State shiftReadyS = new State("shiftReady");
45 private static final State shiftRunningS = new State("shiftRunning");
46 // private static final State shiftLockedS = new State("shiftLocked");
47 private static final State shiftClearingS = new State("shiftClearing");
49 private static final State cowebReadyS = new State("normalReady");
50 private static final State cowebRunningS = new State("normalRunning");
51 // private static final State cowebLockedS = new State("normalLocked");
52 private static final State cowebClearingS = new State("normalClearing");
54 private static final State finiS = new State("fini"); // final state
57 CowebSM(final CowebSMItf frame) {
58 super("ScatterSM", initS);
59 this.frame = frame;
61 setUp(table);
64 private final Condition showErrorDialog = new Condition() {
65 public boolean condition(final Input i) {
66 frame.showInvalidDataDialog(((ManagerError) i).getMessage());
67 return true;
71 private final Condition render = new Condition() {
72 public boolean condition(final Input i) {
73 CowebManager manager = (CowebManager) frame.getManager();
75 boolean ok = false;
76 if (i == UserActionInput.start) {
77 ok = manager.doRendering(false);
79 // else if (i == UserActionInput.continua) {
80 // ok = manager.continueRendering();
81 // }
82 else if (i == UserActionInput.redraw) {
83 ok = manager.doRendering(true);
85 else {
86 //Modification: line below commented
87 //assert (false);
90 if (!ok) {
91 frame.showInvalidDataDialog(
92 frame.getManager().getErrorMessage());
93 return false;
95 return true;
99 private final Transition initMachine = new Transition() {
100 public void transition(final Input i) {
102 addSensibleItem(frame.getControlForm());
103 addSensibleItem(frame.getCowebPlotMenuItem());
105 // frame.getCowebPlotMenuItem().setSelected(true);
106 ((CowebControlForm2)frame.getControlForm()).setPlotType(CowebControlForm2.TYPE_SHIFTED);
108 //frame.getControlForm().setAutomaticBounds(false);
110 initShiftMode.transition(null);
111 shiftResetted.transition(null);
116 * Shift mode
118 private final Transition initShiftMode = new Transition() {
119 public void transition(final Input i) {
120 ((CowebControlForm2)frame.getControlForm()).setPlotType(CowebControlForm2.TYPE_SHIFTED);
122 // frame.getContinueAction().setVisible(true);
123 // frame.getRedrawAction().setVisible(true);
124 // frame.getResetAction().setVisible(true);
126 frame.getSlider().setVisible(false);
130 private final Transition shiftStopOnly = new Transition() {
131 public void transition(final Input i) {
132 setSensibleItemsEnabled(false);
133 setNoRunItemsEnabled(false);
135 frame.getStartAction().setEnabled(false);
136 frame.getStopAction().setEnabled(true);
137 // frame.getContinueAction().setEnabled(false);
138 // frame.getRedrawAction().setEnabled(false);
139 // frame.getResetAction().setEnabled(false);
143 // private final Transition shiftLock = new Transition() {
144 // public void transition(final Input i) {
145 //// frame.getControlForm().setIterationsEnabled(true);
147 // setNoRunItemsEnabled(true);
149 // frame.getStartAction().setEnabled(false);
150 // frame.getStopAction().setEnabled(false);
151 //// frame.getContinueAction().setEnabled(true);
152 //// frame.getRedrawAction().setEnabled(true);
153 //// frame.getResetAction().setEnabled(true);
154 // }
155 // };
157 private final Transition shiftResetted = new Transition() {
158 public void transition(final Input i) {
159 setSensibleItemsEnabled(true);
160 setNoRunItemsEnabled(true);
162 frame.getStartAction().setEnabled(true);
163 frame.getStopAction().setEnabled(false);
164 // frame.getContinueAction().setEnabled(false);
165 // frame.getRedrawAction().setEnabled(false);
166 // frame.getResetAction().setEnabled(false);
173 * Coweb mode
175 private final Transition initCowebMode = new Transition() {
176 public void transition(Input i) {
177 ((CowebControlForm2)frame.getControlForm()).setPlotType(CowebControlForm2.TYPE_COWEB);
179 // frame.getContinueAction().setVisible(false);
180 //frame.getRedrawAction().setVisible(false);
181 // frame.getResetAction().setVisible(false);
183 frame.getSlider().setVisible(true);
185 cowebResetted.transition(null);
189 private final Transition cowebStopOnly = new Transition() {
190 public void transition(final Input i) {
191 setSensibleItemsEnabled(false);
192 setNoRunItemsEnabled(false);
194 frame.getStartAction().setEnabled(false);
195 frame.getStopAction().setEnabled(true);
199 // the same as resetted but with redraw enabled
200 // private final Transition cowebLock = new Transition() {
201 // public void transition(Input i) {
202 // setSensibleItemsEnabled(true);
203 // setNoRunItemsEnabled(true);
205 // frame.getStartAction().setEnabled(true);
206 // frame.getStopAction().setEnabled(false);
207 //// frame.getRedrawAction().setEnabled(true);
208 // }
209 // };
211 private final Transition cowebResetted = new Transition() {
212 public void transition(Input i) {
213 setSensibleItemsEnabled(true);
214 setNoRunItemsEnabled(true);
216 frame.getStartAction().setEnabled(true);
217 frame.getStopAction().setEnabled(false);
218 // frame.getRedrawAction().setEnabled(false);
224 * Misc
226 private final Transition managerClear = new Transition() {
227 public void transition(final Input i) {
228 frame.getManager().clear();
232 // note that we don't wait for thread to really finish...
233 private final Transition cleanup = new Transition() {
234 public void transition(final Input i) {
235 frame.getManager().stopRendering();
240 * Transition matrix
242 private final Object[][][] table = new Object[][][]
244 // init
246 {initS},
247 {Input.go, null, initMachine, shiftReadyS},
248 {UserActionInput.close, null, cleanup, finiS} // fast user... or this is executued by the awt thread mmhh...
251 // coweb
253 {cowebReadyS},
254 {UserActionInput.start, render, cowebStopOnly, cowebRunningS},
255 {UserActionInput.start, null, null, cowebReadyS},
256 {UserActionInput.clear, null, managerClear, cowebClearingS},
257 {UserActionInput.close, null, cleanup, finiS},
258 {UserMenuInput.cowebMode, null, null, cowebReadyS},
259 {UserMenuInput.shiftMode, null, initShiftMode, shiftReadyS},
261 {ManagerInput.start, null, cowebStopOnly, cowebRunningS}, // user zoomed
262 {ManagerInput.end, null, null, cowebReadyS}, // this arrives after an error
264 {ManagerError.class, showErrorDialog, cowebResetted, cowebReadyS}
267 {cowebRunningS},
268 {ManagerInput.start, null, null, cowebRunningS}, // the thread sends an input we ignore
269 {ManagerInput.end, null, cowebResetted, cowebReadyS},
270 {UserActionInput.close, null, cleanup, finiS},
272 {ManagerError.class, showErrorDialog, cowebResetted, cowebReadyS}
275 {cowebClearingS},
276 {ManagerInput.start, null, null, cowebClearingS},
277 {ManagerInput.end, null, cowebResetted, cowebReadyS},
278 {UserActionInput.close, null, cleanup, finiS}
280 // shift
282 {shiftReadyS},
283 {UserActionInput.start, render, shiftStopOnly, shiftRunningS},
284 {UserActionInput.start, null, null, shiftReadyS},
285 {UserActionInput.clear, null, managerClear, shiftClearingS},
286 {UserActionInput.close, null, cleanup, finiS},
287 {UserMenuInput.cowebMode, null, initCowebMode, cowebReadyS},
288 {UserMenuInput.shiftMode, null, null, shiftReadyS},
290 {ManagerInput.start, null, shiftStopOnly, shiftRunningS}, // user zoomed
291 {ManagerInput.end, null, null, shiftReadyS}, // this arrives after an error
293 {ManagerError.class, showErrorDialog, shiftResetted, shiftReadyS}
296 {shiftRunningS},
297 {ManagerInput.start, null, null, shiftRunningS},
298 {ManagerInput.end, null, shiftResetted, shiftReadyS},
299 {UserActionInput.close, null, cleanup, finiS},
301 {ManagerError.class, showErrorDialog, shiftResetted, shiftReadyS}
304 {shiftClearingS},
305 {ManagerInput.start, null, null, shiftClearingS},
306 {ManagerInput.end, null, shiftResetted, shiftReadyS},
307 {UserActionInput.close, null, cleanup, finiS},
309 {ManagerError.class, showErrorDialog, shiftResetted, shiftReadyS}
312 // finish
314 {finiS}, // final state
315 {ManagerInput.class, null, null, finiS},
316 {UserActionInput.class, null, null, finiS}
321 final class UserMenuInput extends Input {
323 UserMenuInput(final String name) {
324 super(name);
327 static final UserMenuInput shiftMode = new UserMenuInput("shiftMode");
328 static final UserMenuInput cowebMode = new UserMenuInput("cowebMode");