Browse Source

REPORT-64005 【主题边框】单元格的高度没有自适应文本内容

【问题原因】
单元格样式预览面板自适应内容高度

【改动思路】
同上
feature/x
Starryi 3 years ago
parent
commit
100d24c16c
  1. 23
      designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java
  2. 45
      designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java
  3. 7
      designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java

23
designer-base/src/main/java/com/fr/design/cell/CellRectangleStylePreviewPane.java

@ -73,7 +73,26 @@ public class CellRectangleStylePreviewPane extends JPanel {
}
@Override
public Dimension getMinimumSize() {
return getPreferredSize();
public void setPreferredSize(Dimension preferredSize) {
super.setPreferredSize(preferredSize);
int hw = preferredSize.width / 2;
int hh = preferredSize.height / 2;
cellStylePreviewPaneGrid[0][0].setPreferredSize(new Dimension(hw, hh));
cellStylePreviewPaneGrid[0][1].setPreferredSize(new Dimension(hw, hh));
cellStylePreviewPaneGrid[1][0].setPreferredSize(new Dimension(hw, hh));
cellStylePreviewPaneGrid[1][1].setPreferredSize(new Dimension(hw, hh));
}
@Override
public Dimension getPreferredSize() {
Dimension d00 = cellStylePreviewPaneGrid[0][0].getPreferredSize();
Dimension d01 = cellStylePreviewPaneGrid[0][1].getPreferredSize();
Dimension d10 = cellStylePreviewPaneGrid[1][0].getPreferredSize();
Dimension d11 = cellStylePreviewPaneGrid[1][1].getPreferredSize();
int width = Math.max(d00.width + d01.width, d10.width + d11.width);
int height = Math.max(d00.height + d10.height, d01.height + d11.height);
return new Dimension(width, height);
}
}

45
designer-base/src/main/java/com/fr/design/cell/CellStylePreviewPane.java

@ -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);
}
}

7
designer-base/src/main/java/com/fr/design/mainframe/theme/ThemedCellStyleListPane.java

@ -149,7 +149,6 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane<ThemedCellStyl
super();
setLayout(new BorderLayout(5, 0));
setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
setPreferredSize(new Dimension(getPreferredSize().width, 80));
button = new UIRadioButton();
button.setBorder(BorderFactory.createEmptyBorder());
previewArea = new CellRectangleStylePreviewPane();
@ -162,6 +161,12 @@ public class ThemedCellStyleListPane extends FurtherBasicBeanPane<ThemedCellStyl
button.setSelected(isSelected);
previewArea.setPlainText(value.getName());
previewArea.setStyle(value.getStyle(), value.getCellBorderStyle());
int preferredWidth = list.getWidth() - 15 - button.getPreferredSize().width;
preferredWidth = Math.max(0, preferredWidth);
int preferredHeight = 0;
previewArea.setPreferredSize(new Dimension(preferredWidth, preferredHeight));
return this;
}
}

Loading…
Cancel
Save