From dc7c88c652eb2c00bba4a52ab8ec0ec2d65fb08b Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Wed, 28 Mar 2012 14:34:25 -0500 Subject: [PATCH] Issue #427 initial input event code Change-Id: I37dc96ed8dbef37d8e3f7a8ae39fc6fcad59f4aa Former-commit-id: bbf96992ee51c336a5111dc31ed0b430211edeba [formerly 5fdc253d77e25cccf894d5e57c63b0ee4c05be01 [formerly 6297c04332bb349d8351b07e2ffd1c24c046ccd7]] Former-commit-id: 5fdc253d77e25cccf894d5e57c63b0ee4c05be01 Former-commit-id: 40dd73ba4d1cbf8353476f475c1e99975eafcf6f --- .../ui/editor/CollaborationEditor.java | 6 +- .../CollaborationEditorInputHandler.java | 92 +++++++++++++-- .../ui/editor/event/InputEvent.java | 111 ++++++++++++++++++ .../ui/role/DataProviderEventController.java | 86 ++++++++++++++ .../ui/role/ParticipantEventController.java | 5 + 5 files changed, 287 insertions(+), 13 deletions(-) create mode 100644 cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/event/InputEvent.java diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/CollaborationEditor.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/CollaborationEditor.java index 5c708f33d3..a726a50121 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/CollaborationEditor.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/CollaborationEditor.java @@ -25,7 +25,6 @@ import org.eclipse.ui.IWorkbenchPart; import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession; import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager; -import com.raytheon.uf.viz.core.rsc.IInputHandler.InputPriority; import com.raytheon.viz.ui.editor.AbstractEditor; import com.raytheon.viz.ui.panes.PaneManager; @@ -54,10 +53,7 @@ public class CollaborationEditor extends AbstractEditor implements @Override protected PaneManager getNewPaneManager() { - PaneManager pm = new PaneManager(); - pm.registerMouseHandler(new CollaborationEditorInputHandler(), - InputPriority.SYSTEM_RESOURCE); - return pm; + return new PaneManager(); } @Override diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/CollaborationEditorInputHandler.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/CollaborationEditorInputHandler.java index e3102997f6..28ffc20813 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/CollaborationEditorInputHandler.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/CollaborationEditorInputHandler.java @@ -21,6 +21,15 @@ package com.raytheon.uf.viz.collaboration.ui.editor; import org.eclipse.swt.widgets.Event; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.common.status.UFStatus.Priority; +import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException; +import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession; +import com.raytheon.uf.viz.collaboration.comm.identity.event.IDisplayEvent; +import com.raytheon.uf.viz.collaboration.ui.editor.event.InputEvent; +import com.raytheon.uf.viz.collaboration.ui.editor.event.InputEvent.EventType; +import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.uf.viz.core.rsc.IInputHandler; /** @@ -44,9 +53,31 @@ import com.raytheon.uf.viz.core.rsc.IInputHandler; public class CollaborationEditorInputHandler implements IInputHandler { + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(CollaborationEditorInputHandler.class); + + private ISharedDisplaySession session; + + private IDisplayPane displayPane; + + public CollaborationEditorInputHandler(ISharedDisplaySession session, + IDisplayPane displayPane) { + this.session = session; + this.displayPane = displayPane; + } + + private void sendEvent(IDisplayEvent event) { + try { + session.sendEvent(session.getCurrentDataProvider(), event); + } catch (CollaborationException e) { + statusHandler.handle(Priority.PROBLEM, "Error sending input event", + e); + } + } + protected boolean isSessionLeader() { - // TODO this should query the session somehow for the current role - return false; + // TODO does this work? + return session.getUserID().equals(session.getCurrentSessionLeader()); } /* @@ -57,7 +88,14 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleMouseDown(int x, int y, int mouseButton) { - return !isSessionLeader(); + boolean leader = isSessionLeader(); + if (leader) { + double[] coords = displayPane.screenToGrid(x, y, 0); + InputEvent event = new InputEvent(EventType.MOUSE_DOWN, coords[0], + coords[1], mouseButton); + sendEvent(event); + } + return leader; } /* @@ -68,7 +106,14 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleMouseDownMove(int x, int y, int mouseButton) { - return !isSessionLeader(); + boolean leader = isSessionLeader(); + if (leader) { + double[] coords = displayPane.screenToGrid(x, y, 0); + InputEvent event = new InputEvent(EventType.MOUSE_DOWN_MOVE, + coords[0], coords[1], mouseButton); + sendEvent(event); + } + return !leader; } /* @@ -79,7 +124,14 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleMouseUp(int x, int y, int mouseButton) { - return !isSessionLeader(); + boolean leader = isSessionLeader(); + if (leader) { + double[] coords = displayPane.screenToGrid(x, y, 0); + InputEvent event = new InputEvent(EventType.MOUSE_UP, coords[0], + coords[1], mouseButton); + sendEvent(event); + } + return !leader; } /* @@ -90,6 +142,7 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleMouseHover(int x, int y) { + // TODO doesn't do anything right now to reduce bandwidth return !isSessionLeader(); } @@ -100,6 +153,7 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleMouseMove(int x, int y) { + // TODO doesn't do anything right now to reduce bandwidth return !isSessionLeader(); } @@ -111,6 +165,7 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleDoubleClick(int x, int y, int button) { + // TODO doesn't do anything right now to reduce bandwidth return !isSessionLeader(); } @@ -123,7 +178,14 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleMouseWheel(Event event, int x, int y) { - return !isSessionLeader(); + boolean leader = isSessionLeader(); + if (leader) { + double[] coords = displayPane.screenToGrid(x, y, 0); + InputEvent mevent = new InputEvent(EventType.MOUSE_WHEEL, + coords[0], coords[1], event.count); + sendEvent(mevent); + } + return !leader; } /* @@ -135,6 +197,7 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleMouseExit(Event event) { + // TODO doesn't do anything right now to reduce bandwidth return !isSessionLeader(); } @@ -147,6 +210,7 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleMouseEnter(Event event) { + // TODO doesn't do anything right now to reduce bandwidth return !isSessionLeader(); } @@ -157,7 +221,13 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleKeyDown(int keyCode) { - return !isSessionLeader(); + boolean leader = isSessionLeader(); + if (leader) { + InputEvent event = new InputEvent(EventType.KEY_DOWN, -1, -1, + keyCode); + sendEvent(event); + } + return !leader; } /* @@ -167,7 +237,13 @@ public class CollaborationEditorInputHandler implements IInputHandler { */ @Override public boolean handleKeyUp(int keyCode) { - return !isSessionLeader(); + boolean leader = isSessionLeader(); + if (leader) { + InputEvent event = new InputEvent(EventType.KEY_DOWN, -1, -1, + keyCode); + sendEvent(event); + } + return !leader; } } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/event/InputEvent.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/event/InputEvent.java new file mode 100644 index 0000000000..891a3edb06 --- /dev/null +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/editor/event/InputEvent.java @@ -0,0 +1,111 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.viz.collaboration.ui.editor.event; + +import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; +import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.viz.collaboration.comm.identity.event.IDisplayEvent; + +/** + * An input event that holds necessary information to recreate the event on a + * different machine. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Mar 27, 2012            njensen     Initial creation
+ * 
+ * 
+ * + * @author njensen + * @version 1.0 + */ + +@DynamicSerialize +public class InputEvent implements IDisplayEvent { + + public enum EventType { + MOUSE_DOWN, MOUSE_DOWN_MOVE, MOUSE_UP, MOUSE_HOVER, MOUSE_MOVE, DOUBLE_CLICK, MOUSE_WHEEL, KEY_UP, KEY_DOWN + } + + @DynamicSerializeElement + protected double x; + + @DynamicSerializeElement + protected double y; + + /** + * Associated metadata with an event. In the case of a button click, it is + * the button id. For a scroll wheel, it is the count. For a key press, it + * is the key code. + */ + @DynamicSerializeElement + protected int eventData; + + @DynamicSerializeElement + protected EventType type; + + public InputEvent() { + + } + + public InputEvent(EventType type, double x, double y, int eventData) { + this.type = type; + this.x = x; + this.y = y; + this.eventData = eventData; + } + + public double getX() { + return x; + } + + public void setX(double x) { + this.x = x; + } + + public double getY() { + return y; + } + + public void setY(double y) { + this.y = y; + } + + public EventType getType() { + return type; + } + + public void setType(EventType type) { + this.type = type; + } + + public int getEventData() { + return eventData; + } + + public void setEventData(int eventData) { + this.eventData = eventData; + } + +} diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/role/DataProviderEventController.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/role/DataProviderEventController.java index eca6ac29e9..5a380b2e96 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/role/DataProviderEventController.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/role/DataProviderEventController.java @@ -19,6 +19,9 @@ **/ package com.raytheon.uf.viz.collaboration.ui.role; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Event; + import com.google.common.eventbus.Subscribe; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; @@ -29,6 +32,8 @@ import com.raytheon.uf.viz.collaboration.comm.identity.event.ParticipantEventTyp import com.raytheon.uf.viz.collaboration.comm.provider.event.VenueParticipantEvent; import com.raytheon.uf.viz.collaboration.ui.editor.EditorSetup; import com.raytheon.uf.viz.collaboration.ui.editor.SharedEditor; +import com.raytheon.uf.viz.collaboration.ui.editor.event.InputEvent; +import com.raytheon.uf.viz.core.IDisplayPane; import com.raytheon.viz.ui.VizWorkbenchManager; import com.raytheon.viz.ui.editor.AbstractEditor; @@ -62,6 +67,8 @@ public class DataProviderEventController extends AbstractRoleEventController { @Subscribe public void participantChanged(VenueParticipantEvent event) { if (event.getEventType().equals(ParticipantEventType.ARRIVED)) { + // TODO this seems to trigger when you create the room, in which + // case you don't need to send it for yourself // TODO instead of going to active editor, should get ones // specifically shared with this session AbstractEditor editor = (AbstractEditor) VizWorkbenchManager @@ -77,4 +84,83 @@ public class DataProviderEventController extends AbstractRoleEventController { } } + @Subscribe + public void sessionLeaderInput(InputEvent event) { + // TODO TBD will this pick up events sent by the data provider (ie this + // cave) too? if so, need to rework it cause this code should only + // execute on the data provider when someone else's cave is the session + // leader. ideally no InputEvents are sent when data provider and + // session leader are one and the same + + // TODO get the actively shared editor, not the active editor + AbstractEditor editor = (AbstractEditor) VizWorkbenchManager + .getInstance().getActiveEditor(); + IDisplayPane pane = editor.getDisplayPanes()[0]; + Event swtEvent = new Event(); + + // translate event type + switch (event.getType()) { + case MOUSE_DOWN: + swtEvent.type = SWT.MouseDown; + break; + case MOUSE_UP: + swtEvent.type = SWT.MouseUp; + break; + case MOUSE_DOWN_MOVE: + case MOUSE_MOVE: + swtEvent.type = SWT.MouseMove; + break; + case DOUBLE_CLICK: + swtEvent.type = SWT.MouseDoubleClick; + break; + case MOUSE_HOVER: + swtEvent.type = SWT.MouseHover; + break; + case MOUSE_WHEEL: + swtEvent.type = SWT.MouseWheel; + break; + case KEY_DOWN: + swtEvent.type = SWT.KeyDown; + break; + case KEY_UP: + swtEvent.type = SWT.KeyUp; + break; + } + + // translate coordinates of event + switch (event.getType()) { + case MOUSE_DOWN: + case MOUSE_DOWN_MOVE: + case MOUSE_UP: + case MOUSE_HOVER: + case MOUSE_MOVE: + case MOUSE_WHEEL: + case DOUBLE_CLICK: + double[] screen = pane.gridToScreen(new double[] { event.getX(), + event.getY() }); + swtEvent.x = (int) Math.round(screen[0]); + swtEvent.y = (int) Math.round(screen[1]); + break; + } + + // translate specific metadata + switch (event.getType()) { + case MOUSE_DOWN: + case MOUSE_DOWN_MOVE: + case MOUSE_UP: + case DOUBLE_CLICK: + swtEvent.button = event.getEventData(); + break; + case MOUSE_WHEEL: + swtEvent.count = event.getEventData(); + break; + case KEY_DOWN: + case KEY_UP: + swtEvent.keyCode = event.getEventData(); + break; + } + + editor.getMouseManager().handleEvent(swtEvent); + } + } diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/role/ParticipantEventController.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/role/ParticipantEventController.java index dd4214369c..412143227f 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/role/ParticipantEventController.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/role/ParticipantEventController.java @@ -26,8 +26,10 @@ import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession; import com.raytheon.uf.viz.collaboration.comm.identity.event.IInitData; import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager; import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditor; +import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditorInputHandler; import com.raytheon.uf.viz.collaboration.ui.editor.EditorSetup; import com.raytheon.uf.viz.collaboration.ui.editor.SharedEditor; +import com.raytheon.uf.viz.core.rsc.IInputHandler.InputPriority; /** * Handles the events of a session that are specific to the Participant role. @@ -60,6 +62,9 @@ public class ParticipantEventController extends AbstractRoleEventController { if (initData instanceof SharedEditor) { SharedEditor se = (SharedEditor) initData; CollaborationEditor editor = EditorSetup.createEditor(se); + editor.registerMouseHandler(new CollaborationEditorInputHandler( + session, editor.getDisplayPanes()[0]), + InputPriority.SYSTEM_RESOURCE); CollaborationDataManager.getInstance().editorCreated( session.getSessionId(), editor); }