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 399a644b4..f8f4cc1a7 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 000000000..6262c34a3 --- /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 ca4d499b1..8a3fe5e1c 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 5ce5b57dd..3be4f96b9 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 @@ -116,12 +116,13 @@ public abstract class AbstractOnlineWidgetBlock extends PreviewWidgetBlock