fix some component sizing issues. resolves #1

This commit is contained in:
Gered 2016-01-04 16:38:19 -05:00
parent 464f4a400e
commit f1eb274ed8
3 changed files with 33 additions and 29 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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));