1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.jface.resource.ImageDescriptor; 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.graphics.Cursor; 16 import org.eclipse.swt.widgets.Display; 17 18 21 public class DragCursors { 22 public static final int INVALID = 0; 23 24 public static final int LEFT = 1; 25 26 public static final int RIGHT = 2; 27 28 public static final int TOP = 3; 29 30 public static final int BOTTOM = 4; 31 32 public static final int CENTER = 5; 33 34 public static final int OFFSCREEN = 6; 35 36 public static final int FASTVIEW = 7; 37 38 private final static Cursor cursors[] = new Cursor[8]; 39 40 public static int positionToDragCursor(int swtPositionConstant) { 41 switch (swtPositionConstant) { 42 case SWT.LEFT: 43 return LEFT; 44 case SWT.RIGHT: 45 return RIGHT; 46 case SWT.TOP: 47 return TOP; 48 case SWT.BOTTOM: 49 return BOTTOM; 50 case SWT.CENTER: 51 return CENTER; 52 } 53 54 return INVALID; 55 } 56 57 64 public static int dragCursorToSwtConstant(int dragCursorId) { 65 switch (dragCursorId) { 66 case LEFT: 67 return SWT.LEFT; 68 case RIGHT: 69 return SWT.RIGHT; 70 case TOP: 71 return SWT.TOP; 72 case BOTTOM: 73 return SWT.BOTTOM; 74 case CENTER: 75 return SWT.CENTER; 76 } 77 78 return SWT.DEFAULT; 79 } 80 81 86 public static Cursor getCursor(int code) { 87 Display display = Display.getCurrent(); 88 if (cursors[code] == null) { 89 ImageDescriptor source = null; 90 ImageDescriptor mask = null; 91 switch (code) { 92 case LEFT: 93 source = WorkbenchImages 94 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_LEFT_SOURCE); 95 mask = WorkbenchImages 96 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_LEFT_MASK); 97 cursors[LEFT] = new Cursor(display, source.getImageData(), mask 98 .getImageData(), 16, 16); 99 break; 100 case RIGHT: 101 source = WorkbenchImages 102 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_RIGHT_SOURCE); 103 mask = WorkbenchImages 104 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_RIGHT_MASK); 105 cursors[RIGHT] = new Cursor(display, source.getImageData(), 106 mask.getImageData(), 16, 16); 107 break; 108 case TOP: 109 source = WorkbenchImages 110 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOP_SOURCE); 111 mask = WorkbenchImages 112 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOP_MASK); 113 cursors[TOP] = new Cursor(display, source.getImageData(), mask 114 .getImageData(), 16, 16); 115 break; 116 case BOTTOM: 117 source = WorkbenchImages 118 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_BOTTOM_SOURCE); 119 mask = WorkbenchImages 120 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_BOTTOM_MASK); 121 cursors[BOTTOM] = new Cursor(display, source.getImageData(), 122 mask.getImageData(), 16, 16); 123 break; 124 case CENTER: 125 source = WorkbenchImages 126 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_STACK_SOURCE); 127 mask = WorkbenchImages 128 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_STACK_MASK); 129 cursors[CENTER] = new Cursor(display, source.getImageData(), 130 mask.getImageData(), 16, 16); 131 break; 132 case OFFSCREEN: 133 source = WorkbenchImages 134 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_OFFSCREEN_SOURCE); 135 mask = WorkbenchImages 136 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_OFFSCREEN_MASK); 137 cursors[OFFSCREEN] = new Cursor(display, source.getImageData(), 138 mask.getImageData(), 16, 16); 139 break; 140 case FASTVIEW: 141 source = WorkbenchImages 142 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOFASTVIEW_SOURCE); 143 mask = WorkbenchImages 144 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOFASTVIEW_MASK); 145 cursors[FASTVIEW] = new Cursor(Display.getCurrent(), source 146 .getImageData(), mask.getImageData(), 16, 16); 147 default: 148 case INVALID: 149 source = WorkbenchImages 150 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_INVALID_SOURCE); 151 mask = WorkbenchImages 152 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJS_DND_INVALID_MASK); 153 cursors[INVALID] = new Cursor(display, source.getImageData(), 154 mask.getImageData(), 16, 16); 155 break; 156 } 157 } 158 return cursors[code]; 159 } 160 161 164 public static void dispose() { 165 for (int idx = 0; idx < cursors.length; idx++) { 166 cursors[idx].dispose(); 167 cursors[idx] = null; 168 } 169 } 170 } 171 | Popular Tags |