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
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
.manifolds
;
27 import java
.util
.ArrayList
;
29 import org
.tsho
.dmc2
.managers
.ManifoldsManager
;
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
;
40 class ManifoldsFrameSM
extends ComponentStateMachine
{
42 private final ManifoldsSMItf frame
;
45 * Components to be disabled while the painting thread
48 private final ArrayList disableOnRunItems
;
50 ManifoldsFrameSM(final ManifoldsSMItf frame
) {
51 super("ManifoldsSM", ManifoldsState
.init
);
54 //sensibleItems = new ArrayList();
55 disableOnRunItems
= new ArrayList();
60 private final Condition renderStart
= new Condition() {
61 public boolean condition(final Input i
) {
62 return ((ManifoldsManager
) frame
.getManager()).doRendering(false);
63 // if (!((ManifoldsManager) frame.getManager()).doRendering(false)) {
64 // frame.showInvalidDataDialog(frame.getManager().getErrorMessage());
71 private final Condition showErrorDialog
= new Condition() {
72 public boolean condition(final Input i
) {
73 frame
.showInvalidDataDialog(((ManagerError
) i
).getMessage());
79 private final Transition init
= new Transition() {
80 public void transition(final Input i
) {
81 addNoRunItem(frame
.getClearAction());
85 private final Transition stopOnly
= new Transition() {
86 public void transition(final Input i
) {
87 setSensibleItemsEnabled(false);
88 setNoRunItemsEnabled(false);
90 frame
.getStartAction().setEnabled(false);
91 frame
.getStopAction().setEnabled(true);
92 frame
.getClearAction().setEnabled(false);
96 private final Transition reset
= new Transition() {
97 public void transition(final Input i
) {
98 setSensibleItemsEnabled(true);
99 setNoRunItemsEnabled(true);
101 frame
.getStartAction().setEnabled(true);
102 frame
.getStopAction().setEnabled(false);
103 frame
.getClearAction().setEnabled(true);
107 private final Transition lock
= new Transition() {
108 public void transition(final Input i
) {
109 setNoRunItemsEnabled(true);
110 //setComponentListEnabled(disableOnRunItems, true);
112 frame
.getStartAction().setEnabled(false);
113 frame
.getStopAction().setEnabled(false);
114 frame
.getClearAction().setEnabled(true);
118 private final Transition managerClear
= new Transition() {
119 public void transition(final Input i
) {
120 frame
.getManager().clear();
124 // note that we don't wait for thread to really finish...
125 private final Transition cleanup
= new Transition() {
126 public void transition(final Input i
) {
127 frame
.getManager().stopRendering();
131 private final Object
[][][] table
= new Object
[][][]
135 {ManifoldsState
.init
},
136 {Input
.go
, null, init
, ManifoldsState
.ready
},
137 {Input
.go
, null, null, ManifoldsState
.ready
},
138 {UserActionInput
.close
, null, cleanup
, ManifoldsState
.fini
} // fast user...
142 {ManifoldsState
.ready
},
144 {UserActionInput
.start
, renderStart
, stopOnly
, ManifoldsState
.running
},
145 {UserActionInput
.start
, null, null, ManifoldsState
.ready
},
146 {UserActionInput
.clear
, null, managerClear
, ManifoldsState
.clearing
},
147 {UserActionInput
.close
, null, cleanup
, ManifoldsState
.fini
},
149 {ManagerInput
.start
, null, stopOnly
, ManifoldsState
.running
}, // user zoomed
150 {ManagerInput
.end
, null, reset
, ManifoldsState
.ready
},
152 {ManagerError
.class, showErrorDialog
, reset
, ManifoldsState
.ready
}
155 {ManifoldsState
.running
},
157 {ManagerInput
.start
, null, null, ManifoldsState
.running
},
158 {ManagerInput
.end
, null, reset
, ManifoldsState
.ready
},
159 {UserActionInput
.close
, null, cleanup
, ManifoldsState
.fini
},
161 {ManagerError
.class, showErrorDialog
, reset
, ManifoldsState
.ready
}
164 {ManifoldsState
.clearing
},
166 {ManagerInput
.start
, null, null, ManifoldsState
.clearing
},
167 {ManagerInput
.end
, null, reset
, ManifoldsState
.ready
},
168 {UserActionInput
.close
, null, cleanup
, ManifoldsState
.fini
},
170 {ManagerError
.class, showErrorDialog
, reset
, ManifoldsState
.ready
}
174 {ManifoldsState
.fini
}, // final state
175 {ManagerInput
.class, null, null, ManifoldsState
.fini
},
176 {UserActionInput
.class, null, null, ManifoldsState
.fini
}
182 final class ManifoldsState
extends State
{
183 ManifoldsState(final String name
) {
188 ManifoldsState init
= new ManifoldsState("init"); // initial state
190 ManifoldsState ready
= new ManifoldsState("ready");
192 ManifoldsState running
= new ManifoldsState("running");
194 ManifoldsState clearing
= new ManifoldsState("clearing");
196 ManifoldsState fini
= new ManifoldsState("fini"); // final state