Starryi
3 years ago
5 changed files with 94 additions and 129 deletions
@ -0,0 +1,82 @@ |
|||||||
|
package com.fr.design.cell; |
||||||
|
|
||||||
|
import com.fr.base.NameStyle; |
||||||
|
import com.fr.base.ScreenResolution; |
||||||
|
import com.fr.base.Style; |
||||||
|
import com.fr.design.mainframe.theme.TemplateThemeBlock; |
||||||
|
import com.fr.general.IOUtils; |
||||||
|
|
||||||
|
import javax.swing.Icon; |
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JPanel; |
||||||
|
import java.awt.Dimension; |
||||||
|
import java.awt.Graphics; |
||||||
|
import java.awt.Graphics2D; |
||||||
|
import java.awt.Image; |
||||||
|
import java.awt.Toolkit; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Starryi |
||||||
|
* @version 1.0 |
||||||
|
* Created by Starryi on 2021/9/3 |
||||||
|
*/ |
||||||
|
public class CellStylePreviewPane extends JPanel { |
||||||
|
|
||||||
|
private static final Image transparentBackgroundImage = Toolkit.getDefaultToolkit().createImage(CellStylePreviewPane.class.getResource("/com/fr/design/images/transparent_background.png")); |
||||||
|
private final float transparentBackgroundWidth; |
||||||
|
private final float transparentBackgroundHeight; |
||||||
|
private final float transparentBackgroundAspect; |
||||||
|
private String paintText = "Report"; |
||||||
|
private Style style = Style.DEFAULT_STYLE; |
||||||
|
|
||||||
|
public CellStylePreviewPane() { |
||||||
|
transparentBackgroundWidth = transparentBackgroundImage.getWidth(null); |
||||||
|
transparentBackgroundHeight = transparentBackgroundImage.getHeight(null); |
||||||
|
transparentBackgroundAspect = 1.0F * transparentBackgroundImage.getWidth(null) / transparentBackgroundImage.getHeight(null); |
||||||
|
} |
||||||
|
|
||||||
|
public void setStyle(Style style) { |
||||||
|
this.style = style; |
||||||
|
if (style instanceof NameStyle) { |
||||||
|
paintText = ((NameStyle) style).getName(); |
||||||
|
} |
||||||
|
repaint(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void paintComponent(Graphics g) { |
||||||
|
Graphics2D g2d = (Graphics2D) g; |
||||||
|
int resolution = ScreenResolution.getScreenResolution(); |
||||||
|
|
||||||
|
int width = getWidth(); |
||||||
|
int height = getHeight(); |
||||||
|
|
||||||
|
float scaleWidth = 1.0F * getWidth() / transparentBackgroundWidth; |
||||||
|
float scaleHeight = 1.0F * getHeight() / transparentBackgroundHeight; |
||||||
|
float maxScale = Math.max(scaleWidth, scaleHeight); |
||||||
|
|
||||||
|
if (maxScale <= 1) { |
||||||
|
scaleWidth = scaleHeight = 1; |
||||||
|
} else { |
||||||
|
scaleHeight = scaleWidth = maxScale; |
||||||
|
} |
||||||
|
g2d.drawImage(transparentBackgroundImage, 0, 0, (int) (transparentBackgroundWidth * scaleWidth), (int) (transparentBackgroundHeight * scaleHeight), null); |
||||||
|
|
||||||
|
if (style == Style.DEFAULT_STYLE) { |
||||||
|
// 如果是默认的style,就只写"Report"上去
|
||||||
|
Style.paintContent(g2d, paintText, style, width, height, resolution); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
Style.paintBackground(g2d, style, width, height); |
||||||
|
|
||||||
|
Style.paintContent(g2d, paintText, style, width, height, resolution); |
||||||
|
|
||||||
|
Style.paintBorder(g2d, style, getWidth() - 3, getHeight() - 3); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Dimension getMinimumSize() { |
||||||
|
return getPreferredSize(); |
||||||
|
} |
||||||
|
} |
After Width: | Height: | Size: 24 KiB |
Loading…
Reference in new issue