diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java index e52416b8..4fdc2f06 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java @@ -48,11 +48,14 @@ import the.bytecode.club.bytecodeviewer.util.SyntaxLanguage; public class FileViewer extends ResourceViewer { + public static final float ZOOM_STEP_SIZE = 1.5f; public final SearchableRSyntaxTextArea textArea = (SearchableRSyntaxTextArea) Configuration.rstaTheme.apply(new SearchableRSyntaxTextArea()); public final JPanel mainPanel = new JPanel(new BorderLayout()); + public BufferedImage originalImage; public BufferedImage image; public boolean canRefresh; + public int zoomSteps = 0; public FileViewer(final ResourceContainer container, final String name) { @@ -93,24 +96,42 @@ public class FileViewer extends ResourceViewer !hexViewerOnly) { canRefresh = true; - + image = MiscUtils.loadImage(image, contents); //gifs fail because of this - + if (image == null) { + JHexEditor hex = new JHexEditor(contents); + mainPanel.add(hex); + return; + } + originalImage = image; + mainPanel.add(new ImageJLabel(image), BorderLayout.CENTER); - mainPanel.addMouseWheelListener(e -> - { + mainPanel.addMouseWheelListener(e -> { int notches = e.getWheelRotation(); - - if (notches < 0) //zoom in - image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() + 10, - image.getHeight() + 10); - else //zoom out - image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() - 10, - image.getHeight() - 10); - - mainPanel.removeAll(); - mainPanel.add(new ImageJLabel(image), BorderLayout.CENTER); - mainPanel.updateUI(); + int width = originalImage.getWidth(); + int height = originalImage.getHeight(); + int oldZoomSteps = zoomSteps; + + if (notches < 0) { + //zoom in + zoomSteps++; + } else { + //zoom out + zoomSteps--; + } + + try { + double factor = Math.pow(ZOOM_STEP_SIZE, zoomSteps); + int newWidth = (int) (width * factor); + int newHeight = (int) (height * factor); + image = Scalr.resize(originalImage, Scalr.Method.SPEED, newWidth, newHeight); + + mainPanel.removeAll(); + mainPanel.add(new ImageJLabel(image), BorderLayout.CENTER); + mainPanel.updateUI(); + } catch (Throwable ignored) { + zoomSteps = oldZoomSteps; + } }); return; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java index 137baf5a..d1554db9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/ResourceType.java @@ -17,14 +17,14 @@ public enum ResourceType JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"), ZIP_ARCHIVE(IconResources.zipIcon, "zip"), ANDROID_ARCHIVE(IconResources.androidIcon, "apk", "wapk", "dex"), - IMAGE_FILE(IconResources.imageIcon, "png", "jpg", "jpeg", "bmp", "wbmp", "gif", "tif"), + IMAGE_FILE(IconResources.imageIcon, "png", "jpg", "jpeg", "bmp", "wbmp", "gif", "tif", "webp"), CONFIG_TEXT_FILE(IconResources.configIcon, "properties", "xml", "jsp", "mf", "config", "csv", "yml", "yaml", "ini", "json", "sql", "gradle", "dockerfile", "htaccess", "plugin", "attachprovider", "transportservice", "connector"), JAVA_FILE(IconResources.javaIcon, "java"), TEXT_FILE(IconResources.textIcon, "txt", "md", "log", "html", "css"), CPP_FILE(IconResources.cplusplusIcon, "c", "cpp", "h"), - CSHAR_FILE(IconResources.csharpIcon, "cs"), + CSHARP_FILE(IconResources.csharpIcon, "cs"), BAT_FILE(IconResources.batIcon, "bat", "batch"), SH_FILE(IconResources.shIcon, "sh", "bash"), ;