Browse Source

无jira任务 修复GridRow中字符偏上的问题

fbp/merge
vito 4 months ago
parent
commit
1fec193a8d
  1. 33
      designer-realize/src/main/java/com/fr/grid/GridRowUI.java

33
designer-realize/src/main/java/com/fr/grid/GridRowUI.java

@ -24,6 +24,7 @@ import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.font.FontRenderContext; import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
/** /**
@ -31,14 +32,13 @@ import java.awt.geom.Rectangle2D;
* @since 2012-3-22下午5:54:21 * @since 2012-3-22下午5:54:21
*/ */
public class GridRowUI extends ComponentUI { public class GridRowUI extends ComponentUI {
private Color detailsBackground = UIManager.getColor("Center.GridColumnRowColor");
protected Color editedBackground = UIManager.getColor("Center.GridColumnRowEditedColor"); protected Color editedBackground = UIManager.getColor("Center.GridColumnRowEditedColor");
protected Color selectedBackground = UIManager.getColor("Center.GridColumnRowSelectedColor"); protected Color selectedBackground = UIManager.getColor("Center.GridColumnRowSelectedColor");
private int resolution ; private final int resolution;
GridRowUI(int resolution){ GridRowUI(int resolution) {
if (resolution == 0){ if (resolution == 0) {
resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); resolution = DesignerUIModeConfig.getInstance().getScreenResolution();
} }
this.resolution = resolution; this.resolution = resolution;
@ -49,12 +49,12 @@ public class GridRowUI extends ComponentUI {
if (!(c instanceof GridRow)) { if (!(c instanceof GridRow)) {
throw new IllegalArgumentException("The component c to paint must be a GridColumn!"); throw new IllegalArgumentException("The component c to paint must be a GridColumn!");
} }
Graphics2D g2d = (Graphics2D) g; Graphics2D g2d = (Graphics2D) g.create();
GridRow gridRow = (GridRow) c; GridRow gridRow = (GridRow) c;
ElementCasePane reportPane = gridRow.getElementCasePane(); ElementCasePane reportPane = gridRow.getElementCasePane();
// size // size
Dimension size = gridRow.getSize(); Dimension size = gridRow.getSize();
float time = (float)resolution/DesignerUIModeConfig.getInstance().getScreenResolution(); float time = (float) resolution / DesignerUIModeConfig.getInstance().getScreenResolution();
g2d.setFont(gridRow.getFont().deriveFont(gridRow.getFont().getSize2D() * time)); g2d.setFont(gridRow.getFont().deriveFont(gridRow.getFont().getSize2D() * time));
ElementCase elementCase = reportPane.getEditingElementCase(); ElementCase elementCase = reportPane.getEditingElementCase();
@ -135,7 +135,7 @@ public class GridRowUI extends ComponentUI {
paintText += "(F)"; paintText += "(F)";
} }
} }
drawNormalContent(i, g2d, gridRow, paintText, tmpIncreaseHeight, isSelectedBounds, elementCase, size, tmpHeight1); drawNormalContent(g2d, gridRow, paintText, tmpIncreaseHeight, isSelectedBounds, size, tmpHeight1);
} }
} }
@ -154,16 +154,19 @@ public class GridRowUI extends ComponentUI {
} }
private void drawNormalContent(int i, Graphics2D g2d, GridRow gridRow, String paintText, double tmpIncreaseHeight, boolean isSelectedBounds private void drawNormalContent(Graphics2D g2d, GridRow gridRow, String paintText,
, ElementCase elementCase, Dimension size, double tmpHeight1) { double increaseHeight, boolean isSelectedBounds,
Dimension size, double y) {
// FontMetrics // FontMetrics
FontRenderContext fontRenderContext = g2d.getFontRenderContext(); FontRenderContext fontRenderContext = g2d.getFontRenderContext();
float time = (float)resolution/DesignerUIModeConfig.getInstance().getScreenResolution(); float time = (float) resolution / DesignerUIModeConfig.getInstance().getScreenResolution();
float fmAscent = GraphHelper.getFontMetrics(gridRow.getFont()).getAscent() * time;
double stringWidth = gridRow.getFont().getStringBounds(paintText, fontRenderContext).getWidth() * time; double stringWidth = gridRow.getFont().getStringBounds(paintText, fontRenderContext).getWidth() * time;
double stringHeight = gridRow.getFont().getStringBounds(paintText, fontRenderContext).getHeight() * time; // 为了居中获取可视边界
Rectangle2D bounds = new TextLayout(paintText, gridRow.getFont(), fontRenderContext).getBounds();
double stringHeight = bounds.getHeight() * time;
// 如果高度太小了就不画了 // 如果高度太小了就不画了
if (stringHeight <= tmpIncreaseHeight + 2) { if (stringHeight <= increaseHeight + 2) {
if (isSelectedBounds) { if (isSelectedBounds) {
g2d.setColor(gridRow.getSelectedForeground()); g2d.setColor(gridRow.getSelectedForeground());
} else { } else {
@ -175,7 +178,9 @@ public class GridRowUI extends ComponentUI {
} }
} }
GraphHelper.drawString(g2d, paintText, (size.width - stringWidth) / 2, tmpHeight1 + (tmpIncreaseHeight - stringHeight) / 2 + GridHeader.SIZE_ADJUST / 2 + fmAscent - 2); GraphHelper.drawString(g2d, paintText,
(size.width - stringWidth) / 2,
y + (increaseHeight - stringHeight) / 2.0 + stringHeight);
} }
} }

Loading…
Cancel
Save