|
|
|
@ -1,19 +1,26 @@
|
|
|
|
|
package com.fr.design.cell; |
|
|
|
|
|
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
import com.fr.base.GraphHelper; |
|
|
|
|
import com.fr.base.NameStyle; |
|
|
|
|
import com.fr.base.ScreenResolution; |
|
|
|
|
import com.fr.base.Style; |
|
|
|
|
import com.fr.general.FRFont; |
|
|
|
|
import com.fr.general.IOUtils; |
|
|
|
|
import com.fr.stable.unit.PT; |
|
|
|
|
|
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import java.awt.AlphaComposite; |
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Composite; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.Font; |
|
|
|
|
import java.awt.FontMetrics; |
|
|
|
|
import java.awt.Graphics; |
|
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
import java.awt.RenderingHints; |
|
|
|
|
import java.awt.image.BufferedImage; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author Starryi |
|
|
|
@ -22,6 +29,7 @@ import java.awt.image.BufferedImage;
|
|
|
|
|
*/ |
|
|
|
|
public class CellStylePreviewPane extends JPanel { |
|
|
|
|
|
|
|
|
|
public static final int MINIMUM_HEIGHT = 40; |
|
|
|
|
private static final BufferedImage transparentBackgroundImage = IOUtils.readImage("/com/fr/design/images/transparent_background.png"); |
|
|
|
|
private final float transparentBackgroundWidth; |
|
|
|
|
private final float transparentBackgroundHeight; |
|
|
|
@ -31,6 +39,7 @@ public class CellStylePreviewPane extends JPanel {
|
|
|
|
|
public CellStylePreviewPane() { |
|
|
|
|
transparentBackgroundWidth = transparentBackgroundImage.getWidth(null); |
|
|
|
|
transparentBackgroundHeight = transparentBackgroundImage.getHeight(null); |
|
|
|
|
setPreferredSize(new Dimension(0, 0)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setPaintText(String paintText) { |
|
|
|
@ -118,7 +127,39 @@ public class CellStylePreviewPane extends JPanel {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Dimension getMinimumSize() { |
|
|
|
|
return getPreferredSize(); |
|
|
|
|
public Dimension getPreferredSize() { |
|
|
|
|
Dimension size = super.getPreferredSize(); |
|
|
|
|
int width = size.width; |
|
|
|
|
int height = size.height; |
|
|
|
|
|
|
|
|
|
if (height != 0) { |
|
|
|
|
// 使用者设置了一个高度
|
|
|
|
|
return size; |
|
|
|
|
} else if (width == 0) { |
|
|
|
|
// 使用者未设置任何尺寸
|
|
|
|
|
return new Dimension(width, MINIMUM_HEIGHT); |
|
|
|
|
} else { |
|
|
|
|
// 使用者设置了宽度,但未设置高度
|
|
|
|
|
return getAutoWrapContentPreferredSize(width, height); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Dimension getAutoWrapContentPreferredSize(int width, int height) { |
|
|
|
|
int resolution = ScreenResolution.getScreenResolution(); |
|
|
|
|
|
|
|
|
|
// 计算文本区域高度
|
|
|
|
|
final FRFont frFont = style.getFRFont(); |
|
|
|
|
final Font rfont = frFont.applyResolutionNP(resolution); |
|
|
|
|
final FontMetrics metrics = GraphHelper.getFontMetrics(rfont); |
|
|
|
|
final int textLineHeight = metrics.getHeight(); |
|
|
|
|
final double textLineSpacing = PT.pt2pix(style.getLineSpacing(), resolution); |
|
|
|
|
|
|
|
|
|
List textLineList = BaseUtils.getLineTextList(paintText, style, rfont, height, width, resolution); |
|
|
|
|
|
|
|
|
|
double textLinesHeight = textLineList.size() * textLineHeight + Math.max(0, textLineList.size() - 1) * textLineSpacing; |
|
|
|
|
|
|
|
|
|
height = (int) Math.max(MINIMUM_HEIGHT, textLinesHeight); |
|
|
|
|
|
|
|
|
|
return new Dimension(width, height); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|