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
.managers
;
29 import java
.awt
.event
.ComponentAdapter
;
30 import java
.awt
.event
.ComponentEvent
;
32 import org
.jfree
.chart
.StandardLegend
;
33 import org
.jfree
.data
.Range
;
34 import org
.tsho
.dmc2
.core
.CoreStatusEvent
;
35 import org
.tsho
.dmc2
.core
.CoreStatusListener
;
36 import org
.tsho
.dmc2
.core
.VariableDoubles
;
37 import org
.tsho
.dmc2
.core
.chart
.DmcPlotRenderer
;
38 import org
.tsho
.dmc2
.core
.chart
.LyapunovRenderer
;
39 import org
.tsho
.dmc2
.core
.model
.Model
;
40 import org
.tsho
.dmc2
.core
.model
.SimpleMap
;
41 import org
.tsho
.dmc2
.ui
.InvalidData
;
42 import org
.tsho
.dmc2
.ui
.lyapunov
.LyapunovControlForm2
;
43 import org
.tsho
.dmc2
.core
.model
.ODE
;
44 import org
.tsho
.dmc2
.ui
.lyapunov
.*;
46 public class LyapunovManager
extends AbstractManager
47 implements AbstractManager
.Crosshair
,
48 AbstractManager
.GridLines
,
49 AbstractManager
.ConnectDots
,
50 AbstractManager
.BigDots
,
51 AbstractManager
.AxesVisibility
{
53 private LyapunovComponent component
;
56 //? seems that interferes with frame of the superclass // private ManagerListener frame;
57 private LyapunovControlForm2 form
;
59 private LyapunovRenderer renderer
;
63 private boolean gridlines
;
64 private boolean crosshair
;
65 private boolean connectWithDots
;
66 private boolean bigDots
;
68 public LyapunovManager(LyapunovComponent component
) {
70 super((ManagerListener2
) component
);
71 this.component
= component
;
72 this.model
= component
.getModel();
73 this.form
= (LyapunovControlForm2
) component
.getControlForm();
79 this.type
= LyapunovControlForm2
.TYPE_VS_TIME
;
81 renderer
= new LyapunovRenderer(plot
, model
, component
);
82 plot
.setPlotRenderer(renderer
);
84 chart
.setTitle(model
.getName());
85 setCrosshair(crosshair
);
87 chart
.setLegend(new StandardLegend());
89 // stop everything on resizing
90 chartPanel
.addComponentListener(new ComponentAdapter() {
91 public void componentResized(ComponentEvent e
) {
92 LyapunovManager
.this.stopRendering();
96 plot
.addCoreStatusListener( new CoreStatusListener() {
97 public void sendCoreStatus(final CoreStatusEvent event
) {
98 if (event
.getType() == CoreStatusEvent
.REDRAW
) {
101 else if (event
.getType() == CoreStatusEvent
.REPAINT
) {
102 chartPanel
.repaint();
108 public boolean doRendering() {
109 plot
.setDrawGridLines(gridlines
);
111 plot
.setNoData(false);
113 case LyapunovControlForm2
.TYPE_VS_TIME
:
114 return renderVsTime();
116 case LyapunovControlForm2
.TYPE_VS_PAR
:
117 return renderVsParameter();
119 case LyapunovControlForm2
.TYPE_PAR_SPACE
:
123 throw new InternalError("invalid type");
127 public boolean renderVsTime() {
128 VariableDoubles parameters
;
129 VariableDoubles initial
;
130 Range timeRange
, verRange
;
135 parameters
= form
.getParameters();
136 //parameters = form.getParameterValues();
137 initial
= form
.getInitialValues();
138 timeRange
= form
.getTimeRange();
139 verRange
= form
.getVerticalRange();
141 stepSize
=0;//needs to be initialized in any case..
142 if (model
instanceof ODE
)
143 stepSize
=form
.getStepSize();
145 catch (InvalidData e
) {
146 frame
.showInvalidDataDialog(e
.getMessage());
150 if (!(model
instanceof ODE
)) {
151 renderer
.initializeVsTime(parameters
, initial
, timeRange
);
154 renderer
.initializeVsTime(parameters
,initial
,timeRange
,stepSize
);
156 renderer
.setConnectWithLines(connectWithDots
);
157 renderer
.setBigDots(bigDots
);
159 xAxis
.setLabel("time");
160 yAxis
.setLabel("exponent(s)");
161 plot
.setDataRanges(timeRange
, verRange
);
167 public boolean renderVsParameter() {
168 VariableDoubles parameters
;
169 VariableDoubles initial
;
171 Range parRange
, verRange
;
172 int iterations
=0;//initialization is needed since compiler overcautious
177 parameters
= form
.getParameters();
178 initial
= form
.getInitialValues();
179 parRange
= form
.getFirstParameterRange();
180 verRange
= form
.getVerticalRange();
181 if (model
instanceof ODE
){
182 timePeriod
= form
.getTimePeriod();
183 stepSize
=form
.getStepSize();
186 iterations
= form
.getIterations();
189 catch (InvalidData e
) {
190 frame
.showInvalidDataDialog(e
.getMessage());
194 label
= form
.getLabelOnH();
196 if (!(model
instanceof ODE
)){
197 renderer
.initializeVsParameter(parameters
, initial
, label
, parRange
, iterations
);
200 renderer
.initializeVsParameter(parameters
,initial
, label
,parRange
,timePeriod
,stepSize
);
202 renderer
.setConnectWithLines(connectWithDots
);
203 renderer
.setBigDots(bigDots
);
205 xAxis
.setLabel(label
);
206 yAxis
.setLabel("exponent(s)");
207 plot
.setDataRanges(parRange
, verRange
);
213 public boolean renderArea() {
214 VariableDoubles parameters
= null;
215 VariableDoubles initial
;
216 String firstLabel
, secondLabel
;
217 Range firstParRange
, secondParRange
;
224 parameters
= form
.getParameters();
225 initial
= form
.getInitialValues();
226 firstParRange
= form
.getFirstParameterRange();
227 secondParRange
= form
.getSecondParameterRange();
228 epsilon
= form
.getEpsilon();
229 if (model
instanceof ODE
){
230 timePeriod
= form
.getTimePeriod();
231 stepSize
=form
.getStepSize();
234 iterations
= form
.getIterations();
236 } catch (InvalidData e2
) {
237 frame
.showInvalidDataDialog(e2
.getMessage());
241 firstLabel
= form
.getLabelOnH();
242 secondLabel
= form
.getLabelOnV();
244 if (model
instanceof ODE
){
245 renderer
.initializeParArea(initial
, parameters
, firstLabel
, secondLabel
, epsilon
, timePeriod
,stepSize
);
248 renderer
.initializeParArea(initial
, parameters
, firstLabel
, secondLabel
, epsilon
, iterations
);
250 plot
.setDataRanges(firstParRange
, secondParRange
);
256 class RefreshThread
extends Thread
{
258 int state
= DmcPlotRenderer
.STATE_NONE
;
262 super("DMCDUE - LyapunovRefresh");
268 int newState
= renderer
.getState();
270 if (newState
!= state
) {
275 case DmcPlotRenderer
.STATE_NONE
:
279 case DmcPlotRenderer
.STATE_RUNNING
:
280 // frame.progressString("plotting...");
283 case DmcPlotRenderer
.STATE_FINISHED
:
284 case DmcPlotRenderer
.STATE_STOPPED
:
285 // frame.progressString("ok. ");
293 if ((state
& DmcPlotRenderer
.STATE_RUNNING
) != 0 ) {
294 chartPanel
.repaint();
299 catch (InterruptedException e2
) {}
304 private void launchThread() {
306 plot
.getPlotRenderer().setState(DmcPlotRenderer
.STATE_NONE
);
308 Thread refreshJob
= new RefreshThread();
311 Thread plotJob
= new PlotThread("DMCDUE - Lyapunov plotter", false);
312 plotJob
.setPriority(Thread
.currentThread().getPriority() - 1);
316 public void stopRendering() {
320 public void clear() {
321 plot
.setNoData(true);
326 public void setCrosshair(boolean flag
) {
328 chartPanel
.setHorizontalAxisTrace(flag
);
329 chartPanel
.setVerticalAxisTrace(flag
);
332 public boolean isCrosshair() {
336 public boolean isGridlines() {
340 public void setGridlines(boolean b
) {
344 public void setBigDots(boolean flag
) {
348 public boolean isBigDots() {
352 public void setConnectDots(boolean flag
) {
353 connectWithDots
= flag
;
356 public boolean isConnectDots() {
357 return connectWithDots
;
360 public void setType(byte b
) {
364 public byte getType() {
368 public LyapunovControlForm2
getForm(){
372 public LyapunovRenderer
getRenderer(){