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
+
diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java
index 1027b749..da05cb40 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();
@@ -112,6 +114,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/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();
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 0cdc6679..c5c11c34 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
@@ -44,7 +44,7 @@ public class JHexEditor extends JPanel implements FocusListener, AdjustmentListe
super();
this.buff = buff;
- this.font = new Font("Monospaced", Font.PLAIN, BytecodeViewer.viewer.getFontSize());
+ this.font = new Font(Font.MONOSPACED, Font.PLAIN, BytecodeViewer.viewer.getFontSize());
checkSize();
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..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
@@ -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;
@@ -47,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)
{
@@ -79,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
@@ -92,24 +95,42 @@ public class FileViewer extends ResourceViewer
!hexViewerOnly)
{
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);
+ 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;
}
@@ -125,6 +146,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());
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"),
;