Package jsynoptic.plugins.java3d

Source Code of jsynoptic.plugins.java3d.SwitchAnimator

/* ========================
* 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-2008, by :
*     Corporate:
*         EADS Astrium
*     Individual:
*         Claude Cazenave
*
* $Id: SwitchAnimator.java,v 1.2 2008/11/05 18:14:51 cazenave Exp $
*
* Changes
* -------
* 23 oct. 2008  : Initial public release
*
*/
package jsynoptic.plugins.java3d;

import java.util.BitSet;

import javax.media.j3d.Switch;

/**
* Animator for the Switch scene graph object
*/
public class SwitchAnimator extends IntegerDataAnimator {

    static final int[] _caps={Switch.ALLOW_SWITCH_WRITE};
   
    /**
     * Empty ctor for serialization
     */
    public SwitchAnimator(){
        super();
    }
       
    /**
     *
     */
    public SwitchAnimator(Class<? extends Data> dataClass, int dataClassParam) {
        super(dataClass,dataClassParam);
    }
   
    @Override
    protected int[] getCapabilities() {
        return _caps;
    }

    @Override
    public void cleanup() {
        ((SwitchData)_data).apply();
    }
   
    /**
     * Converts a int into a bitset
     * @param a the value
     * @param b the bitset to update
     */
    public static void intToBitSet (int a, BitSet b){
        int tmp=a;
        for(int i=0;i<32;i++){
            if((tmp&1) == 1) b.set(i); else b.clear(i);
            tmp=tmp>>1;
        }
    }

    /**
     * Converts a bitset into an int
     * Returns a valid result only if bitset size does not exceed 32
     * @param b the bitset
     * @return a best effort result that can be wrong if size is too big
     */
    public static int bitSetToInt(BitSet b){
        int res=0;
        for(int i=0;i<b.size();i++){
            int bp=(b.get(i) ? 1 : 0)<<i;
            res|=bp;
        }
        return res;
    }

    public static final int SELECTION=1;
    public static final int MASK=2;

    public static class SwitchData extends IntegerData {
       
        static final long serialVersionUID = 1231689110762138828L;
       
        final int _kind;
       
        public SwitchData(int kind){
            _kind=kind;
            params=new int[1];
            _sources=new SourceHolder[1];
        }
       
        public void updateFrom(DataAnimator.Data dataCopy) {
            super.updateFrom(dataCopy);
            apply(); // TODO check
        }

        public void set(Values v) {
            set(v.intValues, v.data);
        }
       
        public Values get(){
            Values ret=new Values(true);
            ret.intValues=getValues();
            ret.data=getDataSources();
           
            return ret;
        }
       
        public void apply() {
            super.apply();
            for (GraphObjectReference o : getReferences()) {
                if(o.getObject() instanceof Switch){
                    Switch s=((Switch)o.getObject());
                    switch(_kind){
                    case SELECTION:
                        if(s.getWhichChild()!=params[0]){
                            s.setWhichChild(params[0]);
                        }
                        break;
                    case MASK:
                        BitSet b=new BitSet();
                        intToBitSet(params[0],b);
                        if(!b.equals(s.getChildMask())){
                            ((Switch)o.getObject()).setChildMask(b);
                        }
                        break;
                    }
                }
            }
        }
    }
}
TOP

Related Classes of jsynoptic.plugins.java3d.SwitchAnimator

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.