Browse Source

REPORT-60982 主题获取-点击获取主题后网络较慢时过渡不合理

【问题原因】
修改主题下载交互
1. 添加加载动画
2. 下载是弹窗菜单不消失

【改动思路】
同上
bugfix/11.0
Starryi 3 years ago
parent
commit
18c92584ee
  1. 31
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/DownloadSuitableThemeAction.java
  2. 50
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/LoadingMenuItem.java
  3. 31
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/actions/SharedComponentActionMenuItemUI.java
  4. 3
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java
  5. BIN
      designer-form/src/main/resources/com/fr/design/form/images/loading.gif

31
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.file.HistoryTemplateListCache;
import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIMenuItem;
import com.fr.design.gui.imenu.UIMenuItemUI; import com.fr.design.gui.imenu.UIMenuItemUI;
import com.fr.design.gui.imenu.UIPopupMenu;
import com.fr.design.i18n.Toolkit; import com.fr.design.i18n.Toolkit;
import com.fr.design.login.DesignerLoginHelper; import com.fr.design.login.DesignerLoginHelper;
import com.fr.design.login.DesignerLoginSource; import com.fr.design.login.DesignerLoginSource;
@ -39,22 +40,35 @@ import java.util.concurrent.ExecutionException;
*/ */
public class DownloadSuitableThemeAction extends UpdateAction { public class DownloadSuitableThemeAction extends UpdateAction {
private final String themePath; private final String themePath;
private final UIPopupMenu popupMenu;
private boolean downloading = false; private boolean downloading = false;
private JTemplate<?, ?> currentTemplate; private JTemplate<?, ?> currentTemplate;
public DownloadSuitableThemeAction(String themePath) { public DownloadSuitableThemeAction(String themePath, UIPopupMenu popupMenu) {
this.themePath = themePath; this.themePath = themePath;
this.popupMenu = popupMenu;
this.putValue(Action.SMALL_ICON, null); this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme")); this.setName(Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme"));
} }
@Override @Override
public UIMenuItem createMenuItem() { public UIMenuItem createMenuItem() {
UIMenuItem menuItem = super.createMenuItem(); return getLoadingMenuItem();
menuItem.setOpaque(true); }
menuItem.setBackground(ColorConstants.BACKGROUND);
menuItem.setUI(new SharedComponentActionMenuItemUI()); public LoadingMenuItem getLoadingMenuItem() {
return menuItem; 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 @Override
@ -91,6 +105,8 @@ public class DownloadSuitableThemeAction extends UpdateAction {
} }
downloading = true; downloading = true;
LoadingMenuItem menuItem = getLoadingMenuItem();
menuItem.startLoading();
new SwingWorker<FormTheme, Void>() { new SwingWorker<FormTheme, Void>() {
@Override @Override
@ -109,11 +125,14 @@ public class DownloadSuitableThemeAction extends UpdateAction {
onThemeFetched(theme); onThemeFetched(theme);
downloading = false; downloading = false;
LoadingMenuItem menuItem = getLoadingMenuItem();
menuItem.stopLoading();
} }
}.execute(); }.execute();
} }
public void onThemeFetched(FormTheme theme) { public void onThemeFetched(FormTheme theme) {
popupMenu.menuSelectionChanged(false);
if (theme == null) { if (theme == null) {
return; return;
} }

50
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);
}
}
}

31
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.ButtonModel;
import javax.swing.JMenu; import javax.swing.JMenu;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import javax.swing.JPopupMenu; import javax.swing.MenuSelectionManager;
import java.awt.Color; import java.awt.Color;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
@ -20,6 +20,16 @@ import java.awt.Graphics2D;
*/ */
public class SharedComponentActionMenuItemUI extends UIMenuItemUI { public class SharedComponentActionMenuItemUI extends UIMenuItemUI {
private final boolean autoClosePopup;
public SharedComponentActionMenuItemUI(boolean autoClosePopup) {
this.autoClosePopup = autoClosePopup;
}
public SharedComponentActionMenuItemUI() {
this(true);
}
@Override @Override
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) { protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
ButtonModel model = menuItem.getModel(); ButtonModel model = menuItem.getModel();
@ -27,18 +37,19 @@ public class SharedComponentActionMenuItemUI extends UIMenuItemUI {
int menuWidth = menuItem.getWidth(); int menuWidth = menuItem.getWidth();
int menuHeight = menuItem.getHeight(); 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())) { if (model.isArmed() || (menuItem instanceof JMenu && model.isSelected())) {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 7); GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, UIConstants.FLESH_BLUE, 0);
} else {
GUIPaintUtils.fillPaint((Graphics2D) g, 0, 0, menuWidth, menuHeight, true, Constants.NULL, menuItem.getBackground(), 7);
} }
g.setColor(oldColor); 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); @Override
protected void doClick(MenuSelectionManager msm) {
if (autoClosePopup) {
super.doClick(msm);
} else {
menuItem.doClick(0);
} }
} }
} }

3
designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java

@ -116,12 +116,13 @@ public abstract class AbstractOnlineWidgetBlock extends PreviewWidgetBlock<Onlin
public JPopupMenu createRightClickPopupMenu() { public JPopupMenu createRightClickPopupMenu() {
UIPopupMenu popupMenu = new UIPopupMenu(); UIPopupMenu popupMenu = new UIPopupMenu();
popupMenu.setOnlyText(true); popupMenu.setOnlyText(true);
popupMenu.setOpaque(true);
popupMenu.setBackground(ColorConstants.BACKGROUND); popupMenu.setBackground(ColorConstants.BACKGROUND);
OnlineShareWidget widget = getWidget(); OnlineShareWidget widget = getWidget();
String suitableThemeFile = widget.getThemePath(); String suitableThemeFile = widget.getThemePath();
if (StringUtils.isNotEmpty(suitableThemeFile)) { if (StringUtils.isNotEmpty(suitableThemeFile)) {
popupMenu.add(new DownloadSuitableThemeAction(suitableThemeFile).createMenuItem()); popupMenu.add(new DownloadSuitableThemeAction(suitableThemeFile, popupMenu).createMenuItem());
} }
popupMenu.add(new Jump2DetailAction(getWidget().getId()).createMenuItem()); popupMenu.add(new Jump2DetailAction(getWidget().getId()).createMenuItem());

BIN
designer-form/src/main/resources/com/fr/design/form/images/loading.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Loading…
Cancel
Save