initial import
[iDMC.git] / src / java / org / tsho / dmc2 / ui / basin / BasinControlForm2.java
bloba85c673c7083c139ffbea0851d486c3df10e118b
1 /*
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
20 * later version.
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.ui.basin;
29 import java.awt.Component;
30 import java.io.File;
31 import java.io.IOException;
33 import javax.swing.JFrame;
34 import javax.swing.JPanel;
35 import javax.swing.WindowConstants;
37 import org.jfree.data.Range;
38 import org.tsho.dmc2.core.VariableDoubles;
39 import org.tsho.dmc2.core.VariableItems;
40 import org.tsho.dmc2.core.dlua.Lua;
41 import org.tsho.dmc2.core.model.Model;
42 import org.tsho.dmc2.core.model.ModelException;
43 import org.tsho.dmc2.ui.AbstractControlForm;
44 import org.tsho.dmc2.ui.AbstractPlotComponent;
45 import org.tsho.dmc2.ui.FormHelper;
46 import org.tsho.dmc2.ui.InvalidData;
47 import org.tsho.dmc2.ui.components.GetFloat;
48 import org.tsho.dmc2.ui.components.GetInt;
50 import com.jgoodies.forms.layout.CellConstraints;
51 import com.jgoodies.forms.layout.FormLayout;
52 import com.jgoodies.forms.layout.RowSpec;
54 public final class BasinControlForm2 extends AbstractControlForm {
56 private VariableItems parFields;
57 private GetFloat infinityField;
58 private GetInt limitField;
59 private GetInt iterationsField;
60 private GetInt trialsField;
61 private GetFloat lowerHRangeField;
62 private GetFloat upperHRangeField;
63 private GetFloat lowerVRangeField;
64 private GetFloat upperVRangeField;
65 private int type;
67 public BasinControlForm2(final Model model, AbstractPlotComponent frame) {
68 super(frame);
69 setOpaque(true);
70 type=0;//currently the only type for the basin component
72 parFields = FormHelper.createFields(model.getParNames(), "parameter");
74 infinityField = new GetFloat(
75 "infinity", FormHelper.FIELD_LENGTH,
76 new Range(0, Double.MAX_VALUE));
78 limitField = new GetInt(
79 "limit", FormHelper.FIELD_LENGTH,
80 new Range(1, Integer.MAX_VALUE));
82 iterationsField = new GetInt(
83 "limits", FormHelper.FIELD_LENGTH,
84 new Range(1, Integer.MAX_VALUE));
86 trialsField=new GetInt(
87 "trials",FormHelper.FIELD_LENGTH,
88 new Range(1,Integer.MAX_VALUE));
90 lowerHRangeField = new GetFloat(
91 "lower horizontal range", FormHelper.FIELD_LENGTH);
92 upperHRangeField = new GetFloat(
93 "upper horizontal range", FormHelper.FIELD_LENGTH);
94 lowerVRangeField = new GetFloat(
95 "lower vertical range", FormHelper.FIELD_LENGTH);
96 upperVRangeField = new GetFloat(
97 "upper vertical range", FormHelper.FIELD_LENGTH);
99 FormLayout layout = new FormLayout("f:p:n", "");
101 setLayout(layout);
102 layout.appendRow(new RowSpec("f:p:n"));
103 add(createPanel(), new CellConstraints(1, 1));
106 private JPanel createPanel() {
108 FormHelper.FormBuilder builder;
109 builder = FormHelper.controlFormBuilder(this,false);
111 VariableItems.Iterator i;
112 builder.addTitle("Parameters");
113 i = parFields.iterator();
114 while (i.hasNext()) {
115 builder.addRow(i.nextLabel(), (Component) i.value());
118 builder.addTitle("Algorithm");
119 builder.addRow("infinity", infinityField);
121 builder.addSubtitle("attractor");
122 builder.addRow("transients", limitField);
123 builder.addRow("iterations", iterationsField);
124 builder.addRow("trials",trialsField);
125 builder.addGap();
127 builder.addTitle("Ranges");
128 builder.addSubtitle("horizontal");
129 builder.addRow("min", lowerHRangeField);
130 builder.addRow("max", upperHRangeField);
131 builder.addGap();
132 builder.addSubtitle("vertical");
133 builder.addRow("min", lowerVRangeField);
134 builder.addRow("max", upperVRangeField);
136 return builder.getPanel();
139 // Enabled state
141 public void setEnabled(boolean flag) {
142 super.setEnabled(flag);
144 VariableItems.Iterator i;
145 i = parFields.iterator();
146 while (i.hasNext()) {
147 ((GetFloat) i.nextValue()).setEditable(flag);
149 infinityField.setEditable(flag);
150 limitField.setEditable(flag);
151 iterationsField.setEditable(flag);
152 trialsField.setEditable(flag);
153 lowerHRangeField.setEditable(flag);
154 upperHRangeField.setEditable(flag);
155 lowerVRangeField.setEditable(flag);
156 upperVRangeField.setEditable(flag);
159 // Parameters
161 public VariableDoubles getParameterValues() throws InvalidData {
162 return FormHelper.collectFieldValues(parFields);
165 public void setParameterValues(final VariableDoubles init) {
166 FormHelper.setFieldValues(parFields, init);
169 // Power
171 public double getInfinity() throws InvalidData {
172 return infinityField.getValue();
175 public void setInfinity(double value) {
176 infinityField.setValue(value);
179 // Limit
181 public int getLimit() throws InvalidData {
182 return limitField.getValue();
185 public void setLimit(int t) {
186 limitField.setValue(t);
189 // Limit
191 public int getIterations() throws InvalidData {
192 return iterationsField.getValue();
195 public void setIterations(int t) {
196 iterationsField.setValue(t);
199 //trials
201 public int getTrials() throws InvalidData{
202 return trialsField.getValue();
205 public void setTrials(int t){
206 trialsField.setValue(t);
209 // Ranges
211 public Range getXRange() throws InvalidData {
212 if (lowerHRangeField.getValue() >= upperHRangeField.getValue()) {
213 throw new InvalidData("Invalid horizontal range");
215 return new Range(
216 lowerHRangeField.getValue(), upperHRangeField.getValue());
219 public void setXRange(Range range) {
220 lowerHRangeField.setValue(range.getLowerBound());
221 upperHRangeField.setValue(range.getUpperBound());
224 public Range getYRange() throws InvalidData {
225 if (lowerVRangeField.getValue() >= upperVRangeField.getValue()) {
226 throw new InvalidData("Invalid vertical range");
228 return new Range(
229 lowerVRangeField.getValue(), upperVRangeField.getValue());
232 public void setYRange(Range range) {
233 lowerHRangeField.setValue(range.getLowerBound());
234 upperHRangeField.setValue(range.getUpperBound());
238 protected String getFormType() {
239 //return AbstractControlForm.BASIN+"_B"+type;
240 return "BASIN"+"_B"+type;
243 public void setType(int type){
244 this.type=type;