1 11 package org.eclipse.swt.dnd; 12 13 import org.eclipse.swt.*; 14 import org.eclipse.swt.graphics.*; 15 import org.eclipse.swt.widgets.*; 16 17 18 50 public class DropTargetEffect extends DropTargetAdapter { 51 Control control; 52 53 63 public DropTargetEffect(Control control) { 64 if (control == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 65 this.control = control; 66 } 67 68 74 public Control getControl() { 75 return control; 76 } 77 78 87 public Widget getItem(int x, int y) { 88 if (control instanceof Table) { 89 return getItem((Table) control, x, y); 90 } 91 if (control instanceof Tree) { 92 return getItem((Tree) control, x, y); 93 } 94 return null; 95 } 96 97 Widget getItem(Table table, int x, int y) { 98 Point coordinates = new Point(x, y); 99 coordinates = table.toControl(coordinates); 100 Item item = table.getItem(coordinates); 101 if (item == null) { 102 Rectangle area = table.getClientArea(); 103 if (area.contains(coordinates)) { 104 for (int x1 = area.x; x1 < area.x + area.width; x1++) { 106 Point pt = new Point(x1, coordinates.y); 107 item = table.getItem(pt); 108 if (item != null) { 109 break; 110 } 111 } 112 } 113 } 114 return item; 115 } 116 117 Widget getItem(Tree tree, int x, int y) { 118 Point coordinates = new Point(x, y); 119 coordinates = tree.toControl(coordinates); 120 Item item = tree.getItem(coordinates); 121 if (item == null) { 122 Rectangle area = tree.getClientArea(); 123 if (area.contains(coordinates)) { 124 for (int x1 = area.x; x1 < area.x + area.width; x1++) { 126 Point pt = new Point(x1, coordinates.y); 127 item = tree.getItem(pt); 128 if (item != null) { 129 break; 130 } 131 } 132 } 133 } 134 return item; 135 } 136 137 TreeItem nextItem(Tree tree, TreeItem item) { 138 if (item == null) return null; 139 if (item.getExpanded()) return item.getItem(0); 140 TreeItem childItem = item; 141 TreeItem parentItem = childItem.getParentItem(); 142 int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); 143 int count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount(); 144 while (true) { 145 if (index + 1 < count) return parentItem == null ? tree.getItem(index + 1) : parentItem.getItem(index + 1); 146 if (parentItem == null) return null; 147 childItem = parentItem; 148 parentItem = childItem.getParentItem(); 149 index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); 150 count = parentItem == null ? tree.getItemCount() : parentItem.getItemCount(); 151 } 152 } 153 154 TreeItem previousItem(Tree tree, TreeItem item) { 155 if (item == null) return null; 156 TreeItem childItem = item; 157 TreeItem parentItem = childItem.getParentItem(); 158 int index = parentItem == null ? tree.indexOf(childItem) : parentItem.indexOf(childItem); 159 if (index == 0) return parentItem; 160 TreeItem nextItem = parentItem == null ? tree.getItem(index-1) : parentItem.getItem(index-1); 161 int count = nextItem.getItemCount(); 162 while (count > 0 && nextItem.getExpanded()) { 163 nextItem = nextItem.getItem(count - 1); 164 count = nextItem.getItemCount(); 165 } 166 return nextItem; 167 } 168 } 169 | Popular Tags |