Better zoom for images
This commit is contained in:
parent
09b120ee89
commit
0653e8583e
2 changed files with 38 additions and 17 deletions
|
@ -48,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)
|
||||||
{
|
{
|
||||||
|
@ -93,24 +96,42 @@ public class FileViewer extends ResourceViewer
|
||||||
!hexViewerOnly)
|
!hexViewerOnly)
|
||||||
{
|
{
|
||||||
canRefresh = true;
|
canRefresh = true;
|
||||||
|
|
||||||
image = MiscUtils.loadImage(image, contents); //gifs fail because of this
|
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.add(new ImageJLabel(image), BorderLayout.CENTER);
|
||||||
mainPanel.addMouseWheelListener(e ->
|
mainPanel.addMouseWheelListener(e -> {
|
||||||
{
|
|
||||||
int notches = e.getWheelRotation();
|
int notches = e.getWheelRotation();
|
||||||
|
int width = originalImage.getWidth();
|
||||||
if (notches < 0) //zoom in
|
int height = originalImage.getHeight();
|
||||||
image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() + 10,
|
int oldZoomSteps = zoomSteps;
|
||||||
image.getHeight() + 10);
|
|
||||||
else //zoom out
|
if (notches < 0) {
|
||||||
image = Scalr.resize(image, Scalr.Method.SPEED, image.getWidth() - 10,
|
//zoom in
|
||||||
image.getHeight() - 10);
|
zoomSteps++;
|
||||||
|
} else {
|
||||||
mainPanel.removeAll();
|
//zoom out
|
||||||
mainPanel.add(new ImageJLabel(image), BorderLayout.CENTER);
|
zoomSteps--;
|
||||||
mainPanel.updateUI();
|
}
|
||||||
|
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"),
|
||||||
;
|
;
|
||||||
|
|
Loading…
Reference in a new issue