Package simtools.ui

Source Code of simtools.ui.JPropertiesPanel

/* ========================
* 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: JPropertiesPanel.java,v 1.9 2008/09/29 10:02:47 ogor Exp $$
*
* Changes
* -------
* 11 jan 2005 : Initial public release (JB);
*
*/
package simtools.ui;

import java.util.Collection;
import java.util.Iterator;
import javax.swing.JDialog;

import simtools.util.NamedProperties;

/**
* This class is the base class for UI components used to customize shapes
*
* @see simtools.shapes.AbstractShape
* @author Jean-Baptiste Lièvremont
*/
public abstract class JPropertiesPanel extends GridBagPanel implements NamedProperties {
    /**
     * Name of shape related to this UI component
     */
    protected String _shapeName;

    /**
     * The list of properties managed by this panel
     */
    protected transient String[] _propertyNames = null;

    /**
     * The dialog from which the jpanel is displayed
     */
    protected JDialog _owner;

    public JPropertiesPanel(String shapeName) {
      this(null, shapeName);
    }
   
    public JPropertiesPanel(JDialog owner, String shapeName) {
        super();
        this._owner = owner;
        this._shapeName = shapeName;
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.util.NamedProperties#getInnerProperties()
     */
    public Collection getInnerProperties() {
        return null;
    }

    public void setProperties(NamedProperties properties) {
        // 1. manage inner shapes if any
        Collection c = getInnerProperties();
        Collection cshape = properties.getInnerProperties();
        if ((c != null) && (cshape != null)) {
            Iterator it = c.iterator();
            Iterator itshape = cshape.iterator();
            while (it.hasNext() && itshape.hasNext()) {
                NamedProperties as = (NamedProperties) itshape.next();
                JPropertiesPanel np = (JPropertiesPanel) it.next();
                np.setProperties(as);
            }
        }
        String[] props = properties.getPropertyNames();
        if (props != null) {
            // 2. set local properties
            for (int j = 0; j < props.length; j++) {
                String pname = props[j];
                Object value = properties.getPropertyValue(pname);
                setPropertyValue(pname, value);
            }
        }
    }

    /**
     * @return the name of the shape related to this UI component
     */
    public String getShapeName() {
        return _shapeName;
    }

    /**
     * @param owner,
     *            the dialog from which the jpanel is displayed
     */
    public void setOwner(JDialog owner) {
        _owner = owner;
    }

    public JDialog getOwner() {
        return _owner;
    }

    /**
     * Some warnings can be displayed in shape properties dialog box. Overload
     * this method whenever the state of panel components has to be checked
     * @return ture if a message has been displayed
     */
    public boolean updateWarnings() {
        hideWarning();
        return false;
    }

    /**
     * @param warningMessage
     */
    protected void displayWarning(String warningMessage) {
        if (_owner instanceof MessageDisplayer) {
            ((MessageDisplayer) _owner).displayWarning(warningMessage);
        }
    }

    /**
     *
     */
    protected void hideWarning() {
        if (_owner instanceof MessageDisplayer) {
            ((MessageDisplayer) _owner).clearAllMessages();
        }
    }
}
TOP

Related Classes of simtools.ui.JPropertiesPanel

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.