mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-20 07:45:36 +00:00
selecting appropriate icon size for ribbon/nonribbon
This commit is contained in:
@@ -45,6 +45,8 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
@@ -345,7 +347,10 @@ public class View {
|
||||
}
|
||||
|
||||
public static ImageIcon getIcon(String name, int size) {
|
||||
ImageIcon icon = getIcon(name);
|
||||
ImageIcon icon = getIcon(getPrefferedIconName(name, size));
|
||||
if (icon.getIconWidth() == size && icon.getIconHeight() == size) {
|
||||
return icon;
|
||||
}
|
||||
icon.getImage();
|
||||
BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
|
||||
bi.createGraphics().drawImage(icon.getImage(), 0, 0, size, size, null, null);
|
||||
@@ -374,6 +379,28 @@ public class View {
|
||||
root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing);
|
||||
}
|
||||
|
||||
public static boolean iconExists(String resource) {
|
||||
return View.class.getResource("/com/jpexs/decompiler/flash/gui/graphics/" + resource + ".png") != null;
|
||||
}
|
||||
|
||||
private static String getPrefferedIconName(String resource, int preferredSize) {
|
||||
Matcher m = Pattern.compile("(.*[^0-9])([0-9]+)").matcher(resource);
|
||||
if (m.matches()) {
|
||||
int origSize = Integer.parseInt(m.group(2));
|
||||
String name = m.group(1);
|
||||
if (origSize != preferredSize) {
|
||||
if (iconExists(name + preferredSize)) {
|
||||
return name + preferredSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
public static ImageWrapperResizableIcon getResizableIcon(String resource, int preferredSize) {
|
||||
return getResizableIcon(getPrefferedIconName(resource, preferredSize));
|
||||
}
|
||||
|
||||
public static ImageWrapperResizableIcon getResizableIcon(String resource) {
|
||||
return ImageWrapperResizableIcon.getIcon(View.class.getResource("/com/jpexs/decompiler/flash/gui/graphics/" + resource + ".png"), new Dimension(256, 256));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user