From 69482865eb05a847baff672c9fee8d91dd41093f Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Date: Fri, 7 Dec 2012 21:56:51 +0100 Subject: [PATCH] Use preview unattended mouse events for moving the canvas and add mouse button information to them. --- .../legend/manager/LegendManagerUI.java | 2 +- .../legend/mouse/LegendMouseListener.java | 6 +- .../org/gephi/preview/ProcessingApplet.java | 88 +++++++++++-------- .../gephi/preview/api/PreviewMouseEvent.java | 10 ++- 4 files changed, 65 insertions(+), 41 deletions(-) diff --git a/DesktopLegend/src/org/gephi/desktop/legend/manager/LegendManagerUI.java b/DesktopLegend/src/org/gephi/desktop/legend/manager/LegendManagerUI.java index 597fca36d7..bd386efcc5 100644 --- a/DesktopLegend/src/org/gephi/desktop/legend/manager/LegendManagerUI.java +++ b/DesktopLegend/src/org/gephi/desktop/legend/manager/LegendManagerUI.java @@ -262,7 +262,7 @@ private void addLegendButtonActionPerformed(java.awt.event.ActionEvent evt) {//G refreshActiveLegendsComboBox(); } else { JOptionPane.showMessageDialog( - this, customBuilder.stepsNeededToBuild(), + null, customBuilder.stepsNeededToBuild(), NbBundle.getMessage(LegendManagerUI.class, "LegendManagerUI.stepsNeededToBuildItem"), JOptionPane.INFORMATION_MESSAGE, null); diff --git a/Legend API/src/org/gephi/legend/mouse/LegendMouseListener.java b/Legend API/src/org/gephi/legend/mouse/LegendMouseListener.java index b7d67f309a..86d60cc7fe 100644 --- a/Legend API/src/org/gephi/legend/mouse/LegendMouseListener.java +++ b/Legend API/src/org/gephi/legend/mouse/LegendMouseListener.java @@ -184,7 +184,6 @@ public void mousePressed(PreviewMouseEvent event, PreviewProperties previewPrope relativeY = 0; LegendController.getInstance().selectItem(null); - event.setConsumed(true); return; } } @@ -273,6 +272,7 @@ public void mouseDragged(PreviewMouseEvent event, PreviewProperties previewPrope previewProperties.putValue(LegendModel.getProperty(LegendProperty.LEGEND_PROPERTIES, itemIndex, LegendProperty.WIDTH), newWidth); previewProperties.putValue(LegendModel.getProperty(LegendProperty.LEGEND_PROPERTIES, itemIndex, LegendProperty.HEIGHT), newHeight); } + event.setConsumed(true); } } else if (currentTransformation.equals(TRANSFORMATION_TRANSLATE_OPERATION)) { float newOriginX = event.x - relativeX; @@ -280,11 +280,11 @@ public void mouseDragged(PreviewMouseEvent event, PreviewProperties previewPrope previewProperties.putValue(LegendModel.getProperty(LegendProperty.LEGEND_PROPERTIES, itemIndex, LegendProperty.USER_ORIGIN_X), newOriginX); previewProperties.putValue(LegendModel.getProperty(LegendProperty.LEGEND_PROPERTIES, itemIndex, LegendProperty.USER_ORIGIN_Y), newOriginY); + + event.setConsumed(true); } - } } - event.setConsumed(true); } @Override diff --git a/PreviewAPI/src/org/gephi/preview/ProcessingApplet.java b/PreviewAPI/src/org/gephi/preview/ProcessingApplet.java index f7956e097c..38f18398d6 100644 --- a/PreviewAPI/src/org/gephi/preview/ProcessingApplet.java +++ b/PreviewAPI/src/org/gephi/preview/ProcessingApplet.java @@ -155,11 +155,29 @@ private PVector screenPositionToModelPosition(PVector screenPos) { private PVector getMouseModelPosition(){ return screenPositionToModelPosition(new PVector(mouseX, mouseY)); } + + private PreviewMouseEvent buildPreviewMouseEvent(PreviewMouseEvent.Type type){ + PVector pos = getMouseModelPosition(); + PreviewMouseEvent.Button button; + + switch(mouseButton){ + case CENTER: + button = PreviewMouseEvent.Button.MIDDLE; + break; + case RIGHT: + button = PreviewMouseEvent.Button.RIGHT; + break; + case LEFT: + default: + button = PreviewMouseEvent.Button.LEFT; + } + + return new PreviewMouseEvent((int)pos.x, (int)pos.y, type, button, keyEvent); + } @Override public void mouseClicked() { - PVector pos = getMouseModelPosition(); - if (previewController.sendMouseEvent(new PreviewMouseEvent((int)pos.x, (int)pos.y, PreviewMouseEvent.Type.CLICKED, keyEvent))) { + if (previewController.sendMouseEvent(buildPreviewMouseEvent(PreviewMouseEvent.Type.CLICKED))) { previewController.refreshPreview(); redraw(); } @@ -167,49 +185,47 @@ public void mouseClicked() { @Override public void mousePressed() { - if (mouseButton == RIGHT) { - ref.set(mouseX, mouseY, 0); - redraw(); - } else { - PVector pos = getMouseModelPosition(); - if (previewController.sendMouseEvent(new PreviewMouseEvent((int)pos.x, (int)pos.y, PreviewMouseEvent.Type.PRESSED, keyEvent))) { - previewController.refreshPreview(); - redraw(); - } - } + previewController.sendMouseEvent(buildPreviewMouseEvent(PreviewMouseEvent.Type.PRESSED)); + + previewController.refreshPreview(); + handleMousePress(); + redraw(); } - + @Override public void mouseDragged() { - if (mouseButton == RIGHT) { - setMoving(true); - trans.set(mouseX, mouseY, 0); - trans.sub(ref); - trans.div(scaling); // ensure const. moving speed whatever the zoom is - trans.add(lastMove); - redraw(); - } else { - PVector pos = getMouseModelPosition(); - if (previewController.sendMouseEvent(new PreviewMouseEvent((int)pos.x, (int)pos.y, PreviewMouseEvent.Type.DRAGGED, keyEvent))) { - previewController.refreshPreview(); - redraw(); - } + if (!previewController.sendMouseEvent(buildPreviewMouseEvent(PreviewMouseEvent.Type.DRAGGED))) { + handleMouseDrag(); } + redraw(); } @Override public void mouseReleased() { - if (mouseButton == RIGHT) { - lastMove.set(trans); - setMoving(false); - redraw(); - } else { - PVector pos = getMouseModelPosition(); - if (previewController.sendMouseEvent(new PreviewMouseEvent((int)pos.x, (int)pos.y, PreviewMouseEvent.Type.RELEASED, keyEvent))) { - previewController.refreshPreview(); - redraw(); - } + if (!previewController.sendMouseEvent(buildPreviewMouseEvent(PreviewMouseEvent.Type.RELEASED))) { + handleMouseRelease(); } + + previewController.refreshPreview(); + redraw(); + } + + private void handleMousePress(){ + ref.set(mouseX, mouseY, 0); + } + + private void handleMouseDrag(){ + setMoving(true); + trans.set(mouseX, mouseY, 0); + trans.sub(ref); + trans.div(scaling); // ensure const. moving speed whatever the zoom is + trans.add(lastMove); + } + + private void handleMouseRelease() { + lastMove.set(trans); + setMoving(false); + redraw(); } @Override diff --git a/PreviewAPI/src/org/gephi/preview/api/PreviewMouseEvent.java b/PreviewAPI/src/org/gephi/preview/api/PreviewMouseEvent.java index 1d4a5747be..dcceb793af 100644 --- a/PreviewAPI/src/org/gephi/preview/api/PreviewMouseEvent.java +++ b/PreviewAPI/src/org/gephi/preview/api/PreviewMouseEvent.java @@ -58,7 +58,14 @@ public enum Type { DRAGGED } + public enum Button{ + LEFT, + RIGHT, + MIDDLE + } + public final Type type; + public final Button button; public final int x; public final int y; private boolean consumed; @@ -68,10 +75,11 @@ public enum Type { */ public final KeyEvent keyEvent; - public PreviewMouseEvent(int x, int y, Type type, KeyEvent keyEvent) { + public PreviewMouseEvent(int x, int y, Type type, Button button, KeyEvent keyEvent) { this.x = x; this.y = y; this.type = type; + this.button = button; this.keyEvent = keyEvent; consumed = false; }