mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
improved zooming
This commit is contained in:
+14
-3
@@ -57,6 +57,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
private Clipboard clipboard;
|
private Clipboard clipboard;
|
||||||
|
|
||||||
|
private double zoomLevel = 1;
|
||||||
|
|
||||||
public CanvasPlugin(ISwingUI swingUI) {
|
public CanvasPlugin(ISwingUI swingUI) {
|
||||||
this.swingUI = swingUI;
|
this.swingUI = swingUI;
|
||||||
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||||
@@ -201,7 +203,8 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
|
|
||||||
public ActionFactory.DeleteSelectionAction getDeleteSelectionAction() {
|
public ActionFactory.DeleteSelectionAction getDeleteSelectionAction() {
|
||||||
if (deleteSelectionAction == null) {
|
if (deleteSelectionAction == null) {
|
||||||
deleteSelectionAction = ActionFactory.getInstance().createDeleteSelectionAction(plugInPort);
|
deleteSelectionAction = ActionFactory.getInstance().createDeleteSelectionAction(
|
||||||
|
plugInPort);
|
||||||
}
|
}
|
||||||
return deleteSelectionAction;
|
return deleteSelectionAction;
|
||||||
}
|
}
|
||||||
@@ -257,11 +260,19 @@ public class CanvasPlugin implements IPlugIn, ClipboardOwner {
|
|||||||
canvasPanel.scrollRectToVisible(visibleRect);
|
canvasPanel.scrollRectToVisible(visibleRect);
|
||||||
canvasPanel.revalidate();
|
canvasPanel.revalidate();
|
||||||
}
|
}
|
||||||
// canvasPanel.validate();
|
|
||||||
// canvasPanel.repaint();
|
|
||||||
break;
|
break;
|
||||||
case ZOOM_CHANGED:
|
case ZOOM_CHANGED:
|
||||||
|
Rectangle visibleRect = canvasPanel.getVisibleRect();
|
||||||
refreshSize();
|
refreshSize();
|
||||||
|
// Try to set the visible area to be centered with the previous
|
||||||
|
// one.
|
||||||
|
double zoomFactor = (Double) params[0] / zoomLevel;
|
||||||
|
visibleRect.setBounds((int) (visibleRect.x * zoomFactor),
|
||||||
|
(int) (visibleRect.y * zoomFactor), visibleRect.width, visibleRect.height);
|
||||||
|
canvasPanel.scrollRectToVisible(visibleRect);
|
||||||
|
canvasPanel.revalidate();
|
||||||
|
|
||||||
|
zoomLevel = (Double) params[0];
|
||||||
break;
|
break;
|
||||||
case REPAINT:
|
case REPAINT:
|
||||||
canvasPanel.repaint();
|
canvasPanel.repaint();
|
||||||
|
|||||||
Reference in New Issue
Block a user