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
.data
.Range
;
33 import org
.tsho
.dmc2
.core
.CoreStatusEvent
;
34 import org
.tsho
.dmc2
.core
.CoreStatusListener
;
35 import org
.tsho
.dmc2
.core
.VariableDoubles
;
36 import org
.tsho
.dmc2
.core
.chart
.CyclesRenderer
;
37 import org
.tsho
.dmc2
.core
.chart
.DmcPlotRenderer
;
38 import org
.tsho
.dmc2
.core
.model
.SimpleMap
;
39 import org
.tsho
.dmc2
.ui
.InvalidData
;
40 import org
.tsho
.dmc2
.ui
.cycles
.CyclesControlForm2
;
46 public class CyclesManager
extends AbstractManager
47 implements AbstractManager
.Crosshair
,
48 AbstractManager
.BigDots
,
49 AbstractManager
.GridLines
,
50 AbstractManager
.Transparency
,
51 AbstractManager
.AxesVisibility
{
53 private final SimpleMap model
;
54 private final CyclesControlForm2 form
;
56 private CyclesRenderer plotRenderer
;
58 private boolean crosshair
;
59 private boolean bigDots
;
60 private boolean gridLines
;
62 private final int refreshSleepTime
= 500;
64 public CyclesManager(final SimpleMap model
,
65 final CyclesControlForm2 form
,
66 final ManagerListener2 frame
) {
70 this.model
= (SimpleMap
) model
;
76 plotRenderer
= new CyclesRenderer(model
, plot
);
77 plot
.setPlotRenderer(plotRenderer
);
79 plot
.setDrawGridLines(gridLines
);
80 plot
.setForegroundAlpha(0.1F
);
81 chart
.setTitle(model
.getName());
83 setCrosshair(crosshair
);
85 // stop everything on resizing
86 chartPanel
.addComponentListener(new ComponentAdapter() {
87 public void componentResized(final ComponentEvent e
) {
88 CyclesManager
.this.stopRendering();
92 plot
.addCoreStatusListener( new CoreStatusListener() {
93 public void sendCoreStatus(final CoreStatusEvent event
) {
94 if (event
.getType() == CoreStatusEvent
.REDRAW
) {
97 else if (event
.getType() == CoreStatusEvent
.REPAINT
) {
104 public boolean doRendering() {
106 VariableDoubles initial
;
107 VariableDoubles parameters
;
108 VariableDoubles rangeMin
, rangeMax
;
118 initial
= model
.getVariables();
119 parameters
= form
.getParameterValues();
120 rangeMin
= form
.getRangeMin();
121 rangeMax
= form
.getRangeMax();
123 xRange
= form
.getXRange();
124 yRange
= form
.getYRange();
125 xLabel
= form
.getLabelOnX();
126 yLabel
= form
.getLabelOnY();
127 epsilon
= form
.getEpsilon();
128 period
= form
.getPeriod();
129 maxTries
= form
.getMaxTries();
131 catch (InvalidData e
) {
132 errorMessage
= e
.getMessage();
136 plot
.setNoData(false);
139 plotRenderer
.initialize(
143 epsilon
, period
, maxTries
);
145 plotRenderer
.setBigDots(bigDots
);
147 plot
.setDataRanges(xRange
, yRange
);
149 xAxis
.setLabel(xLabel
);
150 yAxis
.setLabel(yLabel
);
156 private void launchThread() {
158 plot
.getPlotRenderer().setState(DmcPlotRenderer
.STATE_NONE
);
160 Thread refreshJob
= new RefreshThread();
163 Thread plotJob
= new PlotThread("DMCDUE - Cycles plotter", false);
164 plotJob
.setPriority(Thread
.currentThread().getPriority() - 1);
168 class RefreshThread
extends Thread
{
170 int state
= CyclesRenderer
.STATE_NONE
;
174 super("DMCDUE - CyclesRefresh");
180 int newState
= plotRenderer
.getState();
182 if (newState
!= state
) {
187 case CyclesRenderer
.STATE_NONE
:
191 case CyclesRenderer
.STATE_RUNNING
:
192 // frame.progressString("plotting...");
195 case CyclesRenderer
.STATE_FINISHED
:
196 case CyclesRenderer
.STATE_STOPPED
:
197 // frame.progressString("ok. ");
205 if ((state
& CyclesRenderer
.STATE_RUNNING
) != 0 ) {
206 chartPanel
.repaint();
210 sleep(refreshSleepTime
);
212 catch (InterruptedException e2
) {}
217 public void stopRendering() {
221 public void setGridlines(final boolean flag
) {
222 plot
.setDrawGridLines(flag
);
225 public void setCrosshair(final boolean flag
) {
227 chartPanel
.setHorizontalAxisTrace(flag
);
228 chartPanel
.setVerticalAxisTrace(flag
);
231 public boolean isCrosshair() {
235 public void clear() {
236 plot
.setNoData(true);
241 public boolean isBigDots() {
245 public void setBigDots(boolean b
) {
249 public boolean isGridlines() {
253 public void setAlpha(final boolean flag
) {
257 public void setAlphaValue(final float f
) {
258 plot
.setForegroundAlpha(f
);
261 public float getAlphaValue() {
262 return plot
.getForegroundAlpha();