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>.
11 * The software program was developed within a research project financed
12 * by the Italian Ministry of Universities, the Universities of Udine and
13 * Ca'Foscari of Venice, the Friuli-Venezia Giulia Region.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or any
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.
25 package org
.tsho
.dmc2
.ui
.manifolds
;
27 import java
.awt
.Component
;
29 import java
.io
.IOException
;
31 import javax
.swing
.JFrame
;
32 import javax
.swing
.JPanel
;
33 import javax
.swing
.WindowConstants
;
35 import org
.jfree
.data
.Range
;
36 import org
.tsho
.dmc2
.core
.VariableDoubles
;
37 import org
.tsho
.dmc2
.core
.VariableItems
;
38 import org
.tsho
.dmc2
.core
.dlua
.Lua
;
39 import org
.tsho
.dmc2
.core
.model
.Model
;
40 import org
.tsho
.dmc2
.core
.model
.ModelException
;
41 import org
.tsho
.dmc2
.ui
.AbstractControlForm
;
42 import org
.tsho
.dmc2
.ui
.AbstractPlotComponent
;
43 import org
.tsho
.dmc2
.ui
.FormHelper
;
44 import org
.tsho
.dmc2
.ui
.InvalidData
;
45 import org
.tsho
.dmc2
.ui
.components
.GetFloat
;
46 import org
.tsho
.dmc2
.ui
.components
.GetInt
;
48 import com
.jgoodies
.forms
.layout
.CellConstraints
;
49 import com
.jgoodies
.forms
.layout
.FormLayout
;
50 import com
.jgoodies
.forms
.layout
.RowSpec
;
52 public final class ManifoldsControlForm2
extends AbstractControlForm
{
54 private VariableItems nodeFields
;
55 private VariableItems parFields
;
57 private GetFloat epsilonField
;
59 private GetInt firstIterationField
;
60 private GetInt lastIterationField
;
62 private GetFloat lowerHLRangeField
;
63 private GetFloat upperHLRangeField
;
64 private GetFloat lowerVLRangeField
;
65 private GetFloat upperVLRangeField
;
67 private GetFloat lowerHRangeField
;
68 private GetFloat upperHRangeField
;
69 private GetFloat lowerVRangeField
;
70 private GetFloat upperVRangeField
;
72 public ManifoldsControlForm2(final Model model
, AbstractPlotComponent frame
) {
76 nodeFields
= FormHelper
.createFields(
77 model
.getVarNames(), "node");
78 parFields
= FormHelper
.createFields(model
.getParNames(), "parameter");
80 epsilonField
= new GetFloat(
81 "epsilon", FormHelper
.FIELD_LENGTH
,
82 new Range(0, Double
.MAX_VALUE
));
84 firstIterationField
= new GetInt(
85 "first iteration", FormHelper
.FIELD_LENGTH
,
86 new Range(1, Integer
.MAX_VALUE
));
88 lastIterationField
= new GetInt(
89 "last iteration", FormHelper
.FIELD_LENGTH
,
90 new Range(1, Integer
.MAX_VALUE
));
92 lowerHLRangeField
= new GetFloat(
93 "lower horizontal lockout range", FormHelper
.FIELD_LENGTH
);
94 upperHLRangeField
= new GetFloat(
95 "upper horizontal lockout range", FormHelper
.FIELD_LENGTH
);
96 lowerVLRangeField
= new GetFloat(
97 "lower vertical lockout range", FormHelper
.FIELD_LENGTH
);
98 upperVLRangeField
= new GetFloat(
99 "upper vertical lockout range", FormHelper
.FIELD_LENGTH
);
101 lowerHRangeField
= new GetFloat(
102 "lower horizontal plot range", FormHelper
.FIELD_LENGTH
);
103 upperHRangeField
= new GetFloat(
104 "upper horizontal plot range", FormHelper
.FIELD_LENGTH
);
105 lowerVRangeField
= new GetFloat(
106 "lower vertical plot range", FormHelper
.FIELD_LENGTH
);
107 upperVRangeField
= new GetFloat(
108 "upper vertical plot range", FormHelper
.FIELD_LENGTH
);
110 FormLayout layout
= new FormLayout("f:p:n", "");
113 layout
.appendRow(new RowSpec("f:p:n"));
114 add(createPanel(), new CellConstraints(1, 1));
117 private JPanel
createPanel() {
119 FormHelper
.FormBuilder builder
;
120 builder
= FormHelper
.controlFormBuilder(this,false);
122 VariableItems
.Iterator i
;
124 builder
.addTitle("Parameters");
125 i
= parFields
.iterator();
126 while (i
.hasNext()) {
127 builder
.addRow(i
.nextLabel(), (Component
) i
.value());
130 builder
.addTitle("Node approximation");
131 i
= nodeFields
.iterator();
132 while (i
.hasNext()) {
133 builder
.addRow(i
.nextLabel(), (Component
) i
.value());
136 builder
.addTitle("Algorithm");
137 builder
.addRow("epsilon", epsilonField
);
139 builder
.addSubtitle("iterations");
140 builder
.addRow("first", firstIterationField
);
141 builder
.addRow("last", lastIterationField
);
143 builder
.addTitle("Plot ranges");
144 builder
.addSubtitle("horizontal");
145 builder
.addRow("min", lowerHRangeField
);
146 builder
.addRow("max", upperHRangeField
);
148 builder
.addSubtitle("vertical");
149 builder
.addRow("min", lowerVRangeField
);
150 builder
.addRow("max", upperVRangeField
);
152 builder
.addTitle("Lockout region ranges");
153 builder
.addSubtitle("horizontal");
154 builder
.addRow("min", lowerHLRangeField
);
155 builder
.addRow("max", upperHLRangeField
);
157 builder
.addSubtitle("vertical");
158 builder
.addRow("min", lowerVLRangeField
);
159 builder
.addRow("max", upperVLRangeField
);
161 return builder
.getPanel();
166 public void setEnabled(boolean flag
) {
167 super.setEnabled(flag
);
169 VariableItems
.Iterator i
;
170 i
= parFields
.iterator();
171 while (i
.hasNext()) {
172 ((GetFloat
) i
.nextValue()).setEditable(flag
);
174 i
= nodeFields
.iterator();
175 while (i
.hasNext()) {
176 ((GetFloat
) i
.nextValue()).setEditable(flag
);
179 epsilonField
.setEditable(flag
);
180 firstIterationField
.setEditable(flag
);
181 lastIterationField
.setEditable(flag
);
182 lowerHRangeField
.setEditable(flag
);
183 upperHRangeField
.setEditable(flag
);
184 lowerVRangeField
.setEditable(flag
);
185 upperVRangeField
.setEditable(flag
);
187 lowerHLRangeField
.setEditable(flag
);
188 upperHLRangeField
.setEditable(flag
);
189 lowerVLRangeField
.setEditable(flag
);
190 upperVLRangeField
.setEditable(flag
);
195 public VariableDoubles
getParameterValues() throws InvalidData
{
196 return FormHelper
.collectFieldValues(parFields
);
199 public void setParameterValues(final VariableDoubles init
) {
200 FormHelper
.setFieldValues(parFields
, init
);
205 public VariableDoubles
getNodeValues() throws InvalidData
{
206 return FormHelper
.collectFieldValues(nodeFields
);
209 public void setNodeValues(final VariableDoubles init
) {
210 FormHelper
.setFieldValues(nodeFields
, init
);
215 public double getEpsilon() throws InvalidData
{
216 return epsilonField
.getValue();
219 public void setEpsilon(double value
) {
220 epsilonField
.setValue(value
);
225 public int getIterationsFirst() throws InvalidData
{
226 if (firstIterationField
.getValue() > lastIterationField
.getValue()) {
227 throw new InvalidData("Invalid iterations values");
229 return firstIterationField
.getValue();
232 public void setIterationsFirst(int t
) {
233 firstIterationField
.setValue(t
);
236 public int getIterationsLast() throws InvalidData
{
237 return lastIterationField
.getValue();
240 public void setIterationsLast(int t
) {
241 lastIterationField
.setValue(t
);
246 public Range
getHorizontalRange() throws InvalidData
{
247 if (lowerHRangeField
.getValue() >= upperHRangeField
.getValue()) {
248 throw new InvalidData("Invalid horizontal range");
251 lowerHRangeField
.getValue(), upperHRangeField
.getValue());
254 public void setHorizontalRange(Range range
) {
255 lowerHRangeField
.setValue(range
.getLowerBound());
256 upperHRangeField
.setValue(range
.getUpperBound());
259 public Range
getVerticalRange() throws InvalidData
{
260 if (lowerVRangeField
.getValue() >= upperVRangeField
.getValue()) {
261 throw new InvalidData("Invalid vertical range");
264 lowerHRangeField
.getValue(), upperHRangeField
.getValue());
267 public void setVerticalRange(Range range
) {
268 lowerHRangeField
.setValue(range
.getLowerBound());
269 upperHRangeField
.setValue(range
.getUpperBound());
274 public Range
getLockoutHRange() throws InvalidData
{
275 if (lowerHLRangeField
.getValue() >= upperHLRangeField
.getValue()) {
276 throw new InvalidData("Invalid horizontal range");
279 lowerHLRangeField
.getValue(), upperHLRangeField
.getValue());
282 public void setLockoutHRange(Range range
) {
283 lowerHLRangeField
.setValue(range
.getLowerBound());
284 upperHLRangeField
.setValue(range
.getUpperBound());
287 public Range
getLockoutVRange() throws InvalidData
{
288 if (lowerVLRangeField
.getValue() >= upperVLRangeField
.getValue()) {
289 throw new InvalidData("Invalid vertical range");
292 lowerHLRangeField
.getValue(), upperHLRangeField
.getValue());
295 public void setLockoutVRange(Range range
) {
296 lowerHLRangeField
.setValue(range
.getLowerBound());
297 upperHLRangeField
.setValue(range
.getUpperBound());
304 public static void main(String[] args) {
308 File f = new File("/home/tsho-debian/workspace.common/dmcDue/models/lorenz.lua");
309 // File f = new File("/home/tsho-debian/workspace.common/dmcDue/models/logist.lua");
310 model = Lua.newModel(f);
312 catch (IOException e) {
315 catch (ModelException e) {
319 JFrame frame = new JFrame();
320 frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
321 ManifoldsControlForm2 panel = new ManifoldsControlForm2(model);
322 frame.getContentPane().add(panel);
323 frame.setTitle(panel.getClass().getName());
330 protected String
getFormType() {