Browse Source

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

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

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

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

@ -3,22 +3,14 @@
*/ */
package com.fr.design.gui.icombobox; package com.fr.design.gui.icombobox;
import com.fr.base.FRContext;
import com.fr.base.GraphHelper; import com.fr.base.GraphHelper;
import com.fr.base.ScreenResolution;
import com.fr.general.FRFont;
import com.fr.stable.Constants; import com.fr.stable.Constants;
import java.awt.Component; import com.fr.stable.StringUtils;
import java.awt.Dimension;
import java.awt.Font; import javax.swing.*;
import java.awt.FontMetrics; import java.awt.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath; import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D; 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)); 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. * CellRenderer.
*/ */
@ -67,33 +66,29 @@ public class LineComboBox extends UIComboBox {
JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JLabel comp= (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); JLabel comp= (JLabel)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
this.style = ((Integer) value).intValue(); this.style = ((Integer) value).intValue();
String displayString = toStringFromStyle(style);
if (StringUtils.isNotEmpty(displayString)) {
comp.setText(" " + displayString);
} else {
comp.setText(null); comp.setText(null);
}
return comp; return comp;
} }
public void paint(Graphics g) { public void paint(Graphics g) {
super.paint(g); super.paint(g);
if (StringUtils.isEmpty(toStringFromStyle(style))) {
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g;
Dimension d = getSize(); Dimension d = getSize();
g2d.setColor(getForeground()); 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 {
GraphHelper.drawLine(g2d, 4, d.height / 2D, d.width - 8D, d.height / 2D, style); GraphHelper.drawLine(g2d, 4, d.height / 2D, d.width - 8D, d.height / 2D, style);
}
if(isShowAxisWithLineStyle()) { // 带有坐标轴箭头的样式. if(isShowAxisWithLineStyle()) { // 带有坐标轴箭头的样式.
drawArrow(g2d, new Point2D.Double(4, d.height / 2D), new Point2D.Double(d.width - 8D, d.height / 2D)); drawArrow(g2d, new Point2D.Double(4, d.height / 2D), new Point2D.Double(d.width - 8D, d.height / 2D));
} }
} }
}
private void drawArrow(Graphics2D g2d, Point2D p0, Point2D p1) { private void drawArrow(Graphics2D g2d, Point2D p0, Point2D p1) {
Point2D s = new Point2D.Double(p1.getX() - p0.getX(), p1.getY() - p0.getY()); Point2D s = new Point2D.Double(p1.getX() - p0.getX(), p1.getY() - p0.getY());

Loading…
Cancel
Save