Package jsynoptic.plugins.syn3d

Source Code of jsynoptic.plugins.syn3d.View3DShape

/* ========================
* 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 CCR
*     Individual:
*         Nicolas Brodu
*
* $Id: View3DShape.java,v 1.7 2005/07/08 13:38:14 cazenave Exp $
*
* Changes
* -------
* 4-Mar-2004 : Creation date (NB);
*
*/
package jsynoptic.plugins.syn3d;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

import jsynoptic.base.ContextualActionProvider;
import jsynoptic.base.Plugin;
import jsynoptic.ui.JSynoptic;
import simtools.diagram.Resizable;
import simtools.shapes.AbstractShape;
import syn3d.ui.Transformator;

/**
* @author Nicolas Brodu
*
* This JSynoptic shape can be included in a Synoptic, and provide a view to a 3D universe
*/
public abstract class View3DShape extends AbstractShape implements ContextualActionProvider, Resizable {

    protected transient SynopticViewNode node = null;
    protected transient Plugin plugin;
    protected transient boolean rotating, zooming, translating, operating;
   
    /**
     * @param ox
     * @param oy
     */
    public View3DShape(Plugin plugin, int ox, int oy, int w, int h) {
        super(ox, oy);
    _w = w;
    _h = h;
    this.plugin = plugin;
    }

   
    /* (non-Javadoc)
     * @see simtools.shapes.AbstractShape#draw(java.awt.Graphics2D)
     */
    public void draw(Graphics2D g) {
        BufferedImage img = null;
        if (node!=null) img = node.getSnapShot();
        if (img==null) {
            Color c = g.getColor();
            g.setColor(Color.black);
            g.fillRect(_ox,_oy-_h,_w,_h);
            g.setColor(c);
        } else g.drawImage(img,_ox,_oy-_h,null);
    }


    /* (non-Javadoc)
     * @see jsynoptic.base.ContextualActionProvider#getActions(double, double, java.lang.Object, int)
     */
    public String[] getActions(double x, double y, Object o, int context) {
        if ((context==ContextualActionProvider.MOUSE_OUT_CONTEXT)
        || (context==ContextualActionProvider.MOUSE_OVER_CONTEXT)
        || (context==ContextualActionProvider.MOUSE_PRESSED_CONTEXT)) {
            if (node==null) return null;
            Transformator transformator = node.getTransformator();
            if (transformator==null) return null;

        if (context==MOUSE_OVER_CONTEXT) {
          return new String[] {"mouseOver"};
        }

        if (context==MOUSE_OUT_CONTEXT) {
            return new String[] {"mouseOut"};
        }

        if (context==MOUSE_PRESSED_CONTEXT) {
            return new String[] {"mousePressed"};
        }
      return null;
        }  
        return new String[] {"Link to Scene", "Rotate", "Translate", "Zoom"};
       
        // TODO : unlink => allow resizing
    }


    /* (non-Javadoc)
     * @see jsynoptic.base.ContextualActionProvider#doAction(double, double, java.lang.Object, java.lang.String)
     */
    public boolean doAction(double x, double y, Object o, String action) {
   
        if (action.equals("Rotate")) {
            JSynoptic.setStatus("Left-click the mouse to start the rotation");
            operating = false;
            rotating = true;
            return true;
        }
        if (action.equals("Translate")) {
            JSynoptic.setStatus("Left-click the mouse to start the translation");
            operating = false;
            translating = true;
            return true;
        }
        if (action.equals("Zoom")) {
            JSynoptic.setStatus("Left-click the mouse to start zooming in or out");
            operating = false;
            zooming = true;
            return true;
        }
       
        if (action.equals("mousePressed")) {
            if (rotating) {
                operating = !operating;
                if (operating) {
                    node.getTransformator().init2DPosition((int)x, _h - (int)y);
                    JSynoptic.setStatus("Move the mouse to rotate, left-click again to stop");
                }
                else {
                    rotating = false;
                    JSynoptic.setStatus("");
                }
            }
            if (zooming) {
                operating = !operating;
                if (operating) {
                    node.getTransformator().init2DPosition((int)x, _h - (int)y);
                    JSynoptic.setStatus("Move the mouse to zoom in or out, left-click again to stop");
                }
                else {
                    zooming = false;
                    JSynoptic.setStatus("");
                }
            }
            if (translating) {
                operating = !operating;
                if (operating) {
                    node.getTransformator().init2DPosition((int)x, _h - (int)y);
                    JSynoptic.setStatus("Move the mouse to translate the scene, left-click again to stop");
                }
                else {
                    translating = false;
                    JSynoptic.setStatus("");
                }
            }
            return true;
        }

        if (action.equals("mouseOver")) {
            if (!operating) return true;
            if (zooming) node.getTransformator().zoom2D((int)x, _h - (int)y);
            else if (rotating) node.getTransformator().rotate2D((int)x, _h - (int)y);
            else if (translating) node.getTransformator().translate2D((int)x, _h - (int)y);
            return true
        }
       

        if (action.equals("mouseOut")) {
            JSynoptic.setStatus("");
            return true;
        }
        return false;
    }


    /* (non-Javadoc)
     * @see jsynoptic.base.ContextualActionProvider#canDoAction(double, double, java.lang.Object, java.lang.String, int)
     */
    public boolean canDoAction(double x, double y, Object o, String action, int context) {
        return true;
    }

    /* (non-Javadoc)
     * @see simtools.diagram.Resizable#resize(int, int)
     */
    public void resize(int dx, int dy) {
        if (node!=null) return; // no resizing when attached
        Rectangle bounds = getBounds();
        _w += dx;
        _h += dy;
        bounds.add(getBounds());
        notifyChange(bounds);
    }

    /* made parent method public
     * @see simtools.shapes.AbstractShape#notifyChange()
     */
    public synchronized void notifyChange() {
        super.notifyChange();
    }
}
TOP

Related Classes of jsynoptic.plugins.syn3d.View3DShape

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.