/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2008, by :
* Corporate:
* EADS Astrium
* Individual:
* Claude Cazenave
*
* $Id: DiscDialog.java,v 1.1 2008/12/17 22:37:52 cazenave Exp $
*
* Changes
* -------
* 31 janv. 08 : Initial public release
*
*/
package jsynoptic.plugins.java3d.panels;
import java.awt.BorderLayout;
import java.awt.Dialog;
import java.awt.Point;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import simtools.ui.GridBagPanel;
/**
*
*/
public class DiscDialog extends JDialog {
JTextField _tfR;
JCheckBox _cbUp;
JTextField _tfDiv;
GridBagPanel _panel;
public class Result {
public float radius=1.f;
public boolean up=true;
public int divisions=10;
}
Result _result=null;
public DiscDialog(Window windowAncestor, Point location,String title) {
super(windowAncestor,title,Dialog.ModalityType.APPLICATION_MODAL);
if(location!=null){
setLocation(location);
}
JButton b = new JButton("OK"); // TODO I18N
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
getValues();
dispose();
}
});
JPanel p = new JPanel();
p.add(b);
JButton u = new JButton("CANCEL"); // TODO I18N
u.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
p.add(u);
getContentPane().add(BorderLayout.SOUTH, p);
createPanel();
getContentPane().add(BorderLayout.CENTER, _panel);
pack();
setVisible(true);
}
public Result getResult(){
return _result;
}
private void createPanel(){
Result r=new Result();
_panel=new GridBagPanel();
_panel.addOnCurrentRow(new JLabel("Radius")); // TODO i18N
_panel.addOnCurrentRow(_tfR=new JTextField(""+r.radius,PointsDialog.NDIGIT));
_panel.carriageReturn();
_panel.addOnCurrentRow(new JLabel("Up")); // TODO i18N
_panel.addOnCurrentRow(_cbUp=new JCheckBox());
_cbUp.setSelected(r.up);
_panel.carriageReturn();
_panel.addOnCurrentRow(new JLabel("Divisions")); // TODO i18N
_panel.addOnCurrentRow(_tfDiv=new JTextField(""+r.divisions),3);
_panel.carriageReturn();
}
private void getValues(){
Result r=new Result();
try{
r.radius=Float.parseFloat(_tfR.getText());
}
catch(NumberFormatException nfe){
_tfR.setText(""+r.radius);
}
r.up=_cbUp.isSelected();
try{
r.divisions=Integer.parseInt(_tfDiv.getText());
}
catch(NumberFormatException nfe){
_tfDiv.setText(""+r.divisions);
}
_result=r;
}
}