1
0
mirror of https://github.com/SKCraft/Launcher.git synced 2024-11-27 12:46:22 +01:00

Refactor startup and add new dark fancy theme.

This commit is contained in:
sk89q 2015-02-20 01:38:18 -08:00
parent 4b5bf7dca9
commit 540a3bcaab
10 changed files with 437 additions and 38 deletions

View File

@ -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) {
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");
System.setProperty("com.skcraft.launcher.laf", "org.pushingpixels.substance.api.skin.SubstanceMarinerLookAndFeel");
Launcher.main(args);
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<Window> {
private final Launcher launcher;
private CustomWindowSupplier(Launcher launcher) {
this.launcher = launcher;
}
@Override
public Window get() {
return new FancyLauncherFrame(launcher);
}
}
}

View File

@ -0,0 +1,26 @@
/*
* SKCraft Launcher
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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);
}
}

View File

@ -0,0 +1,21 @@
/*
* SKCraft Launcher
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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);
}
}

View File

@ -0,0 +1,16 @@
/*
* SKCraft Launcher
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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());
}
}

View File

@ -0,0 +1,94 @@
/*
* SKCraft Launcher
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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");
}
}

View File

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

View File

@ -0,0 +1,27 @@
/*
* SKCraft Launcher
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> 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<Window> {
private final Launcher launcher;
public DefaultLauncherSupplier(Launcher launcher) {
this.launcher = launcher;
}
@Override
public Window get() {
return new LauncherFrame(launcher);
}
}

View File

@ -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<Window> mainWindowSupplier = new DefaultLauncherSupplier(this);
@Getter private final File baseDir;
@Getter private final Properties properties;
@Getter private final InstanceList instances;
@ -323,22 +326,24 @@ public final class Launcher {
}
/**
* Bootstrap.
*
* @param args args
* Show the launcher.
*/
public static void main(String[] args) {
SimpleLogFormatter.configureGlobalLogger();
LauncherArguments options = new LauncherArguments();
try {
new JCommander(options, args);
} catch (ParameterException e) {
System.err.print(e.getMessage());
System.exit(1);
return;
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();
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);
Launcher launcher = createFromArguments(args);
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
} else {
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 " +

View File

@ -354,7 +354,7 @@ public class LauncherFrame extends JFrame {
@Override
public void gameClosed() {
new LauncherFrame(launcher).setVisible(true);
launcher.showLauncherWindow();
}
}

View File

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