Browse Source

REPORT-57806 主题获取

【问题原因】
1. 实现在线共享组件/组件包的新弹窗界面
2. 实现组件包封面右键按钮列表
3. 共享组件模块中下载和应用主题埋点

【改动思路】
同上
research/11.0
Starryi 3 years ago
parent
commit
b1b583d34f
  1. 17
      designer-form/src/main/java/com/fr/design/mainframe/share/AbstractWidgetSelectPane.java
  2. 15
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/AbstractWidgetPopupPreviewPane.java
  3. 14
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/LocalWidgetPopupPreviewPane.java
  4. 194
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/AbstractOnlineWidgetBlock.java
  5. 3
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java
  6. 3
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetPackageBlock.java
  7. 9
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/LocalWidgetSelectPane.java
  8. 212
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetPopupPreviewPane.java
  9. 8
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetSelectPane.java
  10. 4
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackageSelectPane.java
  11. 5
      designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackagesShowPane.java
  12. 35
      designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java

17
designer-form/src/main/java/com/fr/design/mainframe/share/AbstractWidgetSelectPane.java

@ -1,6 +1,7 @@
package com.fr.design.mainframe.share;
import com.fr.design.mainframe.share.ui.base.PopupPreviewPane;
import com.fr.design.mainframe.share.ui.base.AbstractWidgetPopupPreviewPane;
import com.fr.design.mainframe.share.ui.base.LocalWidgetPopupPreviewPane;
import com.fr.design.mainframe.share.ui.block.PreviewWidgetBlock;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils;
@ -13,16 +14,16 @@ import java.awt.Container;
* @Author: Yuan.Wang
* @Date: 2021/1/15
*/
public abstract class AbstractWidgetSelectPane extends JPanel {
public abstract class AbstractWidgetSelectPane<T> extends JPanel {
private static final int SCROLL_BAR_HEIGHT = 10;
private final PopupPreviewPane previewPane;
private final AbstractWidgetPopupPreviewPane<T> previewPane;
private String currentShowWidgetID;
public AbstractWidgetSelectPane() {
this.previewPane = new PopupPreviewPane();
this.previewPane = createPopupPreviewPane();
}
public void showPreviewPane(PreviewWidgetBlock<?> comp, String showWidgetID) {
public void showPreviewPane(PreviewWidgetBlock<T> comp, String showWidgetID) {
if (ComparatorUtils.equals(currentShowWidgetID, showWidgetID)) {
return;
}
@ -36,7 +37,7 @@ public abstract class AbstractWidgetSelectPane extends JPanel {
this.currentShowWidgetID = StringUtils.EMPTY;
}
private void popupPreviewPane(PreviewWidgetBlock<?> comp, String showWidgetID) {
private void popupPreviewPane(PreviewWidgetBlock<T> comp, String showWidgetID) {
if (previewPane.isVisible()) {
previewPane.setVisible(false);
}
@ -44,7 +45,7 @@ public abstract class AbstractWidgetSelectPane extends JPanel {
if (!previewPane.isVisible() && comp.getWidth() != 0 && comp.getHeight() != 0) {
//父容器是GroupPane,要获得的是GroupPane的父容器
Container parentContainer =getParentContainer();
previewPane.setComp(comp.getPreviewImage());
previewPane.populateBean(comp);
int popupPosY = comp.getLocationOnScreen().y - parentContainer.getLocationOnScreen().y;
if (previewPane.getHeight() + popupPosY > parentContainer.getHeight() + SCROLL_BAR_HEIGHT) {
popupPosY -= (previewPane.getHeight() + popupPosY - parentContainer.getHeight() - SCROLL_BAR_HEIGHT);
@ -58,5 +59,7 @@ public abstract class AbstractWidgetSelectPane extends JPanel {
}
}
protected abstract AbstractWidgetPopupPreviewPane<T> createPopupPreviewPane();
abstract protected Container getParentContainer();
}

15
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/AbstractWidgetPopupPreviewPane.java

@ -0,0 +1,15 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.mainframe.share.ui.block.PreviewWidgetBlock;
import javax.swing.JPopupMenu;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2021/9/15
*/
public abstract class AbstractWidgetPopupPreviewPane<T> extends JPopupMenu {
public abstract void populateBean(PreviewWidgetBlock<T> block);
}

14
designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PopupPreviewPane.java → designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/LocalWidgetPopupPreviewPane.java

@ -1,6 +1,9 @@
package com.fr.design.mainframe.share.ui.base;
import com.fr.design.constants.UIConstants;
import com.fr.design.mainframe.share.ui.block.LocalWidgetBlock;
import com.fr.design.mainframe.share.ui.block.PreviewWidgetBlock;
import com.fr.form.share.DefaultSharableWidget;
import com.fr.general.IOUtils;
import javax.swing.BorderFactory;
@ -17,17 +20,16 @@ import java.awt.Toolkit;
/**
* Created by kerry on 2020-06-23
*/
public class PopupPreviewPane extends JPopupMenu {
private Container contentPane;
public class LocalWidgetPopupPreviewPane extends AbstractWidgetPopupPreviewPane<DefaultSharableWidget> {
private Image compImage;
private static final int WIDTH = 400;
private static final int STANDARD_DPI = 128;
private static final int MAX_HEIGHT = 400;
private static final int HEIGHT = 210;
public PopupPreviewPane() {
public LocalWidgetPopupPreviewPane() {
setFocusable(false);
contentPane = new JPanel();
Container contentPane = new JPanel();
contentPane.setBackground(Color.white);
this.setLayout(new BorderLayout());
this.add(contentPane, BorderLayout.CENTER);
@ -36,9 +38,9 @@ public class PopupPreviewPane extends JPopupMenu {
setBorder(BorderFactory.createLineBorder(UIConstants.LINE_COLOR));
}
public void setComp(Image compImage) {
public void populateBean(PreviewWidgetBlock<DefaultSharableWidget> block) {
try {
this.compImage = compImage;
this.compImage = block.getPreviewImage();
this.updateSize();
} catch (Exception e) {
e.printStackTrace();

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

@ -1,27 +1,57 @@
package com.fr.design.mainframe.share.ui.block;
import com.fr.base.theme.FormTheme;
import com.fr.base.theme.FormThemeConfig;
import com.fr.base.theme.TemplateTheme;
import com.fr.base.theme.TemplateThemeConfig;
import com.fr.design.DesignerEnvManager;
import com.fr.design.actions.UpdateAction;
import com.fr.design.constants.UIConstants;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.ilable.UILabel;
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;
import com.fr.design.mainframe.DesignerContext;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.share.ui.online.OnlineResourceManager;
import com.fr.design.mainframe.share.ui.online.OnlineWidgetSelectPane;
import com.fr.design.mainframe.share.ui.online.ResourceLoader;
import com.fr.design.mainframe.share.util.DownloadUtils;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.form.share.bean.OnlineShareWidget;
import com.fr.form.share.constants.ShareComponentConstants;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import com.fr.third.springframework.web.util.UriUtils;
import com.fr.transaction.CallBackAdaptor;
import com.fr.workspace.WorkContext;
import org.jetbrains.annotations.NotNull;
import javax.imageio.ImageIO;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.SwingWorker;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
/**
* Created by kerry on 2020-11-22
*/
public abstract class AbstractOnlineWidgetBlock extends PreviewWidgetBlock<OnlineShareWidget> implements ResourceLoader {
private static final String ONLINE_WIDGET_DETAIL_FORMATTED_URL = "https://market.fanruan.com/reuse/%s";
private final OnlineWidgetSelectPane parentPane;
private UILabel coverLabel;
@ -91,4 +121,168 @@ public abstract class AbstractOnlineWidgetBlock extends PreviewWidgetBlock<Onlin
this.parentPane.repaint();
}
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if (e.getButton() == MouseEvent.BUTTON3) {
this.parentPane.hidePreviewPane();
JPopupMenu popupMenu = createRightClickPopupMenu();
GUICoreUtils.showPopupMenu(popupMenu, this, e.getX(), e.getY());
}
}
public JPopupMenu createRightClickPopupMenu() {
UIPopupMenu popupMenu = new UIPopupMenu();
popupMenu.setOnlyText(true);
popupMenu.setBackground(UIConstants.DEFAULT_BG_RULER);
OnlineShareWidget widget = getWidget();
OnlineShareWidget parentPackage = widget.getParentPackage();
String suitableThemeFile = parentPackage != null ? parentPackage.getThemePath() : null;
if (StringUtils.isNotEmpty(suitableThemeFile)) {
popupMenu.add(new DownloadSuitableThemeAction(suitableThemeFile).createMenuItem());
}
popupMenu.add(new Jump2DetailAction().createMenuItem());
return popupMenu;
}
private static class DownloadSuitableThemeAction extends UpdateAction {
private final String themePath;
private boolean downloading = false;
public DownloadSuitableThemeAction(String themePath) {
this.themePath = themePath;
this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme"));
}
@Override
public void actionPerformed(ActionEvent e) {
if (checkAuthority()) {
saveTheme();
}
}
private boolean checkAuthority() {
if (!WorkContext.getCurrent().isRoot()) {
FineJOptionPane.showMessageDialog(DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme_No_Authority_Tip_Message"),
Toolkit.i18nText("Fine-Design_Share_Download_Suitable_Theme_No_Authority_Tip_Title"),
JOptionPane.WARNING_MESSAGE);
return false;
}
String userName = DesignerEnvManager.getEnvManager().getDesignerLoginUsername();
if (StringUtils.isEmpty(userName)) {
DesignerLoginHelper.showLoginDialog(DesignerLoginSource.NORMAL);
return false;
}
return true;
}
private void saveTheme() {
if (downloading) {
return;
}
downloading = true;
final JTemplate<?,?> template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
new SwingWorker<Boolean, Void>() {
@Override
protected Boolean doInBackground() {
FormTheme theme = fetchRemoteTheme();
if (theme == null) {
return false;
}
theme = ensureThemeHasUniqueName(theme, theme.getName());
if (theme == null) {
return false;
}
String themeName = theme.getName();
saveThemeToConfig(theme, new CallBackAdaptor() {
@Override
public void afterCommit() {
super.afterCommit();
int returnVal = FineJOptionPane.showConfirmDialog(
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Share_Apply_Suitable_Theme_Tip"),
Toolkit.i18nText("Fine-Design_Basic_Confirm"),
FineJOptionPane.OK_CANCEL_OPTION);
if (returnVal == JOptionPane.YES_OPTION) {
applyTheme(template, themeName);
}
}
});
return true;
}
@Override
protected void done() {
downloading = false;
}
}.execute();
}
private FormTheme fetchRemoteTheme() {
return DownloadUtils.downloadThemeFile(themePath);
}
private FormTheme ensureThemeHasUniqueName(FormTheme theme, String expectedName) {
if (!FormThemeConfig.getInstance().contains(expectedName)) {
theme.setName(expectedName);
return theme;
} else {
String newName = (String) FineJOptionPane.showInputDialog(
DesignerContext.getDesignerFrame(),
Toolkit.i18nText("Fine-Design_Share_Rename_Suitable_Theme_Tip"),
Toolkit.i18nText("Fine-Design_Basic_Rename"),
FineJOptionPane.QUESTION_MESSAGE, null, null,
expectedName);
return StringUtils.isEmpty(newName) ? null : ensureThemeHasUniqueName(theme, newName);
}
}
private void saveThemeToConfig(final FormTheme theme, CallBackAdaptor callback) {
FormThemeConfig.getInstance().addTheme(theme, true, callback);
}
private void applyTheme(JTemplate<?,?> template, final String name) {
TemplateThemeConfig<? extends TemplateTheme> config = template.getUsingTemplateThemeConfig();
TemplateTheme theme = config.cachedFetch(name);
template.setTemplateTheme(theme);
}
}
private class Jump2DetailAction extends UpdateAction {
public Jump2DetailAction() {
this.putValue(Action.SMALL_ICON, null);
this.setName(Toolkit.i18nText("Fine-Design_Share_Jump_To_Detail"));
}
@Override
public void actionPerformed(ActionEvent e) {
OnlineShareWidget widget = getWidget();
String id = widget.getId();
if (StringUtils.isNotEmpty(id)) {
Desktop desktop = Desktop.getDesktop();
try {
desktop.browse(new URI(String.format(ONLINE_WIDGET_DETAIL_FORMATTED_URL, id)));
} catch (IOException | URISyntaxException ioException) {
ioException.printStackTrace();
}
}
}
}
}

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

@ -112,7 +112,8 @@ public class OnlineWidgetBlock extends AbstractOnlineWidgetBlock {
@Override
public void mouseClicked(MouseEvent e) {
super.mouseClicked(e);
if (!checkWidgetInstalled() && getDownloadIconRec().contains(e.getX(), e.getY())) {
boolean isLeftClickDownloadIcon = e.getButton() != MouseEvent.BUTTON3 && getDownloadIconRec().contains(e.getX(), e.getY());
if (isLeftClickDownloadIcon && !checkWidgetInstalled()) {
downLoadWidget();
}
}

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

@ -35,7 +35,7 @@ public class OnlineWidgetPackageBlock extends AbstractOnlineWidgetBlock {
detailLabel.addMouseListener(new MouseClickListener() {
@Override
public void mouseClicked(MouseEvent e) {
parentPane.showWidgetDetailPane(widget.getId());
parentPane.showWidgetDetailPane(widget);
}
});
southPane.add(detailLabel, BorderLayout.EAST);
@ -51,7 +51,6 @@ public class OnlineWidgetPackageBlock extends AbstractOnlineWidgetBlock {
this.setPreferredSize(new Dimension(ShareComponentConstants.SHARE_PACKAGE_BLOCK_WIDTH, ShareComponentConstants.SHARE_PACKAGE_BLOCK_HEIGHT));
this.add(createSouthPane(widget, parentPane), BorderLayout.SOUTH);
}
}

9
designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/LocalWidgetSelectPane.java

@ -1,6 +1,8 @@
package com.fr.design.mainframe.share.ui.local;
import com.fr.design.mainframe.share.AbstractWidgetSelectPane;
import com.fr.design.mainframe.share.ui.base.AbstractWidgetPopupPreviewPane;
import com.fr.design.mainframe.share.ui.base.LocalWidgetPopupPreviewPane;
import com.fr.design.mainframe.share.ui.block.LocalWidgetBlock;
import com.fr.form.share.DefaultSharableWidget;
import com.fr.form.share.SharableWidgetProvider;
@ -22,7 +24,7 @@ import java.awt.event.MouseEvent;
/**
* created by Harrison on 2020/03/23
**/
public class LocalWidgetSelectPane extends AbstractWidgetSelectPane {
public class LocalWidgetSelectPane extends AbstractWidgetSelectPane<DefaultSharableWidget> {
private LocalWidgetBlock selectedBlock;
private final Group group;
@ -105,6 +107,11 @@ public class LocalWidgetSelectPane extends AbstractWidgetSelectPane {
return selectedBlock;
}
@Override
protected AbstractWidgetPopupPreviewPane<DefaultSharableWidget> createPopupPreviewPane() {
return new LocalWidgetPopupPreviewPane();
}
@Override
protected Container getParentContainer() {
return this.getParent().getParent();

212
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetPopupPreviewPane.java

@ -0,0 +1,212 @@
package com.fr.design.mainframe.share.ui.online;
import com.fr.design.designer.IntervalConstants;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.share.ui.base.AbstractWidgetPopupPreviewPane;
import com.fr.design.mainframe.share.ui.block.PreviewWidgetBlock;
import com.fr.form.share.bean.OnlineShareWidget;
import com.fr.general.FRFont;
import com.fr.general.IOUtils;
import com.fr.stable.StringUtils;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Toolkit;
/**
* @author Starryi
* @version 1.0
* Created by Starryi on 2021/9/14
*/
public class OnlineWidgetPopupPreviewPane extends AbstractWidgetPopupPreviewPane<OnlineShareWidget> {
private static final int POPUP_WIDTH = 412;
private static final int POPUP_TOP_HEIGHT = 28;
private static final int POPUP_BOTTOM_HEIGHT = 54;
private PreviewImagePane previewImagePane;
private UILabel versionLabel;
private UILabel downloadsLabel;
private UILabel priceLabel;
private final JPanel suitableThemeNamePane;
private UILabel suitableThemeNameLabel;
public OnlineWidgetPopupPreviewPane() {
setPreferredSize(new Dimension(POPUP_WIDTH, getPreferredSize().height));
setLayout(new BorderLayout(0, 0));
setOpaque(true);
setBackground(new Color(0xF0F0F1));
suitableThemeNamePane = createSuitableThemeNamePane();
JPanel previewImagePane = createPreviewImagePane();
JPanel widgetInfoPane = createWidgetInfoPane();
addComponents(suitableThemeNamePane, previewImagePane, widgetInfoPane);
}
private JPanel createSuitableThemeNamePane() {
suitableThemeNameLabel = new UILabel();
suitableThemeNameLabel.setOpaque(false);
suitableThemeNameLabel.setBackground(new Color(0xF5F5F7));
suitableThemeNameLabel.setIcon(IOUtils.readIcon("/com/fr/design/icon/icon_predefined_style.png"));
suitableThemeNameLabel.setIconTextGap(IntervalConstants.INTERVAL_L6);
JPanel content = FRGUIPaneFactory.createBorderLayout_S_Pane();
content.setPreferredSize(new Dimension(POPUP_WIDTH, POPUP_TOP_HEIGHT));
content.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
content.setOpaque(true);
content.setBackground(new Color(0xF5F5F7));
content.add(suitableThemeNameLabel, BorderLayout.CENTER);
JPanel container = FRGUIPaneFactory.createBorderLayout_S_Pane();
container.add(content, BorderLayout.CENTER);
JSeparator separator = new JSeparator();
separator.setPreferredSize(new Dimension(POPUP_WIDTH, 1));
separator.setBackground(new Color(0xE8E8E9));
container.add(separator, BorderLayout.SOUTH);
return container;
}
private JPanel createPreviewImagePane() {
previewImagePane = new PreviewImagePane();
JPanel container = FRGUIPaneFactory.createBorderLayout_S_Pane();
container.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 10));
container.add(previewImagePane, BorderLayout.CENTER);
return container;
}
private JPanel createWidgetInfoPane() {
versionLabel = new UILabel();
versionLabel.setVerticalAlignment(SwingConstants.CENTER);
versionLabel.setFont(FRFont.getInstance(versionLabel.getFont()).deriveFont(12.0F));
downloadsLabel = new UILabel();
downloadsLabel.setVerticalAlignment(SwingConstants.TOP);
downloadsLabel.setFont(FRFont.getInstance(downloadsLabel.getFont()).deriveFont(12.0F));
priceLabel = new UILabel();
priceLabel.setVerticalAlignment(SwingConstants.CENTER);
priceLabel.setHorizontalAlignment(SwingConstants.RIGHT);
priceLabel.setFont(FRFont.getInstance(priceLabel.getFont()).deriveFont(14.0F));
priceLabel.setForeground(new Color(0xE65251));
JPanel container = new JPanel();
container.setPreferredSize(new Dimension(POPUP_WIDTH - 20, POPUP_BOTTOM_HEIGHT));
container.setLayout(new GridBagLayout());
container.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
container.add(versionLabel, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
constraints.gridwidth = 1;
constraints.gridheight = 1;
constraints.weightx = 1;
constraints.weighty = 1;
container.add(downloadsLabel, constraints);
constraints.gridx = 1;
constraints.gridy = 0;
constraints.gridwidth = 1;
constraints.gridheight = 2;
constraints.weightx = 1;
constraints.weighty = 2;
container.add(priceLabel, constraints);
return container;
}
private void addComponents(JComponent... components) {
if (components == null) {
return;
}
JComponent container = this;
for (int i = 0; i < components.length; i++) {
JComponent component = components[i];
if (component != null) {
container.add(component, BorderLayout.NORTH);
if (i < components.length - 1) {
JPanel nextContainer = FRGUIPaneFactory.createBorderLayout_S_Pane();
container.add(nextContainer, BorderLayout.CENTER);
container = nextContainer;
}
}
}
}
@Override
public void populateBean(PreviewWidgetBlock<OnlineShareWidget> block) {
OnlineShareWidget widget = block.getWidget();
OnlineShareWidget parentPackage = widget.getParentPackage();
if (parentPackage != null && StringUtils.isNotEmpty(parentPackage.getThemeName())) {
suitableThemeNamePane.setVisible(true);
suitableThemeNameLabel.setText(parentPackage.getThemeName());
} else {
suitableThemeNamePane.setVisible(false);
}
String priceText = "¥" + widget.getPrice();
if (widget.getPrice() <= 0) {
priceText = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Share_Price_Free");
}
priceLabel.setText(priceText);
versionLabel.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Share_Version") + ": " + widget.getDesignerVersion());
downloadsLabel.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Share_Download_Times") + ": " + widget.getDownloadTimes());
previewImagePane.setPreviewImage(block.getPreviewImage());
int height = (suitableThemeNamePane.isVisible() ? POPUP_TOP_HEIGHT : 0) + 10 + previewImagePane.getPreferredSize().height + POPUP_BOTTOM_HEIGHT;
setPreferredSize(new Dimension(POPUP_WIDTH, height));
}
private static class PreviewImagePane extends JPanel {
private static final Image DEFAULT_IMAGE = IOUtils.readImage("com/fr/base/images/share/component_error.png");
private static final int PREVIEW_IMAGE_WIDTH = POPUP_WIDTH - 20;
private static final int STANDARD_DPI = 128;
private Image previewImage;
public void setPreviewImage(Image previewImage) {
this.previewImage = previewImage;
if (this.previewImage == null) {
this.previewImage = DEFAULT_IMAGE;
}
int dpi = Toolkit.getDefaultToolkit().getScreenResolution();
int imageWidth = this.previewImage.getWidth(null);
int imageHeight = this.previewImage.getHeight(null);
double imageAspectRatio = (double) imageWidth / imageHeight;
int width = (PREVIEW_IMAGE_WIDTH * dpi) / STANDARD_DPI;
int height = (int) (width / imageAspectRatio);
setPreferredSize(new Dimension(width, height));
}
@Override
public void paint(Graphics g) {
g.drawImage(this.previewImage, 0, 0, getWidth(), getHeight(), null);
}
}
}

8
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetSelectPane.java

@ -3,6 +3,7 @@ package com.fr.design.mainframe.share.ui.online;
import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.share.AbstractWidgetSelectPane;
import com.fr.design.mainframe.share.ui.base.AbstractWidgetPopupPreviewPane;
import com.fr.design.mainframe.share.ui.base.LoadingPane;
import com.fr.design.mainframe.share.ui.base.NoMatchPane;
import com.fr.design.mainframe.share.ui.base.PagingFiledPane;
@ -30,7 +31,7 @@ import java.util.concurrent.ExecutionException;
/**
* Created by kerry on 2020-10-19
*/
public class OnlineWidgetSelectPane extends AbstractWidgetSelectPane {
public class OnlineWidgetSelectPane extends AbstractWidgetSelectPane<OnlineShareWidget> {
protected static final int H_GAP = 5;
protected static final int V_GAP = 10;
@ -219,6 +220,11 @@ public class OnlineWidgetSelectPane extends AbstractWidgetSelectPane {
}
}
@Override
protected AbstractWidgetPopupPreviewPane<OnlineShareWidget> createPopupPreviewPane() {
return new OnlineWidgetPopupPreviewPane();
}
protected Container getParentContainer() {
return this.getParent();
}

4
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackageSelectPane.java

@ -25,8 +25,8 @@ public class OnlineWidgetPackageSelectPane extends OnlineWidgetSelectPane {
}
public void showWidgetDetailPane(String id) {
this.parentPane.showWidgetDetailPane(id);
public void showWidgetDetailPane(OnlineShareWidget widgetPackage) {
this.parentPane.showWidgetDetailPane(widgetPackage);
}
protected PreviewWidgetBlock<OnlineShareWidget> createWidgetBlock(OnlineShareWidget provider) {

5
designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackagesShowPane.java

@ -150,10 +150,11 @@ public class OnlineWidgetPackagesShowPane extends AbstractOnlineWidgetShowPane {
return onlineShareWidgets.toArray(new OnlineShareWidget[onlineShareWidgets.size()]);
}
public void showWidgetDetailPane(final String id) {
public void showWidgetDetailPane(final OnlineShareWidget widgetPackage) {
String id = widgetPackage.getId();
currentPackageId = id;
boolean containsCache = cachePanelMap.containsKey(id);
onlineWidgetSelectPane = containsCache ? cachePanelMap.get(id) : new OnlineWidgetSelectPane(() -> ShareUtils.getPackageWidgets(id), 50);
onlineWidgetSelectPane = containsCache ? cachePanelMap.get(id) : new OnlineWidgetSelectPane(() -> ShareUtils.getPackageWidgets(widgetPackage), 50);
downloadLabel.setVisible(!containsCache);
showWidgetDetailPane(onlineWidgetSelectPane);
}

35
designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java

@ -1,5 +1,7 @@
package com.fr.design.mainframe.share.util;
import com.fr.base.theme.FormTheme;
import com.fr.base.theme.TemplateTheme;
import com.fr.design.DesignerEnvManager;
import com.fr.design.extra.PluginConstants;
import com.fr.form.share.base.CancelCheck;
@ -9,6 +11,11 @@ import com.fr.general.CloudCenter;
import com.fr.log.FineLoggerFactory;
import com.fr.stable.ProductConstants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
import com.fr.stable.xml.XMLPrintWriter;
import com.fr.stable.xml.XMLReaderHelper;
import com.fr.stable.xml.XMLableReader;
import com.fr.third.javax.xml.stream.XMLStreamException;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpException;
import com.fr.third.org.apache.http.HttpStatus;
@ -23,8 +30,10 @@ import com.fr.third.org.apache.http.impl.client.HttpClients;
import org.jetbrains.annotations.NotNull;
import javax.crypto.Cipher;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.KeyFactory;
@ -130,6 +139,32 @@ public class DownloadUtils {
}
}
public static FormTheme downloadThemeFile(String themePath) {
try {
CloseableHttpResponse fileRes = getHttpResponse(themePath);
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
fileRes = getHttpResponse(fileRes.getHeaders("Location")[0].getValue());
}
if (fileRes.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = fileRes.getEntity();
InputStream content = entity.getContent();
XMLableReader reader = XMLReaderHelper.createXMLableReader(content, XMLPrintWriter.XML_ENCODER);
FormTheme theme = new FormTheme();
reader.readXMLObject(theme);
if (StringUtils.isNotEmpty(theme.getName())) {
return theme;
}
} else {
FineLoggerFactory.getLogger().info("download theme {} failed", themePath);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(), e);
}
return null;
}
private static CloseableHttpResponse getHttpResponse(String url, String id) throws Exception {
//先登录一下。不然可能失败
CloseableHttpClient client = createClient();

Loading…
Cancel
Save