Merge pull request #329 from ThexXTURBOXx/fixes

Fixes
This commit is contained in:
Konloch 2021-07-21 04:30:42 -07:00 committed by GitHub
commit 67f8d3b819
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 43 deletions

View file

@ -238,6 +238,11 @@
<artifactId>darklaf-extensions-rsyntaxarea</artifactId> <artifactId>darklaf-extensions-rsyntaxarea</artifactId>
<version>0.3.4</version> <version>0.3.4</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.gotson</groupId>
<artifactId>webp-imageio</artifactId>
<version>0.2.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View file

@ -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 * This is caused by the ctrlMouseWheelZoom code, a temporary patch is just removing it worst case
* + Versioning and updating need to be fixed * + Versioning and updating need to be fixed
* + Fix classfile searcher * + Fix classfile searcher
* + JHexEditor in dark mode is nearly unreadable -> Theme support
* + JHexEditor doesn't apply font size from settings
* *
* TODO API BUGS: * TODO API BUGS:
* + All of the plugins that modify code need to include BytecodeViewer.updateAllClassNodeByteArrays(); * + All of the plugins that modify code need to include BytecodeViewer.updateAllClassNodeByteArrays();
@ -110,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 * ^ Easiest way to do this is to read the file header CAFEBABE on resource view
* + Add BCEL Support: * + Add BCEL Support:
* ^ https://github.com/ptnkjke/Java-Bytecode-Editor visualizer as a plugin * ^ 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 Konloch
* @author The entire BCV community * @author The entire BCV community

View file

@ -152,7 +152,7 @@ public class BetterJOptionPane
JOptionPane pane = new JOptionPane(""); JOptionPane pane = new JOptionPane("");
pane.add(panel, 0); 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()); int newHeight = Math.min(minimumHeight, d.getHeight());
d.setMinimumSize(new Dimension(d.getWidth(), newHeight)); 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) private static JDialog createNewJDialogue(Component parentComponent, JOptionPane pane, String title, int style, OnCreate onCreate)
{ {
JDialog dialog = null; JDialog dialog = pane.createDialog(parentComponent, title);
if (JDialog.isDefaultLookAndFeelDecorated()) {
//reflection to cheat our way around the boolean supportsWindowDecorations =
// private createDialog(Component parentComponent, String title, int style) UIManager.getLookAndFeel().getSupportsWindowDecorations();
try if (supportsWindowDecorations) {
{ dialog.setUndecorated(true);
Method createDialog = pane.getClass().getDeclaredMethod("createDialog", Component.class, String.class, int.class); pane.getRootPane().setWindowDecorationStyle(style);
createDialog.setAccessible(true); }
dialog = (JDialog) createDialog.invoke(pane, parentComponent, title, style); }
//check if the dialogue is in a poor location, attempt to correct //check if the dialogue is in a poor location, attempt to correct
if(dialog.getLocation().getY() == 0 || dialog.getLocation().getY() == 1) 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 dialog.setLocationRelativeTo(null); //TODO check if BytecodeViewer.viewer is better on multi monitor for this edgecase
else else
dialog.setLocationRelativeTo(BytecodeViewer.viewer); dialog.setLocationRelativeTo(BytecodeViewer.viewer);
onCreate.onCreate(dialog); onCreate.onCreate(dialog);
}
catch(Exception e)
{
e.printStackTrace();
}
dialog.show(); dialog.show();
dialog.dispose(); dialog.dispose();

View file

@ -28,7 +28,7 @@ public class JHexEditor extends JPanel implements FocusListener, AdjustmentListe
byte[] buff; byte[] buff;
public int cursor; 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; protected int border = 2;
public boolean DEBUG = false; public boolean DEBUG = false;
private final JScrollBar sb; private final JScrollBar sb;

View file

@ -1,6 +1,7 @@
package the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer; package the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.JButton; import javax.swing.JButton;
@ -47,11 +48,14 @@ import the.bytecode.club.bytecodeviewer.util.SyntaxLanguage;
public class FileViewer extends ResourceViewer public class FileViewer extends ResourceViewer
{ {
public static final float ZOOM_STEP_SIZE = 1.5f;
public final SearchableRSyntaxTextArea textArea = (SearchableRSyntaxTextArea) public final SearchableRSyntaxTextArea textArea = (SearchableRSyntaxTextArea)
Configuration.rstaTheme.apply(new SearchableRSyntaxTextArea()); Configuration.rstaTheme.apply(new SearchableRSyntaxTextArea());
public final JPanel mainPanel = new JPanel(new BorderLayout()); public final JPanel mainPanel = new JPanel(new BorderLayout());
public BufferedImage originalImage;
public BufferedImage image; public BufferedImage image;
public boolean canRefresh; public boolean canRefresh;
public int zoomSteps = 0;
public FileViewer(final ResourceContainer container, final String name) public FileViewer(final ResourceContainer container, final String name)
{ {
@ -79,7 +83,6 @@ public class FileViewer extends ResourceViewer
if (!MiscUtils.isPureAscii(contentsAsString) || hexViewerOnly) if (!MiscUtils.isPureAscii(contentsAsString) || hexViewerOnly)
{ {
//TODO: //TODO:
// + Webp?
// + Add file header checks // + Add file header checks
// + Check for CAFEBABE // + Check for CAFEBABE
// + ClassRead then quick-decompile using Pane1 Decompiler // + ClassRead then quick-decompile using Pane1 Decompiler
@ -93,23 +96,41 @@ public class FileViewer extends ResourceViewer
{ {
canRefresh = true; 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.add(new ImageJLabel(image), BorderLayout.CENTER);
mainPanel.addMouseWheelListener(e -> mainPanel.addMouseWheelListener(e -> {
{
int notches = e.getWheelRotation(); int notches = e.getWheelRotation();
int width = originalImage.getWidth();
int height = originalImage.getHeight();
int oldZoomSteps = zoomSteps;
if (notches < 0) //zoom in if (notches < 0) {
image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() + 10, //zoom in
image.getHeight() + 10); zoomSteps++;
else //zoom out } else {
image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() - 10, //zoom out
image.getHeight() - 10); 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.removeAll();
mainPanel.add(new ImageJLabel(image), BorderLayout.CENTER); mainPanel.add(new ImageJLabel(image), BorderLayout.CENTER);
mainPanel.updateUI(); mainPanel.updateUI();
} catch (Throwable ignored) {
zoomSteps = oldZoomSteps;
}
}); });
return; return;
} }
@ -125,6 +146,7 @@ public class FileViewer extends ResourceViewer
textArea.setCodeFoldingEnabled(true); textArea.setCodeFoldingEnabled(true);
textArea.setSyntaxEditingStyle(SyntaxLanguage.detectLanguage(nameLowerCase, contentsAsString).getSyntaxConstant()); textArea.setSyntaxEditingStyle(SyntaxLanguage.detectLanguage(nameLowerCase, contentsAsString).getSyntaxConstant());
textArea.setText(contentsAsString); textArea.setText(contentsAsString);
textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
textArea.setCaretPosition(0); textArea.setCaretPosition(0);
mainPanel.add(textArea.getScrollPane()); mainPanel.add(textArea.getScrollPane());

View file

@ -17,14 +17,14 @@ public enum ResourceType
JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"), JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"),
ZIP_ARCHIVE(IconResources.zipIcon, "zip"), ZIP_ARCHIVE(IconResources.zipIcon, "zip"),
ANDROID_ARCHIVE(IconResources.androidIcon, "apk", "wapk", "dex"), 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", CONFIG_TEXT_FILE(IconResources.configIcon, "properties", "xml", "jsp", "mf", "config",
"csv", "yml", "yaml", "ini", "json", "sql", "gradle", "dockerfile", "htaccess", "csv", "yml", "yaml", "ini", "json", "sql", "gradle", "dockerfile", "htaccess",
"plugin", "attachprovider", "transportservice", "connector"), "plugin", "attachprovider", "transportservice", "connector"),
JAVA_FILE(IconResources.javaIcon, "java"), JAVA_FILE(IconResources.javaIcon, "java"),
TEXT_FILE(IconResources.textIcon, "txt", "md", "log", "html", "css"), TEXT_FILE(IconResources.textIcon, "txt", "md", "log", "html", "css"),
CPP_FILE(IconResources.cplusplusIcon, "c", "cpp", "h"), CPP_FILE(IconResources.cplusplusIcon, "c", "cpp", "h"),
CSHAR_FILE(IconResources.csharpIcon, "cs"), CSHARP_FILE(IconResources.csharpIcon, "cs"),
BAT_FILE(IconResources.batIcon, "bat", "batch"), BAT_FILE(IconResources.batIcon, "bat", "batch"),
SH_FILE(IconResources.shIcon, "sh", "bash"), SH_FILE(IconResources.shIcon, "sh", "bash"),
; ;