From 1fec193a8dad1954e2c4ae33ac4f92a6296efcf6 Mon Sep 17 00:00:00 2001 From: vito Date: Thu, 12 Sep 2024 20:46:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0jira=E4=BB=BB=E5=8A=A1=20=E4=BF=AE?= =?UTF-8?q?=E5=A4=8DGridRow=E4=B8=AD=E5=AD=97=E7=AC=A6=E5=81=8F=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/grid/GridRowUI.java | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/designer-realize/src/main/java/com/fr/grid/GridRowUI.java b/designer-realize/src/main/java/com/fr/grid/GridRowUI.java index d2b7391f84..e979aa9950 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridRowUI.java +++ b/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.Graphics2D; import java.awt.font.FontRenderContext; +import java.awt.font.TextLayout; import java.awt.geom.Rectangle2D; /** @@ -31,15 +32,14 @@ import java.awt.geom.Rectangle2D; * @since 2012-3-22下午5:54:21 */ public class GridRowUI extends ComponentUI { - private Color detailsBackground = UIManager.getColor("Center.GridColumnRowColor"); protected Color editedBackground = UIManager.getColor("Center.GridColumnRowEditedColor"); protected Color selectedBackground = UIManager.getColor("Center.GridColumnRowSelectedColor"); - private int resolution ; + private final int resolution; - GridRowUI(int resolution){ - if (resolution == 0){ - resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); + GridRowUI(int resolution) { + if (resolution == 0) { + resolution = DesignerUIModeConfig.getInstance().getScreenResolution(); } this.resolution = resolution; } @@ -49,12 +49,12 @@ public class GridRowUI extends ComponentUI { if (!(c instanceof GridRow)) { 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; ElementCasePane reportPane = gridRow.getElementCasePane(); // size 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)); ElementCase elementCase = reportPane.getEditingElementCase(); @@ -135,7 +135,7 @@ public class GridRowUI extends ComponentUI { 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 - , ElementCase elementCase, Dimension size, double tmpHeight1) { + private void drawNormalContent(Graphics2D g2d, GridRow gridRow, String paintText, + double increaseHeight, boolean isSelectedBounds, + Dimension size, double y) { // FontMetrics FontRenderContext fontRenderContext = g2d.getFontRenderContext(); - float time = (float)resolution/DesignerUIModeConfig.getInstance().getScreenResolution(); - float fmAscent = GraphHelper.getFontMetrics(gridRow.getFont()).getAscent() * time; + float time = (float) resolution / DesignerUIModeConfig.getInstance().getScreenResolution(); + 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) { g2d.setColor(gridRow.getSelectedForeground()); } else { @@ -175,8 +178,10 @@ 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); } } -} \ No newline at end of file +}