Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13185
Added Files:
SelectTool.java
Log Message:
Implements tools for selection
--- NEW FILE: SelectTool.java ---
//---------------------------------------------------------------------------------
// $Id: SelectTool.java,v 1.1 2005/07/26 12:34:09 rimestad Exp $
//
// Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net)
// Released under the Lesser GNU Public License v2.1
//---------------------------------------------------------------------------------
package net.sourceforge.bprocessor.gl.tool;
import net.sourceforge.bprocessor.gl.GLView;
import net.sourceforge.bprocessor.gl.view.View;
import net.sourceforge.bprocessor.kernel.notification.Notification;
import net.sourceforge.bprocessor.kernel.notification.Notifier;
import net.sourceforge.bprocessor.model.Vertex;
import net.sourceforge.bprocessor.model.VertexFacade;
import java.awt.event.MouseEvent;
import java.util.Iterator;
import java.util.Set;
import org.apache.log4j.Logger;
/**
* The abstracttool
*/
public class SelectTool extends AbstractTool {
/** The logger */
private static Logger log = Logger.getLogger(SelectTool.class);
/**
* KeyListener for the GL Canvas
* @param glv The 3D canvas
*/
public SelectTool(GLView glv) {
super(glv);
}
/**
* Invoked when the mouse cursor has been moved
* @param e The MouseEvent object
*/
protected void moved(MouseEvent e) {
}
/**
* Invoked when the mouse is held pressed and moved
* @param e The MouseEvent object
*/
protected void dragged(MouseEvent e) {
}
/**
* Invoked when a mouse button has been pressed on a component.
* @param e The MouseEvent object
*/
protected void pressed(MouseEvent e) {
}
/**
* Invoked when a mouse button has been released on a component.
* @param e The MouseEvent
*/
protected void released(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
int x = e.getX();
int y = e.getY();
View view = glv.getView();
double[] coords = view.toCanvasCoords(new double[]{x, y});
Vertex v = vertexCollide(coords);
if (v != null) {
Notification n = new Notification(Notification.VERTEX_SELECTED, v.getId());
Notifier.getInstance().sendNotification(n);
}
}
}
/**
* Check if this cordinate collide with another vertex
* @param coord The cordinate to check for collision at
* @return The excisting vertex at coord, null if there ain't any
*/
protected Vertex vertexCollide(double[] coord) {
Set vertexes = VertexFacade.getInstance().findAll();
Iterator it = vertexes.iterator();
while (it.hasNext()) {
Vertex v = (Vertex)it.next();
if (collide(v.getX(), coord[0]) &&
collide(v.getY(), coord[1]) &&
collide(v.getZ(), coord[2])) {
return v;
}
}
return null;
}
/**
* Check if a and b is as close as EPSILON
* @param a The target
* @param b The value
* @return true if |a - b| < EPSILON false otherwise
*/
protected boolean collide(double a, double b) {
return Math.abs(a - b) < EPSILON;
}
}
|