Package jsynoptic.plugins.java3d.tree

Source Code of jsynoptic.plugins.java3d.tree.RootNode$NewUniverseAction

/* ========================
* 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: RootNode.java,v 1.5 2008/03/17 06:58:30 cazenave Exp $
*
* Changes
* -------
* 9 janv. 08  : Initial public release
*
*/
package jsynoptic.plugins.java3d.tree;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

import javax.swing.tree.TreePath;

import jsynoptic.plugins.java3d.Universe;
import jsynoptic.plugins.java3d.UniversePool;

/**
* The root of tree node
*/
public class RootNode extends AbstractNode implements UniversePool.Listener{
    /**
     * Register nodes resources and actions
     */
    static void loadResources(){
        AbstractNodeAction.addActions(null, NewUniverseAction.class, LoadUniverseAction.class);
        UniverseNode.loadResources();
    }
   
    // required for dynamic node creation
    public RootNode(Tree tree, Object graphObject, boolean getChildren) {
        super(tree, graphObject, getChildren);
        UniversePool.getGlobal().addListner(this);
    }

    @Override
    protected void getSceneGraphChildren(ArrayList<Object> list) {
        Universe[] us=getTree().getPool().getSortedList();
        list.addAll(Arrays.asList(us));
    }
   
    /* (non-Javadoc)
     * @see jsynoptic.plugins.java3d.UniversePool.Listener#notifyChange()
     */
    @Override
    public void notifyChange() {
        refresh();
    }

    static class NewUniverseAction extends AbstractNodeAction {
        // required for dynamic action creation
        public NewUniverseAction(){
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            getNode().getTree().getPool().createUniverse();
            getNode().getTree().expandPath(new TreePath(getNode()));
        }
    }
   
    static class LoadUniverseAction extends AbstractNodeAction {
        // required for dynamic action creation
        public LoadUniverseAction() {
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            File f = UniversePool.selectFile(
                    e.getSource() instanceof Component ? (Component) e.getSource() : null,
                    false);
            if (f != null) {
                try {
                    getNode().getTree().getPool().loadUniverse(f);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        }
    }

}
TOP

Related Classes of jsynoptic.plugins.java3d.tree.RootNode$NewUniverseAction

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.