From b1b583d34fe2f26c9a748869ef720ec775e5df28 Mon Sep 17 00:00:00 2001 From: Starryi Date: Sun, 26 Sep 2021 19:54:04 +0800 Subject: [PATCH 1/3] =?UTF-8?q?REPORT-57806=20=E4=B8=BB=E9=A2=98=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 1. 实现在线共享组件/组件包的新弹窗界面 2. 实现组件包封面右键按钮列表 3. 共享组件模块中下载和应用主题埋点 【改动思路】 同上 --- .../share/AbstractWidgetSelectPane.java | 17 +- .../base/AbstractWidgetPopupPreviewPane.java | 15 ++ ....java => LocalWidgetPopupPreviewPane.java} | 14 +- .../ui/block/AbstractOnlineWidgetBlock.java | 194 ++++++++++++++++ .../share/ui/block/OnlineWidgetBlock.java | 3 +- .../ui/block/OnlineWidgetPackageBlock.java | 3 +- .../share/ui/local/LocalWidgetSelectPane.java | 9 +- .../online/OnlineWidgetPopupPreviewPane.java | 212 ++++++++++++++++++ .../ui/online/OnlineWidgetSelectPane.java | 8 +- .../OnlineWidgetPackageSelectPane.java | 4 +- .../OnlineWidgetPackagesShowPane.java | 5 +- .../mainframe/share/util/DownloadUtils.java | 35 +++ 12 files changed, 497 insertions(+), 22 deletions(-) create mode 100644 designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/AbstractWidgetPopupPreviewPane.java rename designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/{PopupPreviewPane.java => LocalWidgetPopupPreviewPane.java} (81%) create mode 100644 designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetPopupPreviewPane.java diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/AbstractWidgetSelectPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/AbstractWidgetSelectPane.java index 96b321c93..1b36f08d1 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/AbstractWidgetSelectPane.java +++ b/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 extends JPanel { private static final int SCROLL_BAR_HEIGHT = 10; - private final PopupPreviewPane previewPane; + private final AbstractWidgetPopupPreviewPane previewPane; private String currentShowWidgetID; public AbstractWidgetSelectPane() { - this.previewPane = new PopupPreviewPane(); + this.previewPane = createPopupPreviewPane(); } - public void showPreviewPane(PreviewWidgetBlock comp, String showWidgetID) { + public void showPreviewPane(PreviewWidgetBlock 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 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 createPopupPreviewPane(); + abstract protected Container getParentContainer(); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/AbstractWidgetPopupPreviewPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/AbstractWidgetPopupPreviewPane.java new file mode 100644 index 000000000..12c2c33ff --- /dev/null +++ b/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 extends JPopupMenu { + + public abstract void populateBean(PreviewWidgetBlock block); +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PopupPreviewPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/LocalWidgetPopupPreviewPane.java similarity index 81% rename from designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PopupPreviewPane.java rename to designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/LocalWidgetPopupPreviewPane.java index 91b1eae89..f78dbf701 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/base/PopupPreviewPane.java +++ b/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 { 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 block) { try { - this.compImage = compImage; + this.compImage = block.getPreviewImage(); this.updateSize(); } catch (Exception e) { e.printStackTrace(); 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 06e513b80..404c319db 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 @@ -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 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 template = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); + new SwingWorker() { + + @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 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(); + } + } + } + } + } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java index 8ad419b03..dffddc81c 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetBlock.java +++ b/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(); } } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetPackageBlock.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetPackageBlock.java index 4b8458594..c3965f0da 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/block/OnlineWidgetPackageBlock.java +++ b/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); } - } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/LocalWidgetSelectPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/LocalWidgetSelectPane.java index 44bdd0fa5..90f1f30c2 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/local/LocalWidgetSelectPane.java +++ b/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 { private LocalWidgetBlock selectedBlock; private final Group group; @@ -105,6 +107,11 @@ public class LocalWidgetSelectPane extends AbstractWidgetSelectPane { return selectedBlock; } + @Override + protected AbstractWidgetPopupPreviewPane createPopupPreviewPane() { + return new LocalWidgetPopupPreviewPane(); + } + @Override protected Container getParentContainer() { return this.getParent().getParent(); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetPopupPreviewPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetPopupPreviewPane.java new file mode 100644 index 000000000..0bbc4851e --- /dev/null +++ b/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 { + 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 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); + } + } +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetSelectPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetSelectPane.java index 61e3ced83..c1a556fc5 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/OnlineWidgetSelectPane.java +++ b/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 { 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 createPopupPreviewPane() { + return new OnlineWidgetPopupPreviewPane(); + } + protected Container getParentContainer() { return this.getParent(); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackageSelectPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackageSelectPane.java index 2271f0c89..15b880483 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackageSelectPane.java +++ b/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 createWidgetBlock(OnlineShareWidget provider) { diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackagesShowPane.java b/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackagesShowPane.java index 887b7c34a..662df3d8d 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/ui/online/widgetpackage/OnlineWidgetPackagesShowPane.java +++ b/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); } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java b/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java index 96c2cc28c..69401c9c2 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/share/util/DownloadUtils.java +++ b/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(); From 20978231b8863568c476b7fc49461ee7932d6e86 Mon Sep 17 00:00:00 2001 From: kerry Date: Mon, 27 Sep 2021 17:03:01 +0800 Subject: [PATCH 2/3] =?UTF-8?q?REPORT-59906=E3=80=90=E5=9B=BA=E5=AE=9A?= =?UTF-8?q?=E5=B8=83=E5=B1=80-=E5=8E=9F=E5=B8=83=E5=B1=80=E6=8E=A8?= =?UTF-8?q?=E8=8D=904.1=E3=80=91=E5=86=B3=E7=AD=96=E6=8A=A5=E8=A1=A8-?= =?UTF-8?q?=E8=87=AA=E9=80=82=E5=BA=94=E5=B8=83=E5=B1=80-=E7=BB=9D?= =?UTF-8?q?=E5=AF=B9=E7=94=BB=E5=B8=83=E5=9D=97=E5=8C=85=E5=90=AB=E5=AD=90?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=9A=84=E5=A4=8D=E7=94=A8=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E6=8B=96=E5=85=A5=E5=88=B0=E5=8D=A0=E4=BD=8D=E5=9D=97?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E6=95=B4=E4=BD=93=E7=BC=A9=E5=B0=8F=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E4=BD=86=E9=87=8C=E9=9D=A2=E7=9A=84=E5=AD=90=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E6=B2=A1=E6=9C=89=E7=AD=89=E6=AF=94=E4=BE=8B=E7=BC=A9?= =?UTF-8?q?=E5=B0=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapters/layout/FRFitLayoutAdapter.java | 6 ++++-- .../designer/beans/models/AddingModel.java | 8 ++++---- .../design/designer/creator/XCreatorUtils.java | 18 ++++++++++++++++++ .../design/designer/creator/XWFitLayout.java | 1 + .../mainframe/FormCreatorDropTarget.java | 16 +++++----------- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java index 3e255d2a4..84013aadf 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/adapters/layout/FRFitLayoutAdapter.java @@ -160,8 +160,10 @@ public class FRFitLayoutAdapter extends FRBodyLayoutAdapter { //布局控件要先判断是不是可编辑 XLayoutContainer topLayout = XCreatorUtils.getHotspotContainer((XCreator) comp).getTopLayout(); - boolean access = topLayout != null && !isMatchEdge && !topLayout.isEditable() && !topLayout.acceptType(XWAbsoluteLayout.class) && !isExtraContainer(comp) && !topLayout.isDragInAble(); - if (access) { + boolean access = topLayout != null && !isMatchEdge && !topLayout.acceptType(XWAbsoluteLayout.class) && !isExtraContainer(comp) && !topLayout.isDragInAble(); + //topLayout.getParent() != container说明当前增加的组件所在容器是嵌套在外部的自适应容器内部的,此时需要判断增加组件所在容器是否可编辑,不可编辑的话就直接返回 false + //否则说明就是往当前自适应容器内部添加组件,不需要判断其是否可编辑 + if (access && (topLayout.getParent() != container && !topLayout.isEditable())) { return false; } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java index e55aa86d3..1926b57b1 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/AddingModel.java @@ -4,8 +4,8 @@ import com.fr.design.designer.beans.AdapterBus; import com.fr.design.designer.beans.ComponentAdapter; import com.fr.design.designer.beans.adapters.component.CompositeComponentAdapter; import com.fr.design.designer.creator.XCreator; +import com.fr.design.designer.creator.XCreatorUtils; import com.fr.design.designer.creator.XLayoutContainer; -import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.designer.creator.XWParameterLayout; import com.fr.design.mainframe.FormDesigner; import com.fr.design.utils.ComponentUtils; @@ -124,11 +124,10 @@ public class AddingModel { */ public boolean add2Container(FormDesigner designer, XLayoutContainer container, int x, int y) { //考虑不同布局嵌套的情况,获取顶层容器 - XLayoutContainer xLayoutContainer = container.getTopLayout(); - if (xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class)) { + XLayoutContainer xLayoutContainer = XCreatorUtils.getTopEditableContainer(container); + if (xLayoutContainer != null) { container = xLayoutContainer; } - Rectangle rect = ComponentUtils.getRelativeBounds(container); if (!ComparatorUtils.equals(container.getOuterLayout(), container.getBackupParent())) { added = container.getLayoutAdapter().addBean(creator, @@ -141,4 +140,5 @@ public class AddingModel { y + designer.getVerticalScaleValue() - rect.y); return added; } + } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java index 38fb9d73e..02ac912c3 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XCreatorUtils.java @@ -402,4 +402,22 @@ public class XCreatorUtils { FineColorFlushUtils.replaceCacheObject(container.toData(), colorGather); FineColorManager.traverse(container.toData(), colorGather); } + + + /** + * 获取容器组件的顶层正编辑的组件 + */ + @Nullable + public static XLayoutContainer getTopEditableContainer(XLayoutContainer container) { + if (container == null) { + return null; + } + XLayoutContainer xLayoutContainer = container.getTopLayout(); + if (xLayoutContainer != null && xLayoutContainer.getParent() != null) { + if (!xLayoutContainer.isEditable()) { + return (XLayoutContainer) xLayoutContainer.getParent(); + } + } + return null; + } } \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java b/designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java index b9814a0f3..5b9a13334 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java +++ b/designer-form/src/main/java/com/fr/design/designer/creator/XWFitLayout.java @@ -796,6 +796,7 @@ public class XWFitLayout extends XLayoutContainer { layout.setContainerHeight(containerHeight); layout.setContainerWidth(containerWidth); addCompInterval(getAcualInterval()); + LayoutUtils.layoutContainer(this); // REPORT-54410: 决策报表,模板中其他组件的宽高修改会影响绝对画布块中组件的宽高和位置 // 绝对布局内的组件尺寸调整需要在绝对布局的bound排除GAP后进行,否则计算出的 diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java b/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java index 926b6be5e..45a6d9647 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormCreatorDropTarget.java @@ -193,7 +193,6 @@ public class FormCreatorDropTarget extends DropTarget { private void dealWithContainer(int x, int y, XLayoutContainer container) { HoverPainter painter = null; - if (container != current || designer.getPainter() == null) { // 如果焦点容器不是当前容器 if (current != null) { @@ -204,15 +203,9 @@ public class FormCreatorDropTarget extends DropTarget { throw new IllegalArgumentException("container can not be null!"); } //获取painter的时候要考虑布局之间嵌套的问题 - XLayoutContainer xLayoutContainer = container.getTopLayout(); - if (xLayoutContainer != null && xLayoutContainer.getParent() != null - && ((XLayoutContainer) xLayoutContainer.getParent()).acceptType(XWAbsoluteLayout.class)) { - if (!xLayoutContainer.isEditable()) { - xLayoutContainer = (XLayoutContainer) xLayoutContainer.getParent(); - } - } + XLayoutContainer xLayoutContainer = XCreatorUtils.getTopEditableContainer(container); painter = AdapterBus.getContainerPainter(designer, - xLayoutContainer != null && xLayoutContainer.acceptType(XWAbsoluteLayout.class) ? xLayoutContainer : container); + xLayoutContainer != null ? xLayoutContainer : container); // 为界面设计器设置提示渲染提示器 designer.setPainter(painter); @@ -227,8 +220,9 @@ public class FormCreatorDropTarget extends DropTarget { } } if (painter != null) { + XLayoutContainer xLayoutContainer = XCreatorUtils.getTopEditableContainer(container); // 为提示渲染器设置焦点位置、区域等渲染参数 - Rectangle rect = ComponentUtils.getRelativeBounds(container); + Rectangle rect = ComponentUtils.getRelativeBounds(xLayoutContainer != null ? xLayoutContainer : container); rect.x -= designer.getArea().getHorizontalValue(); rect.y -= designer.getArea().getVerticalValue(); painter.setRenderingBounds(rect); @@ -236,7 +230,7 @@ public class FormCreatorDropTarget extends DropTarget { painter.setCreator(addingModel.getXCreator()); } } - + private void promptUser(int x, int y, XLayoutContainer container) { if (!addingModel.getXCreator().canEnterIntoParaPane() && container.acceptType(XWParameterLayout.class)) { promptButton.setText(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Forbid_Drag_Into_Para_Pane")); From a1bb9bc52de1b777de11ad96ae28716b23960222 Mon Sep 17 00:00:00 2001 From: kerry Date: Mon, 27 Sep 2021 17:51:24 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=B8=8B=E5=B8=83?= =?UTF-8?q?=E5=B1=80=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/form/layouts/templates/multi/5.frm | 37 +++++++----- .../design/form/layouts/templates/multi/6.frm | 56 ++++++++++++------- 2 files changed, 60 insertions(+), 33 deletions(-) diff --git a/designer-form/src/main/resources/com/fr/design/form/layouts/templates/multi/5.frm b/designer-form/src/main/resources/com/fr/design/form/layouts/templates/multi/5.frm index 5dde2178e..21c56152f 100644 --- a/designer-form/src/main/resources/com/fr/design/form/layouts/templates/multi/5.frm +++ b/designer-form/src/main/resources/com/fr/design/form/layouts/templates/multi/5.frm @@ -59,7 +59,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -91,7 +91,7 @@ - + @@ -99,7 +99,7 @@ - + @@ -107,10 +107,18 @@ - + + + + + + + + + - + @@ -118,37 +126,38 @@ - + - + - + - + - + - - + + + diff --git a/designer-form/src/main/resources/com/fr/design/form/layouts/templates/multi/6.frm b/designer-form/src/main/resources/com/fr/design/form/layouts/templates/multi/6.frm index 3644ecff8..a76dbdb6b 100644 --- a/designer-form/src/main/resources/com/fr/design/form/layouts/templates/multi/6.frm +++ b/designer-form/src/main/resources/com/fr/design/form/layouts/templates/multi/6.frm @@ -75,7 +75,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -91,23 +91,23 @@ - + - + - + - + - + @@ -115,49 +115,67 @@ - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + - + + + + + - - - +