Package jsynoptic.builtin.ui

Source Code of jsynoptic.builtin.ui.PolygonPropertiesPanel

/* ========================
* 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-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: PolygonPropertiesPanel.java,v 1.11 2008/07/22 09:25:17 ogor Exp $
*
* Changes
* -------
* 20 jan 2005 : Initial public release (JB);
*
*/
package jsynoptic.builtin.ui;

import java.util.ResourceBundle;
import javax.swing.ButtonGroup;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTextArea;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ChangeEvent;

import jsynoptic.builtin.PolygonShape;
import jsynoptic.builtin.PolygonShape.PolygonShapePropertiesNames;
import simtools.ui.ActionRadioButton;
import simtools.ui.GridBagPanel;
import simtools.ui.ResourceFinder;

/**
* @author jb
*/
public class PolygonPropertiesPanel extends PropertiesPanel2D {
    protected JTextArea taPoints;

    protected ButtonGroup bg;

    protected ActionRadioButton rbRegular, rbUser;

    protected JLabel lorder;

    protected JSpinner sporder;

    protected JLabel lpoints;

    public static ResourceBundle resources = ResourceFinder.get(PolygonShape.class);

    public PolygonPropertiesPanel(String shapeName) {
        super(true, false, true, true, shapeName);
        addOnCurrentRow(createContent(), 2, true, true, true);
    }

    /*
     * (non-Javadoc)
     *
     * @see jsynoptic.builtin.SimpleShape.PropertiesPanel#createContent()
     */
    protected JComponent createContent() {
        rbRegular = new ActionRadioButton(resources.getString("Regular")) {
            public void stateChanged(ChangeEvent e) {
                lorder.setEnabled(rbRegular.isSelected());
                sporder.setEnabled(rbRegular.isSelected());
            }
        };
        lorder = new JLabel(resources.getString("Order"));
        SpinnerNumberModel snm = new SpinnerNumberModel();
        snm.setMinimum(new Integer(3));
        snm.setValue(new Integer(3));
        sporder = new JSpinner(snm);
        rbUser = new ActionRadioButton(resources.getString("User-defined")) {
            public void stateChanged(ChangeEvent e) {
                lpoints.setEnabled(rbUser.isSelected());
                taPoints.setEnabled(rbUser.isSelected());
            }
        };
        ButtonGroup bg = new ButtonGroup();
        bg.add(rbRegular);
        bg.add(rbUser);
        lpoints = new JLabel(resources.getString("CouplesOfX,YPoints:"));
        taPoints = new JTextArea();
        taPoints.setText("");
        taPoints.setRows(5);
        JScrollPane jsptaPoints = new JScrollPane(taPoints);
        rbRegular.setSelected(true);
        rbUser.setSelected(false);
        rbRegular.apply();
        rbUser.apply();
        // Create panel
        GridBagPanel polygonPanel = new GridBagPanel(resources.getString("Polygon"));
        polygonPanel.addOnCurrentRow(rbRegular);
        polygonPanel.addOnCurrentRow(lorder);
        polygonPanel.addOnCurrentRow(sporder, 1, true, false, true);
        // polygonPanel.carriageReturn();
        polygonPanel.addOnCurrentRow(rbUser);
        polygonPanel.carriageReturn();
        polygonPanel.addOnCurrentRow(lpoints);
        polygonPanel.carriageReturn();
        polygonPanel.addOnCurrentRow(jsptaPoints, 3, true, true, true);
        return polygonPanel;
    }

    protected String fillColorLabel() {
        return resources.getString("FillPolygon");
    }

    public String[] getPropertyNames() {
        if (_propertyNames == null) {
            _propertyNames = new PolygonShapePropertiesNames().getPropertyNames();
        }
        return _propertyNames;
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.ui.JPropertiesPanel#getPropertyValue(java.lang.String)
     */
    public Object getPropertyValue(String name) {
        Object res = super.getPropertyValue(name);
        if (name.equalsIgnoreCase("IS_REGULAR")) {
            return new Boolean(rbRegular.isSelected());
        } else if (name.equalsIgnoreCase("ORDER")) {
            return new Integer(((Number) sporder.getValue()).intValue());
        } else if (name.equalsIgnoreCase("POINTS")) {
            return taPoints.getText();
        }
        return res;
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.ui.JPropertiesPanel#setPropertyValue(java.lang.String,
     *      java.lang.Object)
     */
    public void setPropertyValue(String name, Object value) {
        super.setPropertyValue(name, value);
        if (name.equalsIgnoreCase("IS_REGULAR")) {
            if (value instanceof Boolean) {
                rbRegular.setSelected(((Boolean) value).booleanValue());
                rbUser.setSelected(!((Boolean) value).booleanValue());
                rbRegular.apply();
                rbUser.apply();
            }
        } else if (name.equalsIgnoreCase("ORDER")) {
            if (value instanceof Integer) {
                sporder.setValue(value);
            }
        } else if (name.equalsIgnoreCase("POINTS")) {
            if (value instanceof String) {
                taPoints.setText((String) value);
            }
        }
    }
}
TOP

Related Classes of jsynoptic.builtin.ui.PolygonPropertiesPanel

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.