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
.ui
;
29 import java
.awt
.event
.ItemEvent
;
30 import java
.awt
.event
.ItemListener
;
32 import javax
.swing
.JCheckBox
;
33 import javax
.swing
.JOptionPane
;
34 import javax
.swing
.JPanel
;
35 import javax
.swing
.JSpinner
;
36 import javax
.swing
.SpinnerNumberModel
;
37 import javax
.swing
.event
.ChangeEvent
;
38 import javax
.swing
.event
.ChangeListener
;
40 import com
.jgoodies
.forms
.builder
.DefaultFormBuilder
;
41 import com
.jgoodies
.forms
.layout
.FormLayout
;
46 * To change the template for this generated type comment go to
47 * Window>Preferences>Java>Code Generation>Code and Comments
49 public class WindowsSizePanel
extends JPanel
50 implements ChangeListener
, ItemListener
{
52 private final JSpinner wSpinner
= new JSpinner();
53 private final JSpinner hSpinner
= new JSpinner();
54 private final JCheckBox checkBox
;
56 private final SpinnerNumberModel hModel
;
57 private final SpinnerNumberModel vModel
;
59 private static final boolean DEFAULT_CHECKBOX_SELECTED
= true;
64 public WindowsSizePanel(int width
, int height
) {
67 hModel
= new SpinnerNumberModel(width
, 0, Integer
.MAX_VALUE
, 10);
68 vModel
= new SpinnerNumberModel(height
, 0, Integer
.MAX_VALUE
, 10);
69 wSpinner
.setModel(hModel
);
70 hSpinner
.setModel(vModel
);
72 checkBox
= new JCheckBox();
73 checkBox
.addItemListener(this);
75 if (DEFAULT_CHECKBOX_SELECTED
== true) {
76 checkBox
.setSelected(true);
79 FormLayout layout
= new FormLayout(
80 "right:max(40dlu;pref), 3dlu, fill:min(30dlu;pref), 20dlu",
83 DefaultFormBuilder builder
;
85 builder
= new DefaultFormBuilder(this, layout
);
87 builder
.setDefaultDialogBorder();
89 builder
.appendSeparator("Plot dimensions");
92 builder
.appendRow(builder
.getLineGapSpec());
95 builder
.append("Width", wSpinner
);
98 builder
.append("Height", hSpinner
);
101 builder
.append("Square", checkBox
);
105 public void itemStateChanged(ItemEvent e
) {
106 if (e
.getStateChange() == ItemEvent
.SELECTED
) {
107 hModel
.addChangeListener(this);
108 vModel
.addChangeListener(this);
111 hModel
.removeChangeListener(this);
112 vModel
.removeChangeListener(this);
117 public void stateChanged(final ChangeEvent e
) {
118 if (e
.getSource() == hModel
) {
119 vModel
.setValue(hModel
.getValue());
121 else if (e
.getSource() == vModel
) {
122 hModel
.setValue(vModel
.getValue());
126 public int getWidth() {
127 return ((Number
) wSpinner
.getModel().getValue()).intValue();
130 public int getHeight() {
131 return ((Number
) hSpinner
.getModel().getValue()).intValue();
134 public static void main(String
[] args
) {
136 WindowsSizePanel panel
= new WindowsSizePanel(640, 480);
139 JOptionPane
.showConfirmDialog(null, panel
,
141 JOptionPane
.OK_CANCEL_OPTION
, JOptionPane
.PLAIN_MESSAGE
);
142 if (result
== JOptionPane
.OK_OPTION
) {
143 System
.out
.println(panel
.getWidth());
144 System
.out
.println(panel
.getHeight());