Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add icons and set them on the Window #3

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.