bcv-vf/src/main/java/the/bytecode/club/bytecodeviewer/resources/IconResources.java

197 lines
16 KiB
Java
Raw Normal View History

2021-07-11 12:33:18 +00:00
package the.bytecode.club.bytecodeviewer.resources;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
2015-11-19 03:30:59 +00:00
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
2021-07-25 16:54:08 +00:00
import java.io.InputStream;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
2015-11-19 03:30:59 +00:00
import java.util.ArrayList;
2019-06-01 01:04:07 +00:00
import java.util.List;
2021-04-12 22:31:22 +00:00
import java.util.Objects;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.io.IOUtils;
import org.imgscalr.Scalr;
2021-07-11 12:33:18 +00:00
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
/**
* Any resources loaded by disc or by memory.
*
2018-01-31 15:41:24 +00:00
* @author Konloch
*/
2021-07-11 14:10:42 +00:00
public class IconResources
2021-07-11 12:33:18 +00:00
{
static protected final int HALF_SIZE = 4;
static protected final int SIZE = 9;
2019-06-01 01:04:07 +00:00
public static List<BufferedImage> iconList;
2018-01-31 15:41:24 +00:00
public static BufferedImage icon;
public static ImageIcon nextIcon;
public static ImageIcon prevIcon;
public static ImageIcon busyIcon;
public static ImageIcon busyB64Icon;
public static ImageIcon batIcon;
public static ImageIcon shIcon;
public static ImageIcon csharpIcon;
public static ImageIcon cplusplusIcon;
public static ImageIcon configIcon;
public static ImageIcon jarIcon;
public static ImageIcon zipIcon;
public static ImageIcon packagesIcon;
public static ImageIcon folderIcon;
public static ImageIcon androidIcon;
2021-07-15 17:38:32 +00:00
public static ImageIcon unknownFileIcon;
2018-01-31 15:41:24 +00:00
public static ImageIcon textIcon;
public static ImageIcon classIcon;
public static ImageIcon imageIcon;
public static ImageIcon decodedIcon;
public static ImageIcon javaIcon;
2021-06-28 00:03:43 +00:00
static
{
icon = b642IMG("iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAUd0lEQVR42pWaWXRbVZaGq5iHqgaSeJZsy7YkD7KtwZItebblQfI8x/HseIodO3bixE5iZw4ZSBwyACkCXQ003dD0oigq1UBqFVQ1HSB0wkyvXt1VPNSiavHCC288/b3/I11ZSszQDzuRfO89Z39n/3uffST9BMBP17Dbgna72B1hdmfQ7hK7W+yeoN0btPvE7v8Rdl+Y3Rsc4+7guHcF5wif9/ag3fYd/v70J/zHWlGFcLPRKqth99Yoc1TVKssTc1b74Krxw1Vbh3yxAl+9Mre/QZmnrvFHG+/Xnud4alwxzpEXnJOm+UGfbEH/wv2NAHkwMQ4P6GLk/1hlDyXFKVuXFI/1yQnKolJ0yqLTEhFjTEKsKRlxZgPi01OQkJ6qTJeRBn2mEYlZpjWN13gP7+VzfJ7G8WjRqXo1xwZDQmhe+kBfHhR7QHz7O300fq6LUhYBQkJ1UxDkFggZdEMQIJoTCkCsAhDn6TgdpKMWE5KyzcqSc9JDZsjNCL3WridZAmA3Q3F8zhMVBFpHELGHxJcHk2KVPZAYE4K5BYSkD+hjQuR8kAMQYENKgkwgUTBJFMzJgQhkpIrzRnHKJA6axdl0pFgzkGrNRJotS5nRbokw7e8pco8GRygugk4ixYXhAnGhOF90ml7Nvd5A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dGUFvvh1U64s6js2jcJ/f2daNXgYi0NkaC5JbkC4hNpQDbFX12JIiqWioi+bkKxFrmhrN6NSI+GbBFVmzT+BCGZyYwtHUMrbKTl1fLzuspkI1PHNklSbo8g3x
2021-04-12 20:19:12 +00:00
nextIcon = new ImageIcon(b642IMG("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAMFBMVEX"
+ "///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAABnRSTlMANzlYqPBJSG"
+ "/ZAAAASUlEQVR42mNgwAbS0oAEE4yHyWBmYAzjYDC694OJ4f9"
+ "+BoY3H0BSbz6A2MxA6VciFyDqGAWQTWVkYEkCUrcOsDD8OwtkvMViMwAb8xEUHlHcFAAAAABJRU5ErkJggg=="));
prevIcon = new ImageIcon(b642IMG("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQBAMAAADt3eJSAAAAMFBMVEX"
+ "///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAABnRSTlMANzlYgKhxpRi1AAAATElEQVR42mNgwAZYHIAEExA7qUAYLApMDmCGEwODCojByM/A8FEAyPi/moFh9QewYjCAM1iA+D2KqYwMrIlA6tUGFoa/Z4GMt1hsBgCe1wuKber+SwAAAABJRU5ErkJggg=="));
2021-07-11 14:10:42 +00:00
busyIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/loading.gif")));
2021-04-12 20:19:12 +00:00
busyB64Icon = new ImageIcon(b642IMG("R0lGODlhEAALAPQAAP"
+ "///wAAANra2tDQ0Orq6gcHBwAAAC8vL4KCgmFhYbq6uiMjI0tLS4qKimVlZb6+vicnJwUFBU9PT"
+ "+bm5tjY2PT09Dk5Odzc3PLy8ra2tqCgoMrKyu7u7gAAAAAAAAAAACH5BAkLAAAAIf4aQ3JlYXRlZCB3aXRoIGFqYXhsb2FkLmluZm8AIf8LTkVUU0NBUEUyLjADAQAAACwAAAAAEAALAAAFLSAgjmRpnqSgCuLKAq5AEIM4zDVw03ve27ifDgfkEYe04kDIDC5zrtYKRa2WQgAh+QQJCwAAACwAAAAAEAALAAAFJGBhGAVgnqhpHIeRvsDawqns0qeN5+y967tYLyicBYE7EYkYAgAh+QQJCwAAACwAAAAAEAALAAAFNiAgjothLOOIJAkiGgxjpGKiKMkbz7SN6zIawJcDwIK9W/HISxGBzdHTuBNOmcJVCyoUlk7CEAAh+QQJCwAAACwAAAAAEAALAAAFNSAgjqQIRRFUAo3jNGIkSdHqPI8Tz3V55zuaDacDyIQ+YrBH+hWPzJFzOQQaeavWi7oqnVIhACH5BAkLAAAALAAAAAAQAAsAAAUyICCOZGme1rJY5kRRk7hI0mJSVUXJtF3iOl7tltsBZsNfUegjAY3I5sgFY55KqdX1GgIAIfkECQsAAAAsAAAAABAACwAABTcgII5kaZ4kcV2EqLJipmnZhWGXaOOitm2aXQ4g7P2Ct2ER4AMul00kj5g0Al8tADY2y6C+4FIIACH5BAkLAAAALAAAAAAQAAsAAAUvICCOZGme5ERRk6iy7qpyHCVStA3gNa/7txxwlwv2isSacYUc+l4tADQGQ1mvpBAAIfkECQsAAAAsAAAAABAACwAABS8gII5kaZ7kRFGTqLLuqnIcJVK0DeA1r/u3HHCXC/aKxJpxhRz6Xi0ANAZDWa+kEAA7"));
2018-01-31 15:41:24 +00:00
2021-07-11 14:10:42 +00:00
batIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/bat.png")));
shIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/sh.png")));
csharpIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/c#.png")));
cplusplusIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/c++.png")));
configIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/config.png")));
jarIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/jar.png")));
zipIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/zip.png")));
packagesIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/package.png")));
folderIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/folder.png")));
androidIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/android.png")));
2021-07-15 17:38:32 +00:00
unknownFileIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/file.png")));
2021-07-11 14:10:42 +00:00
textIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/text.png")));
classIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/class.png")));
imageIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/image.png")));
decodedIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/decoded.png")));
javaIcon = new ImageIcon(Objects.requireNonNull(IconResources.class.getResource("/gui/java.png")));
2018-01-31 15:41:24 +00:00
2021-04-12 22:31:22 +00:00
iconList = new ArrayList<>();
2018-01-31 15:41:24 +00:00
int size = 16;
2021-06-28 00:03:43 +00:00
for (int i = 0; i < 24; i++)
{
2018-01-31 15:41:24 +00:00
iconList.add(resize(icon, size, size));
size += 2;
}
}
public static String loadResourceAsString(String resourcePath) throws IOException
{
2021-07-25 16:54:08 +00:00
try (InputStream is = IconResources.class.getResourceAsStream(resourcePath)) {
if (is == null)
return null;
return IOUtils.toString(is, StandardCharsets.UTF_8);
}
}
2018-01-31 15:41:24 +00:00
public static BufferedImage resize(BufferedImage image, int width, int height) {
return Scalr.resize(image, Scalr.Method.ULTRA_QUALITY, width, height);
}
/**
* Decodes a Base64 String as a BufferedImage
*/
public static BufferedImage b642IMG(String imageString) {
BufferedImage image = null;
byte[] imageByte;
try {
imageByte = Base64.decodeBase64(imageString);
2021-07-25 16:54:08 +00:00
try (ByteArrayInputStream bis = new ByteArrayInputStream(imageByte)) {
image = ImageIO.read(bis);
}
2018-01-31 15:41:24 +00:00
} catch (Exception e) {
2021-07-07 02:51:10 +00:00
BytecodeViewer.handleException(e);
2018-01-31 15:41:24 +00:00
}
return image;
}
/**
* The minus sign button icon
*/
public static class ExpandedIcon implements Icon, Serializable
{
static public Icon createExpandedIcon() {
return new ExpandedIcon();
}
public void paintIcon(Component c, Graphics g, int x, int y)
{
Color backgroundColor = c.getBackground();
if(backgroundColor != null)
g.setColor(backgroundColor);
else
g.setColor(Color.white);
g.fillRect(x, y, SIZE-1, SIZE-1);
g.setColor(Color.gray);
g.drawRect(x, y, SIZE-1, SIZE-1);
g.setColor(Color.black);
g.drawLine(x + 2, y + HALF_SIZE, x + (SIZE - 3), y + HALF_SIZE);
}
public int getIconWidth() {
return SIZE;
}
public int getIconHeight() {
return SIZE;
}
}
/**
* The plus sign button icon
*/
public static class CollapsedIcon extends ExpandedIcon
{
static public Icon createCollapsedIcon() {
return new CollapsedIcon();
}
public void paintIcon(Component c, Graphics g, int x, int y)
{
super.paintIcon(c, g, x, y);
g.drawLine(x + HALF_SIZE, y + 2, x + HALF_SIZE, y + (SIZE - 3));
}
}
}