Browse Source

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

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

37
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);
}
}
}
}

Loading…
Cancel
Save