Browse Source

REPORT-53175 【10.0.18】组件背景分离为标题/背景/边框

优化样式面板中线型选择下拉列表的显示,原有的渲染方法会导致
显示文字"无"时字体过大(使用了默认字体),超出下拉框的高度从而
被截断,且不支持其他文字选项.

优化后的文字渲染逻辑使用默认的JComboBox的文字渲染方法,即通过
JComboBox内部的JLabel控件渲染文字. 且提供toStringFromStyle
接口方法,将对应的Int类型线型值,转变为可渲染的文本.
feature/10.0
Starryi 4 years ago
parent
commit
9050f23639
  1. 57
      designer-base/src/main/java/com/fr/design/gui/icombobox/LineComboBox.java

57
designer-base/src/main/java/com/fr/design/gui/icombobox/LineComboBox.java

@ -3,22 +3,14 @@
*/
package com.fr.design.gui.icombobox;
import com.fr.base.FRContext;
import com.fr.base.GraphHelper;
import com.fr.base.ScreenResolution;
import com.fr.general.FRFont;
import com.fr.stable.Constants;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import com.fr.stable.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JList;
/**
@ -59,6 +51,13 @@ public class LineComboBox extends UIComboBox {
this.setSelectedItem(new Integer(style));
}
protected String toStringFromStyle(int style) {
if (style == Constants.LINE_NONE) {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_None");
}
return null;
}
/**
* CellRenderer.
*/
@ -67,31 +66,27 @@ public class LineComboBox extends UIComboBox {
JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel comp= (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
this.style = ((Integer) value).intValue();
comp.setText(null);
String displayString = toStringFromStyle(style);
if (StringUtils.isNotEmpty(displayString)) {
comp.setText(" " + displayString);
} else {
comp.setText(null);
}
return comp;
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
Dimension d = getSize();
g2d.setColor(getForeground());
FRFont font = FRContext.getDefaultValues().getFRFont();
int resolution = ScreenResolution.getScreenResolution();
Font rfont = font.applyResolutionNP(resolution);
g2d.setFont(rfont);
FontMetrics fm = GraphHelper.getFontMetrics(rfont);
if (style == Constants.LINE_NONE) {
//draw "none" string
GraphHelper.drawString(g2d, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_None"), 4, (d.height - fm.getHeight()) / 2D + fm.getAscent());
} else {
if (StringUtils.isEmpty(toStringFromStyle(style))) {
Graphics2D g2d = (Graphics2D) g;
Dimension d = getSize();
g2d.setColor(getForeground());
GraphHelper.drawLine(g2d, 4, d.height / 2D, d.width - 8D, d.height / 2D, style);
}
if(isShowAxisWithLineStyle()) { // 带有坐标轴箭头的样式.
drawArrow(g2d, new Point2D.Double(4, d.height / 2D), new Point2D.Double(d.width - 8D, d.height / 2D));
if(isShowAxisWithLineStyle()) { // 带有坐标轴箭头的样式.
drawArrow(g2d, new Point2D.Double(4, d.height / 2D), new Point2D.Double(d.width - 8D, d.height / 2D));
}
}
}

Loading…
Cancel
Save