KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > dnd > TableDragUnderEffect


1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 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 package org.eclipse.swt.dnd;
12
13  
14 import org.eclipse.swt.graphics.*;
15 import org.eclipse.swt.widgets.*;
16
17 class TableDragUnderEffect extends DragUnderEffect {
18     private Table table;
19     private TableItem currentItem;
20     private TableItem[] selection = new TableItem[0];
21     private int currentEffect = DND.FEEDBACK_NONE;
22     
23 TableDragUnderEffect(Table table) {
24     this.table = table;
25 }
26 void show(int effect, int x, int y) {
27     TableItem item = null;
28     if (effect != DND.FEEDBACK_NONE) item = findItem(x, y);
29     if (item == null) effect = DND.FEEDBACK_NONE;
30     if (currentEffect != effect && currentEffect == DND.FEEDBACK_NONE) {
31         selection = table.getSelection();
32         table.setSelection(new TableItem[0]);
33     }
34     boolean restoreSelection = currentEffect != effect && effect == DND.FEEDBACK_NONE;
35     setDragUnderEffect(effect, item);
36     if (restoreSelection) {
37         table.setSelection(selection);
38         selection = new TableItem[0];
39     }
40 }
41 private TableItem findItem(int x, int y){
42     if (table == null) return null;
43     Point coordinates = new Point(x, y);
44     coordinates = table.toControl(coordinates);
45     return table.getItem(coordinates);
46 }
47 private void setDragUnderEffect(int effect, TableItem item) {
48     if (currentItem != item) {
49         if (item == null) {
50             table.setSelection(new TableItem[0]);
51         } else {
52             table.setSelection(new TableItem[] {item});
53         }
54         currentItem = item;
55     }
56     currentEffect = effect;
57 }
58 }
59
Popular Tags