Browse Source

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

Merge in DESIGN/design from ~STARRYI/design:release/11.0 to release/11.0

* commit '18c92584eeaa93079f28a8b2b00b73de4a11b641':
  REPORT-60982 主题获取-点击获取主题后网络较慢时过渡不合理
bugfix/11.0
starryi 3 years ago
parent
commit
602058f2b8
  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. 37
      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.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<FormTheme, Void>() {
@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;
}

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

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

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() {
UIPopupMenu popupMenu = new UIPopupMenu();
popupMenu.setOnlyText(true);
popupMenu.setOpaque(true);
popupMenu.setBackground(ColorConstants.BACKGROUND);
OnlineShareWidget widget = getWidget();
String suitableThemeFile = widget.getThemePath();
if (StringUtils.isNotEmpty(suitableThemeFile)) {
popupMenu.add(new DownloadSuitableThemeAction(suitableThemeFile).createMenuItem());
popupMenu.add(new DownloadSuitableThemeAction(suitableThemeFile, popupMenu).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