added contact information in 'about' box
[iDMC.git] / src / java / org / tsho / dmc2 / ui / InfoPanel.java
blobc2e0cb47035718d7901b76bb40ff4b2781107a2e
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;
29 import java.awt.BorderLayout;
31 import javax.swing.JPanel;
32 import javax.swing.JScrollPane;
33 import javax.swing.JTextArea;
35 import org.tsho.dmc2.core.model.DifferentiableMap;
36 import org.tsho.dmc2.core.model.InvertibleMap;
37 import org.tsho.dmc2.core.model.Model;
38 import org.tsho.dmc2.core.model.ODE;
39 import org.tsho.dmc2.core.model.SimpleMap;
41 import com.jgoodies.forms.builder.DefaultFormBuilder;
42 import com.jgoodies.forms.layout.CellConstraints;
43 import com.jgoodies.forms.layout.FormLayout;
45 public class InfoPanel extends JPanel {
47 private static Thread showMemoryThread;
49 public InfoPanel(Model model) {
50 super();
52 String modelName = null;
53 String modelType = null;
54 String modelDesc = null;
55 String modelText = null;
56 String modelDim = null;
57 String modelPar = null;
59 if (model != null) {
60 modelName = model.getName();
62 if (model instanceof SimpleMap) {
63 modelType = "discrete";
65 else if (model instanceof ODE) {
66 modelType = "continuous";
68 else {
69 modelType = "undefined (error)";
71 //modelDesc = model.getDescription();
72 modelDesc = null;
73 modelText = model.getModelText();
74 modelDim = Integer.toString(model.getNVar());
75 modelPar = Integer.toString(model.getNPar());
78 //DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
80 FormLayout layout = new FormLayout(
81 // "l:9dlu:n, l:p:n, l:4dlu:n, l:90dlu:n, l:8dlu:n",
82 "l:9dlu:n, l:p:n, l:4dlu:n, l:p:g, l:8dlu:n",
83 "");
85 DefaultFormBuilder builder = new DefaultFormBuilder(this, layout);
86 CellConstraints cc = new CellConstraints();
88 builder.setDefaultDialogBorder();
89 builder.setLeadingColumnOffset(1);
91 builder.appendSeparator("Model specification");
93 JTextArea textField = new JTextArea(modelName);
94 textField.setEditable(false);
95 textField.setLineWrap(true);
96 builder.append("Name:", textField);
98 textField = new JTextArea(modelType);
99 textField.setEditable(false);
100 textField.setLineWrap(true);
101 builder.append("Type:", textField);
103 textField = new JTextArea(modelDim);
104 textField.setEditable(false);
105 textField.setLineWrap(true);
106 builder.append("Dimension:", textField);
108 textField = new JTextArea(modelPar);
109 textField.setEditable(false);
110 textField.setLineWrap(true);
111 builder.append("Parameters:", textField);
113 String str;
114 if (model instanceof InvertibleMap) {
115 str = "yes";
117 else {
118 str = "no";
120 textField = new JTextArea(str);
121 textField.setEditable(false);
122 textField.setLineWrap(true);
123 builder.append("Has inverse:", textField);
125 if (model instanceof DifferentiableMap) {
126 str = "yes";
128 else {
129 str = "no";
131 textField = new JTextArea(str);
132 textField.setEditable(false);
133 textField.setLineWrap(true);
134 builder.append("Has jacobian:", textField);
136 if (modelDesc != null) {
137 builder.appendSeparator("Model description");
139 textField = new JTextArea(modelDesc);
140 textField.setEditable(false);
141 textField.setLineWrap(true);
142 textField.setWrapStyleWord(true);
143 builder.appendRow(builder.getLineGapSpec());
144 builder.appendRow("t:p:n");
145 builder.nextLine(2);
146 //builder.append("Model description:");
147 builder.add(textField,
148 cc.xywh(builder.getColumn(), builder.getRow(), 3, 1));
150 builder.nextLine();
153 if (modelText != null) {
154 builder.appendSeparator("Model text");
156 JPanel panel = new JPanel(new BorderLayout());
157 JTextArea area = new JTextArea(modelText);
158 area.setLineWrap(false);
159 //area.setWrapStyleWord(true);
160 area.setCaretPosition(0);
161 area.setEditable(false);
162 panel.add(new JScrollPane(area));
163 builder.appendRow(builder.getLineGapSpec());
164 builder.appendRow("t:50dlu:g");
165 builder.nextLine(2);
166 //builder.append("Model description:");
167 builder.add(panel,
168 cc.xywh(builder.getColumn(), builder.getRow(), 3, 1));
170 builder.nextLine();
173 builder.appendSeparator("Memory");
175 final JTextArea maxMem = new JTextArea("1");
176 maxMem.setEditable(false);
177 maxMem.setLineWrap(true);
178 builder.append("Max memory:", maxMem);
180 final JTextArea totMem = new JTextArea();
181 totMem.setEditable(false);
182 totMem.setLineWrap(true);
183 builder.append("Total memory:", totMem);
185 final JTextArea freeMem = new JTextArea();
186 freeMem.setEditable(false);
187 freeMem.setLineWrap(true);
188 builder.append("Free memory:", freeMem);
190 // TODO kludge
191 if (showMemoryThread != null) {
192 showMemoryThread.interrupt();
195 // TODO change this to a swing timer
196 showMemoryThread = new Thread("showMemory") {
197 public void run() {
198 Runtime runtime;
199 do {
200 runtime = Runtime.getRuntime();
201 maxMem.setText(Long.toString(runtime.maxMemory()/ (1024 * 1024)) + " MB");
202 totMem.setText(Long.toString(runtime.totalMemory() / (1024 * 1024)) + " MB");
203 freeMem.setText(Long.toString(runtime.freeMemory() / (1024 * 1024)) + " MB");
205 if (Thread.interrupted()) {
206 break;
208 try {
209 Thread.sleep(2000);
210 } catch (InterruptedException e) {
211 break;
213 } while(true);
217 showMemoryThread.start();
220 public void dispose() {
221 // showMemoryThread.interrupt();
222 // showMemoryThread = null;