Skip to content

Commit

Permalink
Use preview unattended mouse events for moving the canvas and add mou…
Browse files Browse the repository at this point in the history
…se button information to them.
  • Loading branch information
eduramiba committed Dec 7, 2012
1 parent 63f1835 commit 6948286
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public void mousePressed(PreviewMouseEvent event, PreviewProperties previewPrope
relativeY = 0;
LegendController.getInstance().selectItem(null);

event.setConsumed(true);
return;
}
}
Expand Down Expand Up @@ -273,18 +272,19 @@ 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;
float newOriginY = event.y - relativeY;

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
Expand Down
88 changes: 52 additions & 36 deletions PreviewAPI/src/org/gephi/preview/ProcessingApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,61 +155,77 @@ 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();
}
}

@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
Expand Down
10 changes: 9 additions & 1 deletion PreviewAPI/src/org/gephi/preview/api/PreviewMouseEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 6948286

Please sign in to comment.