This commit is contained in:
Konloch 2021-07-21 04:33:09 -07:00
commit 6ef91b49b9
6 changed files with 69 additions and 43 deletions

View File

@ -238,6 +238,11 @@
<artifactId>darklaf-extensions-rsyntaxarea</artifactId>
<version>0.3.4</version>
</dependency>
<dependency>
<groupId>com.github.gotson</groupId>
<artifactId>webp-imageio</artifactId>
<version>0.2.1</version>
</dependency>
</dependencies>
<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
* + 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

View File

@ -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();

View File

@ -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();

View File

@ -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());

View File

@ -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"),
;