From 8a7ec74a9add4f204df02bd9316f3d20edf9f2af Mon Sep 17 00:00:00 2001 From: Starryi Date: Mon, 11 Oct 2021 14:46:32 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-60434=20=E3=80=90=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E3=80=91=E5=9C=A8=E7=BA=BF=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E5=8F=B3=E9=94=AE=EF=BC=8C=E9=BC=A0=E6=A0=87=E7=A7=BB=E5=8A=A8?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E8=AF=A6=E6=83=85=E6=97=B6=EF=BC=8C=E5=81=B6?= =?UTF-8?q?=E7=8E=B0=E8=AF=A6=E7=BB=86=E6=B6=88=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 弹窗按钮可见时,鼠标位于弹窗按钮左上角,只要用户向左或向上轻微移动鼠标, 都会导致鼠标移除弹窗按钮区域,并触发其下方控件的鼠标移动事件,进而弹出弹窗预览 界面 2. 共享组件的弹窗预览和弹窗按钮互斥,从而自动关闭弹窗按钮 【改动思路】 重新确定共享组件弹窗的交互方式,包括本地共享组件和在线共享 组件。 1. 弹窗按钮出现时,不支持弹窗预览相关的交互. 2. 使用swing默认行为取消隐藏弹窗按钮 --- .../ui/block/AbstractOnlineWidgetBlock.java | 9 ++-- .../share/ui/block/LocalWidgetBlock.java | 23 +++++++--- .../share/ui/block/OnlineWidgetBlock.java | 43 ++++++++----------- .../share/ui/block/PreviewWidgetBlock.java | 25 +++++++++-- 4 files changed, 63 insertions(+), 37 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java index 751ff62e0..54a813c43 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java @@ -37,8 +37,6 @@ public abstract class AbstractOnlineWidgetBlock extends PreviewWidgetBlock super.mouseClicked(e); if (e.getButton() == MouseEvent.BUTTON3 && !isEdit) { this.parentPane.hidePreviewPane(); - UIPopupMenu popupMenu = new UIPopupMenu(); - popupMenu.setOnlyText(true); - popupMenu.setBackground(UIConstants.DEFAULT_BG_RULER); - popupMenu.add(new PopupMenuItem(new MoveGroupAction())); - popupMenu.add(new PopupMenuItem(new RemoveAction())); - GUICoreUtils.showPopupMenu(popupMenu, this, e.getX(), e.getY()); + JPopupMenu rightClickPopupMenu = getRightClickPopupMenu(); + GUICoreUtils.showPopupMenu(rightClickPopupMenu, this, e.getX(), e.getY()); } } @@ -271,6 +270,18 @@ public class LocalWidgetBlock extends PreviewWidgetBlock return !WidgetSelectedManager.getInstance().isSelectEmpty(); } + @Override + public JPopupMenu createRightClickPopupMenu() { + + UIPopupMenu popupMenu = new UIPopupMenu(); + popupMenu.setOnlyText(true); + popupMenu.setBackground(UIConstants.DEFAULT_BG_RULER); + popupMenu.add(new PopupMenuItem(new MoveGroupAction())); + popupMenu.add(new PopupMenuItem(new RemoveAction())); + + return popupMenu; + } + private class MoveGroupAction extends UpdateAction { public MoveGroupAction() { this.putValue(Action.SMALL_ICON, null); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java index fcf22b9d8..325e28afe 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java @@ -63,10 +63,9 @@ import java.util.concurrent.ExecutionException; * Created by kerry on 2020-10-19 * 商城组件块 */ -public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock implements PopupMenuListener { +public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock { private boolean isMouseEnter = false; private boolean downloading = false; - private boolean popupMenuVisible = false; private static final Color COVER_COLOR = Color.decode("#333334"); protected MouseEvent lastPressEvent; private double process = 0D; @@ -96,7 +95,22 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock implements Popu @Override public JPopupMenu createRightClickPopupMenu() { JPopupMenu popupMenu = super.createRightClickPopupMenu(); - popupMenu.addPopupMenuListener(this); + popupMenu.addPopupMenuListener(new PopupMenuListener() { + @Override + public void popupMenuWillBecomeVisible(PopupMenuEvent e) { + OnlineWidgetBlock.this.repaint(); + } + + @Override + public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { + OnlineWidgetBlock.this.repaint(); + } + + @Override + public void popupMenuCanceled(PopupMenuEvent e) { + OnlineWidgetBlock.this.repaint(); + } + }); return popupMenu; } @@ -124,7 +138,7 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock implements Popu public void mouseClicked(MouseEvent e) { super.mouseClicked(e); boolean isLeftClickDownloadIcon = e.getButton() != MouseEvent.BUTTON3 && getDownloadIconRec().contains(e.getX(), e.getY()); - if (!popupMenuVisible && isLeftClickDownloadIcon && !checkWidgetInstalled()) { + if (!isRightClickPopupMenuVisible() && isLeftClickDownloadIcon && !checkWidgetInstalled()) { downLoadWidget(); } } @@ -281,7 +295,7 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock implements Popu return; } //如果鼠标移动到布局内且布局不可编辑,画出编辑蒙层 - if (!popupMenuVisible && (isMouseEnter || downloading)) { + if (!isRightClickPopupMenuVisible() && (isMouseEnter || downloading)) { Graphics2D g2d = (Graphics2D) g; Composite oldComposite = g2d.getComposite(); //画白色的编辑层 @@ -310,25 +324,6 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock implements Popu } } - @Override - public void popupMenuWillBecomeVisible(PopupMenuEvent e) { - this.popupMenuVisible = true; - repaint(); - } - - @Override - public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { - this.popupMenuVisible = false; - repaint(); - } - - @Override - public void popupMenuCanceled(PopupMenuEvent e) { - this.popupMenuVisible = false; - repaint(); - } - - class WidgetDownloadProcess implements com.fr.design.extra.Process { @Override diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/PreviewWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/PreviewWidgetBlock.java index 8ad9e2b11..58dee8945 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/PreviewWidgetBlock.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/PreviewWidgetBlock.java @@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull; import javax.swing.ImageIcon; import javax.swing.JPanel; +import javax.swing.JPopupMenu; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; @@ -25,12 +26,14 @@ import java.io.Serializable; public abstract class PreviewWidgetBlock extends JPanel implements MouseListener, MouseMotionListener, Serializable { protected T widget; private boolean showing = false; + private final JPopupMenu rightClickPopupMenu; public PreviewWidgetBlock(T widget) { this.widget = widget; initPane(); this.addMouseListener(this); this.addMouseMotionListener(this); + rightClickPopupMenu = this.createRightClickPopupMenu(); } protected void initPane() { @@ -51,6 +54,18 @@ public abstract class PreviewWidgetBlock extends JPanel implements MouseListe return widget; } + protected JPopupMenu createRightClickPopupMenu() { + return null; + } + + protected JPopupMenu getRightClickPopupMenu() { + return rightClickPopupMenu; + } + + protected boolean isRightClickPopupMenuVisible() { + return rightClickPopupMenu != null && rightClickPopupMenu.isVisible(); + } + @NotNull protected abstract Image getCoverImage(); @@ -116,10 +131,12 @@ public abstract class PreviewWidgetBlock extends JPanel implements MouseListe public void mouseMoved(MouseEvent e) { Dimension dimension = getCoverDimension(); Rectangle containerRec = new Rectangle(0, 0, dimension.width, dimension.height); - if (containerRec.contains(e.getX(), e.getY())) { - this.showPreviewPane(); - } else { - this.hidePreviewPane(); + if (!isRightClickPopupMenuVisible()) { + if (containerRec.contains(e.getX(), e.getY())) { + this.showPreviewPane(); + } else { + this.hidePreviewPane(); + } } }