add icon, fix icon positioning

This commit is contained in:
moehreag 2024-06-16 19:24:34 +02:00
parent a3960b933f
commit b6d904595a
4 changed files with 37 additions and 20 deletions

View file

@ -1,9 +1,11 @@
package dev.frogmc.frogloader.impl.gui.component;
import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.plaf.basic.BasicBorders;
import java.awt.*;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URL;
import dev.frogmc.frogloader.impl.mod.ModDependencyResolver;
@ -28,17 +30,29 @@ public class DependencyErrorEntry extends JPanel {
desc.setText("<html>" + description.replace("<", "&lt;").replace("\n", "<br>") + "</html>");
text.add(desc);
add(text, BorderLayout.NORTH);
Box top = Box.createHorizontalBox();
add(top, BorderLayout.NORTH);
if (icon != null) {
URL location = getClass().getResource("/"+icon);
if (location != null) {
try {
int size = 100;
Image image = ImageIO.read(location).getScaledInstance(size, size, Image.SCALE_SMOOTH);
Box container = Box.createVerticalBox();
container.add(new JLabel(new ImageIcon(image)));
container.add(Box.createVerticalGlue());
top.add(container);
} catch (IOException ignored) {
}
}
}
top.add(text);
this.actions = new JPanel(new FlowLayout(FlowLayout.LEFT));
add(this.actions, BorderLayout.SOUTH);
if (icon != null) {
URL location = getClass().getResource(icon);
if (location != null)
add(new JLabel(new ImageIcon(location)), BorderLayout.WEST);
}
}
public void addAction(String label, ActionListener listener) {

View file

@ -87,19 +87,21 @@ public class FrogModProvider implements ModProvider {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
Files.walkFileTree(dir, new SimpleFileVisitor<>(){
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return super.visitFile(file, attrs);
}
if (Files.exists(dir)) {
Files.walkFileTree(dir, new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return super.visitFile(file, attrs);
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return super.postVisitDirectory(dir, exc);
}
});
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return super.postVisitDirectory(dir, exc);
}
});
}
} catch (IOException e) {
LOGGER.error("Failed to clear extracted jij mods!", e);
}

View file

@ -9,4 +9,5 @@ license = "Apache-2.0"
credits = [
{ name = "FrogMC Team", roles = ["author"] }
]
icon = "icon.png"

BIN
src/main/resources/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB