From 18c92584eeaa93079f28a8b2b00b73de4a11b641 Mon Sep 17 00:00:00 2001 From: Starryi Date: Tue, 19 Oct 2021 15:28:44 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-60982=20=E4=B8=BB=E9=A2=98=E8=8E=B7?= =?UTF-8?q?=E5=8F=96-=E7=82=B9=E5=87=BB=E8=8E=B7=E5=8F=96=E4=B8=BB?= =?UTF-8?q?=E9=A2=98=E5=90=8E=E7=BD=91=E7=BB=9C=E8=BE=83=E6=85=A2=E6=97=B6?= =?UTF-8?q?=E8=BF=87=E6=B8=A1=E4=B8=8D=E5=90=88=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 修改主题下载交互 1. 添加加载动画 2. 下载是弹窗菜单不消失 【改动思路】 同上 --- .../actions/DownloadSuitableThemeAction.java | 31 ++++++++--- .../share/ui/actions/LoadingMenuItem.java | 50 ++++++++++++++++++ .../SharedComponentActionMenuItemUI.java | 37 ++++++++----- .../ui/block/AbstractOnlineWidgetBlock.java | 3 +- .../com/fr/design/form/images/loading.gif | Bin 0 -> 3430 bytes 5 files changed, 101 insertions(+), 20 deletions(-) create mode 100644 designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/LoadingMenuItem.java create mode 100644 designer-form/src/main/resources/com/fr/design/form/images/loading.gif diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java index 399a644b40..f8f4cc1a78 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java @@ -10,6 +10,7 @@ import com.fr.design.dialog.FineJOptionPane; import com.fr.design.file.HistoryTemplateListCache; import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIMenuItemUI; +import com.fr.design.gui.imenu.UIPopupMenu; import com.fr.design.i18n.Toolkit; import com.fr.design.login.DesignerLoginHelper; import com.fr.design.login.DesignerLoginSource; @@ -39,22 +40,35 @@ import java.util.concurrent.ExecutionException; */ public class DownloadSuitableThemeAction extends UpdateAction { private final String themePath; + private final UIPopupMenu popupMenu; private boolean downloading = false; private JTemplate currentTemplate; - public DownloadSuitableThemeAction(String themePath) { + public DownloadSuitableThemeAction(String themePath, UIPopupMenu popupMenu) { this.themePath = themePath; + this.popupMenu = popupMenu; this.putValue(Action.SMALL_ICON, null); this.setName(Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme")); } @Override public UIMenuItem createMenuItem() { - UIMenuItem menuItem = super.createMenuItem(); - menuItem.setOpaque(true); - menuItem.setBackground(ColorConstants.BACKGROUND); - menuItem.setUI(new SharedComponentActionMenuItemUI()); - return menuItem; + return getLoadingMenuItem(); + } + + public LoadingMenuItem getLoadingMenuItem() { + Object object = this.getValue(LoadingMenuItem.class.getName()); + if (object == null) { + UIMenuItem menuItem = new LoadingMenuItem(this); + // 设置名字用作单元测 + menuItem.setName(getName()); + setPressedIcon4Button(menuItem); + setDisabledIcon4Button(menuItem); + object = menuItem; + + this.putValue(LoadingMenuItem.class.getName(), object); + } + return (LoadingMenuItem) object; } @Override @@ -91,6 +105,8 @@ public class DownloadSuitableThemeAction extends UpdateAction { } downloading = true; + LoadingMenuItem menuItem = getLoadingMenuItem(); + menuItem.startLoading(); new SwingWorker() { @Override @@ -109,11 +125,14 @@ public class DownloadSuitableThemeAction extends UpdateAction { onThemeFetched(theme); downloading = false; + LoadingMenuItem menuItem = getLoadingMenuItem(); + menuItem.stopLoading(); } }.execute(); } public void onThemeFetched(FormTheme theme) { + popupMenu.menuSelectionChanged(false); if (theme == null) { return; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/LoadingMenuItem.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/LoadingMenuItem.java new file mode 100644 index 0000000000..6262c34a33 --- /dev/null +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/LoadingMenuItem.java @@ -0,0 +1,50 @@ +package com.fr.design.mainframe.share.ui.actions; + +import com.fr.design.gui.imenu.UIMenuItem; +import com.fr.design.mainframe.share.ui.constants.ColorConstants; +import com.fr.general.IOUtils; + +import javax.swing.Action; +import javax.swing.BorderFactory; +import javax.swing.Icon; +import java.awt.Graphics; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2021/10/19 + */ +public class LoadingMenuItem extends UIMenuItem { + private boolean loading = false; + + private final Icon profileIcon = IOUtils.readIcon("/com/fr/design/form/images/loading.gif"); + + public LoadingMenuItem(Action action) { + super(action); + setOpaque(true); + setBackground(ColorConstants.BACKGROUND); + setUI(new SharedComponentActionMenuItemUI(false)); + } + + public void startLoading() { + loading = true; + setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 20)); + revalidate(); + repaint(); + } + + public void stopLoading() { + loading = false; + setBorder(BorderFactory.createEmptyBorder()); + revalidate(); + repaint(); + } + + @Override + protected void paintBorder(Graphics g) { + super.paintBorder(g); + if (loading) { + profileIcon.paintIcon(this, g, getWidth() - 20, 0); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/SharedComponentActionMenuItemUI.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/SharedComponentActionMenuItemUI.java index ca4d499b1d..8a3fe5e1c9 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/SharedComponentActionMenuItemUI.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/SharedComponentActionMenuItemUI.java @@ -8,7 +8,7 @@ import com.fr.stable.Constants; import javax.swing.ButtonModel; import javax.swing.JMenu; import javax.swing.JMenuItem; -import javax.swing.JPopupMenu; +import javax.swing.MenuSelectionManager; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; @@ -20,6 +20,16 @@ import java.awt.Graphics2D; */ public class SharedComponentActionMenuItemUI extends UIMenuItemUI { + private final boolean autoClosePopup; + + public SharedComponentActionMenuItemUI(boolean autoClosePopup) { + this.autoClosePopup = autoClosePopup; + } + + public SharedComponentActionMenuItemUI() { + this(true); + } + @Override protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { ButtonModel model = menuItem.getModel(); @@ -27,18 +37,19 @@ public class SharedComponentActionMenuItemUI extends UIMenuItemUI { int menuWidth = menuItem.getWidth(); int menuHeight = menuItem.getHeight(); - g.setColor(UIConstants.NORMAL_BACKGROUND); - g.fillRect(0, 0, menuWidth, menuHeight); - if (menuItem.isOpaque()) { - if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { - GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); - } else { - GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7); - } - g.setColor(oldColor); - } else if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { - GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); - g.setColor(oldColor); + if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) { + GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 0); + } + + g.setColor(oldColor); + } + + @Override + protected void doClick(MenuSelectionManager msm) { + if (autoClosePopup) { + super.doClick(msm); + } else { + menuItem.doClick(0); } } } 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 5ce5b57dd1..3be4f96b9a 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/main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