[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool SelectTool.java,1.53,1.54
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-02-14 11:56:36
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28252/src/net/sourceforge/bprocessor/gl/tool Modified Files: SelectTool.java Log Message: Added drag selection with the left mousebutton, and fixed the selectionBuffer so that if the selection were too big to fit in the selectionBuffer the size will double and it will try again, that will keep going forever, so some kind of valve have to be added if GL starts to redisplay all the time Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.53 retrieving revision 1.54 diff -C2 -d -r1.53 -r1.54 *** SelectTool.java 1 Feb 2006 09:00:11 -0000 1.53 --- SelectTool.java 14 Feb 2006 11:56:21 -0000 1.54 *************** *** 9,12 **** --- 9,14 ---- import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.model.ClippingPlane; + import net.sourceforge.bprocessor.gl.view.Transformation; + import net.sourceforge.bprocessor.gl.view.View; import net.sourceforge.bprocessor.model.Edge; *************** *** 24,28 **** --- 26,33 ---- import javax.swing.JMenuItem; + import java.util.ArrayList; + import java.util.HashSet; import java.util.Iterator; + import java.util.List; import org.apache.log4j.Logger; *************** *** 35,38 **** --- 40,55 ---- private static Logger log = Logger.getLogger(SelectTool.class); + /** Tempoary vertexes for multiple selection */ + private Vertex first, last, temp1, temp2; + + /** Tempoary edges for multiple selection */ + private Edge e1, e2, e3, e4; + + /** The drag box */ + private HashSet box; + + /** Telling if it were a multiple selection */ + private boolean multipleSelection = false; + /** * The constructor *************** *** 42,45 **** --- 59,76 ---- 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); } *************** *** 58,61 **** --- 89,107 ---- */ protected void dragged(MouseEvent e) { + if (!multipleSelection) { + multipleSelection = true; + + } + 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); findTarget(e); glv.getView().makeTarget(target); *************** *** 67,71 **** */ protected void pressed(MouseEvent e) { ! findTarget(e); if (e.getButton() == MouseEvent.BUTTON3) { if (target != null) { --- 113,121 ---- */ protected void pressed(MouseEvent e) { ! // for multiple selection ! 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.getButton() == MouseEvent.BUTTON3) { if (target != null) { *************** *** 144,148 **** * @param e The MouseEvent */ ! protected void released(MouseEvent e) { } /** --- 194,208 ---- * @param e The MouseEvent */ ! protected void released(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; ! } ! } /** *************** *** 154,165 **** e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { Iterator it = selection.iterator(); while (it.hasNext()) { Object selected = it.next(); if (selected instanceof Surface) { ! Project.getInstance().delete((Surface)selected); } else if (selected instanceof Edge) { ! Project.getInstance().delete((Edge)selected); } else if (selected instanceof Vertex) { ! Project.getInstance().delete((Vertex) selected); } else if (selected instanceof ClippingPlane) { glv.getView().removeClippingPlane((ClippingPlane)selected); --- 214,228 ---- e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { Iterator it = selection.iterator(); + List edges = new ArrayList(); + List vertices = new ArrayList(); + List surfaces = new ArrayList(); while (it.hasNext()) { Object selected = it.next(); if (selected instanceof Surface) { ! surfaces.add((Surface)selected); } else if (selected instanceof Edge) { ! edges.add((Edge)selected); } else if (selected instanceof Vertex) { ! vertices.add((Vertex) selected); } else if (selected instanceof ClippingPlane) { glv.getView().removeClippingPlane((ClippingPlane)selected); *************** *** 168,171 **** --- 231,237 ---- selection.clear(); glv.getView().makeTarget(null); + Project.getInstance().delete(surfaces); + Project.getInstance().delete(edges); + Project.getInstance().delete(vertices); } else { super.keyPressed(e); |