Browse Source
Merge in DESIGN/design from ~STARRYI/design:release/11.0 to release/11.0 * commit 'e2534d993323efe587a1bba7f64483ff820c0ec5': REPORT-58503 【主题切换】预览区ui改版 REPORT-58800 【主题切换】优化主题选择界面 应用主题的交互 REPORT-58389 【FR11二轮回归】设计器-frm模板撤销/切换主题,设计画布都会变小 REPORT-58586 FR11-二轮回归-单元格属性-样式-切换成跟随主题后,鼠标无法上滑至顶部fix-lag
starryi
3 years ago
11 changed files with 129 additions and 204 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