mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
Show clock in titlebar if maximized and status bar hidden
This commit is contained in:
@@ -179,6 +179,7 @@ public final class LayoutMenu {
|
||||
prefs.setPref(FPref.UI_HIDE_STATUS_BAR, !showStatusBar);
|
||||
prefs.save();
|
||||
Singletons.getView().getStatusBar().setVisible(showStatusBar);
|
||||
Singletons.getView().getNavigationBar().updateClockVisibility();
|
||||
SResizingUtil.resizeWindow();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ package forge.gui.toolbox;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
@@ -14,23 +15,35 @@ import javax.swing.Timer;
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class FDigitalClock extends JLabel {
|
||||
private final Calendar now = Calendar.getInstance();
|
||||
private final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
private static final Calendar now = Calendar.getInstance();
|
||||
private static final DateFormat timeFormatter = DateFormat.getTimeInstance(DateFormat.SHORT);
|
||||
private static final ArrayList<FDigitalClock> clocks = new ArrayList<FDigitalClock>();
|
||||
private static Timer timer;
|
||||
private static String currentTimeDisplay;
|
||||
|
||||
public FDigitalClock() {
|
||||
Timer timer = new Timer(60000, new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
now.add(Calendar.MINUTE, 1);
|
||||
updateDisplay();
|
||||
}
|
||||
});
|
||||
updateDisplay();
|
||||
//ensure timer starts when current minute ends
|
||||
timer.setInitialDelay(60000 - (now.get(Calendar.MILLISECOND) + now.get(Calendar.SECOND) * 1000));
|
||||
timer.start();
|
||||
clocks.add(this);
|
||||
if (timer == null) {
|
||||
timer = new Timer(60000, new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
now.add(Calendar.MINUTE, 1);
|
||||
updateTimeDisplay();
|
||||
}
|
||||
});
|
||||
updateTimeDisplay();
|
||||
//ensure timer starts when current minute ends
|
||||
timer.setInitialDelay(60000 - (now.get(Calendar.MILLISECOND) + now.get(Calendar.SECOND) * 1000));
|
||||
timer.start();
|
||||
}
|
||||
else {
|
||||
setText(currentTimeDisplay);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDisplay() {
|
||||
setText(timeFormatter.format(now.getTime()));
|
||||
private static void updateTimeDisplay() {
|
||||
currentTimeDisplay = timeFormatter.format(now.getTime());
|
||||
for (FDigitalClock clock : clocks) {
|
||||
clock.setText(currentTimeDisplay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,19 @@ import javax.swing.event.PopupMenuListener;
|
||||
import forge.Singletons;
|
||||
import forge.gui.menus.ForgeMenu;
|
||||
import forge.gui.toolbox.FButton;
|
||||
import forge.gui.toolbox.FDigitalClock;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class FNavigationBar extends FTitleBarBase {
|
||||
|
||||
private static final ForgeMenu forgeMenu = Singletons.getControl().getForgeMenu();
|
||||
private static final ForgePreferences prefs = Singletons.getModel().getPreferences();
|
||||
|
||||
private final FButton btnForge = new FButton("Forge");
|
||||
private final ForgeMenu forgeMenu = Singletons.getControl().getForgeMenu();
|
||||
private final FDigitalClock clock = new FDigitalClock();
|
||||
private long timeMenuHidden = 0;
|
||||
|
||||
public FNavigationBar(FFrame f) {
|
||||
@@ -27,6 +33,7 @@ public class FNavigationBar extends FTitleBarBase {
|
||||
btnForge.setPreferredSize(new Dimension(100, 23));
|
||||
setIconImage(this.frame.getIconImage()); //set default icon image based on frame icon image
|
||||
FSkin.get(btnForge).setForeground(foreColor);
|
||||
FSkin.get(clock).setForeground(foreColor);
|
||||
addControls();
|
||||
}
|
||||
|
||||
@@ -36,7 +43,19 @@ public class FNavigationBar extends FTitleBarBase {
|
||||
layout.putConstraint(SpringLayout.WEST, btnForge, 1, SpringLayout.WEST, this);
|
||||
layout.putConstraint(SpringLayout.NORTH, btnForge, 1, SpringLayout.NORTH, this);
|
||||
addForgeButtonListeners();
|
||||
|
||||
super.addControls();
|
||||
|
||||
add(clock);
|
||||
layout.putConstraint(SpringLayout.EAST, clock, -6, SpringLayout.WEST, btnMinimize);
|
||||
layout.putConstraint(SpringLayout.NORTH, clock, 4, SpringLayout.NORTH, this);
|
||||
updateClockVisibility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMaximizedChanged() {
|
||||
super.handleMaximizedChanged();
|
||||
updateClockVisibility();
|
||||
}
|
||||
|
||||
private void addForgeButtonListeners() {
|
||||
@@ -61,6 +80,11 @@ public class FNavigationBar extends FTitleBarBase {
|
||||
});
|
||||
}
|
||||
|
||||
//only show clock if maximized and status bar hidden
|
||||
public void updateClockVisibility() {
|
||||
this.clock.setVisible(this.frame.getMaximized() && prefs.getPrefBoolean(FPref.UI_HIDE_STATUS_BAR));
|
||||
}
|
||||
|
||||
public void showForgeMenu(boolean hideIfAlreadyShown) {
|
||||
if (!btnForge.isToggled()) {
|
||||
btnForge.setToggled(true);
|
||||
|
||||
@@ -34,9 +34,9 @@ public abstract class FTitleBarBase extends JMenuBar {
|
||||
protected final FFrame frame;
|
||||
protected final JComponentSkin<FTitleBarBase> skin = FSkin.get(this);
|
||||
protected final SpringLayout layout = new SpringLayout();
|
||||
private final MinimizeButton btnMinimize = new MinimizeButton();
|
||||
private final MaximizeButton btnMaximize = new MaximizeButton();
|
||||
private final CloseButton btnClose = new CloseButton();
|
||||
protected final MinimizeButton btnMinimize = new MinimizeButton();
|
||||
protected final MaximizeButton btnMaximize = new MaximizeButton();
|
||||
protected final CloseButton btnClose = new CloseButton();
|
||||
|
||||
protected FTitleBarBase(FFrame f) {
|
||||
this.frame = f;
|
||||
|
||||
Reference in New Issue
Block a user