mirror of
https://github.com/SKCraft/Launcher.git
synced 2024-11-27 12:46:22 +01:00
Load UI assets in the background.
This commit is contained in:
parent
c1cbff754e
commit
2cd6ba59ff
@ -46,7 +46,7 @@ public class AboutDialog extends JDialog {
|
||||
JPanel container = new JPanel();
|
||||
container.setLayout(new MigLayout("insets dialog"));
|
||||
|
||||
container.add(new JLabel(SwingHelper.readImageIcon(Creator.class, "about_header.png")), "dock north");
|
||||
container.add(new JLabel(SwingHelper.createIcon(Creator.class, "about_header.png")), "dock north");
|
||||
container.add(new JLabel("<html>Version " + version), "wrap");
|
||||
container.add(new JLabel("<html>Licensed under GNU Lesser General Public License, version 3."), "wrap, gapbottom unrel");
|
||||
container.add(new JLabel("<html>Created by the SKCraft team. Visit our website!"), "wrap, gapbottom unrel");
|
||||
|
@ -27,7 +27,7 @@ public class GenerateListingDialog extends JDialog {
|
||||
@Getter private final DirectoryField destDirField = new DirectoryField();
|
||||
@Getter private final JComboBox<ListingType> listingTypeCombo = new JComboBox<>(new ListingTypeComboBoxModel());
|
||||
@Getter private final JTable manifestsTable = new DefaultTable();
|
||||
@Getter private final JLabel gameKeyWarning = new JLabel("Selected listing type won't support adding modpacks using 'game keys'.", SwingHelper.readImageIcon(Creator.class, "warning_icon.png"), SwingConstants.LEFT);
|
||||
@Getter private final JLabel gameKeyWarning = new JLabel("Selected listing type won't support adding modpacks using 'game keys'.", SwingHelper.createIcon(Creator.class, "warning_icon.png"), SwingConstants.LEFT);
|
||||
|
||||
@Getter private final JButton editManifestButton = new JButton("Modify...");
|
||||
|
||||
|
@ -21,13 +21,13 @@ import java.awt.event.KeyEvent;
|
||||
|
||||
public class PackManagerFrame extends JFrame {
|
||||
|
||||
@Getter private final JButton newPackButton = new JButton("New Pack", SwingHelper.readImageIcon(Creator.class, "new.png"));
|
||||
@Getter private final JButton importButton = new JButton("Add Existing", SwingHelper.readImageIcon(Creator.class, "import.png"));
|
||||
@Getter private final JButton editConfigButton = new JButton("Modify", SwingHelper.readImageIcon(Creator.class, "edit.png"));
|
||||
@Getter private final JButton openFolderButton = new JButton("Open", SwingHelper.readImageIcon(Creator.class, "open_folder.png"));
|
||||
@Getter private final JButton checkProblemsButton = new JButton("Check", SwingHelper.readImageIcon(Creator.class, "check.png"));
|
||||
@Getter private final JButton testButton = new JButton("Test", SwingHelper.readImageIcon(Creator.class, "test.png"));
|
||||
@Getter private final JButton buildButton = new JButton("Build", SwingHelper.readImageIcon(Creator.class, "build.png"));
|
||||
@Getter private final JButton newPackButton = new JButton("New Pack", SwingHelper.createIcon(Creator.class, "new.png"));
|
||||
@Getter private final JButton importButton = new JButton("Add Existing", SwingHelper.createIcon(Creator.class, "import.png"));
|
||||
@Getter private final JButton editConfigButton = new JButton("Modify", SwingHelper.createIcon(Creator.class, "edit.png"));
|
||||
@Getter private final JButton openFolderButton = new JButton("Open", SwingHelper.createIcon(Creator.class, "open_folder.png"));
|
||||
@Getter private final JButton checkProblemsButton = new JButton("Check", SwingHelper.createIcon(Creator.class, "check.png"));
|
||||
@Getter private final JButton testButton = new JButton("Test", SwingHelper.createIcon(Creator.class, "test.png"));
|
||||
@Getter private final JButton buildButton = new JButton("Build", SwingHelper.createIcon(Creator.class, "build.png"));
|
||||
|
||||
@Getter private final JMenuItem newPackMenuItem = new JMenuItem("New Pack...");
|
||||
@Getter private final JMenuItem newPackAtLocationMenuItem = new JMenuItem("New Pack at Location...");
|
||||
@ -68,7 +68,7 @@ public class PackManagerFrame extends JFrame {
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
SwingHelper.setIconImage(this, Creator.class, "icon.png");
|
||||
SwingHelper.setFrameIcon(this, Creator.class, "icon.png");
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
|
@ -19,8 +19,8 @@ import java.awt.event.KeyEvent;
|
||||
|
||||
public class WelcomeDialog extends JFrame {
|
||||
|
||||
@Getter private final JButton newButton = new JButton("New Workspace...", SwingHelper.readImageIcon(Creator.class, "new.png"));
|
||||
@Getter private final JButton openButton = new JButton("Open Workspace...", SwingHelper.readImageIcon(Creator.class, "open_folder.png"));
|
||||
@Getter private final JButton newButton = new JButton("New Workspace...", SwingHelper.createIcon(Creator.class, "new.png"));
|
||||
@Getter private final JButton openButton = new JButton("Open Workspace...", SwingHelper.createIcon(Creator.class, "open_folder.png"));
|
||||
@Getter private final JButton helpButton = new JButton("Help");
|
||||
@Getter private final JButton aboutButton = new JButton("About");
|
||||
@Getter private final JButton quitButton = new JButton("Quit");
|
||||
@ -35,7 +35,7 @@ public class WelcomeDialog extends JFrame {
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
SwingHelper.setIconImage(this, Creator.class, "icon.png");
|
||||
SwingHelper.setFrameIcon(this, Creator.class, "icon.png");
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
@ -44,7 +44,7 @@ public class WelcomeDialog extends JFrame {
|
||||
JPanel container = new JPanel();
|
||||
container.setLayout(new MigLayout("insets 50 20"));
|
||||
|
||||
container.add(new JLabel(SwingHelper.readImageIcon(Creator.class, "welcome_logo.png")), "wrap, gap 20 20, gapbottom 30");
|
||||
container.add(new JLabel(SwingHelper.createIcon(Creator.class, "welcome_logo.png")), "wrap, gap 20 20, gapbottom 30");
|
||||
|
||||
container.add(newButton, "grow, gap 50 50, wrap");
|
||||
container.add(openButton, "grow, gap 50 50, wrap");
|
||||
|
@ -19,11 +19,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class ModFileTableModel extends AbstractTableModel {
|
||||
|
||||
private static final ImageIcon WWW_ICON;
|
||||
private static final Icon WWW_ICON;
|
||||
private final List<ModFile> mods;
|
||||
|
||||
static {
|
||||
WWW_ICON = SwingHelper.readImageIcon(Creator.class, "www_icon.png");
|
||||
WWW_ICON = SwingHelper.createIcon(Creator.class, "www_icon.png");
|
||||
}
|
||||
|
||||
public ModFileTableModel(List<ModFile> mods) {
|
||||
@ -49,7 +49,7 @@ public class ModFileTableModel extends AbstractTableModel {
|
||||
public Class<?> getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return ImageIcon.class;
|
||||
return Icon.class;
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
|
@ -17,15 +17,15 @@ import java.util.List;
|
||||
|
||||
public class PackTableModel extends AbstractTableModel {
|
||||
|
||||
private final ImageIcon instanceIcon;
|
||||
private final ImageIcon warningIcon;
|
||||
private final Icon instanceIcon;
|
||||
private final Icon warningIcon;
|
||||
private final List<Pack> packs;
|
||||
|
||||
public PackTableModel(List<Pack> packs) {
|
||||
this.packs = packs;
|
||||
|
||||
instanceIcon = SwingHelper.readImageIcon(Creator.class, "pack_icon.png");
|
||||
warningIcon = SwingHelper.readImageIcon(Creator.class, "warning_icon.png");
|
||||
instanceIcon = SwingHelper.createIcon(Creator.class, "pack_icon.png");
|
||||
warningIcon = SwingHelper.createIcon(Creator.class, "warning_icon.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,7 +50,7 @@ public class PackTableModel extends AbstractTableModel {
|
||||
public Class<?> getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return ImageIcon.class;
|
||||
return Icon.class;
|
||||
default:
|
||||
return String.class;
|
||||
}
|
||||
|
@ -16,10 +16,10 @@ import java.util.List;
|
||||
|
||||
public class ProblemTableModel extends AbstractTableModel {
|
||||
|
||||
private static final ImageIcon WARNING_ICON;
|
||||
private static final Icon WARNING_ICON;
|
||||
|
||||
static {
|
||||
WARNING_ICON = SwingHelper.readImageIcon(Creator.class, "warning_icon.png");
|
||||
WARNING_ICON = SwingHelper.createIcon(Creator.class, "warning_icon.png");
|
||||
}
|
||||
|
||||
private final List<Problem> problems;
|
||||
@ -44,7 +44,7 @@ public class ProblemTableModel extends AbstractTableModel {
|
||||
public Class<?> getColumnClass(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 0:
|
||||
return ImageIcon.class;
|
||||
return Icon.class;
|
||||
case 1:
|
||||
return Problem.class;
|
||||
default:
|
||||
|
@ -58,8 +58,8 @@ public class ConsoleFrame extends JFrame {
|
||||
*/
|
||||
public ConsoleFrame(@NonNull String title, int numLines, boolean colorEnabled) {
|
||||
messageLog = new MessageLog(numLines, colorEnabled);
|
||||
trayRunningIcon = SwingHelper.readIconImage(Launcher.class, "tray_ok.png");
|
||||
trayClosedIcon = SwingHelper.readIconImage(Launcher.class, "tray_closed.png");
|
||||
trayRunningIcon = SwingHelper.createImage(Launcher.class, "tray_ok.png");
|
||||
trayClosedIcon = SwingHelper.createImage(Launcher.class, "tray_closed.png");
|
||||
|
||||
setTitle(title);
|
||||
setIconImage(trayRunningIcon);
|
||||
|
@ -73,7 +73,7 @@ public class LauncherFrame extends JFrame {
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
SwingHelper.setIconImage(this, Launcher.class, "icon.png");
|
||||
SwingHelper.setFrameIcon(this, Launcher.class, "icon.png");
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* SK's Minecraft Launcher
|
||||
* Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> and contributors
|
||||
* Please see LICENSE.txt for license information.
|
||||
*/
|
||||
|
||||
package com.skcraft.launcher.swing;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public final class EmptyIcon implements Icon {
|
||||
|
||||
private int width;
|
||||
private int height;
|
||||
|
||||
public EmptyIcon() {
|
||||
this(0, 0);
|
||||
}
|
||||
|
||||
public EmptyIcon(int width, int height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public int getIconHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public int getIconWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
}
|
||||
|
||||
}
|
@ -13,23 +13,19 @@ import com.skcraft.launcher.util.SharedLocale;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import java.awt.*;
|
||||
|
||||
public class InstanceTableModel extends AbstractTableModel {
|
||||
|
||||
private final InstanceList instances;
|
||||
private final ImageIcon instanceIcon;
|
||||
private final ImageIcon customInstanceIcon;
|
||||
private final ImageIcon downloadIcon;
|
||||
private final Icon instanceIcon;
|
||||
private final Icon customInstanceIcon;
|
||||
private final Icon downloadIcon;
|
||||
|
||||
public InstanceTableModel(InstanceList instances) {
|
||||
this.instances = instances;
|
||||
instanceIcon = new ImageIcon(SwingHelper.readIconImage(Launcher.class, "instance_icon.png")
|
||||
.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
|
||||
customInstanceIcon = new ImageIcon(SwingHelper.readIconImage(Launcher.class, "custom_instance_icon.png")
|
||||
.getScaledInstance(16, 16, Image.SCALE_SMOOTH));
|
||||
downloadIcon = new ImageIcon(SwingHelper.readIconImage(Launcher.class, "download_icon.png")
|
||||
.getScaledInstance(14, 14, Image.SCALE_SMOOTH));
|
||||
instanceIcon = SwingHelper.createIcon(Launcher.class, "instance_icon.png", 16, 16);
|
||||
customInstanceIcon = SwingHelper.createIcon(Launcher.class, "custom_instance_icon.png", 16, 16);
|
||||
downloadIcon = SwingHelper.createIcon(Launcher.class, "download_icon.png", 14, 14);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
@ -290,7 +290,35 @@ public final class SwingHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage readIconImage(Class<?> clazz, String path) {
|
||||
public static Image createImage(Class<?> clazz, String name) {
|
||||
URL resource = clazz.getResource(name);
|
||||
if (resource != null) {
|
||||
return Toolkit.getDefaultToolkit().createImage(resource);
|
||||
} else {
|
||||
log.log(Level.WARNING, "Failed to read image from resource: " + name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Icon createIcon(Class<?> clazz, String name) {
|
||||
Image image = createImage(clazz, name);
|
||||
if (image != null) {
|
||||
return new ImageIcon(image);
|
||||
} else {
|
||||
return new EmptyIcon(16, 16);
|
||||
}
|
||||
}
|
||||
|
||||
public static Icon createIcon(Class<?> clazz, String name, int width, int height) {
|
||||
Image image = createImage(clazz, name);
|
||||
if (image != null) {
|
||||
return new ImageIcon(image.getScaledInstance(width, height, Image.SCALE_SMOOTH));
|
||||
} else {
|
||||
return new EmptyIcon(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
public static BufferedImage readBufferedImage(Class<?> clazz, String path) {
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = clazz.getResourceAsStream(path);
|
||||
@ -304,40 +332,13 @@ public final class SwingHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Image readIconImageScaled(Class<?> clazz, String path, int w, int h) {
|
||||
BufferedImage image = readIconImage(clazz, path);
|
||||
if (image != null) {
|
||||
return image.getScaledInstance(w, h, Image.SCALE_SMOOTH);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setIconImage(JFrame frame, Class<?> clazz, String path) {
|
||||
BufferedImage image = readIconImage(clazz, path);
|
||||
public static void setFrameIcon(JFrame frame, Class<?> clazz, String path) {
|
||||
BufferedImage image = readBufferedImage(clazz, path);
|
||||
if (image != null) {
|
||||
frame.setIconImage(image);
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageIcon readImageIcon(Class<?> clazz, String path) {
|
||||
BufferedImage image = readIconImage(clazz, path);
|
||||
if (image != null) {
|
||||
return new ImageIcon(image);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageIcon readImageIconScaled(Class<?> clazz, String path, int w, int h) {
|
||||
Image image = readIconImageScaled(clazz, path, w, h);
|
||||
if (image != null) {
|
||||
return new ImageIcon(image);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Focus a component.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user