Package jsynoptic.plugins.java3d.edit

Source Code of jsynoptic.plugins.java3d.edit.AppearanceEdit$LightingEnabledEdit

/* ========================
* 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: AppearanceEdit.java,v 1.3 2008/12/17 22:37:53 cazenave Exp $
*
* Changes
* -------
* 22 janv. 08  : Initial public release
*
*/
package jsynoptic.plugins.java3d.edit;

import javax.media.j3d.Appearance;
import javax.media.j3d.ColoringAttributes;
import javax.media.j3d.LineAttributes;
import javax.media.j3d.Material;
import javax.media.j3d.PolygonAttributes;
import javax.media.j3d.SceneGraphObject;
import javax.media.j3d.TransparencyAttributes;
import javax.vecmath.Color3f;

/**
*
*/
public class AppearanceEdit extends SceneGraphObjectEdit<Appearance> {
    public static final String LightingEnabled = "LightingEnabled";
    public static final String Shininess = "Shininess";

   
    /**
     * @param object
     */
    public AppearanceEdit(Appearance object) {
        super(object);
    }

    @Override
    protected void buildProperties() {
        super.buildProperties();
        _properties.add(new ShadingModeEdit(
                _object));
        _properties.add(new AppearanceColorEdit(
                _object));
        _properties.add(new TransparencyModeEdit(
                _object));
        _properties.add(new TransparencyEdit(
                _object));
        _properties.add(new LineWidthEdit(
                _object));
        _properties.add(new PolygonModeEdit(
                _object));

        if(_object.getMaterial()!=null){
            _properties.add(new MaterialColorEdit(
                    _object,MaterialColorEdit.AmbientColor));
            _properties.add(new MaterialColorEdit(
                    _object,MaterialColorEdit.DiffuseColor));
            _properties.add(new MaterialColorEdit(
                    _object,MaterialColorEdit.EmissiveColor));
            _properties.add(new MaterialColorEdit(
                    _object,MaterialColorEdit.SpecularColor));
            _properties.add(new ShininessEdit(_object));
            _properties.add(new LightingEnabledEdit(_object));

            _properties.add(new TextureEdit(_object));
        }      
    }
   
    public String getPresentationName(){
        // TODO i18n
        return "Appearance";
    }

   
    public static class ShadingModeEdit extends EnumEdit<Appearance> {

        public static final String ShadingMode="ShadingMode";
       
        public ShadingModeEdit(Appearance object) {
            super(object, ShadingMode,
                    create("FASTEST", ColoringAttributes.FASTEST,
                            "NICEST", ColoringAttributes.NICEST,
                            "SHADE_FLAT", ColoringAttributes.SHADE_FLAT,
                            "SHADE_GOURAUD", ColoringAttributes.SHADE_GOURAUD));
        }

        @Override
        public Integer getPropertyValue() {
            if(_object.getColoringAttributes()!=null){
                return _object.getColoringAttributes().getShadeModel();
            }
            return null;
        }

        @Override
        public void setPropertyValue(Integer value) {
            if(_object.getColoringAttributes()==null){
                boolean forced2=forceCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
                _object.setColoringAttributes(new ColoringAttributes());
                if(forced2) restoreCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
            }
            boolean forced = forceCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE);
            _object.getColoringAttributes().setShadeModel(value);
            if (forced)
                restoreCapability(ColoringAttributes.ALLOW_SHADE_MODEL_WRITE);
        }
    }

    public static class TransparencyModeEdit extends EnumEdit<Appearance> {

        public static final String TransparencyMode="TransparencyMode";
       
        public TransparencyModeEdit(Appearance object) {
            super(object, TransparencyMode,
                    create("FASTEST", TransparencyAttributes.FASTEST,
                            "NICEST", TransparencyAttributes.NICEST,
                            "NONE", TransparencyAttributes.NONE,
                            "SCREEN_DOOR", TransparencyAttributes.SCREEN_DOOR));
        }

        @Override
        public Integer getPropertyValue() {
            if(_object.getTransparencyAttributes()!=null){
                return _object.getTransparencyAttributes().getTransparencyMode();
            }
            return null;
        }

        @Override
        public void setPropertyValue(Integer value) {
            if(_object.getTransparencyAttributes()==null){
                boolean forced2=forceCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
                _object.setTransparencyAttributes(new TransparencyAttributes());
                if(forced2) restoreCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
            }
            boolean forced = forceCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
            _object.getTransparencyAttributes().setTransparencyMode(value);
            if (forced)
                restoreCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
        }
    }

    public static class TransparencyEdit extends PropertyEdit<Appearance, Float>{

        public static final String Transparency="Transparency";

        public TransparencyEdit(Appearance object) {
            super(object, Transparency);
        }

        @Override
        public Float getPropertyValue() {
            if(_object.getTransparencyAttributes()!=null){
                return _object.getTransparencyAttributes().getTransparency();
            }
            return null;
        }

        @Override
        public void setPropertyValue(Float value) {
            if(_object.getTransparencyAttributes()==null){
                boolean forced2=forceCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
                _object.setTransparencyAttributes(new TransparencyAttributes());
                if(forced2) restoreCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
            }
            boolean forced=forceCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
            _object.getTransparencyAttributes().setTransparency(value);
            if(forced) restoreCapability(TransparencyAttributes.ALLOW_VALUE_WRITE);
        }

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

    public static class AppearanceColorEdit extends PropertyEdit<Appearance, Color3f>{

        public static final String ShadingColor = "ShadingColor";
       
        public AppearanceColorEdit(Appearance object) {
            super(object, ShadingColor);
        }

        @Override
        public Color3f getPropertyValue() {
            Color3f res=new Color3f();
            if(_object.getColoringAttributes()!=null){
                _object.getColoringAttributes().getColor(res);
            }
            return res;
        }

        @Override
        public void setPropertyValue(Color3f res) {
            if(_object.getColoringAttributes()==null){
                boolean forced2=forceCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
                _object.setColoringAttributes(new ColoringAttributes());
                if(forced2) restoreCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
            }
            boolean forced=forceCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
            _object.getColoringAttributes().setColor(res);
            if(forced) restoreCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
        }

        @Override
        public String getDisplayClassName() {
            return "jsynoptic.plugins.java3d.panels.ColorButton";
        }
    }
   
    public static class LineWidthEdit extends PropertyEdit<Appearance, Float>{

        public static final String LineWidth = "LineWidth";
       
        public LineWidthEdit(Appearance object) {
            super(object, LineWidth);
        }

        @Override
        public Float getPropertyValue() {
            if(_object.getLineAttributes()!=null){
                return _object.getLineAttributes().getLineWidth();
            }
            return null;
        }

        @Override
        public void setPropertyValue(Float res) {
            if(_object.getLineAttributes()==null){
                boolean forced2=forceCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
                _object.setLineAttributes(new LineAttributes());
                if(forced2) restoreCapability(Appearance.ALLOW_LINE_ATTRIBUTES_WRITE);
            }
            boolean forced=forceCapability(LineAttributes.ALLOW_WIDTH_WRITE);
            _object.getLineAttributes().setLineWidth(res);
            if(forced) restoreCapability(LineAttributes.ALLOW_WIDTH_WRITE);
        }

        @Override
        public String getDisplayClassName() {
            return "jsynoptic.plugins.java3d.panels.TextField$FloatValue";
        }
    }
   
    public static class PolygonModeEdit extends EnumEdit<Appearance> {

        public static final String PolygonMode="PolygonMode";
       
        public PolygonModeEdit(Appearance object) {
            super(object, PolygonMode,create(
                    "POLYGON_POINT",PolygonAttributes.POLYGON_POINT,
                    "POLYGON_LINE",PolygonAttributes.POLYGON_LINE,
                    "POLYGON_FILL",PolygonAttributes.POLYGON_FILL));
        }

        @Override
        public Integer getPropertyValue() {
            if(_object.getPolygonAttributes()!=null){
                return _object.getPolygonAttributes().getPolygonMode();
            }
            return null;
        }

        @Override
        public void setPropertyValue(Integer res) {
            if(_object.getPolygonAttributes()==null){
                boolean forced2=forceCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
                _object.setPolygonAttributes(new PolygonAttributes());
                if(forced2) restoreCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
            }
            boolean forced=forceCapability(PolygonAttributes.ALLOW_MODE_WRITE);
            _object.getPolygonAttributes().setPolygonMode(res);
            if(forced) restoreCapability(PolygonAttributes.ALLOW_MODE_WRITE);
        }
    }
   
    public static class ShininessEdit extends PropertyEdit<Appearance, Float>{

        public ShininessEdit(Appearance object) {
            super(object, Shininess);
        }
       
        @Override
        protected SceneGraphObject getCapableObject(){
            return _object.getMaterial();
        }
       
        @Override
        public Float getPropertyValue() {
            return _object.getMaterial().getShininess();
        }

        @Override
        public void setPropertyValue(Float value) {
            boolean forced=forceCapability(Material.ALLOW_COMPONENT_WRITE);
            _object.getMaterial().setShininess(value);
            if(forced) restoreCapability(Material.ALLOW_COMPONENT_WRITE);
        }

        @Override
        public String getDisplayClassName() {
            return "jsynoptic.plugins.java3d.panels.TextField$FloatValue";
        }
       
    }
   
    public static class LightingEnabledEdit extends PropertyEdit<Appearance, Boolean>{

        public LightingEnabledEdit(Appearance object) {
            super(object, LightingEnabled);
        }

        @Override
        protected SceneGraphObject getCapableObject(){
            return _object.getMaterial();
        }

        @Override
        public Boolean getPropertyValue() {
            return _object.getMaterial().getLightingEnable();
        }

        @Override
        public void setPropertyValue(Boolean value) {
            boolean forced=forceCapability(Material.ALLOW_COMPONENT_WRITE);
            _object.getMaterial().setLightingEnable(value);
            if(forced) restoreCapability(Material.ALLOW_COMPONENT_WRITE);
        }
       
        @Override
        public String getDisplayClassName() {
            return "jsynoptic.plugins.java3d.panels.CheckBox";
        }
    }

}
TOP

Related Classes of jsynoptic.plugins.java3d.edit.AppearanceEdit$LightingEnabledEdit

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.