1 19 20 package org.netbeans.modules.tasklist.timerwin; 21 22 import java.awt.Component ; 23 import java.awt.Point ; 24 import java.awt.Window ; 25 import java.awt.event.MouseAdapter ; 26 import java.awt.event.MouseEvent ; 27 import java.awt.event.MouseMotionListener ; 28 import javax.swing.SwingUtilities ; 29 30 35 public class MoveWindowMouseListener extends MouseAdapter implements 36 MouseMotionListener { 37 private boolean mp; 38 private Point p; 39 private Component c; 40 41 46 public MoveWindowMouseListener(Component c) { 47 this.c = c; 48 c.addMouseListener(this); 49 c.addMouseMotionListener(this); 50 } 51 52 public void mouseMoved(java.awt.event.MouseEvent e) { 53 } 54 55 public void mouseDragged(java.awt.event.MouseEvent e) { 56 if (mp) { 57 Window w = SwingUtilities.windowForComponent(c); 59 w.setLocation(w.getX() + (e.getX() - p.x), 60 w.getY() + (e.getY() - p.y)); 61 } 62 } 63 64 public void mousePressed(java.awt.event.MouseEvent e) { 65 if (e.getButton() == MouseEvent.BUTTON1) { 66 mp = true; 67 p = e.getPoint(); 68 draggingStarted(); 69 } 70 } 71 72 public void mouseReleased(java.awt.event.MouseEvent e) { 73 if (e.getButton() == MouseEvent.BUTTON1) { 74 mp = false; 75 draggingFinished(); 76 } 77 } 78 79 82 private void draggingFinished() { 83 } 84 85 88 private void draggingStarted() { 89 } 90 } 91 | Popular Tags |