initial import
[iDMC.git] / src / java / org / tsho / dmc2 / ui / cycles / CyclesFrameSM.java
blob3cbf30b938f57ab1abc9dc8da26d2c601f7e17fd
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.cycles;
27 import org.tsho.dmc2.managers.CyclesManager;
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.ManagerInput;
32 import org.tsho.dmc2.sm.State;
33 import org.tsho.dmc2.sm.Transition;
34 import org.tsho.dmc2.sm.UserActionInput;
37 * The State Machine
39 final class CyclesFrameSM extends ComponentStateMachine {
41 private final CyclesSMItf frame;
43 CyclesFrameSM(final CyclesSMItf frame) {
44 super("CyclesSM", CyclesState.init);
46 this.frame = frame;
48 setUp(table);
51 private final Condition renderStart = new Condition() {
52 public boolean condition(final Input i) {
53 if (!((CyclesManager) frame.getManager()).doRendering()) {
54 frame.showInvalidDataDialog(frame.getManager().getErrorMessage());
55 return false;
57 return true;
61 private final Transition init = new Transition() {
62 public void transition(final Input i) {
63 frame.getStopAction().setEnabled(false);
67 private final Transition stopOnly = new Transition() {
68 public void transition(final Input i) {
69 setSensibleItemsEnabled(false);
71 frame.getStartAction().setEnabled(false);
72 frame.getStopAction().setEnabled(true);
73 frame.getClearAction().setEnabled(false);
77 private final Transition reset = new Transition() {
78 public void transition(final Input i) {
79 setSensibleItemsEnabled(true);
81 frame.getStartAction().setEnabled(true);
82 frame.getStopAction().setEnabled(false);
83 frame.getClearAction().setEnabled(true);
87 private final Transition managerClear = new Transition() {
88 public void transition(final Input i) {
89 frame.getManager().clear();
93 // note that we don't wait for thread to really finish...
94 private final Transition cleanup = new Transition() {
95 public void transition(final Input i) {
96 frame.getManager().stopRendering();
100 private final Transition showErrorDialog = new Transition() {
101 public void transition(final Input i) {
102 frame.showInvalidDataDialog(((ManagerError) i).getMessage());
107 private final Object[][][] table = new Object[][][]
109 // init
111 {CyclesState.init},
112 {Input.go, null, init, CyclesState.ready},
113 {Input.go, null, null, CyclesState.ready},
114 {UserActionInput.close, null, cleanup, CyclesState.fini} // fast user...
118 {CyclesState.ready},
120 {UserActionInput.start, renderStart, stopOnly, CyclesState.running},
121 {UserActionInput.start, null, null, CyclesState.ready},
122 {UserActionInput.clear, null, managerClear, CyclesState.clearing},
123 {UserActionInput.close, null, cleanup, CyclesState.fini},
125 {ManagerInput.start, null, stopOnly, CyclesState.running}, // user zoomed
126 {ManagerInput.end, null, reset, CyclesState.ready},
128 {ManagerError.class, null, showErrorDialog, CyclesState.ready}
131 {CyclesState.running},
133 {ManagerInput.start, null, null, CyclesState.running},
134 {ManagerInput.end, null, reset, CyclesState.ready},
135 {UserActionInput.close, null, cleanup, CyclesState.fini}
138 {CyclesState.clearing},
140 {ManagerInput.start, null, null, CyclesState.clearing},
141 {ManagerInput.end, null, reset, CyclesState.ready},
142 {UserActionInput.close, null, cleanup, CyclesState.fini}
144 // finish
146 {CyclesState.fini}, // final state
147 {ManagerInput.class, null, null, CyclesState.fini},
148 {UserActionInput.class, null, null, CyclesState.fini}
154 final class CyclesState extends State {
155 CyclesState(final String name) {
156 super(name);
159 public static final
160 CyclesState init = new CyclesState("init"); // initial state
162 public static final
163 CyclesState ready = new CyclesState("ready");
164 public static final
165 CyclesState running = new CyclesState("running");
166 public static final
167 CyclesState clearing = new CyclesState("clearing");
170 public static final CyclesState fini = new CyclesState("fini"); // final state
173 final class ManagerError extends Input {
174 String message;
176 ManagerError(final String message) {
177 super("ManagerError");
179 this.message = message;
182 public String getMessage() {
183 return message;