Package jsynoptic.plugins.java3d.panels

Source Code of jsynoptic.plugins.java3d.panels.PointsDialog

/* ========================
* 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: PointsDialog.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.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import simtools.ui.GridBagPanel;

/**
*
*/
public class PointsDialog extends JDialog {
    static final int NDIGIT=8;
    JTextField _tf[][];
    GridBagPanel _panel;
    int _nbrPoints;
    double[][] _result=null;
    static final double[][] defaultValues={{0,0,0},{1,0,0},{1,1,0},{0,1,0}};
   
    public PointsDialog(Window windowAncestor, Point location,String title, int nbrPoints) {
        super(windowAncestor,title,Dialog.ModalityType.APPLICATION_MODAL);
        _nbrPoints=nbrPoints;
        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 double[] getResult(){
        if(_result==null){
            return null;
        }
        double[] res=new double[3*_nbrPoints];
        for(int j=0;j<_nbrPoints;j++){
            for(int i=0;i<3;i++){
                res[j*3+i]=_result[j][i];
            }
        }
        return res;
    }
   
    private void createPanel(){
        _panel=new GridBagPanel();
        _tf=new JTextField[_nbrPoints][];
        for(int i=0;i<_nbrPoints;i++){
            _tf[i]=new JTextField[3];
            _panel.addOnCurrentRow(new JLabel("P"+i)); // TODO i18N
            _panel.addOnCurrentRow(_tf[i][0]=new JTextField(""+defaultValues[i][0],NDIGIT));
            _panel.addOnCurrentRow(_tf[i][1]=new JTextField(""+defaultValues[i][1],NDIGIT));
            _panel.addOnCurrentRow(_tf[i][2]=new JTextField(""+defaultValues[i][2],NDIGIT));
            _panel.carriageReturn();           
        }
    }
   
    private void getValues(){
        _result=new double[_nbrPoints][];
        for(int j=0;j<_nbrPoints;j++){
            _result[j]=new double[3];
            for(int i=0;i<3;i++){
                try{
                    _result[j][i]=Double.parseDouble(_tf[j][i].getText());
                }
                catch(NumberFormatException nfe){
                    _tf[j][i].setText(""+defaultValues[j][i]);
                    _result[j][i]=defaultValues[j][i];
                }
            }
        }
   }
   
}
TOP

Related Classes of jsynoptic.plugins.java3d.panels.PointsDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.