From 29507eb565dec8524c8485e35de1f4177ce9cb9c Mon Sep 17 00:00:00 2001 From: Hiraoka Date: Sat, 10 Oct 2020 20:03:11 +0900 Subject: [PATCH] Fix the second issue in #772 (right-click to undo in panel UI) --- src/main/java/featurecat/lizzie/gui/BoardPane.java | 6 +++++- .../java/featurecat/lizzie/gui/CommentPane.java | 1 + src/main/java/featurecat/lizzie/gui/Input.java | 2 +- .../java/featurecat/lizzie/gui/LizzieMain.java | 1 + .../java/featurecat/lizzie/gui/LizziePane.java | 5 +++++ src/main/java/featurecat/lizzie/gui/MainFrame.java | 14 ++++++++++++++ .../java/featurecat/lizzie/gui/SubBoardPane.java | 4 ++++ 7 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/main/java/featurecat/lizzie/gui/BoardPane.java b/src/main/java/featurecat/lizzie/gui/BoardPane.java index ef4d553d4..19d5012e9 100644 --- a/src/main/java/featurecat/lizzie/gui/BoardPane.java +++ b/src/main/java/featurecat/lizzie/gui/BoardPane.java @@ -118,7 +118,7 @@ public void mousePressed(MouseEvent e) { // if (Lizzie.frame.isMouseOver) { // Lizzie.frame.addSuggestionAsBranch(); // } else { - if (!Lizzie.frame.openRightClickMenu(e.getX(), e.getY())) Input.undo(); + Lizzie.frame.onRightClicked(e.getX(), e.getY()); // } } } @@ -144,6 +144,10 @@ public void mouseDragged(MouseEvent e) {} }); } + protected void checkRightClick(MouseEvent e) { + // cancel default behavior of LizziePane + } + /** Clears related status from empty board. */ public void clear() { if (LizzieMain.winratePane != null) { diff --git a/src/main/java/featurecat/lizzie/gui/CommentPane.java b/src/main/java/featurecat/lizzie/gui/CommentPane.java index b3a42bb28..4b640a765 100644 --- a/src/main/java/featurecat/lizzie/gui/CommentPane.java +++ b/src/main/java/featurecat/lizzie/gui/CommentPane.java @@ -75,6 +75,7 @@ public CommentPane(LizzieMain owner) { @Override public void mouseClicked(MouseEvent e) { Lizzie.frame.getFocus(); + Lizzie.frame.checkRightClick(e); } }); scrollPane = new JScrollPane(); diff --git a/src/main/java/featurecat/lizzie/gui/Input.java b/src/main/java/featurecat/lizzie/gui/Input.java index bd5298a41..f3a67c120 100644 --- a/src/main/java/featurecat/lizzie/gui/Input.java +++ b/src/main/java/featurecat/lizzie/gui/Input.java @@ -27,7 +27,7 @@ public void mousePressed(MouseEvent e) { } } else if (e.getButton() == MouseEvent.BUTTON3) // right click { - if (!Lizzie.frame.openRightClickMenu(e.getX(), e.getY())) undo(1); + Lizzie.frame.onRightClicked(e.getX(), e.getY()); } } diff --git a/src/main/java/featurecat/lizzie/gui/LizzieMain.java b/src/main/java/featurecat/lizzie/gui/LizzieMain.java index 5c03a9e44..a533dac36 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieMain.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieMain.java @@ -241,6 +241,7 @@ protected void paintComponent(Graphics g) { @Override public void mouseClicked(MouseEvent e) { Lizzie.frame.getFocus(); + Lizzie.frame.checkRightClick(e); } }); diff --git a/src/main/java/featurecat/lizzie/gui/LizziePane.java b/src/main/java/featurecat/lizzie/gui/LizziePane.java index 15828f3f5..20d20d34d 100644 --- a/src/main/java/featurecat/lizzie/gui/LizziePane.java +++ b/src/main/java/featurecat/lizzie/gui/LizziePane.java @@ -103,10 +103,15 @@ public LizziePane(LizzieMain owner) { @Override public void mouseClicked(MouseEvent e) { Lizzie.frame.getFocus(); + checkRightClick(e); // actual behavior may be modified in subclasses } }); } + protected void checkRightClick(MouseEvent e) { + Lizzie.frame.checkRightClick(e); + } + @Override public LizziePaneUI getUI() { return (LizziePaneUI) ui; diff --git a/src/main/java/featurecat/lizzie/gui/MainFrame.java b/src/main/java/featurecat/lizzie/gui/MainFrame.java index d3074ef09..935ade8d6 100644 --- a/src/main/java/featurecat/lizzie/gui/MainFrame.java +++ b/src/main/java/featurecat/lizzie/gui/MainFrame.java @@ -133,6 +133,20 @@ public boolean processCommentMouseWheelMoved(MouseWheelEvent e) { public abstract void onDoubleClicked(int x, int y); + public void checkRightClick(MouseEvent e) { + if (e.getButton() == MouseEvent.BUTTON3) { + onRightClickedOutsideBoard(); + } + } + + public void onRightClicked(int x, int y) { + if (!openRightClickMenu(x, y)) onRightClickedOutsideBoard(); + } + + private void onRightClickedOutsideBoard() { + Input.undo(); + } + public abstract boolean subBoardOnClick(MouseEvent e); public abstract void onMouseDragged(int x, int y); diff --git a/src/main/java/featurecat/lizzie/gui/SubBoardPane.java b/src/main/java/featurecat/lizzie/gui/SubBoardPane.java index 2e550fb56..15ebdabe8 100644 --- a/src/main/java/featurecat/lizzie/gui/SubBoardPane.java +++ b/src/main/java/featurecat/lizzie/gui/SubBoardPane.java @@ -83,6 +83,10 @@ public void mouseWheelMoved(MouseWheelEvent e) { }); } + protected void checkRightClick(MouseEvent e) { + // cancel default behavior of LizziePane + } + /** * Draws the game board and interface *