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
.BasinRenderer
;
38 import org
.tsho
.dmc2
.core
.chart
.DmcPlotRenderer
;
39 import org
.tsho
.dmc2
.core
.model
.SimpleMap
;
40 import org
.tsho
.dmc2
.ui
.InvalidData
;
41 import org
.tsho
.dmc2
.ui
.basin
.BasinControlForm2
;
42 import org
.tsho
.dmc2
.core
.util
.*;
43 import org
.tsho
.dmc2
.ui
.basin
.*;
49 public class BasinManager
extends AbstractManager
50 implements AbstractManager
.Crosshair
,
51 AbstractManager
.AxesVisibility
,
52 AbstractManager
.BigDots
{
54 private final SimpleMap model
;
55 private final BasinControlForm2 form
;
57 private BasinComponent component
;
58 private BasinRenderer plotRenderer
;
60 private boolean crosshair
;
62 private boolean bigDotsEnabled
=false;
64 private final int refreshSleepTime
= 500;
66 public BasinManager(BasinComponent component
) {
68 super((ManagerListener2
) component
);
69 this.component
= component
;
70 this.model
= (SimpleMap
) component
.getModel();
71 this.form
= (BasinControlForm2
) component
.getControlForm();
75 chartPanel
.setMouseZoomable(true, false);
76 chartPanel
.setPopupMenu(null);
77 setCrosshair(crosshair
);
79 plotRenderer
= new BasinRenderer(model
, plot
, component
);
80 plot
.setPlotRenderer(plotRenderer
);
82 plot
.setDrawGridLines(false);
83 chart
.setTitle(model
.getName());
85 plot
.addCoreStatusListener( new CoreStatusListener() {
86 public void sendCoreStatus(final CoreStatusEvent event
) {
87 if (event
.getType() == CoreStatusEvent
.REDRAW
) {
90 else if (event
.getType() == CoreStatusEvent
.REPAINT
) {
96 // stop everything on resizing
97 chartPanel
.addComponentListener(new ComponentAdapter() {
98 public void componentResized(final ComponentEvent e
) {
99 BasinManager
.this.stopRendering();
104 public boolean doRendering() {
106 plot
.setNoData(false);
108 String
[] vars
= model
.getVariables().labelsArray();
110 xAxis
.setLabel(vars
[0]);
111 if (model
.getNVar() > 1) {
112 yAxis
.setLabel(vars
[1]);
115 yAxis
.setLabel(vars
[0]);
118 plotRenderer
.initialize(
119 VariableDoubles
.toArray(form
.getParameterValues()),
121 form
.getIterations(),
125 plot
.setDataRanges(form
.getXRange(), form
.getYRange());
127 catch (InvalidData e
) {
128 errorMessage
= e
.getMessage();
132 if (plot
.getPlotRenderer() != plotRenderer
) {
133 plot
.setPlotRenderer(plotRenderer
);
142 private void launchThread() {
144 plot
.getPlotRenderer().setState(DmcPlotRenderer
.STATE_NONE
);
146 Thread refreshJob
= new RefreshThread();
149 Thread plotJob
= new PlotThread("DMCDUE - Basin plotter", false);
150 plotJob
.setPriority(Thread
.currentThread().getPriority() - 1);
155 class RefreshThread
extends Thread
{
157 int state
= BasinRenderer
.STATE_NONE
;
161 super("DMCDUE - Basin refresh");
167 int newState
= plotRenderer
.getState();
169 if (newState
!= state
) {
174 case BasinRenderer
.STATE_NONE
:
178 case BasinRenderer
.STATE_RUNNING
:
179 // frame.progressString("plotting...");
182 case BasinRenderer
.STATE_FINISHED
:
183 // frame.progressString("ok. ");
191 if ((state
& BasinRenderer
.STATE_RUNNING
) != 0 ) {
192 chartPanel
.repaint();
196 sleep(refreshSleepTime
);
198 catch (InterruptedException e2
) {}
203 public void stopRendering() {
207 public void setGridlines(final boolean flag
) {
208 plot
.setDrawGridLines(flag
);
211 public void setCrosshair(final boolean flag
) {
213 chartPanel
.setHorizontalAxisTrace(flag
);
214 chartPanel
.setVerticalAxisTrace(flag
);
217 public boolean isCrosshair() {
221 public void clear() {
222 plot
.setNoData(true);
227 public BasinRenderer
getPlotRenderer(){
231 public boolean isBigDots() {
232 return bigDotsEnabled
;
235 public void setBigDots(boolean flag
) {
237 plotRenderer
.setBigDotsEnabled(flag
);