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
;
117 initial
= model
.getVariables();
118 parameters
= form
.getParameterValues();
120 xRange
= form
.getXRange();
121 yRange
= form
.getYRange();
122 xLabel
= form
.getLabelOnX();
123 yLabel
= form
.getLabelOnY();
124 epsilon
= form
.getEpsilon();
125 period
= form
.getPeriod();
126 maxTries
= form
.getMaxTries();
128 catch (InvalidData e
) {
129 errorMessage
= e
.getMessage();
133 plot
.setNoData(false);
136 plotRenderer
.initialize(
137 parameters
, initial
, xLabel
, yLabel
,
138 epsilon
, period
, maxTries
);
140 plotRenderer
.setBigDots(bigDots
);
142 plot
.setDataRanges(xRange
, yRange
);
144 xAxis
.setLabel(xLabel
);
145 yAxis
.setLabel(yLabel
);
151 private void launchThread() {
153 plot
.getPlotRenderer().setState(DmcPlotRenderer
.STATE_NONE
);
155 Thread refreshJob
= new RefreshThread();
158 Thread plotJob
= new PlotThread("DMCDUE - Cycles plotter", false);
159 plotJob
.setPriority(Thread
.currentThread().getPriority() - 1);
163 class RefreshThread
extends Thread
{
165 int state
= CyclesRenderer
.STATE_NONE
;
169 super("DMCDUE - CyclesRefresh");
175 int newState
= plotRenderer
.getState();
177 if (newState
!= state
) {
182 case CyclesRenderer
.STATE_NONE
:
186 case CyclesRenderer
.STATE_RUNNING
:
187 // frame.progressString("plotting...");
190 case CyclesRenderer
.STATE_FINISHED
:
191 case CyclesRenderer
.STATE_STOPPED
:
192 // frame.progressString("ok. ");
200 if ((state
& CyclesRenderer
.STATE_RUNNING
) != 0 ) {
201 chartPanel
.repaint();
205 sleep(refreshSleepTime
);
207 catch (InterruptedException e2
) {}
212 public void stopRendering() {
216 public void setGridlines(final boolean flag
) {
217 plot
.setDrawGridLines(flag
);
220 public void setCrosshair(final boolean flag
) {
222 chartPanel
.setHorizontalAxisTrace(flag
);
223 chartPanel
.setVerticalAxisTrace(flag
);
226 public boolean isCrosshair() {
230 public void clear() {
231 plot
.setNoData(true);
236 public boolean isBigDots() {
240 public void setBigDots(boolean b
) {
244 public boolean isGridlines() {
248 public void setAlpha(final boolean flag
) {
252 public void setAlphaValue(final float f
) {
253 plot
.setForegroundAlpha(f
);
256 public float getAlphaValue() {
257 return plot
.getForegroundAlpha();