From ea408d8f42c9812e49d8bfb1391c5d1b3d4ca306 Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Fri, 25 May 2012 16:28:53 -0500 Subject: [PATCH] Issue #663 Fixed key binding issue, added cursor icon change when tool is selected Change-Id: I9040da01355e64208ef54ccc6d8452ab57c9d3c5 Former-commit-id: 04c9f3a1c8126e329427e128269fe0d963d59b87 [formerly 8c9c33ef9f28f379a213dccf14128dbc1aab0b99] [formerly 2058b7f0ea43dc565f4ca51d939b51b054bc4485 [formerly 5c240b5224ee93a36c5e05ddb15b373645222081]] Former-commit-id: 2058b7f0ea43dc565f4ca51d939b51b054bc4485 Former-commit-id: 11cb7bafb0604efb4ecefac0bea36ea48d1dd9e3 --- .../CollaborationDrawingToolbar.java | 34 +++++++ .../uf/viz/drawing/DrawingToolUIManager.java | 98 ++++++++++++++----- 2 files changed, 109 insertions(+), 23 deletions(-) diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationDrawingToolbar.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationDrawingToolbar.java index 8fe658f055..3b6ee679f9 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationDrawingToolbar.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/telestrator/CollaborationDrawingToolbar.java @@ -27,9 +27,13 @@ import java.util.Set; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; import com.raytheon.uf.viz.collaboration.ui.Activator; import com.raytheon.uf.viz.core.ContextManager; @@ -116,6 +120,36 @@ public class CollaborationDrawingToolbar extends DrawingToolbar implements ContextManager.getInstance(window).activateContexts(this); } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.uf.viz.drawing.DrawingToolbar#initializeComponents(org.eclipse + * .swt.widgets.Shell) + */ + @Override + protected void initializeComponents(Shell shell) { + super.initializeComponents(shell); + Listener activateDeactivate = new Listener() { + @Override + public void handleEvent(Event event) { + switch (event.type) { + case SWT.Activate: + ContextManager.getInstance(PlatformUI.getWorkbench()) + .activateContexts(CollaborationDrawingToolbar.this); + break; + case SWT.Deactivate: + ContextManager.getInstance(PlatformUI.getWorkbench()) + .deactivateContexts( + CollaborationDrawingToolbar.this); + break; + } + } + }; + shell.addListener(SWT.Activate, activateDeactivate); + shell.addListener(SWT.Deactivate, activateDeactivate); + } + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingToolUIManager.java b/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingToolUIManager.java index b641c77b5d..659e018572 100644 --- a/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingToolUIManager.java +++ b/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingToolUIManager.java @@ -22,10 +22,13 @@ package com.raytheon.uf.viz.drawing; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Cursor; import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; import com.raytheon.uf.viz.core.IDisplayPaneContainer; +import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.icon.IconUtil; import com.raytheon.uf.viz.drawing.DrawingToolLayer.DrawMode; import com.raytheon.viz.ui.input.InputAdapter; @@ -58,6 +61,8 @@ public class DrawingToolUIManager extends InputAdapter { private Cursor normal; + private boolean handlingInput = false; + protected IDisplayPaneContainer container; private Shell currentShell = null; @@ -65,19 +70,30 @@ public class DrawingToolUIManager extends InputAdapter { public DrawingToolUIManager(DrawingToolLayer drawingLayer, IDisplayPaneContainer container) { this.drawingLayer = drawingLayer; - - // Create erasor cursor - ImageData data = IconUtil.getImageDescriptor( - Activator.getDefault().getBundle(), "eraser_box.gif") - .getImageData(); - data.alpha = 255; - erasor = new Cursor(Display.getCurrent(), data, 8, 8); - - // Create pencil cursor - pencil = new Cursor(Display.getCurrent(), SWT.CURSOR_HAND); - this.container = container; - container.registerMouseHandler(this); + + VizApp.runAsync(new Runnable() { + @Override + public void run() { + // Create erasor cursor + ImageData data = IconUtil.getImageDescriptor( + Activator.getDefault().getBundle(), "eraser_box.gif") + .getImageData(); + data.alpha = 255; + erasor = new Cursor(Display.getCurrent(), data, 8, 8); + + // Create pencil cursor + data = IconUtil.getImageDescriptor( + Activator.getDefault().getBundle(), "draw.gif") + .getImageData(); + pencil = new Cursor(Display.getCurrent(), data, 1, 15); + + normal = Display.getCurrent().getSystemCursor(SWT.CURSOR_ARROW); + + DrawingToolUIManager.this.container + .registerMouseHandler(DrawingToolUIManager.this); + } + }); } public void dispose() { @@ -87,6 +103,48 @@ public class DrawingToolUIManager extends InputAdapter { container.unregisterMouseHandler(this); } + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.ui.input.InputAdapter#handleMouseExit(org.eclipse.swt + * .widgets.Event) + */ + @Override + public boolean handleMouseExit(Event event) { + if (!handlingInput) { + if (currentShell != null) { + currentShell.setCursor(normal); + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @see + * com.raytheon.viz.ui.input.InputAdapter#handleMouseEnter(org.eclipse.swt + * .widgets.Event) + */ + @Override + public boolean handleMouseEnter(Event event) { + if (handlingInput == false) { + currentShell = ((Control) event.widget).getShell(); + switch (drawingLayer.getDrawMode()) { + case DRAW: + currentShell.setCursor(pencil); + break; + case ERASE: + currentShell.setCursor(erasor); + break; + default: + currentShell.setCursor(normal); + } + } + return false; + } + /* * (non-Javadoc) * @@ -96,15 +154,10 @@ public class DrawingToolUIManager extends InputAdapter { @Override public boolean handleMouseDown(int x, int y, int mouseButton) { if (mouseButton != 1 || drawingLayer.getDrawMode() == DrawMode.NONE - || currentShell != null) { + || handlingInput) { return false; } - currentShell = Display.getCurrent().getActiveShell(); - if (drawingLayer.getDrawMode() == DrawMode.DRAW) { - currentShell.setCursor(pencil); - } else { - currentShell.setCursor(erasor); - } + handlingInput = true; return handleMouseDownMove(x, y, mouseButton); } @@ -116,7 +169,7 @@ public class DrawingToolUIManager extends InputAdapter { */ @Override public boolean handleMouseDownMove(int x, int y, int mouseButton) { - if (currentShell == null) { + if (handlingInput == false) { return false; } @@ -135,18 +188,17 @@ public class DrawingToolUIManager extends InputAdapter { */ @Override public boolean handleMouseUp(int x, int y, int mouseButton) { - if (currentShell == null) { + if (handlingInput == false) { return false; } - currentShell.setCursor(normal); if (drawingLayer.getDrawMode() == DrawMode.DRAW) { drawingLayer.doneDrawing(); } else { drawingLayer.doneErasing(); } container.refresh(); - currentShell = null; + handlingInput = false; return true; }