KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > viewer > swt > SWTMouseManager


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * *
5  * This library is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or (at your option) any later version. *
9  * *
10  * This library is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13  * Lesser General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU Lesser General Public *
16  * License along with this library; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, *
19  * Boston, MA 02110-1301 USA *
20  * *
21  * Or get it online : *
22  * http://www.gnu.org/copyleft/lesser.html *
23  * *
24  * *
25  ******************************************************************************/

26
27 package org.nightlabs.editor2d.viewer.swt;
28
29 import org.eclipse.swt.events.DisposeEvent;
30 import org.eclipse.swt.events.DisposeListener;
31 import org.eclipse.swt.events.MouseAdapter;
32 import org.eclipse.swt.events.MouseEvent;
33 import org.eclipse.swt.events.MouseListener;
34 import org.eclipse.swt.events.MouseMoveListener;
35 import org.eclipse.swt.widgets.Control;
36 import org.nightlabs.editor2d.viewer.AbstractMouseManager;
37 import org.nightlabs.editor2d.viewer.IViewer;
38
39 public class SWTMouseManager
40 extends AbstractMouseManager
41 {
42
43     public SWTMouseManager(IViewer viewer, Control c)
44     {
45         super(viewer);
46         this.control = c;
47     }
48
49     protected Control control = null;
50     public Control getControl() {
51         return control;
52     }
53     
54     protected void init()
55     {
56         control.addMouseMoveListener(mouseMoveListener);
57         control.addDisposeListener(disposeListener);
58     }
59     
60     protected MouseMoveListener mouseMoveListener = new MouseMoveListener()
61     {
62         public void mouseMove(MouseEvent e)
63         {
64             x = e.x;
65             y = e.y;
66             
67             fireMouseChanged();
68             fireMouseMoved(x, y, e.button);
69         }
70     };
71     
72     protected MouseListener mouseListener = new MouseAdapter()
73     {
74         public void mouseUp(MouseEvent e) {
75             fireMouseReleased(e.x, e.y, e.button);
76         }
77     
78         public void mouseDown(MouseEvent e) {
79             fireMousePressed(e.x, e.y, e.button);
80         }
81     };
82         
83     protected DisposeListener disposeListener = new DisposeListener() {
84         public void widgetDisposed(DisposeEvent evt) {
85             control.removeMouseMoveListener(mouseMoveListener);
86         }
87     };
88      
89 }
90
Popular Tags