Skip to content

Commit

Permalink
Add icons and set them on the window. (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored Jan 2, 2024
1 parent bcc2055 commit ca4d60e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
41 changes: 41 additions & 0 deletions src/main/java/net/minecraftforge/installer/Images.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.minecraftforge.installer;

import javax.imageio.ImageIO;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

final class Images {
private Images() {
}

static List<Image> getWindowIcons() {
List<Image> result = new ArrayList<>();
result.add(getImage("/icons/neoforged_background_16x16.png"));
result.add(getImage("/icons/neoforged_background_32x32.png"));
result.add(getImage("/icons/neoforged_background_128x128.png"));
return result;
}

static BufferedImage getImage(String path) {
return getImage(path, null);
}

static BufferedImage getImage(String path, String default_) {
try {
InputStream in = SimpleInstaller.class.getResourceAsStream(path);
if (in == null && default_ != null)
in = new ByteArrayInputStream(InstallerPanel.hexToByteArray(default_));
return ImageIO.read(in);
} catch (IOException e) {
if (default_ == null)
throw new RuntimeException(e);
else
return new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
}
}
}
24 changes: 2 additions & 22 deletions src/main/java/net/minecraftforge/installer/InstallerPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import net.minecraftforge.installer.json.InstallV1;
import net.minecraftforge.installer.json.OptionalLibrary;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.Box;
import javax.swing.BoxLayout;
Expand All @@ -48,10 +47,8 @@
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -128,31 +125,13 @@ public static byte[] hexToByteArray(String s) {
return data;
}

private BufferedImage getImage(String path, String default_)
{
try
{
InputStream in = SimpleInstaller.class.getResourceAsStream(path);
if (in == null && default_ != null)
in = new ByteArrayInputStream(hexToByteArray(default_));
return ImageIO.read(in);
}
catch (IOException e)
{
if (default_ == null)
throw new RuntimeException(e);
else
return new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB);
}
}

public InstallerPanel(File targetDir, InstallV1 profile, File installer)
{
this.profile = profile;
this.installer = installer;

this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
BufferedImage image = getImage(profile.getLogo(), null);
BufferedImage image = Images.getImage(profile.getLogo());
//final BufferedImage urlIcon = getImage(profile.getUrlIcon(), URL);

JPanel logoSplash = new JPanel();
Expand Down Expand Up @@ -415,6 +394,7 @@ public void run(ProgressCallback monitor)
proceedButton.ifPresent(button -> button.setText("Proceed"));

dialog = optionPane.createDialog("NeoForge installer");
dialog.setIconImages(Images.getWindowIcons());
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
int result = (Integer) (optionPane.getValue() != null ? optionPane.getValue() : -1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public ProgressFrame(ProgressCallback parent, String title, Runnable canceler)
setBounds(100, 100, 600, 400);
setContentPane(panel);
setLocationRelativeTo(null);
setIconImages(Images.getWindowIcons());

GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[] { 600, 0 };
Expand Down
Binary file added src/main/resources/icons/neoforged_16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ca4d60e

Please sign in to comment.