Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool SelectStrategy.java, NONE, 1.1 Abstra
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-06-21 13:26:21
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv28315/src/net/sourceforge/bprocessor/gl/tool Modified Files: AbstractTool.java RectTool.java SelectTool.java Added Files: SelectStrategy.java Log Message: Select tool refactoring --- NEW FILE: SelectStrategy.java --- //--------------------------------------------------------------------------------- // $Id: SelectStrategy.java,v 1.1 2006/06/21 13:26:18 henryml 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 java.awt.event.MouseEvent; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Selection; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * SelectStrategy */ public class SelectStrategy implements Strategy { /** The GLView **/ private GLView glv; /** Tempoary edges for multiple selection */ protected Edge e1; /** Tempoary edges for multiple selection */ protected Edge e2; /** Tempoary edges for multiple selection */ protected Edge e3; /** Tempoary edges for multiple selection */ protected Edge e4; /** The drag box */ protected HashSet box; /** The target */ protected Object target; /** Telling if it were a multiple selection */ private boolean multipleSelection = false; /** The x */ private int x; /** The y */ private int y; /** * Constructor * @param glv GLView */ public SelectStrategy(GLView glv) { super(); this.glv = glv; e1 = new Edge(); e1.setConstructor(true); e2 = new Edge(); e2.setConstructor(true); e3 = new Edge(); e3.setConstructor(true); e4 = new Edge(); e4.setConstructor(true); box = new HashSet(); box.add(e1); box.add(e2); box.add(e3); box.add(e4); } /** * Invoked when the mouse cursor has been moved * @param e The MouseEvent object */ public void moved(MouseEvent e) { } /** * Invoked when the mouse cursor has been pressed * @param e The MouseEvent object */ public void pressed(MouseEvent e) { Transformation t = glv.getView().transformation(); Vertex first = t.unProject(new Vertex(e.getX(), View.getHeight() - e.getY(), 0.001)); e1.setFrom(first); e4.setTo(first); Collection selection = Selection.primary(); x = e.getX(); y = e.getY(); View view = glv.getView(); target = view.getObjectAtPoint(x, y); if (e.getClickCount() >= 2 && target instanceof Surface) { Surface surface = (Surface) target; if (surface.getBackDomain() != null) { selection.addAll(surface.getBackDomain().getEnvelope()); } if (surface.getFrontDomain() != null) { selection.addAll(surface.getFrontDomain().getEnvelope()); } } else { if (target == null) { selection.clear(); multipleSelection = true; } else if (e.isShiftDown()) { if (!selection.contains(target)) { selection.add(target); } else { selection.remove(target); } } else { if (!selection.contains(target)) { selection.clear(); selection.add(target); } } } } /** * Invoked when the mouse cursor has been dragged * @param e The MouseEvent object */ public void dragged(MouseEvent e) { if (multipleSelection) { Transformation t = glv.getView().transformation(); Vertex last = t.unProject(new Vertex(e.getX(), View.getHeight() - e.getY(), 0.001)); Vertex temp1 = t.unProject(new Vertex(e.getX(), View.getHeight() - y, 0.001)); Vertex temp2 = t.unProject(new Vertex(x, View.getHeight() - e.getY(), 0.001)); e1.setTo(temp1); e2.setFrom(temp1); e2.setTo(last); e3.setFrom(last); e3.setTo(temp2); e4.setFrom(temp2); Iterator it = box.iterator(); while (it.hasNext()) { Edge constructor = (Edge)it.next(); glv.getView().addTempEdge(constructor); } } } /** * Invoked when the mouse cursor has been released * @param e The MouseEvent object */ public void released(MouseEvent e) { if (multipleSelection) { Collection selection = Selection.primary(); selection.clear(); Iterator it = box.iterator(); while (it.hasNext()) { Edge constructor = (Edge)it.next(); glv.getView().removeTempEdge(constructor); } List l = glv.getView().getObjectInArea(x, y, e.getX(), e.getY()); glv.getView().makeTarget(null); selection.addAll(l); multipleSelection = false; } } } Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** SelectTool.java 20 Jun 2006 13:30:58 -0000 1.60 --- SelectTool.java 21 Jun 2006 13:26:18 -0000 1.61 *************** *** 9,19 **** import net.sourceforge.bprocessor.gl.GLView; - import net.sourceforge.bprocessor.model.Edge; - import java.awt.Cursor; import java.awt.event.MouseEvent; - - import java.util.HashSet; - import org.apache.log4j.Logger; --- 9,14 ---- *************** *** 32,49 **** public SelectTool(GLView glv, Cursor cursor) { super(glv, cursor); - e1 = new Edge(); - e1.setConstructor(true); - e2 = new Edge(); - e2.setConstructor(true); - e3 = new Edge(); - e3.setConstructor(true); - e4 = new Edge(); - e4.setConstructor(true); - - box = new HashSet(); - box.add(e1); - box.add(e2); - box.add(e3); - box.add(e4); } --- 27,30 ---- *************** *** 64,68 **** protected void pressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { ! selectionPressed(e); } } --- 45,49 ---- protected void pressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { ! select.pressed(e); } } *************** *** 73,77 **** */ protected void dragged(MouseEvent e) { ! selectionDragged(e); } --- 54,58 ---- */ protected void dragged(MouseEvent e) { ! select.dragged(e); } *************** *** 81,86 **** */ protected void released(MouseEvent e) { ! selectionReleased(e); } - } --- 62,66 ---- */ protected void released(MouseEvent e) { ! select.released(e); } } Index: RectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/RectTool.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** RectTool.java 20 Jun 2006 13:30:58 -0000 1.9 --- RectTool.java 21 Jun 2006 13:26:18 -0000 1.10 *************** *** 10,13 **** --- 10,14 ---- import java.awt.Cursor; import java.awt.event.MouseEvent; + import java.util.HashSet; import java.util.LinkedList; import java.util.List; *************** *** 27,30 **** --- 28,48 ---- private static Logger log = Logger.getLogger(RectTool.class); + + /** Tempoary edges for multiple selection */ + protected Edge e1; + + /** Tempoary edges for multiple selection */ + protected Edge e2; + + /** Tempoary edges for multiple selection */ + protected Edge e3; + + /** Tempoary edges for multiple selection */ + protected Edge e4; + + /** The drag box */ + protected HashSet box; + + /** * Constructor Index: AbstractTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/AbstractTool.java,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** AbstractTool.java 21 Jun 2006 11:57:54 -0000 1.76 --- AbstractTool.java 21 Jun 2006 13:26:18 -0000 1.77 *************** *** 19,23 **** import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; - import net.sourceforge.bprocessor.gl.view.Transformation; import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.gl.GLView; --- 19,22 ---- *************** *** 34,38 **** import java.net.URL; import java.util.Iterator; - import java.util.List; import java.util.Set; import java.util.HashSet; --- 33,36 ---- *************** *** 53,56 **** --- 51,57 ---- protected static Strategy pan; + /** Select strategy */ + protected static Strategy select; + /** The x axis */ protected Edge xAxis = new Edge(new Vertex(-50, 0, 0), new Vertex(50, 0, 0)); *************** *** 94,128 **** /** The cursor for drag */ private Cursor dragCursor; - - /** Tempoary vertexes for multiple selection */ - private Vertex first; - - /** Tempoary vertexes for multiple selection */ - private Vertex last; - - /** Tempoary vertexes for multiple selection */ - private Vertex temp1; - - /** Tempoary vertexes for multiple selection */ - private Vertex temp2; - - /** Tempoary edges for multiple selection */ - protected Edge e1; - - /** Tempoary edges for multiple selection */ - protected Edge e2; - - /** Tempoary edges for multiple selection */ - protected Edge e3; - - /** Tempoary edges for multiple selection */ - protected Edge e4; - - /** The drag box */ - protected HashSet box; - - /** Telling if it were a multiple selection */ - private boolean multipleSelection = false; - static { --- 95,98 ---- *************** *** 148,151 **** --- 118,124 ---- pan = new PanStrategy(glv); } + if (select == null) { + select = new SelectStrategy(glv); + } } *************** *** 389,393 **** if (e.getButton() == 1) { if (e.isMetaDown() || e.isControlDown()) { ! log.info("select-tool"); } } --- 362,367 ---- if (e.getButton() == 1) { if (e.isMetaDown() || e.isControlDown()) { ! select.pressed(e); ! return; } } *************** *** 745,819 **** } } - - /** - * Handle a pressed event as selection tool - * @param e MouseEvent - */ - protected void selectionPressed(MouseEvent e) { - Transformation t = glv.getView().transformation(); - first = t.unProject(new Vertex(e.getX(), View.getHeight() - e.getY(), 0.001)); - e1.setFrom(first); - e4.setTo(first); - if (e.getClickCount() >= 2 && target instanceof Surface) { - Surface surface = (Surface) target; - if (surface.getBackDomain() != null) { - selection.addAll(surface.getBackDomain().getEnvelope()); - } - if (surface.getFrontDomain() != null) { - selection.addAll(surface.getFrontDomain().getEnvelope()); - } - } else { - if (target == null) { - selection.clear(); - multipleSelection = true; - } else if (e.isShiftDown()) { - if (!selection.contains(target)) { - selection.add(target); - } else { - selection.remove(target); - } - } else { - if (!selection.contains(target)) { - selection.clear(); - selection.add(target); - } - } - } - } - - /** - * Handle a dragged event as selection tool - * @param e MouseEvent - */ - protected void selectionDragged(MouseEvent e) { - if (multipleSelection) { - Transformation t = glv.getView().transformation(); - last = t.unProject(new Vertex(e.getX(), View.getHeight() - e.getY(), 0.001)); - temp1 = t.unProject(new Vertex(e.getX(), View.getHeight() - pressPos[1], 0.001)); - temp2 = t.unProject(new Vertex(pressPos[0], View.getHeight() - e.getY(), 0.001)); - e1.setTo(temp1); - e2.setFrom(temp1); - e2.setTo(last); - e3.setFrom(last); - e3.setTo(temp2); - e4.setFrom(temp2); - displayConstructors(box); - } - } - - /** - * Handle a released event as selection tool - * @param e MouseEvent - */ - protected void selectionReleased(MouseEvent e) { - if (multipleSelection) { - selection.clear(); - clearConstructors(box); - List l = glv.getView().getObjectInArea(pressPos[0], pressPos[1], - e.getX(), e.getY()); - glv.getView().makeTarget(null); - selection.addAll(l); - multipleSelection = false; - } - } } --- 719,721 ---- |