KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > outline > QuickOutlineMouseMoveListener


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.pde.internal.ui.editor.outline;
13
14 import org.eclipse.jface.viewers.TreeViewer;
15 import org.eclipse.swt.events.MouseEvent;
16 import org.eclipse.swt.events.MouseMoveListener;
17 import org.eclipse.swt.graphics.Point;
18 import org.eclipse.swt.widgets.Item;
19 import org.eclipse.swt.widgets.Tree;
20 import org.eclipse.swt.widgets.TreeItem;
21
22 /**
23  * QuickOutlineMouseMoveListener
24  *
25  */

26 public class QuickOutlineMouseMoveListener implements MouseMoveListener {
27
28     private TreeItem fLastItem;
29     
30     private TreeViewer fTreeViewer;
31     
32     /**
33      *
34      */

35     public QuickOutlineMouseMoveListener(TreeViewer treeViewer) {
36         fLastItem = null;
37         fTreeViewer = treeViewer;
38     }
39
40     /* (non-Javadoc)
41      * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
42      */

43     public void mouseMove(MouseEvent e) {
44         Tree tree = fTreeViewer.getTree();
45         if (tree.equals(e.getSource())) {
46             Object JavaDoc o= tree.getItem(new Point(e.x, e.y));
47             if (o instanceof TreeItem) {
48                 if (!o.equals(fLastItem)) {
49                     fLastItem= (TreeItem)o;
50                     tree.setSelection(new TreeItem[] { fLastItem });
51                 } else if (e.y < tree.getItemHeight() / 4) {
52                     // Scroll up
53
Point p= tree.toDisplay(e.x, e.y);
54                     Item item= fTreeViewer.scrollUp(p.x, p.y);
55                     if (item instanceof TreeItem) {
56                         fLastItem= (TreeItem)item;
57                         tree.setSelection(new TreeItem[] { fLastItem });
58                     }
59                 } else if (e.y > tree.getBounds().height - tree.getItemHeight() / 4) {
60                     // Scroll down
61
Point p= tree.toDisplay(e.x, e.y);
62                     Item item= fTreeViewer.scrollDown(p.x, p.y);
63                     if (item instanceof TreeItem) {
64                         fLastItem= (TreeItem)item;
65                         tree.setSelection(new TreeItem[] { fLastItem });
66                     }
67                 }
68             }
69         }
70     }
71     
72 }
73
Popular Tags