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>.
9 * Extended by Alexei Grigoriev <alexei_grigoriev@libero.it>.
13 * The software program was developed within a research project financed
14 * by the Italian Ministry of Universities, the Universities of Udine and
15 * Ca'Foscari of Venice, the Friuli-Venezia Giulia Region.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or any
22 * This program is distributed in the hope that it will be useful, but
23 * WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * General Public License for more details.
27 package org
.tsho
.dmc2
.ui
.basin
;
29 import org
.tsho
.dmc2
.managers
.BasinManager
;
30 import org
.tsho
.dmc2
.sm
.ComponentStateMachine
;
31 import org
.tsho
.dmc2
.sm
.Condition
;
32 import org
.tsho
.dmc2
.sm
.Input
;
33 import org
.tsho
.dmc2
.sm
.ManagerError
;
34 import org
.tsho
.dmc2
.sm
.ManagerInput
;
35 import org
.tsho
.dmc2
.sm
.State
;
36 import org
.tsho
.dmc2
.sm
.Transition
;
37 import org
.tsho
.dmc2
.sm
.UserActionInput
;
42 final class BasinFrameSM
extends ComponentStateMachine
{
44 private final BasinSMItf frame
;
46 BasinFrameSM(final BasinSMItf frame
) {
47 super("BasinSM", BasinState
.init
);
54 private final Condition renderStart
= new Condition() {
55 public boolean condition(final Input i
) {
56 if (!((BasinManager
) frame
.getManager()).doRendering()) {
57 frame
.showInvalidDataDialog(frame
.getManager().getErrorMessage());
64 private final Condition showErrorDialog
= new Condition() {
65 public boolean condition(final Input i
) {
66 frame
.showInvalidDataDialog(((ManagerError
) i
).getMessage());
72 private final Transition init
= new Transition() {
73 public void transition(final Input i
) {
74 frame
.getStopAction().setEnabled(false);
78 private final Transition stopOnly
= new Transition() {
79 public void transition(final Input i
) {
80 setSensibleItemsEnabled(false);
82 frame
.getStartAction().setEnabled(false);
83 frame
.getStopAction().setEnabled(true);
84 frame
.getColorSettingsAction().setEnabled(false);
85 frame
.getClearAction().setEnabled(false);
89 private final Transition reset
= new Transition() {
90 public void transition(final Input i
) {
91 setSensibleItemsEnabled(true);
93 frame
.getStartAction().setEnabled(true);
94 frame
.getStopAction().setEnabled(false);
95 frame
.getColorSettingsAction().setEnabled(true);
96 frame
.getClearAction().setEnabled(true);
100 private final Transition managerClear
= new Transition() {
101 public void transition(final Input i
) {
102 frame
.getManager().clear();
106 // note that we don't wait for thread to really finish...
107 private final Transition cleanup
= new Transition() {
108 public void transition(final Input i
) {
109 frame
.getManager().stopRendering();
113 private final Object
[][][] table
= new Object
[][][]
118 {Input
.go
, null, init
, BasinState
.ready
},
119 {Input
.go
, null, null, BasinState
.ready
},
120 {UserActionInput
.close
, null, cleanup
, BasinState
.fini
} // fast user...
126 {UserActionInput
.start
, renderStart
, stopOnly
, BasinState
.running
},
127 {UserActionInput
.start
, null, null, BasinState
.ready
},
128 {UserActionInput
.clear
, null, managerClear
, BasinState
.clearing
},
129 {UserActionInput
.close
, null, cleanup
, BasinState
.fini
},
131 {ManagerInput
.start
, null, stopOnly
, BasinState
.running
}, // user zoomed
132 {ManagerInput
.end
, null, reset
, BasinState
.ready
},
134 {ManagerError
.class, showErrorDialog
, reset
, BasinState
.ready
}
137 {BasinState
.running
},
139 {ManagerInput
.start
, null, null, BasinState
.running
},
140 {ManagerInput
.end
, null, reset
, BasinState
.ready
},
141 {UserActionInput
.close
, null, cleanup
, BasinState
.fini
},
143 {ManagerError
.class, showErrorDialog
, reset
, BasinState
.ready
}
146 {BasinState
.clearing
},
148 {ManagerInput
.start
, null, null, BasinState
.clearing
},
149 {ManagerInput
.end
, null, reset
, BasinState
.ready
},
150 {UserActionInput
.close
, null, cleanup
, BasinState
.fini
},
152 {ManagerError
.class, showErrorDialog
, reset
, BasinState
.ready
}
156 {BasinState
.fini
}, // final state
157 {ManagerInput
.class, null, null, BasinState
.fini
},
158 {UserActionInput
.class, null, null, BasinState
.fini
}
164 final class BasinState
extends State
{
165 BasinState(final String name
) {
170 BasinState init
= new BasinState("init"); // initial state
173 BasinState ready
= new BasinState("ready");
175 BasinState running
= new BasinState("running");
177 BasinState clearing
= new BasinState("clearing");
180 public static final BasinState fini
= new BasinState("fini"); // final state