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 javax
.swing
.JComponent
;
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
.AbsorbingAreaRenderer
;
38 import org
.tsho
.dmc2
.core
.chart
.DmcPlotRenderer
;
39 import org
.tsho
.dmc2
.core
.model
.DifferentiableMap
;
40 import org
.tsho
.dmc2
.ui
.InvalidData
;
41 import org
.tsho
.dmc2
.ui
.absorbingArea
.AbsorbingAreaComponent
;
42 import org
.tsho
.dmc2
.ui
.absorbingArea
.AbsorbingAreaControlForm2
;
48 public class AbsorbingAreaManager
extends AbstractManager
49 implements AbstractManager
.Crosshair
,
50 AbstractManager
.AxesVisibility
{
52 private final DifferentiableMap model
;
53 private final AbsorbingAreaControlForm2 form
;
55 private AbsorbingAreaRenderer plotRenderer
;
57 private boolean crosshair
;
59 private final int refreshSleepTime
= 500;
61 public AbsorbingAreaManager(final DifferentiableMap model
,
62 final AbsorbingAreaControlForm2 form
,
63 final ManagerListener2 frame
) {
72 chartPanel
.setMouseZoomable(true, false);
73 chartPanel
.setPopupMenu(null);
74 setCrosshair(crosshair
);
76 plotRenderer
= new AbsorbingAreaRenderer(model
, plot
, (AbsorbingAreaComponent
) frame
);
77 plot
.setPlotRenderer(plotRenderer
);
79 plot
.setDrawGridLines(false);
80 chart
.setTitle(model
.getName());
82 plot
.addCoreStatusListener( new CoreStatusListener() {
83 public void sendCoreStatus(final CoreStatusEvent event
) {
84 if (event
.getType() == CoreStatusEvent
.REDRAW
) {
87 else if (event
.getType() == CoreStatusEvent
.REPAINT
) {
93 // stop everything on resizing
94 chartPanel
.addComponentListener(new ComponentAdapter() {
95 public void componentResized(final ComponentEvent e
) {
96 AbsorbingAreaManager
.this.stopRendering();
101 public boolean doRendering() {
103 plot
.setNoData(false);
105 String
[] vars
= model
.getVariables().labelsArray();
107 xAxis
.setLabel(vars
[0]);
108 if (model
.getNVar() > 1) {
109 yAxis
.setLabel(vars
[1]);
112 yAxis
.setLabel(vars
[0]);
115 plotRenderer
.initialize(
116 VariableDoubles
.toArray(form
.getParameterValues()),
118 form
.getIterations(),
119 form
.getTransients());
121 plot
.setDataRanges(form
.getXRange(), form
.getYRange());
123 catch (InvalidData e
) {
124 errorMessage
= e
.getMessage();
128 if (plot
.getPlotRenderer() != plotRenderer
) {
129 plot
.setPlotRenderer(plotRenderer
);
138 private void launchThread() {
140 plot
.getPlotRenderer().setState(DmcPlotRenderer
.STATE_NONE
);
142 Thread refreshJob
= new RefreshThread();
145 Thread plotJob
= new PlotThread("DMCDUE - AbsorbingArea plotter", false);
146 plotJob
.setPriority(Thread
.currentThread().getPriority() - 1);
151 class RefreshThread
extends Thread
{
153 int state
= AbsorbingAreaRenderer
.STATE_NONE
;
157 super("DMCDUE - AbsorbingArea refresh");
163 int newState
= plotRenderer
.getState();
165 if (newState
!= state
) {
170 case AbsorbingAreaRenderer
.STATE_NONE
:
174 case AbsorbingAreaRenderer
.STATE_RUNNING
:
175 // frame.progressString("plotting...");
178 case AbsorbingAreaRenderer
.STATE_FINISHED
:
179 // frame.progressString("ok. ");
187 if ((state
& AbsorbingAreaRenderer
.STATE_RUNNING
) != 0 ) {
188 chartPanel
.repaint();
192 sleep(refreshSleepTime
);
194 catch (InterruptedException e2
) {}
199 public void stopRendering() {
200 //here should come whatever is associated with stop in this case.
201 //note that this might depend on the current state
206 public void setGridlines(final boolean flag
) {
207 plot
.setDrawGridLines(flag
);
210 public void setCrosshair(final boolean flag
) {
212 chartPanel
.setHorizontalAxisTrace(flag
);
213 chartPanel
.setVerticalAxisTrace(flag
);
216 public boolean isCrosshair() {
220 public void clear() {
221 plot
.setNoData(true);
226 public AbsorbingAreaRenderer
getPlotRenderer(){
230 public void handleMouseClicked(int x
, int y
){
231 plotRenderer
.setMouseClicked(true);
232 plotRenderer
.setXClicked(x
);
233 plotRenderer
.setYClicked(y
);