Skip to content

Commit

Permalink
Some ui alignements
Browse files Browse the repository at this point in the history
  • Loading branch information
RetGal committed Feb 14, 2024
1 parent 2462667 commit 8263a4c
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/main/java/mpo/dayon/assistant/gui/AssistantFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,14 @@ private JTabbedPane createTabbedPane() {
tabbedPane.addTab(translate("settings"), settingsPanel);
// must not be focusable or the key listener won't work
tabbedPane.setFocusable(false);
tabbedPane.setBorder(null);
return tabbedPane;
}

private StatusBar createStatusBar(Set<Counter<?>> counters) {
final StatusBar statusBar = new StatusBar();
final Component horizontalStrut = Box.createHorizontalStrut(10);
statusBar.add(horizontalStrut);
for (Counter<?> counter : counters) {
statusBar.addSeparator();
statusBar.addCounter(counter, counter.getWidth());
Expand All @@ -263,7 +266,7 @@ private StatusBar createStatusBar(Set<Counter<?>> counters) {
statusBar.addRamInfo();
statusBar.addSeparator();
statusBar.addConnectionDuration();
statusBar.add(Box.createHorizontalStrut(10));
statusBar.add(horizontalStrut);
return statusBar;
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/mpo/dayon/assisted/gui/AssistedFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ private StatusBar createStatusBar() {
final StatusBar statusBar = new StatusBar();
statusBar.addSeparator();
statusBar.addRamInfo();
statusBar.add(Box.createHorizontalStrut(10));
return statusBar;
}

Expand All @@ -84,8 +83,8 @@ void onReady() {

private void toggleStartButton(boolean enable) {
startAction.setEnabled(enable);
startButton.setVisible(enable);
stopAction.setEnabled(!enable);
startButton.setVisible(enable);
stopButton.setVisible(!enable);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/mpo/dayon/common/gui/common/BaseFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,12 @@ protected void setupToolBar(ToolBar toolBar) {
toolBar.addAction(createExitAction(), alignmentY);
toolBar.add(DEFAULT_SPACER);
add(toolBar, BorderLayout.NORTH);
toolBar.setBorder(null);
this.toolBar = toolBar;
}

protected void setupStatusBar(StatusBar statusBar) {
statusBar.add(Box.createHorizontalStrut(10));
add(statusBar, BorderLayout.SOUTH);
this.statusBar = statusBar;
}
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/mpo/dayon/common/gui/statusbar/StatusBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@
import java.awt.*;
import java.util.TimerTask;

import static javax.swing.BoxLayout.LINE_AXIS;
import static javax.swing.SwingConstants.*;
import static mpo.dayon.common.babylon.Babylon.translate;

public class StatusBar extends JPanel {

private static final int HEIGHT = 5;
private final JLabel message = new JLabel();
private final JLabel sessionDuration = new JLabel("00:00:00");

public StatusBar() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
add(Box.createHorizontalStrut(5));
setLayout(new BoxLayout(this, LINE_AXIS));
add(Box.createHorizontalStrut(10));
add(message);
add(Box.createHorizontalGlue());
}
Expand All @@ -36,35 +40,38 @@ public void setSessionDuration(String sessionDuration) {

public void addCounter(Counter<?> counter, int width) {
final JLabel lbl = new JLabel(counter.getUid());
lbl.setHorizontalAlignment(SwingConstants.CENTER);
lbl.setSize(new Dimension(width, 5));
lbl.setPreferredSize(new Dimension(width, 5));
final Dimension dimension = new Dimension(width, HEIGHT);
lbl.setHorizontalAlignment(CENTER);
lbl.setSize(dimension);
lbl.setPreferredSize(dimension);
lbl.setToolTipText(counter.getShortDescription());
counter.addListener((CounterListener) (counter1, value) -> lbl.setText(counter1.formatInstantValue(value)));
add(lbl);
}

public void addRamInfo() {
final JLabel lbl = new JLabel();
lbl.setHorizontalAlignment(SwingConstants.CENTER);
lbl.setSize(new Dimension(110, 5));
lbl.setPreferredSize(new Dimension(110, 5));
final Dimension dimension = new Dimension(110, HEIGHT);
lbl.setHorizontalAlignment(CENTER);
lbl.setSize(dimension);
lbl.setPreferredSize(dimension);
BigBrother.get().registerRamInfo(new MemoryCounter(lbl));
lbl.setToolTipText(translate("memory.info"));
add(lbl);
}

public void addConnectionDuration() {
sessionDuration.setHorizontalAlignment(SwingConstants.CENTER);
sessionDuration.setSize(new java.awt.Dimension(100, 5));
sessionDuration.setPreferredSize(new java.awt.Dimension(100, 5));
final Dimension dimension = new Dimension(65, HEIGHT);
sessionDuration.setHorizontalAlignment(RIGHT);
sessionDuration.setSize(dimension);
sessionDuration.setPreferredSize(dimension);
sessionDuration.setToolTipText(translate("session.duration"));
add(sessionDuration);
}

public void addSeparator() {
final JToolBar.Separator separator = new JToolBar.Separator();
separator.setOrientation(SwingConstants.VERTICAL);
separator.setOrientation(VERTICAL);
add(separator);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/mpo/dayon/common/utils/SystemUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static java.lang.String.format;
import static java.lang.System.getProperty;
import static java.nio.charset.StandardCharsets.UTF_8;
import static mpo.dayon.common.utils.UnitUtilities.toByteSize;

public final class SystemUtilities {

Expand Down Expand Up @@ -93,7 +94,7 @@ public static String getSystemPropertiesEx() {
public static String getRamInfo() {
final double freeMG = Runtime.getRuntime().freeMemory();
final double totalMG = Runtime.getRuntime().totalMemory();
return format("%s of %s", UnitUtilities.toByteSize(totalMG - freeMG, false), UnitUtilities.toByteSize(totalMG, false));
return format("%s of %s", toByteSize(totalMG - freeMG), toByteSize(totalMG));
}

public static void safeClose(Closeable... closeables) {
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/mpo/dayon/common/utils/UnitUtilities.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package mpo.dayon.common.utils;

import static java.lang.Math.pow;
import static java.lang.Math.*;
import static java.lang.String.format;

public abstract class UnitUtilities {
Expand Down Expand Up @@ -84,7 +84,7 @@ String getFormatter() {
}

public static String toByteSize(double bytes) {
return toByteSize(bytes, true);
return toByteSize(bytes, false);
}

static String toByteSize(double bytes, boolean withDecimal) {
Expand Down Expand Up @@ -120,24 +120,24 @@ public static String toElapsedTime(long millis) {
return format("%.2fs", secs);
}
if (secs < 3600) {
return format("%dm%02ds", toMinutes(secs), Math.round(secs) % 60);
return format("%dm%02ds", toMinutes(secs), round(secs) % 60);
}
if (secs < 86400) {
return format("%dh%02dm%02ds", toHours(secs), toMinutes(secs) % 60, Math.round(secs) % 60);
return format("%dh%02dm%02ds", toHours(secs), toMinutes(secs) % 60, round(secs) % 60);
}
// noinspection NumericCastThatLosesPrecision
return format("%dd%02dh%02dm%02ds", (int) Math.floor(toHours(secs) / 24.0), toHours(secs) % 24,
toMinutes(secs) % 60, Math.round(secs) % 60);
return format("%dd%02dh%02dm%02ds", floor(toHours(secs) / 24.0), toHours(secs) % 24,
toMinutes(secs) % 60, round(secs) % 60);
}

private static int toMinutes(double seconds) {
// noinspection NumericCastThatLosesPrecision
return (int) Math.floor(seconds / 60);
return (int) floor(seconds / 60);
}

private static int toHours(double seconds) {
// noinspection NumericCastThatLosesPrecision
return (int) Math.floor(seconds / 3600);
return (int) floor(seconds / 3600);
}

/**
Expand Down

0 comments on commit 8263a4c

Please sign in to comment.