Package jsynoptic.plugins.java3d.panels

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

/* ========================
* 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-2007, by :
*     Corporate:
*         EADS Astrium
*     Individual:
*         Claude Cazenave
*
* $Id: PropertiesPanel.java,v 1.3 2008/09/30 05:56:05 cazenave Exp $
*
* Changes
* -------
* 24 janv. 08  : Initial public release
*
*/
package jsynoptic.plugins.java3d.panels;

import java.awt.Frame;
import java.util.ArrayList;

import javax.media.j3d.SceneGraphObject;
import javax.swing.JComponent;
import javax.swing.JLabel;

import jsynoptic.plugins.java3d.AnimatorFactory;
import jsynoptic.plugins.java3d.edit.PropertyEdit;

/**
*/
public class PropertiesPanel<T extends SceneGraphObject> extends
        simtools.ui.GridBagPanel {
    final Frame _owner;

    public PropertiesPanel(Frame owner) {
        this(owner, (PropertyEdit<T, ?>) null);
    }

    public PropertiesPanel(Frame owner, PropertyEdit<T, ?> p) {
        super();
        _owner = owner;
        if (p != null) {
            add(p);
        }
    }

    public PropertiesPanel(Frame owner, String title) {
        this(owner, null, title);
    }

    public PropertiesPanel(Frame owner, PropertyEdit<T, ?> p, String title) {
        super(title);
        _owner = owner;
        if (p != null) {
            add(p);
        }
    }

    public void add(ArrayList<PropertyEdit<T, ?>> list) {
        for (PropertyEdit<T, ?> p : list) {
            add(p);
        }
    }

    public void add(PropertyEdit<T, ?> p) {
        add(p, true);
    }

    @SuppressWarnings("unchecked")
    public <E> void add(PropertyEdit<T, E> p, boolean useLabel) {
        if (useLabel)
            addOnCurrentRow(new JLabel(p.getPresentationName()));
        String cname = p.getDisplayClassName();
        JComponent o = null;
        try {
            Class<?> c = (Class<?>) Class.forName(cname);
            o = (JComponent) c.newInstance();
        } catch (ClassNotFoundException e) {
        } catch (InstantiationException e) {
        } catch (IllegalAccessException e) {
        }
        if (o != null) {
            if (o instanceof Editor) {
                ((Editor<T, E>) o).edit(p);
            }
            if (o instanceof NeedsDialog) {
                ((NeedsDialog) o).set(p.getPresentationName(), _owner);
            }
            AnimatorFactory.Parameters anFactParam=p.getAnimatorParameters();
            addOnCurrentRow(o, 1, false, false, anFactParam==null);
            if(anFactParam!=null){
                addOnCurrentRow(new AnimatorButton<T,E>(anFactParam, p, o, _owner), 1, false, false, true);
            }
        } else {
            addOnCurrentRow(new JLabel(cname + " Not Found"));
        }
        carriageReturn();
    }

    public interface NeedsDialog {
        public void set(String title, Frame owner);
    }

    public interface Editor<T extends SceneGraphObject, E> {
        public void edit(PropertyEdit<T, E> editor);
    }
}
TOP

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

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.