mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
add snapshot notification button
This commit is contained in:
@@ -26,6 +26,7 @@ import java.awt.event.WindowAdapter;
|
|||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@ public enum FControl implements KeyEventDispatcher {
|
|||||||
private boolean altKeyLastDown;
|
private boolean altKeyLastDown;
|
||||||
private CloseAction closeAction;
|
private CloseAction closeAction;
|
||||||
private final List<HostedMatch> currentMatches = Lists.newArrayList();
|
private final List<HostedMatch> currentMatches = Lists.newArrayList();
|
||||||
|
private String snapsVersion = "";
|
||||||
|
|
||||||
public enum CloseAction {
|
public enum CloseAction {
|
||||||
NONE,
|
NONE,
|
||||||
@@ -212,6 +214,12 @@ public enum FControl implements KeyEventDispatcher {
|
|||||||
|
|
||||||
/** After view and model have been initialized, control can start.*/
|
/** After view and model have been initialized, control can start.*/
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
//get version string
|
||||||
|
try {
|
||||||
|
URL url = new URL("https://downloads.cardforge.org/dailysnapshots/version.txt");
|
||||||
|
snapsVersion = FileUtil.readFileToString(url);
|
||||||
|
|
||||||
|
} catch (Exception e) {}
|
||||||
// Preloads skin components (using progress bar).
|
// Preloads skin components (using progress bar).
|
||||||
FSkin.loadFull(true);
|
FSkin.loadFull(true);
|
||||||
|
|
||||||
@@ -267,6 +275,12 @@ public enum FControl implements KeyEventDispatcher {
|
|||||||
FView.SINGLETON_INSTANCE.setSplashProgessBarMessage(localizer.getMessage("lblOpeningMainWindow"));
|
FView.SINGLETON_INSTANCE.setSplashProgessBarMessage(localizer.getMessage("lblOpeningMainWindow"));
|
||||||
SwingUtilities.invokeLater(() -> Singletons.getView().initialize());
|
SwingUtilities.invokeLater(() -> Singletons.getView().initialize());
|
||||||
}
|
}
|
||||||
|
public String compareVersion(String currentVersion) {
|
||||||
|
if (currentVersion.isEmpty() || snapsVersion.isEmpty()
|
||||||
|
|| !currentVersion.contains("SNAPSHOT") || currentVersion.equalsIgnoreCase(snapsVersion))
|
||||||
|
return "";
|
||||||
|
return "NEW SNAPSHOT AVAILABLE!!!";
|
||||||
|
}
|
||||||
|
|
||||||
private void setGlobalKeyboardHandler() {
|
private void setGlobalKeyboardHandler() {
|
||||||
final KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
final KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
|
||||||
|
|||||||
@@ -12,17 +12,22 @@ import java.awt.Window;
|
|||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.WindowEvent;
|
import java.awt.event.WindowEvent;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
import javax.swing.SpringLayout;
|
import javax.swing.SpringLayout;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
|
import forge.control.FControl;
|
||||||
|
import forge.download.AutoUpdater;
|
||||||
import forge.gui.framework.ILocalRepaint;
|
import forge.gui.framework.ILocalRepaint;
|
||||||
import forge.toolbox.FSkin;
|
import forge.toolbox.FSkin;
|
||||||
import forge.toolbox.FSkin.Colors;
|
import forge.toolbox.FSkin.Colors;
|
||||||
import forge.toolbox.FSkin.SkinColor;
|
import forge.toolbox.FSkin.SkinColor;
|
||||||
import forge.toolbox.FSkin.SkinnedLabel;
|
import forge.toolbox.FSkin.SkinnedLabel;
|
||||||
import forge.toolbox.FSkin.SkinnedMenuBar;
|
import forge.toolbox.FSkin.SkinnedMenuBar;
|
||||||
|
import forge.util.BuildInfo;
|
||||||
import forge.util.Localizer;
|
import forge.util.Localizer;
|
||||||
|
import forge.util.RSSReader;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public abstract class FTitleBarBase extends SkinnedMenuBar {
|
public abstract class FTitleBarBase extends SkinnedMenuBar {
|
||||||
@@ -42,6 +47,7 @@ public abstract class FTitleBarBase extends SkinnedMenuBar {
|
|||||||
protected final FullScreenButton btnFullScreen = new FullScreenButton();
|
protected final FullScreenButton btnFullScreen = new FullScreenButton();
|
||||||
protected final MaximizeButton btnMaximize = new MaximizeButton();
|
protected final MaximizeButton btnMaximize = new MaximizeButton();
|
||||||
protected final CloseButton btnClose = new CloseButton();
|
protected final CloseButton btnClose = new CloseButton();
|
||||||
|
protected final UpdaterButton btnUpdateShortcut = new UpdaterButton();
|
||||||
|
|
||||||
protected FTitleBarBase(ITitleBarOwner owner0) {
|
protected FTitleBarBase(ITitleBarOwner owner0) {
|
||||||
this.owner = owner0;
|
this.owner = owner0;
|
||||||
@@ -71,6 +77,11 @@ public abstract class FTitleBarBase extends SkinnedMenuBar {
|
|||||||
add(btnLockTitleBar);
|
add(btnLockTitleBar);
|
||||||
layout.putConstraint(SpringLayout.EAST, btnLockTitleBar, 0, SpringLayout.WEST, btnMinimize);
|
layout.putConstraint(SpringLayout.EAST, btnLockTitleBar, 0, SpringLayout.WEST, btnMinimize);
|
||||||
layout.putConstraint(SpringLayout.SOUTH, btnLockTitleBar, 0, SpringLayout.SOUTH, btnMinimize);
|
layout.putConstraint(SpringLayout.SOUTH, btnLockTitleBar, 0, SpringLayout.SOUTH, btnMinimize);
|
||||||
|
|
||||||
|
add(btnUpdateShortcut);
|
||||||
|
layout.putConstraint(SpringLayout.EAST, btnUpdateShortcut, 0, SpringLayout.WEST, btnMinimize);
|
||||||
|
layout.putConstraint(SpringLayout.SOUTH, btnUpdateShortcut, 0, SpringLayout.SOUTH, btnMinimize);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int offset = owner instanceof FDialog && ((FDialog)owner).allowResize() ? 0 : -1;
|
int offset = owner instanceof FDialog && ((FDialog)owner).allowResize() ? 0 : -1;
|
||||||
@@ -408,4 +419,34 @@ public abstract class FTitleBarBase extends SkinnedMenuBar {
|
|||||||
g2d.drawLine(x2, y1, x1, y2);
|
g2d.drawLine(x2, y1, x1, y2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public class UpdaterButton extends TitleBarButton {
|
||||||
|
final int MARQUEE_SPEED_DIV = 25;
|
||||||
|
final int REPAINT_WITHIN_MS = 25;
|
||||||
|
final String displayText = FControl.instance.compareVersion(BuildInfo.getVersionString());
|
||||||
|
private UpdaterButton() {
|
||||||
|
setToolTipText(Localizer.getInstance().getMessage("btnCheckForUpdates"));
|
||||||
|
setPreferredSize(new Dimension(160, 25));
|
||||||
|
setEnabled(!displayText.isEmpty());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
try {
|
||||||
|
new AutoUpdater(false).attemptToUpdate(CompletableFuture.supplyAsync(() -> RSSReader.getCommitLog(null, null, null)));
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void paintComponent(Graphics g) {
|
||||||
|
g.translate((int)((System.currentTimeMillis() / MARQUEE_SPEED_DIV) % (getWidth() * 2)) - getWidth(), 0);
|
||||||
|
super.paintComponent(g);
|
||||||
|
int thickness = 2;
|
||||||
|
Graphics2D g2d = (Graphics2D) g;
|
||||||
|
FSkin.setGraphicsColor(g2d, foreColor);
|
||||||
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
g2d.setStroke(new BasicStroke(thickness));
|
||||||
|
g2d.drawString(displayText, 0, 17);
|
||||||
|
repaint(REPAINT_WITHIN_MS);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user