package frame; //Import section import java.awt.Cursor; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.MouseEvent; import java.util.ArrayList; import javax.swing.event.MouseInputAdapter; //TODO legacy support checker in a different class /** * Mouse Listener customized for SlideBrowserPanel user interaction * * MouseAdapter okay for j2se 1.6+ * Use MouseInputAdapter for j2se 1.5- * * @param Panel that made/added the adapter * @return */ public class mouseAction extends MouseInputAdapter{ //Class variables private SlideBrowserPanel sbp; int doubleClickSpeed = 300; long mouseDownTime; Point lastClickPos; //Constructor public mouseAction(SlideBrowserPanel r) { //Separates mouse actions to associate //with given panel sbp = r; mouseDownTime = 0; lastClickPos = new Point(0,0); } //Mouse Listener methods public void mouseClicked(MouseEvent e) { // TODO Whatever we need to do //Double Click checker lastClickPos = e.getPoint(); Rectangle box = new Rectangle(e.getPoint()); box.grow(3, 3); long currentTime = System.currentTimeMillis(); if(box.contains(lastClickPos) && ((currentTime - mouseDownTime) < doubleClickSpeed)) { //Do double click action at point sbp.checkNodeDoubleClick(e.getPoint()); } else { //Do single click action at point sbp.checkNodeClick(e.getPoint()); mouseDownTime = currentTime; lastClickPos = e.getPoint(); } sbp.repaint(); } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) { sbp.checkNodeClick(e.getPoint()); if(e.isPopupTrigger()) { showPopUp(e); sbp.repaint(); } } public void mouseReleased(MouseEvent e) { sbp.checkNodeClick(e.getPoint()); if(e.isPopupTrigger()) { showPopUp(e); sbp.repaint(); } } //Mouse Motion Listener methods public void mouseDragged(MouseEvent e) { //Update mouse x and y and icons sbp.updatePosition(e.getPoint()); sbp.repaint(); //TODO icon resizing } public void mouseMoved(MouseEvent e) { //Animate when over stuff for emphasis? // If cursor is not over edge of hit box reset it to the default. Point p = e.getPoint(); ArrayList nodeList = sbp.getNodeList(); for(int i = 0; i < nodeList.size(); i++) { if(!nodeList.get(i).onDragEdge(p)) { if(sbp.getCursor() != Cursor.getDefaultCursor()) { sbp.setCursor(Cursor.getDefaultCursor()); //sbp.repaint(); } } } } /** * Show Popup menu when right button is clicked @ pointer * * @param MouseEvent, PopupTrigger */ private void showPopUp(MouseEvent e) { sbp.showPopUp(e.getComponent(), e.getPoint()); sbp.repaint(); } }