Browse Source

Pull request #7081: REPORT-63760 7 REPORT-64006 7 & REPORT-64005

Merge in DESIGN/design from ~STARRYI/design:feature/x to feature/x

* commit '100d24c16cc297feff52dbde0f9522eaaad14d10':
  REPORT-64005 【主题边框】单元格的高度没有自适应文本内容
  REPORT-63760 【主题切换】撤销以后,样式设置有问题 & REPORT-64006 【模板主题】单元格自定义样式背景色设置不生效
feature/x
starryi 3 years ago
parent
commit
8177964d23
  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. 20
      designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java
  4. 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);
}
}

20
designer-base/src/main/java/com/fr/design/mainframe/backgroundpane/ColorBackgroundQuickPane.java

@ -19,7 +19,17 @@ public class ColorBackgroundQuickPane extends BackgroundQuickPane {
public ColorBackgroundQuickPane() {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
colorSelectBox = new NewColorSelectBox(100);
colorSelectBox = new NewColorSelectBox(100) {
@Override
public boolean shouldResponseChangeListener() {
// ColorBackgroundQuickPane注册监听器ChangeListenerImpl的逻辑不能丢,因为里面有修改字段backgroundChange的逻辑.
// 所以在监听器重复注册以及UndoState重复生成时,应该保留ChangeListenerImpl, 而放弃NewColorSelectBox内部自己注册
// ChangeListener
// REPORT-63760 【主题切换】撤销以后,样式设置有问题
// REPORT-64006 【模板主题】单元格自定义样式背景色设置不生效
return false;
}
};
this.add(colorSelectBox, BorderLayout.NORTH);
}
@ -41,14 +51,10 @@ public class ColorBackgroundQuickPane extends BackgroundQuickPane {
}
@Override
public boolean shouldResponseChangeListener() {
// NewColorSelectBox实现了UIObserver接口,这里就不要重复注册监听器了,以避免产生重复UndoState.
return false;
public void registerChangeListener(final UIObserverListener listener) {
this.colorSelectBox.addSelectChangeListener(new ChangeListenerImpl(listener));
}
@Override
public void registerChangeListener(final UIObserverListener listener) { }
@Override
/**
* 是否为ColorBackground 类型

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