KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > timerwin > MoveWindowMouseListener


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.timerwin;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Point JavaDoc;
24 import java.awt.Window JavaDoc;
25 import java.awt.event.MouseAdapter JavaDoc;
26 import java.awt.event.MouseEvent JavaDoc;
27 import java.awt.event.MouseMotionListener JavaDoc;
28 import javax.swing.SwingUtilities JavaDoc;
29
30 /**
31  * Dragging a window.
32  *
33  * @author tl
34  */

35 public class MoveWindowMouseListener extends MouseAdapter JavaDoc implements
36         MouseMotionListener JavaDoc {
37     private boolean mp;
38     private Point JavaDoc p;
39     private Component JavaDoc c;
40
41     /**
42      * Creates a new instance of MoveWindowMouseListener.
43      *
44      * @param c window where this component resides will be dragged.
45      */

46     public MoveWindowMouseListener(Component JavaDoc c) {
47         this.c = c;
48         c.addMouseListener(this);
49         c.addMouseMotionListener(this);
50     }
51
52     public void mouseMoved(java.awt.event.MouseEvent JavaDoc e) {
53     }
54
55     public void mouseDragged(java.awt.event.MouseEvent JavaDoc e) {
56         if (mp) {
57             // TAUtils.LOGGER.fine(e.getPoint() + " " + p);
58
Window JavaDoc 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 JavaDoc 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 JavaDoc e) {
73         if (e.getButton() == MouseEvent.BUTTON1) {
74             mp = false;
75             draggingFinished();
76         }
77     }
78
79     /**
80      * Will be called when the dragging was finished.
81      */

82     private void draggingFinished() {
83     }
84
85     /**
86      * Will be called when the dragging was started.
87      */

88     private void draggingStarted() {
89     }
90 }
91
Popular Tags