Middle mouse click activates mouse movement scroll mode, similar to web

browsers
This commit is contained in:
Branislav Stojkovic
2019-01-15 23:37:56 +01:00
parent e5fff0b538
commit 984edc196b
4 changed files with 32 additions and 3 deletions
Binary file not shown.
Binary file not shown.
@@ -17,6 +17,7 @@
*/ */
package org.diylc.swing.plugins.canvas; package org.diylc.swing.plugins.canvas;
import java.awt.Cursor;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle; import java.awt.Rectangle;
@@ -106,6 +107,11 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
private Clipboard clipboard; private Clipboard clipboard;
private double zoomLevel = 1; 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) { public CanvasPlugin(ISwingUI swingUI) {
this.swingUI = swingUI; this.swingUI = swingUI;
@@ -141,8 +147,17 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override @Override
public void mouseClicked(MouseEvent e) { 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()); e.getClickCount());
}
} }
@Override @Override
@@ -210,8 +225,18 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
@Override @Override
public void mouseMoved(MouseEvent e) { public void mouseMoved(MouseEvent e) {
canvasPanel.setCursor(plugInPort.getCursorAt(e.getPoint())); if (mouseScrollMode) {
plugInPort.mouseMoved(e.getPoint(), Utils.isMac() ? e.isMetaDown() : e.isControlDown(), e.isShiftDown(), e.isAltDown()); 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());
}
} }
}); });
} }
+4
View File
@@ -2206,6 +2206,10 @@
<releaseDate>2018-12-26 00:00:00.000 CET</releaseDate> <releaseDate>2018-12-26 00:00:00.000 CET</releaseDate>
<name></name> <name></name>
<changes> <changes>
<org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType>
<description>Middle mouse click activates mouse movement scroll mode, similar to web browsers</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change> <org.diylc.appframework.update.Change>
<changeType>NEW_FEATURE</changeType> <changeType>NEW_FEATURE</changeType>
<description>When "High Quality Rendering" option is checked, some components are rendered with 3D shading for better looks</description> <description>When "High Quality Rendering" option is checked, some components are rendered with 3D shading for better looks</description>