mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Middle mouse click activates mouse movement scroll mode, similar to web
browsers
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package org.diylc.swing.plugins.canvas;
|
||||
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
@@ -106,6 +107,11 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
private Clipboard clipboard;
|
||||
|
||||
private double zoomLevel = 1;
|
||||
|
||||
// mouse scroll mode
|
||||
private boolean mouseScrollMode = false;
|
||||
private Point mouseScrollPrevLocation = null;
|
||||
private static double MOUSE_SCROLL_SPEED = 0.8;
|
||||
|
||||
public CanvasPlugin(ISwingUI swingUI) {
|
||||
this.swingUI = swingUI;
|
||||
@@ -141,8 +147,17 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown(),
|
||||
if (!mouseScrollMode && e.getButton() == MouseEvent.BUTTON2) {
|
||||
mouseScrollPrevLocation = null;
|
||||
mouseScrollMode = true;
|
||||
canvasPanel.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
|
||||
} else if (mouseScrollMode) {
|
||||
mouseScrollMode = false;
|
||||
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
||||
} else {
|
||||
plugInPort.mouseClicked(e.getPoint(), e.getButton(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown(),
|
||||
e.getClickCount());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,8 +225,18 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e) {
|
||||
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
||||
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown());
|
||||
if (mouseScrollMode) {
|
||||
if (mouseScrollPrevLocation != null) {
|
||||
int dx = (int) ((e.getPoint().x - mouseScrollPrevLocation.x) * MOUSE_SCROLL_SPEED);
|
||||
int dy = (int) ((e.getPoint().y - mouseScrollPrevLocation.y) * MOUSE_SCROLL_SPEED);
|
||||
scrollPane.getHorizontalScrollBar().setValue(scrollPane.getHorizontalScrollBar().getValue() + dx);
|
||||
scrollPane.getVerticalScrollBar().setValue(scrollPane.getVerticalScrollBar().getValue() + dy);
|
||||
}
|
||||
mouseScrollPrevLocation = e.getPoint();
|
||||
} else {
|
||||
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint()));
|
||||
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user