You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.2 KiB
74 lines
2.2 KiB
package com.fr.widgettheme.theme.panel; |
|
|
|
|
|
import com.fr.base.svg.IconUtils; |
|
import com.fr.widgettheme.theme.widget.style.ThemedWidgetStyle; |
|
import com.fr.design.border.UIRoundedBorder; |
|
import com.fr.stable.StringUtils; |
|
|
|
import javax.swing.Icon; |
|
import javax.swing.JLabel; |
|
import java.awt.BorderLayout; |
|
import java.awt.Color; |
|
import java.awt.Dimension; |
|
import java.awt.Graphics; |
|
import java.awt.LayoutManager; |
|
|
|
/** |
|
* 主题界面预览控件单元格子,控件图表直接用icon |
|
* |
|
* @author John.Ying |
|
* @since 11.0 |
|
* Created on 2023/3/18 |
|
*/ |
|
public class ControlPreviewCellWithIcon extends ControlPreviewCell { |
|
private static final int CONTROL_ALPHA = 16; |
|
|
|
JLabel jLabel; |
|
Icon icon; |
|
Icon defaultIcon; |
|
|
|
public ControlPreviewCellWithIcon() { |
|
this(DEFAULT, DEFAULT_MESSAGE); |
|
} |
|
|
|
public ControlPreviewCellWithIcon(String value) { |
|
this(DEFAULT, value); |
|
} |
|
|
|
public ControlPreviewCellWithIcon(LayoutManager layoutManager, String value) { |
|
this.setLayout(layoutManager); |
|
this.value = value; |
|
this.setPreferredSize(new Dimension(100, 27)); |
|
} |
|
|
|
/** |
|
* 根据icon地址绘制一个图标,用jlabel进行展示 |
|
* |
|
* @param url icon地址 |
|
*/ |
|
public void drawIcon(String url) { |
|
if (StringUtils.isEmpty(url)) { |
|
return; |
|
} |
|
defaultIcon = IconUtils.readIcon(url); |
|
icon = setStyleTwoIcon(icon, defaultIcon); |
|
this.jLabel = new JLabel(icon); |
|
jLabel.setPreferredSize(new Dimension(21, 17)); |
|
|
|
} |
|
|
|
@Override |
|
public void paintComponent(Graphics g) { |
|
super.paintComponent(g); |
|
ThemedWidgetStyle widgetStyle = (ThemedWidgetStyle) reportTheme.getWidgetStyle(); |
|
//风格一边框不显示主题色 |
|
Color borderColor = widgetStyle.getBorderStyle().getBorderColor(); |
|
this.setBorder(new UIRoundedBorder(widgetStyle.getBorderStyle().getLineType() |
|
, borderColor, (int) widgetStyle.getBorderStyle().getRadius())); |
|
icon = setStyleTwoIcon(icon, defaultIcon); |
|
this.jLabel.setIcon(icon); |
|
this.add(jLabel, BorderLayout.EAST); |
|
paintBgColor(g, widgetStyle, CONTROL_ALPHA); |
|
} |
|
}
|
|
|