Package syn3d.nodes

Source Code of syn3d.nodes.SwitchNode$Action

/* ========================
* 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-2004, by :
*     Corporate:
*         EADS Corporate Research Center
*     Individual:
*         Nicolas Brodu
*
* $Id: SwitchNode.java,v 1.8 2005/09/02 11:57:30 ogor Exp $
*
* Changes
* -------
* 19-Mar-2004 : Creation date (NB);
*
*/
package syn3d.nodes;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;

import javax.swing.Icon;

import syn3d.base.ActiveNode;

/**
*
*/
public class SwitchNode extends GroupNode implements Serializable {

    protected BitSet status;
   
    static final long serialVersionUID = -885391816655801164L;
   
    protected static int anonymousNodeNumber = 0;

    public SwitchNode(ActiveNode parent) {
        super(parent);
        anonymousNodeNumber++;
        name = NodeResourcesManager.getNodeName("Switch") + ((anonymousNodeNumber == 1) ? "" : String.valueOf(anonymousNodeNumber));
        status = new BitSet();
    }

    protected void addChild(ActiveNode child) {
        super.addChild(child);
        // new children are active by default
        setStatus(child, true);
    }

    protected void removeChild(ActiveNode child) {
        int idx = children.indexOf(child);
        int size = children.size();
        // Why isn't there a shift function for bit masks ???
        for (int i = idx; i<size-1; ++i) status.set(i, status.get(i+1));
        super.removeChild(child);
    }
   
   
    protected static class Action {
        public String displayString;
        public int childNum;
       
        public Action(String displayString, int childNum) {
            this.displayString = displayString;
            this.childNum = childNum;
        }
       
        public String toString() {
            return displayString;
        }
    }
   
    public List getActions() {
        int len = children.size();
        ArrayList actions = new ArrayList();
        for (int i=0; i<len; ++i) {
            String name = ((ActiveNode)children.get(i)).getName();
            if ((name == null) || name.equals("")) name = NodeResourcesManager.getMessages().print1args("NodeNum", new Integer(i+1));
            actions.add(new Action(status.get(i) ? NodeResourcesManager.getMessages().print1args("Hide", name) : NodeResourcesManager.getMessages().print1args("Show", name), i));
        }
        return actions;
    }

    public void doAction(Object action) {
        if (!(action instanceof Action)) return; // includes null case
        status.flip(((Action)action).childNum);
        notifyInternalChange();
    }

    protected static Icon icon = NodeResourcesManager.resources.getIcon("switchIcon");
    public Icon getIcon() {
        return icon;
    }

    public void restoreReferences(ActiveNode parent) {
        // TODO Auto-generated method stub
        super.restoreReferences(parent);
    }

    public boolean saveChildren() {
        // TODO Auto-generated method stub
        return super.saveChildren();
    }

    // Switch API. Child classes should overload this to make it effective in the underlying 3D model
   
    public void setStatus(ActiveNode child, boolean status) {
        int i = children.indexOf(child);
        if (i==-1) return;
        this.status.set(i,status);
        notifyInternalChange();
    }

    public boolean getStatus(ActiveNode child) {
        int i = children.indexOf(child);
        if (i==-1) return false;
        return status.get(i);
    }
   
}
TOP

Related Classes of syn3d.nodes.SwitchNode$Action

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.