kuangshuai
3 years ago
19 changed files with 589 additions and 72 deletions
@ -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); |
||||
} |
@ -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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue