upgraded idmclib version to 0.2.0
[iDMC.git] / src / java / org / tsho / dmc2 / ui / WindowsSizePanel.java
blob4f482a73a7f5a7d747b9e8e0637c9db8a41fbefe
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.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;
43 /**
44 * @author tsho
46 * To change the template for this generated type comment go to
47 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;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;
61 /**
64 public WindowsSizePanel(int width, int height) {
65 super();
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",
81 "");
83 DefaultFormBuilder builder;
85 builder = new DefaultFormBuilder(this, layout);
87 builder.setDefaultDialogBorder();
89 builder.appendSeparator("Plot dimensions");
90 builder.nextLine();
92 builder.appendRow(builder.getLineGapSpec());
93 builder.nextLine();
95 builder.append("Width", wSpinner);
96 builder.nextLine();
98 builder.append("Height", hSpinner);
99 builder.nextLine();
101 builder.append("Square", checkBox);
102 builder.nextLine();
105 public void itemStateChanged(ItemEvent e) {
106 if (e.getStateChange() == ItemEvent.SELECTED) {
107 hModel.addChangeListener(this);
108 vModel.addChangeListener(this);
110 else {
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);
138 int result =
139 JOptionPane.showConfirmDialog(null, panel,
140 "WindowSizePAnel",
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());