From f1eb274ed8e156e7d8598b944ddea40a2a1a4765 Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 4 Jan 2016 16:38:19 -0500 Subject: [PATCH] fix some component sizing issues. resolves #1 --- .../java/org/fenix/llanfair/gui/Core.java | 30 ++++++++++--------- .../java/org/fenix/llanfair/gui/Footer.java | 30 ++++++++++--------- .../java/org/fenix/llanfair/gui/RunPane.java | 2 +- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/fenix/llanfair/gui/Core.java b/src/main/java/org/fenix/llanfair/gui/Core.java index d090656..bcae905 100644 --- a/src/main/java/org/fenix/llanfair/gui/Core.java +++ b/src/main/java/org/fenix/llanfair/gui/Core.java @@ -221,25 +221,30 @@ class Core extends JPanel implements ActionListener { if (graphics != null) { Time tmFake = new Time(600000L); Time tmRun = run.getTime(Segment.SET); + + FontMetrics coreFontMetric = graphics.getFontMetrics(Settings.coreFont.get()); + FontMetrics coreOtherTimeFontMetric = graphics.getFontMetrics(Settings.coreOtherTimeFont.get()); + FontMetrics coreTimerFontMetric = graphics.getFontMetrics(Settings.coreTimerFont.get()); + FontMetrics coreSegmentTimerFontMetric = graphics.getFontMetrics(Settings.coreSegmentTimerFont.get()); + // Segment Name - FontMetrics metric = graphics.getFontMetrics(); int wName = 0; int hName = 0; if (Settings.coreShowSegmentName.get()) { for (int i = 0; i < run.getRowCount(); i++) { String sName = run.getSegment(i).getName(); - wName = Math.max(wName, metric.stringWidth(sName)); + wName = Math.max(wName, coreFontMetric.stringWidth(sName)); } - hName = metric.getHeight(); + hName = coreFontMetric.getHeight(); } // Segment Times int wTime = 0; int hTime = 0; - int hBuff = metric.getHeight(); - int wBuff = metric.stringWidth( + int hBuff = coreOtherTimeFontMetric.getHeight(); + int wBuff = coreOtherTimeFontMetric.stringWidth( "" + (tmRun == null ? tmFake : tmRun) ); - wBuff += metric.stringWidth("XX:"); + wBuff += coreOtherTimeFontMetric.stringWidth("XX:"); if (Settings.coreShowBestTime.get()) { hTime = hTime + hBuff; @@ -262,22 +267,19 @@ class Core extends JPanel implements ActionListener { wIcon = hIcon; } // Run Timer - metric = graphics.getFontMetrics(Settings.coreTimerFont.get()); - int wSpTimer = metric.stringWidth( + int wSpTimer = coreTimerFontMetric.stringWidth( "" + (tmRun == null ? tmFake : tmRun) ); - int hSpTimer = metric.getHeight(); + int hSpTimer = coreTimerFontMetric.getHeight(); + // Segment Timer int wSeTimer = 0; int hSeTimer = 0; if (Settings.coreShowSegmentTimer.get()) { - metric = graphics.getFontMetrics( - Settings.coreSegmentTimerFont.get() - ); - wSeTimer = metric.stringWidth( + wSeTimer = coreSegmentTimerFontMetric.stringWidth( "" + (tmRun == null ? tmFake : tmRun) ); - hSeTimer = metric.getHeight(); + hSeTimer = coreSegmentTimerFontMetric.getHeight(); } int maxHeight = Math.max(hIcon, hSpTimer + hSeTimer); diff --git a/src/main/java/org/fenix/llanfair/gui/Footer.java b/src/main/java/org/fenix/llanfair/gui/Footer.java index 37f9025..058390e 100644 --- a/src/main/java/org/fenix/llanfair/gui/Footer.java +++ b/src/main/java/org/fenix/llanfair/gui/Footer.java @@ -97,40 +97,42 @@ class Footer extends JPanel { @Override public Dimension getPreferredSize() { Graphics graphics = getGraphics(); if (resize && (graphics != null)) { - FontMetrics metrics = graphics.getFontMetrics(); + FontMetrics coreFontMetrics = graphics.getFontMetrics(Settings.coreFont.get()); + FontMetrics coreOtherTimeFontMetrics = graphics.getFontMetrics(Settings.coreOtherTimeFont.get()); int timeW; - int timeH = metrics.getHeight(); + int timeH = coreOtherTimeFontMetrics.getHeight(); int smtmW; if (run.getRowCount() > 0) { Time segmentTime = run.getSegment(0).getTime(Segment.RUN); Time tenthTime = new Time(segmentTime.getMilliseconds() / 10L); - timeW = metrics.stringWidth("" + segmentTime); - smtmW = metrics.stringWidth("" + tenthTime); + timeW = coreOtherTimeFontMetrics.stringWidth("" + segmentTime); + smtmW = coreOtherTimeFontMetrics.stringWidth("" + tenthTime); } else { - timeW = metrics.stringWidth("" + Time.ZERO); + timeW = coreOtherTimeFontMetrics.stringWidth("" + Time.ZERO); smtmW = timeW; } - - int liveW = metrics.stringWidth("" + Language.LB_FT_LIVE); - int prevW = metrics.stringWidth("" + Language.LB_FT_SEGMENT); - int bestW = metrics.stringWidth("" + Language.LB_FT_BEST); - int dltaW = metrics.stringWidth("" + Language.LB_FT_DELTA); - int dltbW = metrics.stringWidth("" + Language.LB_FT_DELTA_BEST); + + int labelH = coreFontMetrics.getHeight(); + int liveW = coreFontMetrics.stringWidth("" + Language.LB_FT_LIVE); + int prevW = coreFontMetrics.stringWidth("" + Language.LB_FT_SEGMENT); + int bestW = coreFontMetrics.stringWidth("" + Language.LB_FT_BEST); + int dltaW = coreFontMetrics.stringWidth("" + Language.LB_FT_DELTA); + int dltbW = coreFontMetrics.stringWidth("" + Language.LB_FT_DELTA_BEST); boolean ftBest = Settings.footerShowBestTime.get(); boolean ftLabels = Settings.footerShowDeltaLabels.get(); boolean ftVerbose = Settings.footerVerbose.get(); boolean ftTwoLines = Settings.footerMultiline.get(); - int height = timeH; + int height = Math.max(timeH, labelH); int width = prevW + timeW + smtmW + INSET * 2; if (ftLabels) { width += dltaW; } if (ftVerbose) { width += timeW + liveW - (ftLabels ? 0 : dltaW) - + metrics.stringWidth(" []"); + + coreOtherTimeFontMetrics.stringWidth(" []"); } if (ftBest) { if (ftTwoLines) { @@ -138,7 +140,7 @@ class Footer extends JPanel { int breakW = bestW + timeW + smtmW + (ftLabels ? dltbW : 0); width = Math.max(width, breakW); } else { - width += timeW + smtmW + metrics.stringWidth("| "); + width += timeW + smtmW + coreOtherTimeFontMetrics.stringWidth("| "); } if (ftVerbose) { width += 5; diff --git a/src/main/java/org/fenix/llanfair/gui/RunPane.java b/src/main/java/org/fenix/llanfair/gui/RunPane.java index 9c98566..50c3c6e 100644 --- a/src/main/java/org/fenix/llanfair/gui/RunPane.java +++ b/src/main/java/org/fenix/llanfair/gui/RunPane.java @@ -287,7 +287,7 @@ public class RunPane extends JPanel { */ private void placeComponents() { add(title, GBC.grid(0, 0).insets(3, 0, 1, 0).fill(GBC.B)); - add(subTitle, GBC.grid(0, 1).insets(3, 0, 0, 0)); + add(subTitle, GBC.grid(0, 1).insets(3, 0, 0, 0).fill(GBC.B)); add(attemptCounter, GBC.grid(0, 2).insets(1, 0, 1, 3).anchor(GBC.LE)); add(createSeparator(), GBC.grid(0, 3).insets(3, 0).fill(GBC.H)); add(history, GBC.grid(0, 4).fill(GBC.H).insets(0, 5));