initial import
[iDMC.git] / src / java / org / tsho / dmc2 / ui / basin / BasinFrameSM.java
blob6aa5d14b00489cd81abdcfc56c03b3016db14c74
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>.
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
20 * later version.
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;
40 * The State Machine
42 final class BasinFrameSM extends ComponentStateMachine {
44 private final BasinSMItf frame;
46 BasinFrameSM(final BasinSMItf frame) {
47 super("BasinSM", BasinState.init);
49 this.frame = frame;
51 setUp(table);
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());
58 return false;
60 return true;
64 private final Condition showErrorDialog = new Condition() {
65 public boolean condition(final Input i) {
66 frame.showInvalidDataDialog(((ManagerError) i).getMessage());
67 return true;
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[][][]
115 // init
117 {BasinState.init},
118 {Input.go, null, init, BasinState.ready},
119 {Input.go, null, null, BasinState.ready},
120 {UserActionInput.close, null, cleanup, BasinState.fini} // fast user...
124 {BasinState.ready},
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}
154 // finish
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) {
166 super(name);
169 public static final
170 BasinState init = new BasinState("init"); // initial state
172 public static final
173 BasinState ready = new BasinState("ready");
174 public static final
175 BasinState running = new BasinState("running");
176 public static final
177 BasinState clearing = new BasinState("clearing");
180 public static final BasinState fini = new BasinState("fini"); // final state