Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl GLMouseListener.java,1.2,1.3
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-07-22 11:22:53
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20045 Modified Files: GLMouseListener.java Log Message: Added doubleclick response and a timer to let the mouse control zoom with button 2 and prepared for mousewheel control Index: GLMouseListener.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/GLMouseListener.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** GLMouseListener.java 18 Jul 2005 10:45:38 -0000 1.2 --- GLMouseListener.java 22 Jul 2005 11:22:42 -0000 1.3 *************** *** 10,15 **** import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import javax.swing.Timer; ! import javax.swing.event.MouseInputListener; import org.apache.log4j.Logger; --- 10,20 ---- import java.awt.event.ActionListener; import java.awt.event.MouseEvent; + import java.awt.event.MouseWheelEvent; + import java.awt.event.MouseWheelListener; + import java.awt.event.MouseMotionListener; + import java.awt.event.MouseListener; + import javax.swing.Timer; ! import org.apache.log4j.Logger; *************** *** 18,28 **** * The mouse listener */ ! public class GLMouseListener implements MouseInputListener { /** The logger */ private static Logger log = Logger.getLogger(GLMouseListener.class); - /** The previous pressed button */ - private int prevButton; - /** The mouse position last time the mouse was pressed initializes to (0,0) */ private int[] pressPos = new int[2]; --- 23,30 ---- * The mouse listener */ ! public class GLMouseListener implements MouseListener, MouseMotionListener, MouseWheelListener { /** The logger */ private static Logger log = Logger.getLogger(GLMouseListener.class); /** The mouse position last time the mouse was pressed initializes to (0,0) */ private int[] pressPos = new int[2]; *************** *** 37,40 **** --- 39,48 ---- private GLView glv = null; + /** The zoom action listener */ + private ActionListener zoomAction; + + /** The move action listener */ + private ActionListener moveAction; + /** The carmera move timer */ private Timer timer; *************** *** 46,50 **** public GLMouseListener(GLView glv) { this.glv = glv; ! timer = new Timer(10, new CameraMove(this, glv)); } --- 54,68 ---- public GLMouseListener(GLView glv) { this.glv = glv; ! timer = new Timer(10, null); ! timer.start(); ! moveAction = new CameraMoveTimer(this, glv); ! zoomAction = new CameraZoomTimer(this, glv); ! } ! ! /** ! * Called when the mouse wheel is moved ! * @param e The MouseWheelEvent object ! */ ! public void mouseWheelMoved(MouseWheelEvent e) { } *************** *** 54,62 **** */ public void mouseDragged(MouseEvent e) { ! if (e.getButton() == MouseEvent.BUTTON1) { ! // ! } else if (e.getButton() == MouseEvent.BUTTON3) { ! this.dx = pressPos[0] - e.getX(); ! this.dy = pressPos[1] - e.getY(); } glv.repaint(); --- 72,80 ---- */ public void mouseDragged(MouseEvent e) { ! int x = e.getX(); ! int y = e.getY(); ! if (e.getButton() == MouseEvent.BUTTON3) { ! this.dx = x - pressPos[0]; ! this.dy = y - pressPos[1]; } glv.repaint(); *************** *** 68,72 **** --- 86,103 ---- */ public void mouseMoved(MouseEvent e) { + int x = e.getX(); + int y = e.getY(); + AbstractViewListener avl = glv.getEventListener(); + double[] coord = avl.toCanvasCoords(new double[] {x, y}); + + coord = glv.snapToGrid(coord); + // snap to vertexes + coord = avl.aligned(coord); + //check for snap point change + glv.checkVertexSnap(coord); + //change the activeEdge according to mouse position + glv.changeTo(coord); + glv.repaint(); } *************** *** 100,115 **** pressPos[0] = e.getX(); pressPos[1] = e.getY(); if (log.isDebugEnabled()) { ! log.debug("[mousePressed] " + currentButton); } ! if (currentButton == MouseEvent.BUTTON3) { ! this.dx = pressPos[0]; ! this.dy = pressPos[1]; ! timer.start(); } ! prevButton = currentButton; glv.repaint(); } ! /** * Invoked when a mouse button has been released on a component. --- 131,166 ---- pressPos[0] = e.getX(); pressPos[1] = e.getY(); + + AbstractViewListener avl = glv.getEventListener(); + double[] coords = avl.toCanvasCoords(new double[]{pressPos[0], pressPos[1]}); + // snap to grid + coords = glv.snapToGrid(coords); + // snap to vertex + coords = avl.aligned(coords); + if (log.isDebugEnabled()) { ! log.debug("[mousePressed] " + currentButton + ! "coords(" + coords[0] + ", " + coords[1] + ", " + coords[2] + ")"); } ! ! if (e.getClickCount() >= 2) { ! if (currentButton == MouseEvent.BUTTON1) { ! // double click on Button1 => surface end ! glv.endSurface(coords); ! } ! } else { ! // we did not double click ! if (currentButton == MouseEvent.BUTTON1) { ! glv.addEdge(coords); ! } else if (currentButton == MouseEvent.BUTTON2) { ! timer.addActionListener(zoomAction); ! } else if (currentButton == MouseEvent.BUTTON3) { ! timer.addActionListener(moveAction); ! } } ! glv.removeVertexSnap(); glv.repaint(); } ! /** * Invoked when a mouse button has been released on a component. *************** *** 118,158 **** public void mouseReleased(MouseEvent e) { int currentButton = e.getButton(); ! if (prevButton == MouseEvent.BUTTON1) { ! if (currentButton == MouseEvent.BUTTON1) { ! if (log.isDebugEnabled()) { ! log.debug("[mouseReleased] Button1 -> Button1"); ! } ! } else { ! if (log.isDebugEnabled()) { ! log.debug("[mouseReleased] Button1 -> other button"); ! } ! } ! } else if (prevButton == MouseEvent.BUTTON2) { ! if (currentButton == MouseEvent.BUTTON2) { ! if (log.isDebugEnabled()) { ! log.debug("[mouseReleased] Button2 -> Button2"); ! } ! } else { ! if (log.isDebugEnabled()) { ! log.debug("[mouseReleased] Button2 -> other button"); ! } ! } ! } else if (prevButton == MouseEvent.BUTTON3) { ! if (currentButton == MouseEvent.BUTTON3) { ! timer.stop(); ! this.dx = 0; ! this.dy = 0; ! if (log.isDebugEnabled()) { ! log.debug("[mouseReleased] Button3 -> Button3"); ! } ! } else { ! if (log.isDebugEnabled()) { ! log.debug("[mouseReleased] Button3 -> other button"); ! } ! } ! } else { ! log.warn("Case not handled no such button: " + prevButton); } - prevButton = currentButton; glv.repaint(); } --- 169,181 ---- public void mouseReleased(MouseEvent e) { int currentButton = e.getButton(); ! if (currentButton == MouseEvent.BUTTON3) { ! timer.removeActionListener(moveAction); ! this.dx = 0; ! this.dy = 0; ! } else if (currentButton == MouseEvent.BUTTON2) { ! timer.removeActionListener(zoomAction); ! this.dx = 0; ! this.dy = 0; } glv.repaint(); } *************** *** 175,180 **** * Carama move timer class */ ! protected class CameraMove implements ActionListener { ! /** The calling mouselistener */ private GLMouseListener glml; --- 198,203 ---- * Carama move timer class */ ! private class CameraMoveTimer implements ActionListener { ! /** The calling mouselistener */ private GLMouseListener glml; *************** *** 187,191 **** * @param glv the GLView */ ! protected CameraMove(GLMouseListener glml, GLView glv) { this.glml = glml; this.glv = glv; --- 210,214 ---- * @param glv the GLView */ ! public CameraMoveTimer(GLMouseListener glml, GLView glv) { this.glml = glml; this.glv = glv; *************** *** 203,205 **** --- 226,263 ---- } } + + /** + * Camara zoom timer + */ + private class CameraZoomTimer implements ActionListener { + /** The calling mouselistener */ + private GLMouseListener glml; + + /** The current GLView */ + private GLView glv; + + /** + * The Constructor + * @param glml the mouselistener caller + * @param glv the GLView + */ + public CameraZoomTimer(GLMouseListener glml, GLView glv) { + this.glml = glml; + this.glv = glv; + } + + /** + * executed every time camaraMove is sceduled + * @param e The ActionEvent + */ + public void actionPerformed(ActionEvent e) { + AbstractViewListener avl = glv.getEventListener(); + if (glml.getdy() > 0) { + avl.zoom(0.9); + } else { + avl.zoom(1.0); + } + glv.repaint(); + } + } } |