From 540a3bcaabbf5e665aea3e7f9f0ae27acad39a4e Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 20 Feb 2015 01:38:18 -0800 Subject: [PATCH] Refactor startup and add new dark fancy theme. --- .../com/skcraft/launcher/FancyLauncher.java | 59 +++++-- .../skcraft/launcher/FancyLauncherFrame.java | 26 +++ .../launcher/skin/LauncherButtonShaper.java | 21 +++ .../launcher/skin/LauncherLookAndFeel.java | 16 ++ .../skcraft/launcher/skin/LauncherSkin.java | 94 +++++++++++ .../launcher/skin/graphite.colorschemes | 153 ++++++++++++++++++ .../launcher/DefaultLauncherSupplier.java | 27 ++++ .../java/com/skcraft/launcher/Launcher.java | 66 ++++---- .../launcher/dialog/LauncherFrame.java | 2 +- .../skcraft/launcher/swing/SwingHelper.java | 11 ++ 10 files changed, 437 insertions(+), 38 deletions(-) create mode 100644 launcher-fancy/src/main/java/com/skcraft/launcher/FancyLauncherFrame.java create mode 100644 launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherButtonShaper.java create mode 100644 launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherLookAndFeel.java create mode 100644 launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherSkin.java create mode 100644 launcher-fancy/src/main/resources/com/skcraft/launcher/skin/graphite.colorschemes create mode 100644 launcher/src/main/java/com/skcraft/launcher/DefaultLauncherSupplier.java diff --git a/launcher-fancy/src/main/java/com/skcraft/launcher/FancyLauncher.java b/launcher-fancy/src/main/java/com/skcraft/launcher/FancyLauncher.java index 50dd243..d6a3383 100644 --- a/launcher-fancy/src/main/java/com/skcraft/launcher/FancyLauncher.java +++ b/launcher-fancy/src/main/java/com/skcraft/launcher/FancyLauncher.java @@ -6,18 +6,59 @@ package com.skcraft.launcher; -import javax.swing.*; +import com.google.common.base.Supplier; +import com.skcraft.launcher.swing.SwingHelper; +import lombok.extern.java.Log; +import javax.swing.*; +import java.awt.*; +import java.util.logging.Level; + +@Log public class FancyLauncher { - public static void main(String[] args) { - UIManager.getLookAndFeelDefaults().put("ClassLoader", FancyLauncher.class.getClassLoader()); - JFrame.setDefaultLookAndFeelDecorated(true); - JDialog.setDefaultLookAndFeelDecorated(true); - System.setProperty("sun.awt.noerasebackground", "true"); - System.setProperty("substancelaf.windowRoundedCorners", "false"); - System.setProperty("com.skcraft.launcher.laf", "org.pushingpixels.substance.api.skin.SubstanceMarinerLookAndFeel"); - Launcher.main(args); + public static void main(final String[] args) { + Launcher.setupLogger(); + + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + try { + UIManager.getLookAndFeelDefaults().put("ClassLoader", FancyLauncher.class.getClassLoader()); + UIManager.getDefaults().put("SplitPane.border", BorderFactory.createEmptyBorder()); + JFrame.setDefaultLookAndFeelDecorated(true); + JDialog.setDefaultLookAndFeelDecorated(true); + System.setProperty("sun.awt.noerasebackground", "true"); + System.setProperty("substancelaf.windowRoundedCorners", "false"); + + if (!SwingHelper.setLookAndFeel("com.skcraft.launcher.skin.LauncherLookAndFeel")) { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } + + Launcher launcher = Launcher.createFromArguments(args); + launcher.setMainWindowSupplier(new CustomWindowSupplier(launcher)); + launcher.showLauncherWindow(); + } catch (Throwable t) { + log.log(Level.WARNING, "Load failure", t); + SwingHelper.showErrorDialog(null, "Uh oh! The updater couldn't be opened because a " + + "problem was encountered.", "Launcher error", t); + } + } + }); + } + + private static class CustomWindowSupplier implements Supplier { + + private final Launcher launcher; + + private CustomWindowSupplier(Launcher launcher) { + this.launcher = launcher; + } + + @Override + public Window get() { + return new FancyLauncherFrame(launcher); + } } } diff --git a/launcher-fancy/src/main/java/com/skcraft/launcher/FancyLauncherFrame.java b/launcher-fancy/src/main/java/com/skcraft/launcher/FancyLauncherFrame.java new file mode 100644 index 0000000..5706e3c --- /dev/null +++ b/launcher-fancy/src/main/java/com/skcraft/launcher/FancyLauncherFrame.java @@ -0,0 +1,26 @@ +/* + * SKCraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher; + +import com.skcraft.launcher.dialog.LauncherFrame; +import lombok.NonNull; + +public class FancyLauncherFrame extends LauncherFrame { + + /** + * Create a new frame. + * + * @param launcher the launcher + */ + public FancyLauncherFrame(@NonNull Launcher launcher) { + super(launcher); + + setSize(900, 650); + setLocationRelativeTo(null); + } + +} diff --git a/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherButtonShaper.java b/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherButtonShaper.java new file mode 100644 index 0000000..2ed037e --- /dev/null +++ b/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherButtonShaper.java @@ -0,0 +1,21 @@ +/* + * SKCraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.skin; + +import org.pushingpixels.substance.api.shaper.ClassicButtonShaper; + +import javax.swing.*; +import java.awt.*; + +public class LauncherButtonShaper extends ClassicButtonShaper { + + public Dimension getPreferredSize(AbstractButton button, Dimension uiPreferredSize) { + Dimension size = super.getPreferredSize(button, uiPreferredSize); + return new Dimension(size.width + 5, size.height + 4); + } + +} diff --git a/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherLookAndFeel.java b/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherLookAndFeel.java new file mode 100644 index 0000000..80d4725 --- /dev/null +++ b/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherLookAndFeel.java @@ -0,0 +1,16 @@ +/* + * SKCraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.skin; + +import org.pushingpixels.substance.api.SubstanceLookAndFeel; + +public class LauncherLookAndFeel extends SubstanceLookAndFeel { + + public LauncherLookAndFeel() { + super(new LauncherSkin()); + } +} diff --git a/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherSkin.java b/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherSkin.java new file mode 100644 index 0000000..15470d3 --- /dev/null +++ b/launcher-fancy/src/main/java/com/skcraft/launcher/skin/LauncherSkin.java @@ -0,0 +1,94 @@ +/* + * SKCraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher.skin; + +import org.pushingpixels.substance.api.*; +import org.pushingpixels.substance.api.painter.border.ClassicBorderPainter; +import org.pushingpixels.substance.api.painter.border.CompositeBorderPainter; +import org.pushingpixels.substance.api.painter.border.DelegateBorderPainter; +import org.pushingpixels.substance.api.painter.decoration.FlatDecorationPainter; +import org.pushingpixels.substance.api.painter.fill.FractionBasedFillPainter; +import org.pushingpixels.substance.api.painter.highlight.ClassicHighlightPainter; +import org.pushingpixels.substance.api.skin.GraphiteSkin; + +public class LauncherSkin extends GraphiteSkin { + + public LauncherSkin() { + ColorSchemes schemes = SubstanceSkin.getColorSchemes("com/skcraft/launcher/skin/graphite.colorschemes"); + + SubstanceColorScheme activeScheme = schemes.get("Graphite Active"); + SubstanceColorScheme selectedDisabledScheme = schemes.get("Graphite Selected Disabled"); + SubstanceColorScheme selectedScheme = schemes.get("Graphite Selected"); + SubstanceColorScheme disabledScheme = schemes.get("Graphite Disabled"); + SubstanceColorScheme enabledScheme = schemes.get("Graphite Enabled"); + SubstanceColorScheme backgroundScheme = schemes.get("Graphite Background"); + SubstanceColorScheme highlightScheme = schemes.get("Graphite Highlight"); + SubstanceColorScheme borderScheme = schemes.get("Graphite Border"); + SubstanceColorScheme separatorScheme = schemes.get("Graphite Separator"); + SubstanceColorScheme textHighlightScheme = schemes.get("Graphite Text Highlight"); + SubstanceColorScheme highlightMarkScheme = schemes.get("Graphite Highlight Mark"); + SubstanceColorScheme tabHighlightScheme = schemes.get("Graphite Tab Highlight"); + + SubstanceColorSchemeBundle scheme = new SubstanceColorSchemeBundle(activeScheme, enabledScheme, disabledScheme); + + // highlight fill scheme + custom alpha for rollover unselected state + scheme.registerHighlightColorScheme(highlightScheme, 0.6f, ComponentState.ROLLOVER_UNSELECTED); + scheme.registerHighlightColorScheme(highlightScheme, 0.8f, ComponentState.SELECTED); + scheme.registerHighlightColorScheme(highlightScheme, 1.0f, ComponentState.ROLLOVER_SELECTED); + scheme.registerHighlightColorScheme(highlightScheme, 0.75f, ComponentState.ARMED, ComponentState.ROLLOVER_ARMED); + + // highlight border scheme + scheme.registerColorScheme(highlightScheme, ColorSchemeAssociationKind.HIGHLIGHT_BORDER, ComponentState.getActiveStates()); + scheme.registerColorScheme(borderScheme, ColorSchemeAssociationKind.BORDER); + scheme.registerColorScheme(separatorScheme, ColorSchemeAssociationKind.SEPARATOR); + + // text highlight scheme + scheme.registerColorScheme(textHighlightScheme, ColorSchemeAssociationKind.TEXT_HIGHLIGHT, ComponentState.SELECTED, ComponentState.ROLLOVER_SELECTED); + scheme.registerColorScheme(highlightScheme, ComponentState.ARMED, ComponentState.ROLLOVER_ARMED); + scheme.registerColorScheme(highlightMarkScheme, ColorSchemeAssociationKind.HIGHLIGHT_MARK, ComponentState.getActiveStates()); + scheme.registerColorScheme(highlightMarkScheme, ColorSchemeAssociationKind.MARK, ComponentState.ROLLOVER_SELECTED, ComponentState.ROLLOVER_UNSELECTED); + scheme.registerColorScheme(borderScheme, ColorSchemeAssociationKind.MARK, ComponentState.SELECTED); + scheme.registerColorScheme(disabledScheme, 0.5f, ComponentState.DISABLED_UNSELECTED); + scheme.registerColorScheme(selectedDisabledScheme, 0.65f, ComponentState.DISABLED_SELECTED); + scheme.registerColorScheme(highlightScheme, ComponentState.ROLLOVER_SELECTED); + scheme.registerColorScheme(selectedScheme, ComponentState.SELECTED); + + scheme.registerColorScheme(tabHighlightScheme, ColorSchemeAssociationKind.TAB, ComponentState.ROLLOVER_SELECTED); + + this.registerDecorationAreaSchemeBundle(scheme, backgroundScheme, DecorationAreaType.NONE); + + this.setSelectedTabFadeStart(0.1); + this.setSelectedTabFadeEnd(0.3); + + this.buttonShaper = new LauncherButtonShaper(); + this.watermark = null; + this.fillPainter = new FractionBasedFillPainter("Graphite", + new float[] { 0.0f, 0.5f, 1.0f }, + new ColorSchemeSingleColorQuery[] { + ColorSchemeSingleColorQuery.ULTRALIGHT, + ColorSchemeSingleColorQuery.LIGHT, + ColorSchemeSingleColorQuery.LIGHT }); + this.decorationPainter = new FlatDecorationPainter(); + this.highlightPainter = new ClassicHighlightPainter(); + this.borderPainter = new CompositeBorderPainter("Graphite", + new ClassicBorderPainter(), new DelegateBorderPainter( + "Graphite Inner", new ClassicBorderPainter(), + 0xA0FFFFFF, 0x60FFFFFF, 0x60FFFFFF, + new ColorSchemeTransform() { + @Override + public SubstanceColorScheme transform( + SubstanceColorScheme scheme) { + return scheme.tint(0.25f); + } + })); + + this.highlightBorderPainter = new ClassicBorderPainter(); + + this.watermarkScheme = schemes.get("Graphite Watermark"); + } + +} diff --git a/launcher-fancy/src/main/resources/com/skcraft/launcher/skin/graphite.colorschemes b/launcher-fancy/src/main/resources/com/skcraft/launcher/skin/graphite.colorschemes new file mode 100644 index 0000000..2c05502 --- /dev/null +++ b/launcher-fancy/src/main/resources/com/skcraft/launcher/skin/graphite.colorschemes @@ -0,0 +1,153 @@ +Graphite Enabled { + kind=Dark + colorUltraLight=#4A4A4A + colorExtraLight=#464646 + colorLight=#424242 + colorMid=#3F3F3F + colorDark=#353535 + colorUltraDark=#313131 + colorForeground=#B4B4B4 +} + +Graphite Border { + kind=Dark + colorUltraLight=#616161 + colorExtraLight=#5A5A5A + colorLight=#4F4F4F + colorMid=#414141 + colorDark=#323232 + colorUltraDark=#2B2B2B + colorForeground=#EDEDED +} + +Graphite Background { + kind=Dark + colorUltraLight=#555555 + colorExtraLight=#444444 + colorLight=#333333 + colorMid=#222222 + colorDark=#111111 + colorUltraDark=#000000 + colorForeground=#B4B4B4 +} + +Graphite Watermark { + kind=Dark + colorUltraLight=#555555 + colorExtraLight=#444444 + colorLight=#333333 + colorMid=#222222 + colorDark=#111111 + colorUltraDark=#000000 + colorForeground=#B4B4B4 +} + +Graphite Active { + kind=Dark + colorUltraLight=#777777 + colorExtraLight=#6F6F6F + colorLight=#636363 + colorMid=#535353 + colorDark=#434343 + colorUltraDark=#3B3B3B + colorForeground=#C8C8C8 +} + +Graphite Selected { + kind=Dark + colorUltraLight=#727272 + colorExtraLight=#696969 + colorLight=#606060 + colorMid=#505050 + colorDark=#404040 + colorUltraDark=#383838 + colorForeground=#C8C8C8 +} + +Graphite Selected Disabled { + kind=Dark + colorUltraLight=#777777 + colorExtraLight=#6F6F6F + colorLight=#636363 + colorMid=#535353 + colorDark=#434343 + colorUltraDark=#3B3B3B + colorForeground=#202020 +} + +Graphite Disabled { + kind=Dark + colorUltraLight=#646464 + colorExtraLight=#5E5E5E + colorLight=#545454 + colorMid=#474747 + colorDark=#3A3A3A + colorUltraDark=#333333 + colorForeground=#CCCCCC +} + +Graphite Highlight { + kind=Dark + colorUltraLight=#373737 + colorExtraLight=#373737 + colorLight=#373737 + colorMid=#373737 + colorDark=#373737 + colorUltraDark=#373737 + colorForeground=#CCCCCC +} + +Graphite Tab Highlight { + kind=Light + colorUltraLight=#FBFCFF + colorExtraLight=#F2F6FB + colorLight=#CED7E0 + colorMid=#BCC0C5 + colorDark=#62666B + colorUltraDark=#363B3F + colorForeground=#EDEDED +} + +Graphite Highlight Mark { + kind=Dark + colorUltraLight=#616161 + colorExtraLight=#5A5A5A + colorLight=#4F4F4F + colorMid=#414141 + colorDark=#323232 + colorUltraDark=#2B2B2B + colorForeground=#2B2B2B +} + +Graphite Text Highlight { + kind=Light + colorUltraLight=#BDBEC0 + colorExtraLight=#B8BBBD + colorLight=#A4A9AE + colorMid=#9A9D9F + colorDark=#686B6D + colorUltraDark=#505355 + colorForeground=#2B2F33 +} + +Graphite Separator { + kind=Dark + colorUltraLight=#565656 + colorExtraLight=#525252 + colorLight=#4F4F4F + colorMid=#383838 + colorDark=#353535 + colorUltraDark=#333333 + colorForeground=#B4B4B4 +} + +Graphite Aqua { + kind=Light + colorUltraLight=#6383FF + colorExtraLight=#577EFF + colorLight=#4A6FFF + colorMid=#355FFB + colorDark=#1A3DE6 + colorUltraDark=#153BE1 + colorForeground=#FFFFFF +} \ No newline at end of file diff --git a/launcher/src/main/java/com/skcraft/launcher/DefaultLauncherSupplier.java b/launcher/src/main/java/com/skcraft/launcher/DefaultLauncherSupplier.java new file mode 100644 index 0000000..181da15 --- /dev/null +++ b/launcher/src/main/java/com/skcraft/launcher/DefaultLauncherSupplier.java @@ -0,0 +1,27 @@ +/* + * SKCraft Launcher + * Copyright (C) 2010-2014 Albert Pham and contributors + * Please see LICENSE.txt for license information. + */ + +package com.skcraft.launcher; + +import com.google.common.base.Supplier; +import com.skcraft.launcher.dialog.LauncherFrame; + +import java.awt.*; + +public class DefaultLauncherSupplier implements Supplier { + + private final Launcher launcher; + + public DefaultLauncherSupplier(Launcher launcher) { + this.launcher = launcher; + } + + @Override + public Window get() { + return new LauncherFrame(launcher); + } + +} diff --git a/launcher/src/main/java/com/skcraft/launcher/Launcher.java b/launcher/src/main/java/com/skcraft/launcher/Launcher.java index bdab9ee..de6f1ef 100644 --- a/launcher/src/main/java/com/skcraft/launcher/Launcher.java +++ b/launcher/src/main/java/com/skcraft/launcher/Launcher.java @@ -9,12 +9,12 @@ package com.skcraft.launcher; import com.beust.jcommander.JCommander; import com.beust.jcommander.ParameterException; import com.google.common.base.Strings; +import com.google.common.base.Supplier; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import com.skcraft.launcher.auth.AccountList; import com.skcraft.launcher.auth.LoginService; import com.skcraft.launcher.auth.YggdrasilLoginService; -import com.skcraft.launcher.dialog.LauncherFrame; import com.skcraft.launcher.launch.LaunchSupervisor; import com.skcraft.launcher.model.minecraft.VersionManifest; import com.skcraft.launcher.persistence.Persistence; @@ -25,10 +25,12 @@ import com.skcraft.launcher.util.SharedLocale; import com.skcraft.launcher.util.SimpleLogFormatter; import lombok.Getter; import lombok.NonNull; +import lombok.Setter; import lombok.extern.java.Log; import org.apache.commons.io.FileUtils; import javax.swing.*; +import java.awt.*; import java.io.File; import java.io.FileFilter; import java.io.IOException; @@ -50,6 +52,7 @@ public final class Launcher { @Getter private final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); + @Getter @Setter private Supplier mainWindowSupplier = new DefaultLauncherSupplier(this); @Getter private final File baseDir; @Getter private final Properties properties; @Getter private final InstanceList instances; @@ -323,21 +326,23 @@ public final class Launcher { } /** - * Bootstrap. - * - * @param args args + * Show the launcher. */ - public static void main(String[] args) { - SimpleLogFormatter.configureGlobalLogger(); + public void showLauncherWindow() { + mainWindowSupplier.get().setVisible(true); + } + /** + * Create a new launcher from arguments. + * + * @param args the arguments + * @return the launcher + * @throws ParameterException thrown on a bad parameter + * @throws IOException throw on an I/O error + */ + public static Launcher createFromArguments(String[] args) throws ParameterException, IOException { LauncherArguments options = new LauncherArguments(); - try { - new JCommander(options, args); - } catch (ParameterException e) { - System.err.print(e.getMessage()); - System.exit(1); - return; - } + new JCommander(options, args); Integer bsVersion = options.getBootstrapVersion(); log.info(bsVersion != null ? "Bootstrap version " + bsVersion + " detected" : "Not bootstrapped"); @@ -350,27 +355,32 @@ public final class Launcher { log.info("Using current directory " + dir.getAbsolutePath()); } - final File baseDir = dir; + return new Launcher(dir); + } + + /** + * Setup loggers and perform initialization. + */ + public static void setupLogger() { + SimpleLogFormatter.configureGlobalLogger(); + } + + /** + * Bootstrap. + * + * @param args args + */ + public static void main(final String[] args) { + setupLogger(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { - String lafName = System.getProperty("com.skcraft.launcher.laf"); - if (lafName != null) { - try { - UIManager.setLookAndFeel(lafName); - } catch (Exception e) { - log.log(Level.WARNING, "Failed to set look and feel to " + lafName, e); - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } - } else { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } - + Launcher launcher = createFromArguments(args); + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.getDefaults().put("SplitPane.border", BorderFactory.createEmptyBorder()); - Launcher launcher = new Launcher(baseDir); - new LauncherFrame(launcher).setVisible(true); + launcher.showLauncherWindow(); } catch (Throwable t) { log.log(Level.WARNING, "Load failure", t); SwingHelper.showErrorDialog(null, "Uh oh! The updater couldn't be opened because a " + diff --git a/launcher/src/main/java/com/skcraft/launcher/dialog/LauncherFrame.java b/launcher/src/main/java/com/skcraft/launcher/dialog/LauncherFrame.java index b39c941..8f60639 100644 --- a/launcher/src/main/java/com/skcraft/launcher/dialog/LauncherFrame.java +++ b/launcher/src/main/java/com/skcraft/launcher/dialog/LauncherFrame.java @@ -354,7 +354,7 @@ public class LauncherFrame extends JFrame { @Override public void gameClosed() { - new LauncherFrame(launcher).setVisible(true); + launcher.showLauncherWindow(); } } diff --git a/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java b/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java index ba49fdb..0810242 100644 --- a/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java +++ b/launcher/src/main/java/com/skcraft/launcher/swing/SwingHelper.java @@ -376,4 +376,15 @@ public final class SwingHelper { SwingHelper.removeOpaqueness(container); return container; } + + public static boolean setLookAndFeel(String lookAndFeel) { + try { + UIManager.setLookAndFeel(lookAndFeel); + return true; + } catch (Exception e) { + log.log(Level.WARNING, "Failed to set look and feel to " + lookAndFeel, e); + return false; + } + } + }