/** Pop the cursor on top of the cursorStack and set it as the canvas cursor. */ public void popCursor() { if (curCursor != null) { // We must manually dispose of cursors under SWT curCursor.dispose(); } if (cursorStack.isEmpty()) { curCursor = null; } else { curCursor = (Cursor) cursorStack.pop(); } // This sets the cursor back to default setCursor(curCursor); }
/** * Set the canvas cursor, and remember the previous cursor on the cursor stack. Under the hood it * is mapping the java.awt.Cursor to org.eclipse.swt.graphics.Cursor objects. * * @param newCursor new cursor to push onto the cursor stack */ public void pushCursor(final java.awt.Cursor newCursor) { Cursor swtCursor = null; if (newCursor.getType() == java.awt.Cursor.N_RESIZE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEN); } else if (newCursor.getType() == java.awt.Cursor.NE_RESIZE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZENE); } else if (newCursor.getType() == java.awt.Cursor.NW_RESIZE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZENW); } else if (newCursor.getType() == java.awt.Cursor.S_RESIZE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZES); } else if (newCursor.getType() == java.awt.Cursor.SE_RESIZE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZESE); } else if (newCursor.getType() == java.awt.Cursor.SW_RESIZE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZESW); } else if (newCursor.getType() == java.awt.Cursor.E_RESIZE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEE); } else if (newCursor.getType() == java.awt.Cursor.W_RESIZE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEW); } else if (newCursor.getType() == java.awt.Cursor.TEXT_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_IBEAM); } else if (newCursor.getType() == java.awt.Cursor.HAND_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_HAND); } else if (newCursor.getType() == java.awt.Cursor.MOVE_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_SIZEALL); } else if (newCursor.getType() == java.awt.Cursor.CROSSHAIR_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_CROSS); } else if (newCursor.getType() == java.awt.Cursor.WAIT_CURSOR) { swtCursor = new Cursor(getDisplay(), SWT.CURSOR_WAIT); } if (swtCursor != null) { if (curCursor != null) { cursorStack.push(curCursor); } curCursor = swtCursor; setCursor(swtCursor); } }