[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool SelectTool.java,1.2,1.3
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-08-05 10:55:43
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31013 Modified Files: SelectTool.java Log Message: added notifications and selction of surfaces Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SelectTool.java 27 Jul 2005 11:01:54 -0000 1.2 --- SelectTool.java 5 Aug 2005 10:55:31 -0000 1.3 *************** *** 11,14 **** --- 11,15 ---- import net.sourceforge.bprocessor.kernel.notification.Notification; + import net.sourceforge.bprocessor.kernel.notification.NotificationListener; import net.sourceforge.bprocessor.kernel.notification.Notifier; *************** *** 17,20 **** --- 18,23 ---- import net.sourceforge.bprocessor.model.Vertex; import net.sourceforge.bprocessor.model.VertexFacade; + import net.sourceforge.bprocessor.model.Surface; + import net.sourceforge.bprocessor.model.SurfaceFacade; import java.awt.event.MouseEvent; *************** *** 28,35 **** * The selecttool */ ! public class SelectTool extends AbstractTool { /** The logger */ private static Logger log = Logger.getLogger(SelectTool.class); /** * The constructor --- 31,47 ---- * The selecttool */ ! public class SelectTool extends AbstractTool implements NotificationListener { /** The logger */ private static Logger log = Logger.getLogger(SelectTool.class); + /** The selected vertex */ + protected static Vertex selectedVertex = null; + + /** The selected edge */ + protected static Edge selectedEdge = null; + + /** The selected surface */ + protected static Surface selectedSurface = null; + /** * The constructor *************** *** 59,75 **** */ 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) { --- 71,95 ---- */ protected void pressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { + if (selectedVertex != null) { + Notification n = new Notification(Notification.VERTEX_DESELECTED, + selectedVertex.getId()); + Notifier.getInstance().sendNotification(n); + } + if (selectedEdge != null) { + Notification n = new Notification(Notification.EDGE_DESELECTED, + selectedEdge.getId()); + Notifier.getInstance().sendNotification(n); + } + if (selectedSurface != null) { + Notification n = new Notification(Notification.SURFACE_DESELECTED, + selectedSurface.getId()); + Notifier.getInstance().sendNotification(n); + } + 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) { *************** *** 79,82 **** --- 99,112 ---- Edge edge = edgeCollide(coords); if (edge != null) { + if (e.getClickCount() >= 2) { + Set s = SurfaceFacade.getInstance().findByEdge(edge); + Iterator i = s.iterator(); + Surface sur = null; + if (i.hasNext()) { + sur = (Surface)i.next(); + } + Notification n = new Notification(Notification.SURFACE_SELECTED, sur.getId()); + Notifier.getInstance().sendNotification(n); + } Notification n = new Notification(Notification.EDGE_SELECTED, edge.getId()); Notifier.getInstance().sendNotification(n); *************** *** 85,88 **** --- 115,125 ---- } } + + /** + * Invoked when a mouse button has been released on a component. + * @param e The MouseEvent + */ + protected void released(MouseEvent e) { + } /** *************** *** 125,137 **** */ 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; --- 162,173 ---- */ protected Vertex vertexCollide(double[] coord) { ! Set vertexes = VertexFacade.getInstance().findByLocation(coord[0], ! coord[1], ! coord[2], ! EPSILON); Iterator it = vertexes.iterator(); while (it.hasNext()) { Vertex v = (Vertex)it.next(); ! return v; } return null; *************** *** 147,149 **** --- 183,222 ---- return Math.abs(a - b) < EPSILON; } + + /** + * Handle a notification + * @param n The notification + */ + public void handleNotification(Notification n) { + if (n.getType().equals(Notification.VERTEX_SELECTED)) { + selectedVertex = VertexFacade.getInstance().findById(n.getObject()); + } else if (n.getType().equals(Notification.VERTEX_DESELECTED)) { + selectedVertex = null; + } else if (n.getType().equals(Notification.EDGE_SELECTED)) { + selectedEdge = EdgeFacade.getInstance().findById(n.getObject()); + } else if (n.getType().equals(Notification.EDGE_DESELECTED)) { + selectedEdge = null; + } else if (n.getType().equals(Notification.SURFACE_SELECTED)) { + selectedSurface = SurfaceFacade.getInstance().findById(n.getObject()); + } else if (n.getType().equals(Notification.SURFACE_DESELECTED)) { + selectedSurface = null; + } + } + + /** + * Should the listener handle this notification + * @param type The notification type + * @return Returns true on SELECTED events; otherwise false + */ + public boolean isNotificationEnabled(String type) { + if (type.equals(Notification.VERTEX_SELECTED) || + type.equals(Notification.VERTEX_DESELECTED) || + type.equals(Notification.EDGE_SELECTED) || + type.equals(Notification.EDGE_DESELECTED) || + type.equals(Notification.SURFACE_SELECTED) || + type.equals(Notification.SURFACE_DESELECTED)) { + return true; + } + return false; + } } |