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 751ff62e0f..54a813c43a 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 fcf22b9d84..325e28afef 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 8ad9e2b11c..58dee8945c 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(); + } } }