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
.JFreeChart
;
33 import org
.jfree
.chart
.axis
.NumberAxis
;
34 import org
.jfree
.data
.Range
;
35 import org
.tsho
.dmc2
.core
.CoreStatusEvent
;
36 import org
.tsho
.dmc2
.core
.CoreStatusListener
;
37 import org
.tsho
.dmc2
.core
.VariableDoubles
;
38 import org
.tsho
.dmc2
.core
.chart
.DmcPlotRenderer
;
39 import org
.tsho
.dmc2
.core
.chart
.DmcRenderablePlot
;
40 import org
.tsho
.dmc2
.core
.chart
.ManifoldsRenderer
;
41 import org
.tsho
.dmc2
.core
.chart
.jfree
.DmcChartPanel
;
42 import org
.tsho
.dmc2
.core
.model
.DifferentiableMap
;
43 import org
.tsho
.dmc2
.ui
.InvalidData
;
44 import org
.tsho
.dmc2
.ui
.manifolds
.ManifoldsControlForm2
;
46 public class ManifoldsManager
extends AbstractManager
47 implements AbstractManager
.GridLines
,
48 AbstractManager
.Crosshair
,
49 AbstractManager
.AxesVisibility
{
51 private final DifferentiableMap model
;
52 private final ManifoldsControlForm2 form
;
54 private ManifoldsRenderer plotRenderer
;
56 private boolean gridlines
;
57 private boolean crosshair
;
58 private byte plotType
;
60 public ManifoldsManager(
61 final DifferentiableMap model
,
62 final ManifoldsControlForm2 form
,
63 final ManagerListener2 frame
) {
74 plotRenderer
= new ManifoldsRenderer(model
, plot
);
75 plot
.setPlotRenderer(plotRenderer
);
77 plot
.setForegroundAlpha(0.2F
);
78 plot
.setAntialias(false);
80 setCrosshair(crosshair
);
81 chart
.setTitle(model
.getName());
83 plot
.addCoreStatusListener(new CoreStatusListener() {
84 public void sendCoreStatus(final CoreStatusEvent event
) {
85 if (event
.getType() == CoreStatusEvent
.REDRAW
) {
88 else if (event
.getType() == CoreStatusEvent
.REPAINT
) {
94 // stop everything on resizing
95 chartPanel
.addComponentListener(new ComponentAdapter() {
96 public void componentResized(final ComponentEvent e
) {
97 ManifoldsManager
.this.stopRendering();
102 public ManifoldsManager(
103 final DifferentiableMap model
,
104 final ManifoldsControlForm2 form
,
105 final ManagerListener2 frame
,
106 final DmcChartPanel otherPanel
) {
117 xAxis
= (NumberAxis
) ((DmcRenderablePlot
) otherPanel
.getChart().getPlot()).getDomainAxis();
118 yAxis
= (NumberAxis
) ((DmcRenderablePlot
) otherPanel
.getChart().getPlot()).getRangeAxis();
120 plot
= new DmcRenderablePlot(xAxis
, yAxis
);
121 plotRenderer
= new ManifoldsRenderer(model
, plot
);
122 plot
.setPlotRenderer(plotRenderer
);
124 plot
.addCoreStatusListener(new CoreStatusListener() {
125 public void sendCoreStatus(final CoreStatusEvent event
) {
126 if (event
.getType() == CoreStatusEvent
.REDRAW
) {
129 else if (event
.getType() == CoreStatusEvent
.REPAINT
) {
130 chartPanel
.repaint();
135 chart
= new JFreeChart(model
.getName(), plot
);
137 chartPanel
= new DmcChartPanel(chart
);
138 chartPanel
.setMouseZoomable(true, false);
140 // stop everything on resizing
141 chartPanel
.addComponentListener(new ComponentAdapter() {
142 public void componentResized(final ComponentEvent e
) {
143 ManifoldsManager
.this.stopRendering();
147 setCrosshair(crosshair
);
151 public boolean doRendering(final boolean redraw
) {
153 return render(redraw
);
157 public boolean render(boolean redraw
) {
158 VariableDoubles parameters
;
159 VariableDoubles initial
;
162 Range horRange
, verRange
;
163 Range lockoutHRange
, lockoutVRange
;
164 int firstIteration
, lastIteration
;
167 initial
= form
.getNodeValues();
168 parameters
= form
.getParameterValues();
169 epsilon
= form
.getEpsilon();
170 horRange
= form
.getHorizontalRange();
171 verRange
= form
.getVerticalRange();
172 lockoutHRange
= form
.getLockoutHRange();
173 lockoutVRange
= form
.getLockoutVRange();
174 firstIteration
= form
.getIterationsFirst();
175 lastIteration
= form
.getIterationsLast();
177 catch (InvalidData e
) {
178 getFrame().showInvalidDataDialog(e
.getMessage());
182 plot
.setNoData(false);
183 plot
.setDrawGridLines(gridlines
);
185 if (plot
.getPlotRenderer() != plotRenderer
) {
186 plot
.setPlotRenderer(plotRenderer
);
189 plotRenderer
.initialize(
191 initial
, parameters
, epsilon
, lockoutHRange
,
192 lockoutVRange
, firstIteration
, lastIteration
);
194 //xAxis.setLabel(parLabel);
195 //yAxis.setLabel(varLabel);
198 plot
.setDataRanges(horRange
, verRange
);
205 class RefreshThread
extends Thread
{
206 int state
= ManifoldsRenderer
.STATE_NONE
;
209 super("DMCDUE - ManifoldsRefresh");
215 int newState
= plotRenderer
.getState();
217 if (newState
!= state
) {
222 case ManifoldsRenderer
.STATE_NONE
:
226 case ManifoldsRenderer
.STATE_RUNNING
:
227 // ratio = plot.getIterations();
228 // frame.progressString("plotting...");
231 case ManifoldsRenderer
.STATE_FINISHED
:
232 // frame.progressString("ok. ");
236 case ManifoldsRenderer
.STATE_STOPPED
:
237 // frame.progressString("stopped, ok.");
246 if ((state
& ManifoldsRenderer
.STATE_RUNNING
) != 0 ) {
248 chartPanel
.repaint();
254 catch (InterruptedException e2
) {}
258 // private void report() {
259 // frame.progressCount(plot.getIndex());
261 // frame.progressPercent((plot.getIndex() * 100 / ratio));
266 private void launchThread() {
268 plot
.getPlotRenderer().setState(DmcPlotRenderer
.STATE_NONE
);
270 Thread refreshJob
= new RefreshThread();
273 Thread plotJob
= new PlotThread("DMCDUE - Manifoldes plotter", false);
274 plotJob
.setPriority(Thread
.currentThread().getPriority() - 1);
278 public void stopRendering() {
282 public void setAlpha(boolean flag
) {
286 public void setAlphaValue(float f
) {
287 plot
.setForegroundAlpha(f
);
290 public float getAlphaValue() {
291 return plot
.getForegroundAlpha();
294 public void setCrosshair(boolean flag
) {
296 chartPanel
.setHorizontalAxisTrace(flag
);
297 chartPanel
.setVerticalAxisTrace(flag
);
300 public boolean isCrosshair() {
304 public boolean isGridlines() {
308 public void setGridlines(boolean b
) {
312 public void clear() {
313 plot
.setNoData(true);
318 public byte getPlotType() {
322 public void setPlotType(byte b
) {
324 case (ManifoldsRenderer
.TYPE_UNSTABLE
| ManifoldsRenderer
.TYPE_STABLE
):
328 case ManifoldsRenderer
.TYPE_UNSTABLE
:
329 plotType
&= ~ManifoldsRenderer
.TYPE_STABLE
;
330 plotType
|= ManifoldsRenderer
.TYPE_UNSTABLE
;
333 case ManifoldsRenderer
.TYPE_STABLE
:
334 plotType
&= ~ManifoldsRenderer
.TYPE_UNSTABLE
;
335 plotType
|= ManifoldsRenderer
.TYPE_STABLE
;
338 case (ManifoldsRenderer
.TYPE_RIGHT
| ManifoldsRenderer
.TYPE_LEFT
):
342 case ManifoldsRenderer
.TYPE_RIGHT
:
343 plotType
&= ~ManifoldsRenderer
.TYPE_LEFT
;
344 plotType
|= ManifoldsRenderer
.TYPE_RIGHT
;
347 case ManifoldsRenderer
.TYPE_LEFT
:
348 plotType
&= ~ManifoldsRenderer
.TYPE_RIGHT
;
349 plotType
|= ManifoldsRenderer
.TYPE_LEFT
;