[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool AltRectTool.java, NONE, 1.1 Tool.java
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2006-07-10 15:26:54
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26758/net/sourceforge/bprocessor/gl/tool Modified Files: Tool.java ToolFactory.java Added Files: AltRectTool.java Log Message: adding a alternative rectangle tool --- NEW FILE: AltRectTool.java --- //--------------------------------------------------------------------------------- // $Id: AltRectTool.java,v 1.1 2006/07/10 15:26:38 nordholt 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.Cursor; import java.awt.event.MouseEvent; import java.util.List; import java.util.LinkedList; import org.apache.log4j.Logger; import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Vertex; /** * An alternative Rectangle Tool */ public class AltRectTool extends AbstractPencil { /** The logger */ private static Logger log = Logger.getLogger(AltRectTool.class); /** The edges of the rectangle */ private List rectangle; /** The edge that will be moving while making the rectangle */ private Edge movingEdge; /** The base edge of the rectangle */ private Edge baseEdge; /** The last value of currents vertex where the rectangle was moved */ private Vertex lastCurrent; /** Dragging flag */ private boolean dragging; /** * Constructor * @param glv GLView * @param cursor Cursor */ public AltRectTool(GLView glv, Cursor cursor) { super(glv, cursor); rectangle = new LinkedList(); movingEdge = null; baseEdge = null; lastCurrent = null; dragging = false; } /** * Update feedback */ public void updateFeedback() { if (start != null) { if (baseEdge == null) { Edge edge = new Edge(start.vertex(), current.vertex()); List edges = new LinkedList(); edges.add(edge); feedback(edges); } else { Vertex delta = lastCurrent.minus(current.vertex()); Vertex baseProjection = baseEdge.getDirection(); baseProjection.scale(1 / baseProjection.length()); baseProjection.scale(delta.dot(baseProjection)); Vertex movement = baseProjection.minus(delta); movingEdge.move(movement.getX(), movement.getY(), movement.getZ()); lastCurrent = current.vertex(); } } } /** * On vertex - to make "apply" work */ public void onVertex() { if (start != null) { if (baseEdge == null) { setUpRectangle(); } else { double length = start.vertex().minus(current.vertex()).length(); Vertex direction = movingEdge.getFrom().minus(baseEdge.getTo()); direction.scale((length - direction.length()) / direction.length()); movingEdge.move(direction.getX(), direction.getY(), direction.getZ()); insertEdges(rectangle); cleanUp(); feedback(rectangle); } updateFeedback(); updateConstructors(); } } /** * Creates the base edge of the rectangle and sets up the * rectangle. */ private void setUpRectangle() { rectangle = new LinkedList(); baseEdge = new Edge(start.vertex(), current.vertex()); movingEdge = new Edge(current.vertex().copy(), start.vertex().copy()); rectangle.add(baseEdge); rectangle.add(new Edge(current.vertex(), movingEdge.getFrom())); rectangle.add(movingEdge); rectangle.add(new Edge(movingEdge.getTo(), start.vertex())); feedback(rectangle); } /** * Update the length field */ protected void updateLength() { if (baseEdge == null) { super.updateLength(); } else { glv.setLength(baseEdge.getFrom().minus(movingEdge.getTo()).length()); } } /** * @param e MouseEvent */ protected void moved(MouseEvent e) { current = findIntersection(e); if (current != null) { updateFeedback(); updateConstructors(); } } /** * @param e MouseEvent */ protected void pressed(MouseEvent e) { if (start == null) { start = current; lastCurrent = start.vertex(); } else if (baseEdge == null) { setUpRectangle(); } else { insertEdges(rectangle); cleanUp(); feedback(rectangle); } updateFeedback(); updateConstructors(); } /** * @param e MouseEvent */ protected void dragged(MouseEvent e) { moved(e); if (!dragging) { dragging = true; } } /** * @param e MouseEvent */ protected void released(MouseEvent e) { if (dragging) { pressed(e); dragging = false; } } /** * do clean up */ public void cleanUp() { baseEdge = null; movingEdge = null; start = null; rectangle = new LinkedList(); dragging = false; super.cleanUp(); } } Index: ToolFactory.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/ToolFactory.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** ToolFactory.java 9 Jul 2006 16:20:57 -0000 1.52 --- ToolFactory.java 10 Jul 2006 15:26:38 -0000 1.53 *************** *** 119,122 **** --- 119,125 ---- /** The Offset tool */ private OffsetTool offset; + + /** The Alternative Rect tool */ + private AltRectTool altRect; /** The selection button */ *************** *** 159,162 **** --- 162,168 ---- private JToggleButton offBut; + /** The alternative rect tool button */ + private JToggleButton altRectBut; + /** * Constructor *************** *** 208,211 **** --- 214,218 ---- constructor = new ConstructorTool(glv, pencilcursor); offset = new OffsetTool(glv, pencilcursor); + altRect = new AltRectTool(glv, pencilcursor); Toolbar tb = Toolbar.getInstance(); *************** *** 215,218 **** --- 222,226 ---- eraserBut = this.registerTool(Tool.ERASER_TOOL, eraser, "Biconeraser.gif", "Eraser"); this.registerTool(Tool.RECT_TOOL, rect, "Brect.gif", "Rectangle"); + this.registerTool(Tool.ALT_RECT_TOOL, altRect, "Biconaltrect.gif", "Alt. Rectangle"); this.registerTool(Tool.ARC_TOOL, arc, "Barc.gif", "Arc"); Index: Tool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/Tool.java,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Tool.java 9 Jul 2006 16:20:57 -0000 1.24 --- Tool.java 10 Jul 2006 15:26:38 -0000 1.25 *************** *** 54,57 **** --- 54,59 ---- /** The Offset tool */ public static final int OFFSET_TOOL = 16; + /** The Alternative Rect tool */ + public static final int ALT_RECT_TOOL = 17; /** |