/* ========================
* 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: ControlledSyn3DBuiltin.java,v 1.1 2005/06/14 13:12:40 ogor Exp $
*
* Changes
* -------
* 19-Mar-2004 : Creation date (NB);
*
*/
package syn3d.builtin;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import syn3d.base.Syn3DPlugin;
import syn3d.nodes.SceneNode;
/**
* This plugin provides interactive navigation into the scene 3D
*
* @author Nicolas Brodu
*/
public class ControlledSyn3DBuiltin extends Syn3DPlugin implements MouseListener, MouseMotionListener, MouseWheelListener, KeyListener {
// See also API to activate/deactivate default event handling system
protected boolean handleMouseClicked = true;
protected boolean handleMouseWheelMoved = true;
protected boolean handleMousePressed = true;
protected boolean handleMouseDragged = true;
protected boolean handleKeyTyped = true;
// Default event handling code. May be deactivated on demand
public void mousePressed(MouseEvent e) {
if (!handleMousePressed) return;
((SceneNode)e.getSource()).init2DPosition(e.getX(), e.getY());
}
public void mouseDragged(MouseEvent e) {
if (!handleMouseDragged) return;
SceneNode scene = (SceneNode)e.getSource();
if ((e.getModifiersEx() & MouseEvent.BUTTON1_DOWN_MASK) == MouseEvent.BUTTON1_DOWN_MASK) {
scene.rotate2D(e.getX(), e.getY());
}
if ((e.getModifiersEx() & MouseEvent.BUTTON2_DOWN_MASK) == MouseEvent.BUTTON2_DOWN_MASK) {
scene.translate2D(e.getX(), e.getY());
}
if ((e.getModifiersEx() & MouseEvent.BUTTON3_DOWN_MASK) == MouseEvent.BUTTON3_DOWN_MASK) {
scene.zoom2D(e.getX(), e.getY());
}
}
public void mouseWheelMoved(MouseWheelEvent e) {
if (!handleMouseWheelMoved) return;
((SceneNode)e.getSource()).zoom(e.getWheelRotation());
}
public void keyTyped(KeyEvent e) {
if (!handleKeyTyped) return;
SceneNode scene = (SceneNode)e.getSource();
if ((e.getKeyChar() == 'p') || (e.getKeyChar() == 'P')) {
// Change the projection policy
scene.changeProjection();
} else if (( e.getKeyChar() == 'r') || (e.getKeyChar() == 'R')){
scene.reset();
} else if ( e.getKeyChar() == '\n') {
// enter for auto-zoom
scene.autoZoom();
}
}
public void mouseClicked(MouseEvent e) {
if (!handleMouseClicked) return;
SceneNode scene = (SceneNode)e.getSource();
// Control adds the new selection to the old
// If not selected, then erase old selection
if ((e.getModifiersEx() & MouseEvent.CTRL_DOWN_MASK) == MouseEvent.CTRL_DOWN_MASK) {
scene.toggleSinglePick(e.getX(), e.getY());
}
// Shift selects everything in the rectangle region defined by the last click
// position and this position
else if (((e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) == MouseEvent.SHIFT_DOWN_MASK)) {
scene.toggleAllPicks(e.getX(), e.getY());
}
else scene.pick(e.getX(), e.getY());
}
/** Use this method to test if the builtin plugin handles this event */
public boolean isHandleKeyTyped() {
return handleKeyTyped;
}
/** Use this method to activate builtin handling of this event */
public void setHandleKeyTyped(boolean handleKeyTyped) {
this.handleKeyTyped = handleKeyTyped;
}
/** Use this method to test if the builtin plugin handles this event */
public boolean isHandleMouseClicked() {
return handleMouseClicked;
}
/** Use this method to activate builtin handling of this event */
public void setHandleMouseClicked(boolean handleMouseClicked) {
this.handleMouseClicked = handleMouseClicked;
}
/** Use this method to test if the builtin plugin handles this event */
public boolean isHandleMouseDragged() {
return handleMouseDragged;
}
/** Use this method to activate builtin handling of this event */
public void setHandleMouseDragged(boolean handleMouseDragged) {
this.handleMouseDragged = handleMouseDragged;
}
/** Use this method to test if the builtin plugin handles this event */
public boolean isHandleMousePressed() {
return handleMousePressed;
}
/** Use this method to activate builtin handling of this event */
public void setHandleMousePressed(boolean handleMousePressed) {
this.handleMousePressed = handleMousePressed;
}
/** Use this method to test if the builtin plugin handles this event */
public boolean isHandleMouseWheelMoved() {
return handleMouseWheelMoved;
}
/** Use this method to activate builtin handling of this event */
public void setHandleMouseWheelMoved(boolean handleMouseWheelMoved) {
this.handleMouseWheelMoved = handleMouseWheelMoved;
}
/** Methods to implement **/
public void mouseReleased(MouseEvent e){
}
public void mouseMoved(MouseEvent e){
}
public void keyReleased(KeyEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void keyPressed(KeyEvent e){
}
}