Package jsynoptic.plugins.java3d.edit

Source Code of jsynoptic.plugins.java3d.edit.MaterialColorEdit

/* ========================
* 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: MaterialColorEdit.java,v 1.3 2008/10/14 16:40:51 cazenave Exp $
*
* Changes
* -------
* 22 janv. 08  : Initial public release
*
*/
package jsynoptic.plugins.java3d.edit;

import javax.media.j3d.Appearance;
import javax.media.j3d.Material;
import javax.media.j3d.SceneGraphObject;
import javax.vecmath.Color3f;

import jsynoptic.plugins.java3d.Tuple3fAnimator;
import jsynoptic.plugins.java3d.Tuple3fData;
import jsynoptic.plugins.java3d.AnimatorFactory.Parameters;
import jsynoptic.plugins.java3d.Tuple3fData.ColorData;

public class MaterialColorEdit extends PropertyEdit<Appearance, Color3f>{

    public static final String AmbientColor = "AmbientColor";
    public static final String DiffuseColor = "DiffuseColor";
    public static final String EmissiveColor = "EmissiveColor";
    public static final String SpecularColor = "SpecularColor";
   
    public MaterialColorEdit(Appearance object, String name) {
        super(object, name);
    }

    @Override
    protected SceneGraphObject getCapableObject(){
        return _object.getMaterial();
    }
   
    @Override
    public Color3f getPropertyValue() {
        Color3f res=new Color3f();
        if(_propertyName.equals(AmbientColor)){
            _object.getMaterial().getAmbientColor(res);
        }
        else if(_propertyName.equals(DiffuseColor)){
            _object.getMaterial().getDiffuseColor(res);
        }
        else if(_propertyName.equals(EmissiveColor)){
            _object.getMaterial().getEmissiveColor(res);
        }
        else if(_propertyName.equals(SpecularColor)){
            _object.getMaterial().getSpecularColor(res);
        }
        return res;
    }

    @Override
    public void setPropertyValue(Color3f res) {
        boolean forced=forceCapability(Material.ALLOW_COMPONENT_WRITE);
        if(_propertyName.equals(AmbientColor)){
            _object.getMaterial().setAmbientColor(res);
        }
        else if(_propertyName.equals(DiffuseColor)){
            _object.getMaterial().setDiffuseColor(res);
        }
        else if(_propertyName.equals(EmissiveColor)){
            _object.getMaterial().setEmissiveColor(res);
        }
        else if(_propertyName.equals(SpecularColor)){
            _object.getMaterial().setSpecularColor(res);
        }
        if(forced) restoreCapability(Material.ALLOW_COMPONENT_WRITE);
    }

    @Override
    public String getDisplayClassName() {
        return "jsynoptic.plugins.java3d.panels.ColorButton";
    }

    /* (non-Javadoc)
     * @see jsynoptic.plugins.java3d.edit.PropertyEdit#getAnimatorParameters()
     */
    @Override
    public Parameters getAnimatorParameters() {
        int type=0;
        if(_propertyName.equals(AmbientColor)){
            type=Tuple3fData.DIFFUSE;
        }
        else if(_propertyName.equals(DiffuseColor)){
            type=Tuple3fData.DIFFUSE;
        }
        else if(_propertyName.equals(EmissiveColor)){
            type=Tuple3fData.DIFFUSE;
        }
        else if(_propertyName.equals(SpecularColor)){
            type=Tuple3fData.DIFFUSE;
        }
        return new Parameters(Tuple3fAnimator.class, ColorData.class, type);
    }
   
   
}
TOP

Related Classes of jsynoptic.plugins.java3d.edit.MaterialColorEdit

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.