Use RSTA's file type detector

This commit is contained in:
Nico Mexis 2022-01-03 20:05:56 +01:00
parent dda0604696
commit 54fc4e5e48
No known key found for this signature in database
GPG Key ID: 27D6E17CE092AB78
4 changed files with 12 additions and 8 deletions

View File

@ -3,11 +3,13 @@ package the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.apache.commons.io.FilenameUtils;
import org.fife.ui.rsyntaxtextarea.FileTypeUtil;
import org.imgscalr.Scalr;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
@ -19,7 +21,6 @@ import the.bytecode.club.bytecodeviewer.resources.Resource;
import the.bytecode.club.bytecodeviewer.resources.ResourceContainer;
import the.bytecode.club.bytecodeviewer.resources.ResourceType;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.SyntaxLanguage;
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
@ -143,7 +144,7 @@ public class FileViewer extends ResourceViewer
}
textArea.setCodeFoldingEnabled(true);
textArea.setSyntaxEditingStyle(SyntaxLanguage.detectLanguage(nameLowerCase, contentsAsString).getSyntaxConstant());
textArea.setSyntaxEditingStyle(FileTypeUtil.get().guessContentType(new File(nameLowerCase)));
textArea.setText(contentsAsString);
textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, (int) BytecodeViewer.viewer.fontSpinner.getValue()));
textArea.setCaretPosition(0);

View File

@ -15,6 +15,7 @@ import javax.swing.JPanel;
import me.konloch.kontainer.io.DiskReader;
import me.konloch.kontainer.io.DiskWriter;
import org.apache.commons.compress.utils.FileNameUtils;
import org.fife.ui.rsyntaxtextarea.FileTypeUtil;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.Configuration;
import the.bytecode.club.bytecodeviewer.gui.components.FileChooser;
@ -26,7 +27,6 @@ import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJMenu;
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJMenuItem;
import the.bytecode.club.bytecodeviewer.util.DialogUtils;
import the.bytecode.club.bytecodeviewer.util.MiscUtils;
import the.bytecode.club.bytecodeviewer.util.SyntaxLanguage;
import static the.bytecode.club.bytecodeviewer.Constants.fs;
import static the.bytecode.club.bytecodeviewer.Constants.tempDirectory;
@ -88,7 +88,7 @@ public class PluginWriter extends JFrame
area.setOnCtrlS(this::save);
area.setText(content);
area.setCaretPosition(0);
area.setSyntaxEditingStyle(SyntaxLanguage.detectLanguage(pluginName, content).getSyntaxConstant());
area.setSyntaxEditingStyle(FileTypeUtil.get().guessContentType(new File(pluginName)));
content = null;
JButton run = new JButton("Run");

View File

@ -29,9 +29,10 @@ import javax.swing.ImageIcon;
public enum ResourceType
{
//TODO tar/gzip?
//TODO add the files icons for the missing files from the.bytecode.club.bytecodeviewer.util.SyntaxLanguage
// TODO tar/gzip?
// TODO add the files icons for the missing files from the.bytecode.club.bytecodeviewer.util.SyntaxLanguage
// or from org.fife.ui.rsyntaxtextarea.FileTypeUtil or from org.fife.ui.rsyntaxtextarea.SyntaxConstants
CLASS_FILE(IconResources.classIcon, "class"),
JAVA_ARCHIVE(IconResources.jarIcon, "jar", "war", "ear"),
ZIP_ARCHIVE(IconResources.zipIcon, "zip"),

View File

@ -23,7 +23,9 @@ import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
/**
* @author ThexXTURBOXx
* @deprecated See {@link org.fife.ui.rsyntaxtextarea.FileTypeUtil#guessContentType(java.io.File)}
*/
@Deprecated
public enum SyntaxLanguage
{
XML(SyntaxConstants.SYNTAX_STYLE_XML,
@ -92,4 +94,4 @@ public enum SyntaxLanguage
}
return NONE;
}
}
}