From 09b120ee89e9e14171b8bfe715d19140c9c944d0 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 21 Jul 2021 10:56:37 +0200 Subject: [PATCH 1/7] Fix FileViewer not reading font size from settings --- .../bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java | 2 ++ 1 file changed, 2 insertions(+) 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 c227ddd5..e52416b8 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 @@ -1,6 +1,7 @@ package the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer; import java.awt.BorderLayout; +import java.awt.Font; import java.awt.image.BufferedImage; import javax.swing.ImageIcon; import javax.swing.JButton; @@ -125,6 +126,7 @@ public class FileViewer extends ResourceViewer textArea.setCodeFoldingEnabled(true); textArea.setSyntaxEditingStyle(SyntaxLanguage.detectLanguage(nameLowerCase, contentsAsString).getSyntaxConstant()); textArea.setText(contentsAsString); + textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue())); textArea.setCaretPosition(0); mainPanel.add(textArea.getScrollPane()); From 0653e8583e2081384068721e70ebd991b24b2fea Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 21 Jul 2021 11:29:52 +0200 Subject: [PATCH 2/7] Better zoom for images --- .../gui/resourceviewer/viewer/FileViewer.java | 51 +++++++++++++------ .../resources/ResourceType.java | 4 +- 2 files changed, 38 insertions(+), 17 deletions(-) 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"), ; From a291fec94186c761c1508c92ebabd2c338b90941 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 21 Jul 2021 12:26:32 +0200 Subject: [PATCH 3/7] Fix newer JDKs --- .../gui/components/BetterJOptionPane.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/BetterJOptionPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/BetterJOptionPane.java index 9c3dc6ed..a738a224 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/BetterJOptionPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/BetterJOptionPane.java @@ -151,8 +151,8 @@ public class BetterJOptionPane //create a new option pane with a empty text and just 'ok' JOptionPane pane = new JOptionPane(""); pane.add(panel, 0); - - JDialog dialog = createNewJDialogue(parentComponent, pane, panel.getName(), 0, (d)-> + + JDialog dialog = createNewJDialogue(parentComponent, pane, panel.getName(), ERROR_MESSAGE, (d)-> { int newHeight = Math.min(minimumHeight, d.getHeight()); d.setMinimumSize(new Dimension(d.getWidth(), newHeight)); @@ -165,28 +165,23 @@ public class BetterJOptionPane private static JDialog createNewJDialogue(Component parentComponent, JOptionPane pane, String title, int style, OnCreate onCreate) { - JDialog dialog = null; - - //reflection to cheat our way around the - // private createDialog(Component parentComponent, String title, int style) - try - { - Method createDialog = pane.getClass().getDeclaredMethod("createDialog", Component.class, String.class, int.class); - createDialog.setAccessible(true); - dialog = (JDialog) createDialog.invoke(pane, parentComponent, title, style); - - //check if the dialogue is in a poor location, attempt to correct - if(dialog.getLocation().getY() == 0 || dialog.getLocation().getY() == 1) - dialog.setLocationRelativeTo(null); //TODO check if BytecodeViewer.viewer is better on multi monitor for this edgecase - else - dialog.setLocationRelativeTo(BytecodeViewer.viewer); - - onCreate.onCreate(dialog); - } - catch(Exception e) - { - e.printStackTrace(); + JDialog dialog = pane.createDialog(parentComponent, title); + if (JDialog.isDefaultLookAndFeelDecorated()) { + boolean supportsWindowDecorations = + UIManager.getLookAndFeel().getSupportsWindowDecorations(); + if (supportsWindowDecorations) { + dialog.setUndecorated(true); + pane.getRootPane().setWindowDecorationStyle(style); + } } + + //check if the dialogue is in a poor location, attempt to correct + if (dialog.getLocation().getY() == 0 || dialog.getLocation().getY() == 1) + dialog.setLocationRelativeTo(null); //TODO check if BytecodeViewer.viewer is better on multi monitor for this edgecase + else + dialog.setLocationRelativeTo(BytecodeViewer.viewer); + + onCreate.onCreate(dialog); dialog.show(); dialog.dispose(); From 37343ec4e08dd59939cd77eaaab2592350f61c00 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 21 Jul 2021 12:33:50 +0200 Subject: [PATCH 4/7] Safer way to set font size --- .../bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditor.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditor.java index 3762c025..7c8a8aa9 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditor.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/hexviewer/JHexEditor.java @@ -28,7 +28,7 @@ public class JHexEditor extends JPanel implements FocusListener, AdjustmentListe byte[] buff; public int cursor; - protected static Font font = new Font("Monospaced", Font.PLAIN, 12); + protected static Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12); protected int border = 2; public boolean DEBUG = false; private final JScrollBar sb; From b782af642e9dcf8e0a87641f000a371669f5daa6 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 21 Jul 2021 12:33:55 +0200 Subject: [PATCH 5/7] Add bug TODOs --- .../java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index f35e7ba2..935db5a1 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -75,6 +75,8 @@ import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; * This is caused by the ctrlMouseWheelZoom code, a temporary patch is just removing it worst case * + Versioning and updating need to be fixed * + Fix classfile searcher + * + JHexEditor in dark mode is nearly unreadable -> Theme support + * + JHexEditor doesn't apply font size from settings * * TODO API BUGS: * + All of the plugins that modify code need to include BytecodeViewer.updateAllClassNodeByteArrays(); From 7a5f679ac86b91a60a63ec423781b07264b85ede Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 21 Jul 2021 12:41:37 +0200 Subject: [PATCH 6/7] Add WebP support --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 42be1227..ca51cd11 100644 --- a/pom.xml +++ b/pom.xml @@ -238,6 +238,11 @@ darklaf-extensions-rsyntaxarea 0.3.4 + + com.github.gotson + webp-imageio + 0.2.1 + From 6354e1ce15264460f8ddbf06c58764495a14c134 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 21 Jul 2021 12:44:33 +0200 Subject: [PATCH 7/7] Add TODOs --- .../java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java | 2 ++ .../bytecodeviewer/gui/resourceviewer/viewer/FileViewer.java | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index 935db5a1..6ccda15f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -112,6 +112,8 @@ import static the.bytecode.club.bytecodeviewer.util.MiscUtils.guessLanguage; * ^ Easiest way to do this is to read the file header CAFEBABE on resource view * + Add BCEL Support: * ^ https://github.com/ptnkjke/Java-Bytecode-Editor visualizer as a plugin + * + Add animated GIF support to image viewer + * + Add drag support to images (allow not only to zoom, but also to drag the image) * * @author Konloch * @author The entire BCV community 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 4fdc2f06..7c64b0c7 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 @@ -83,7 +83,6 @@ public class FileViewer extends ResourceViewer if (!MiscUtils.isPureAscii(contentsAsString) || hexViewerOnly) { //TODO: - // + Webp? // + Add file header checks // + Check for CAFEBABE // + ClassRead then quick-decompile using Pane1 Decompiler @@ -97,7 +96,7 @@ public class FileViewer extends ResourceViewer { canRefresh = true; - image = MiscUtils.loadImage(image, contents); //gifs fail because of this + image = MiscUtils.loadImage(image, contents); if (image == null) { JHexEditor hex = new JHexEditor(contents); mainPanel.add(hex);