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
.lyapunov
;
29 import org
.tsho
.dmc2
.managers
.LyapunovManager
;
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
;
38 import org
.tsho
.dmc2
.core
.chart
.LyapunovRenderer
;
43 final class LyapunovFrameSM
extends ComponentStateMachine
{
45 private final LyapunovSMItf frame
;
47 LyapunovFrameSM(final LyapunovSMItf frame
) {
48 super("LyapunovSM", LyapunovState
.init
);
54 //? 21.7.2004 changed to false (from true)
58 private final Condition renderStart
= new Condition() {
59 public boolean condition(final Input i
) {
60 return ((LyapunovManager
) frame
.getManager()).doRendering();
64 private final Condition renderRedraw
= new Condition() {
65 public boolean condition(final Input i
) {
66 LyapunovManager manager
=(LyapunovManager
) frame
.getManager();
67 LyapunovRenderer renderer
= manager
.getRenderer();
69 //to decomment after renderer is OK
70 //renderer.setHoldLegend=true;
71 //renderer.setRedrawExistingChart=true;
72 renderer
.setPass(renderer
.getPass()+1);
74 if (renderer
.getPass()==1)
75 b
=manager
.doRendering();
83 private final Condition showErrorDialog
= new Condition() {
84 public boolean condition(final Input i
) {
85 frame
.showInvalidDataDialog(((ManagerError
) i
).getMessage());
90 private final Condition notAreaChart
= new Condition() {
91 public boolean condition(final Input i
) {
93 LyapunovManager manager
=(LyapunovManager
) frame
.getManager();
94 if (manager
.getType()== LyapunovControlForm2
.TYPE_PAR_SPACE
)
100 return true;//needed if the Lyapunov plot component is being closed while rendering
105 private final Transition init
= new Transition() {
106 public void transition(final Input i
) {
107 frame
.getStopAction().setEnabled(false);
111 private final Transition stopOnly
= new Transition() {
112 public void transition(final Input i
) {
113 setSensibleItemsEnabled(false);
115 frame
.getStartAction().setEnabled(false);
116 frame
.getStopAction().setEnabled(true);
117 frame
.getClearAction().setEnabled(false);
121 private final Transition reset
= new Transition() {
122 public void transition(final Input i
) {
124 LyapunovManager manager
=(LyapunovManager
) frame
.getManager();
125 LyapunovRenderer renderer
= manager
.getRenderer();
127 if (manager
.getType()!=LyapunovControlForm2
.TYPE_PAR_SPACE
|| renderer
.getPass()==0){
128 setSensibleItemsEnabled(true);
130 frame
.getStartAction().setEnabled(true);
131 frame
.getStopAction().setEnabled(false);
132 frame
.getClearAction().setEnabled(true);
136 //exception can be thrown while closing the Lyapunov plot component while rendering
141 private final Transition managerClear
= new Transition() {
142 public void transition(final Input i
) {
143 frame
.getManager().clear();
147 // note that we don't wait for thread to really finish...
148 private final Transition cleanup
= new Transition() {
149 public void transition(final Input i
) {
150 frame
.getManager().stopRendering();
156 private final Object
[][][] table
= new Object
[][][] {
159 {LyapunovState
.init
},
160 {Input
.go
, null, init
, LyapunovState
.ready
},
161 {Input
.go
, null, null, LyapunovState
.ready
},
162 {UserActionInput
.close
, null, cleanup
, LyapunovState
.fini
} // fast user...
166 {LyapunovState
.ready
},
168 {UserActionInput
.start
, renderStart
, stopOnly
, LyapunovState
.running
},
169 {UserActionInput
.start
, null, null, LyapunovState
.ready
},
170 {UserActionInput
.clear
, null, managerClear
, LyapunovState
.clearing
},
171 {UserActionInput
.close
, null, cleanup
, LyapunovState
.fini
},
173 {ManagerInput
.start
, null, stopOnly
, LyapunovState
.running
}, // user zoomed
174 {ManagerInput
.end
, null, reset
, LyapunovState
.ready
},
176 {ManagerError
.class, showErrorDialog
, reset
, LyapunovState
.ready
}
178 {LyapunovState
.running
},
180 {ManagerInput
.start
, null, null, LyapunovState
.running
},
181 {ManagerInput
.end
, notAreaChart
, reset
, LyapunovState
.ready
},
182 {ManagerInput
.end
, renderRedraw
, reset
, LyapunovState
.ready
},
183 {ManagerInput
.end
, null, reset
, LyapunovState
.ready
},
184 {UserActionInput
.close
, null, cleanup
, LyapunovState
.fini
},
186 {ManagerError
.class, showErrorDialog
, reset
, LyapunovState
.ready
}
188 {LyapunovState
.clearing
},
190 {ManagerInput
.start
, null, null, LyapunovState
.clearing
},
191 {ManagerInput
.end
, null, reset
, LyapunovState
.ready
},
192 {UserActionInput
.close
, null, cleanup
, LyapunovState
.fini
},
194 {ManagerError
.class, showErrorDialog
, reset
, LyapunovState
.ready
}
198 {LyapunovState
.fini
}, // final state
199 {ManagerInput
.class, null, null, LyapunovState
.fini
},
200 {UserActionInput
.class, null, null, LyapunovState
.fini
}
206 final class LyapunovState
extends State
{
207 LyapunovState(final String name
) {
212 LyapunovState init
= new LyapunovState("init"); // initial state
215 LyapunovState ready
= new LyapunovState("ready");
217 LyapunovState running
= new LyapunovState("running");
219 LyapunovState clearing
= new LyapunovState("clearing");
221 public static final LyapunovState fini
= new LyapunovState("fini"); // final state