Code Outsourcing from Model.java

This commit is contained in:
zerdei 2014-02-05 16:44:59 +01:00
parent 336a076809
commit 4999971014
12 changed files with 1680 additions and 1333 deletions

View File

@ -0,0 +1,105 @@
package com.modcrafting.luyten;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.Reader;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
/**
* Drag-Drop (only MainWindow should be called from here)
*/
public class DropListener implements DropTargetListener {
private MainWindow mainWindow;
public DropListener(MainWindow mainWindow) {
this.mainWindow = mainWindow;
}
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent event) {
event.acceptDrop(DnDConstants.ACTION_COPY);
Transferable transferable = event.getTransferable();
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
DataFlavor[] flavors = transferable.getTransferDataFlavors();
for (DataFlavor flavor : flavors) {
try {
if (flavor.isFlavorJavaFileListType()) {
List<File> files = (List<File>) transferable
.getTransferData(flavor);
if (files.size() > 1) {
event.rejectDrop();
return;
}
if (files.size() == 1) {
mainWindow.onFileDropped(files.get(0));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
event.dropComplete(true);
} else {
DataFlavor[] flavors = transferable.getTransferDataFlavors();
boolean handled = false;
for (int zz = 0; zz < flavors.length; zz++) {
if (flavors[zz].isRepresentationClassReader()) {
try {
Reader reader = flavors[zz].getReaderForText(transferable);
BufferedReader br = new BufferedReader(reader);
List<File> list = new ArrayList<File>();
String line = null;
while ((line = br.readLine()) != null) {
try {
if (new String("" + (char) 0).equals(line))
continue;
File file = new File(new URI(line));
list.add(file);
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (list.size() > 1) {
event.rejectDrop();
return;
}
if (list.size() == 1) {
mainWindow.onFileDropped(list.get(0));
}
event.getDropTargetContext().dropComplete(true);
handled = true;
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
if (!handled) {
event.rejectDrop();
}
}
}
@Override
public void dragEnter(DropTargetDragEvent arg0) {}
@Override
public void dragExit(DropTargetEvent arg0) {}
@Override
public void dragOver(DropTargetDragEvent arg0) {}
@Override
public void dropActionChanged(DropTargetDragEvent arg0) {}
}

View File

@ -0,0 +1,177 @@
package com.modcrafting.luyten;
import java.awt.Component;
import java.io.File;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
/**
* FileChoosers for Open and Save
*/
public class FileDialog {
private ConfigSaver configSaver;
private LuytenPreferences luytenPrefs;
private Component parent;
private JFileChooser fcOpen;
private JFileChooser fcSave;
private JFileChooser fcSaveAll;
public FileDialog(Component parent) {
this.parent = parent;
configSaver = ConfigSaver.getLoadedInstance();
luytenPrefs = configSaver.getLuytenPreferences();
new Thread() {
public void run() {
initOpenDialog();
initSaveDialog();
initSaveAllDialog();
};
}.start();
}
public File doOpenDialog() {
File selectedFile = null;
initOpenDialog();
retrieveOpenDialogDir(fcOpen);
int returnVal = fcOpen.showOpenDialog(parent);
saveOpenDialogDir(fcOpen);
if (returnVal == JFileChooser.APPROVE_OPTION) {
selectedFile = fcOpen.getSelectedFile();
}
return selectedFile;
}
public File doSaveDialog(String recommendedFileName) {
File selectedFile = null;
initSaveDialog();
retrieveSaveDialogDir(fcSave);
fcSave.setSelectedFile(new File(recommendedFileName));
int returnVal = fcSave.showSaveDialog(parent);
saveSaveDialogDir(fcSave);
if (returnVal == JFileChooser.APPROVE_OPTION) {
selectedFile = fcSave.getSelectedFile();
}
return selectedFile;
}
public File doSaveAllDialog(String recommendedFileName) {
File selectedFile = null;
initSaveAllDialog();
retrieveSaveDialogDir(fcSaveAll);
fcSaveAll.setSelectedFile(new File(recommendedFileName));
int returnVal = fcSaveAll.showSaveDialog(parent);
saveSaveDialogDir(fcSaveAll);
if (returnVal == JFileChooser.APPROVE_OPTION) {
selectedFile = fcSaveAll.getSelectedFile();
}
return selectedFile;
}
public synchronized void initOpenDialog() {
if (fcOpen == null) {
fcOpen = createFileChooser("*.jar", "*.zip", "*.class");
retrieveOpenDialogDir(fcOpen);
}
}
public synchronized void initSaveDialog() {
if (fcSave == null) {
fcSave = createFileChooser("*.txt", "*.java");
retrieveSaveDialogDir(fcSave);
}
}
public synchronized void initSaveAllDialog() {
if (fcSaveAll == null) {
fcSaveAll = createFileChooser("*.jar", "*.zip");
retrieveSaveDialogDir(fcSaveAll);
}
}
private JFileChooser createFileChooser(String... fileFilters) {
JFileChooser fc = new JFileChooser();
for (String fileFilter : fileFilters) {
fc.addChoosableFileFilter(new FileChooserFileFilter(fileFilter));
}
fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
fc.setMultiSelectionEnabled(false);
return fc;
}
public class FileChooserFileFilter extends FileFilter {
String objType;
public FileChooserFileFilter(String string) {
objType = string;
}
@Override
public boolean accept(File f) {
if (f.isDirectory())
return false;
return f.getName().toLowerCase().endsWith(objType.substring(1));
}
@Override
public String getDescription() {
return objType;
}
}
private void retrieveOpenDialogDir(JFileChooser fc) {
try {
String currentDirStr = luytenPrefs.getFileOpenCurrentDirectory();
if (currentDirStr != null && currentDirStr.trim().length() > 0) {
File currentDir = new File(currentDirStr);
if (currentDir.exists() && currentDir.isDirectory()) {
fc.setCurrentDirectory(currentDir);
}
}
} catch (Exception exc) {
exc.printStackTrace();
}
}
private void saveOpenDialogDir(JFileChooser fc) {
try {
File currentDir = fc.getCurrentDirectory();
if (currentDir != null && currentDir.exists() && currentDir.isDirectory()) {
luytenPrefs.setFileOpenCurrentDirectory(currentDir.getAbsolutePath());
}
} catch (Exception exc) {
exc.printStackTrace();
}
}
private void retrieveSaveDialogDir(JFileChooser fc) {
try {
String currentDirStr = luytenPrefs.getFileSaveCurrentDirectory();
if (currentDirStr != null && currentDirStr.trim().length() > 0) {
File currentDir = new File(currentDirStr);
if (currentDir.exists() && currentDir.isDirectory()) {
fc.setCurrentDirectory(currentDir);
}
}
} catch (Exception exc) {
exc.printStackTrace();
}
}
private void saveSaveDialogDir(JFileChooser fc) {
try {
File currentDir = fc.getCurrentDirectory();
if (currentDir != null && currentDir.exists() && currentDir.isDirectory()) {
luytenPrefs.setFileSaveCurrentDirectory(currentDir.getAbsolutePath());
}
} catch (Exception exc) {
exc.printStackTrace();
}
}
}

View File

@ -3,7 +3,4 @@ package com.modcrafting.luyten;
public class FileEntryNotFoundException extends Exception {
private static final long serialVersionUID = 1L;
public FileEntryNotFoundException() {
super();
}
}

View File

@ -3,7 +3,4 @@ package com.modcrafting.luyten;
public class FileIsBinaryException extends Exception {
private static final long serialVersionUID = 1L;
public FileIsBinaryException() {
super();
}
}

View File

@ -0,0 +1,233 @@
package com.modcrafting.luyten;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Enumeration;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.zip.ZipException;
import java.util.zip.ZipOutputStream;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;
import com.strobel.assembler.metadata.ITypeLoader;
import com.strobel.assembler.metadata.JarTypeLoader;
import com.strobel.assembler.metadata.MetadataSystem;
import com.strobel.assembler.metadata.TypeDefinition;
import com.strobel.assembler.metadata.TypeReference;
import com.strobel.core.StringUtilities;
import com.strobel.decompiler.DecompilationOptions;
import com.strobel.decompiler.DecompilerSettings;
import com.strobel.decompiler.PlainTextOutput;
import com.strobel.decompiler.languages.java.JavaFormattingOptions;
/**
* Performs Save and Save All
*/
public class FileSaver {
private JProgressBar bar;
private JLabel label;
public FileSaver(JProgressBar bar, JLabel label) {
this.bar = bar;
this.label = label;
}
public void saveText(final String text, final File file) {
new Thread(new Runnable() {
@Override
public void run() {
try (FileWriter fw = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw);) {
label.setText("Extracting: " + file.getName());
bar.setVisible(true);
bw.write(text);
bw.flush();
label.setText("Complete");
} catch (Exception e1) {
label.setText("Cannot save file: " + file.getName());
e1.printStackTrace();
JOptionPane.showMessageDialog(null, e1.toString(), "Error!", JOptionPane.ERROR_MESSAGE);
} finally {
bar.setVisible(false);
}
}
}).start();
}
public void saveAllDecompiled(final File inFile, final File outFile) {
new Thread(new Runnable() {
@Override
public void run() {
try {
bar.setVisible(true);
label.setText("Extracting: " + outFile.getName());
String inFileName = inFile.getName().toLowerCase();
if (inFileName.endsWith(".jar") || inFileName.endsWith(".zip")) {
doSaveJarDecompiled(inFile, outFile);
} else if (inFileName.endsWith(".class")) {
doSaveClassDecompiled(inFile, outFile);
} else {
doSaveUnknownFile(inFile, outFile);
}
label.setText("Complete");
} catch (Exception e1) {
e1.printStackTrace();
label.setText("Cannot save file: " + outFile.getName());
JOptionPane.showMessageDialog(null, e1.toString(), "Error!", JOptionPane.ERROR_MESSAGE);
} finally {
bar.setVisible(false);
}
}
}).start();
}
private void doSaveJarDecompiled(File inFile, File outFile) throws Exception {
try (JarFile jfile = new JarFile(inFile);
FileOutputStream dest = new FileOutputStream(outFile);
BufferedOutputStream buffDest = new BufferedOutputStream(dest);
ZipOutputStream out = new ZipOutputStream(buffDest);) {
byte data[] = new byte[1024];
DecompilerSettings settings = cloneSettings();
LuytenTypeLoader typeLoader = new LuytenTypeLoader();
MetadataSystem metadataSystem = new MetadataSystem(typeLoader);
ITypeLoader jarLoader = new JarTypeLoader(jfile);
typeLoader.getTypeLoaders().add(jarLoader);
DecompilationOptions decompilationOptions = new DecompilationOptions();
decompilationOptions.setSettings(settings);
decompilationOptions.setFullDecompilation(true);
Enumeration<JarEntry> ent = jfile.entries();
while (ent.hasMoreElements()) {
JarEntry entry = ent.nextElement();
label.setText("Extracting: " + entry.getName());
bar.setVisible(true);
if (entry.getName().endsWith(".class")) {
JarEntry etn = new JarEntry(entry.getName().replace(".class", ".java"));
label.setText("Extracting: " + etn.getName());
out.putNextEntry(etn);
try {
String internalName = StringUtilities.removeRight(entry.getName(), ".class");
TypeReference type = metadataSystem.lookupType(internalName);
TypeDefinition resolvedType = null;
if ((type == null) || ((resolvedType = type.resolve()) == null)) {
throw new Exception("Unable to resolve type.");
}
Writer writer = new OutputStreamWriter(out);
settings.getLanguage().decompileType(resolvedType,
new PlainTextOutput(writer), decompilationOptions);
writer.flush();
} finally {
out.closeEntry();
}
} else {
try {
JarEntry etn = new JarEntry(entry.getName());
out.putNextEntry(etn);
try {
InputStream in = jfile.getInputStream(entry);
if (in != null) {
try {
int count;
while ((count = in.read(data, 0, 1024)) != -1) {
out.write(data, 0, count);
}
} finally {
in.close();
}
}
} finally {
out.closeEntry();
}
} catch (ZipException ze) {
// some jar-s contain duplicate pom.xml entries: ignore it
if (!ze.getMessage().contains("duplicate")) {
throw ze;
}
}
}
}
}
}
private void doSaveClassDecompiled(File inFile, File outFile) throws Exception {
DecompilerSettings settings = cloneSettings();
LuytenTypeLoader typeLoader = new LuytenTypeLoader();
MetadataSystem metadataSystem = new MetadataSystem(typeLoader);
TypeReference type = metadataSystem.lookupType(inFile.getCanonicalPath());
DecompilationOptions decompilationOptions = new DecompilationOptions();
decompilationOptions.setSettings(settings);
decompilationOptions.setFullDecompilation(true);
TypeDefinition resolvedType = null;
if (type == null || ((resolvedType = type.resolve()) == null)) {
throw new Exception("Unable to resolve type.");
}
StringWriter stringwriter = new StringWriter();
settings.getLanguage().decompileType(resolvedType,
new PlainTextOutput(stringwriter), decompilationOptions);
String decompiledSource = stringwriter.toString();
try (FileWriter fw = new FileWriter(outFile);
BufferedWriter bw = new BufferedWriter(fw);) {
bw.write(decompiledSource);
bw.flush();
}
}
private void doSaveUnknownFile(File inFile, File outFile) throws Exception {
try (FileInputStream in = new FileInputStream(inFile);
FileOutputStream out = new FileOutputStream(outFile);) {
byte data[] = new byte[1024];
int count;
while ((count = in.read(data, 0, 1024)) != -1) {
out.write(data, 0, count);
}
}
}
private DecompilerSettings cloneSettings() {
DecompilerSettings settings = ConfigSaver.getLoadedInstance().getDecompilerSettings();
DecompilerSettings newSettings = new DecompilerSettings();
if (newSettings.getFormattingOptions() == null) {
newSettings.setFormattingOptions(JavaFormattingOptions.createDefault());
}
// synchronized: against main menu changes
synchronized (settings) {
newSettings.setExcludeNestedTypes(settings.getExcludeNestedTypes());
newSettings.setFlattenSwitchBlocks(settings.getFlattenSwitchBlocks());
newSettings.setForceExplicitImports(settings.getForceExplicitImports());
newSettings.setForceExplicitTypeArguments(settings.getForceExplicitTypeArguments());
newSettings.setOutputFileHeaderText(settings.getOutputFileHeaderText());
newSettings.setLanguage(settings.getLanguage());
newSettings.setShowSyntheticMembers(settings.getShowSyntheticMembers());
newSettings.setAlwaysGenerateExceptionVariableForCatchBlocks(settings
.getAlwaysGenerateExceptionVariableForCatchBlocks());
newSettings.setOutputDirectory(settings.getOutputDirectory());
newSettings.setRetainRedundantCasts(settings.getRetainRedundantCasts());
newSettings.setIncludeErrorDiagnostics(settings.getIncludeErrorDiagnostics());
newSettings.setIncludeLineNumbersInBytecode(settings.getIncludeLineNumbersInBytecode());
newSettings.setRetainPointlessSwitches(settings.getRetainPointlessSwitches());
newSettings.setUnicodeOutputEnabled(settings.isUnicodeOutputEnabled());
newSettings.setMergeVariables(settings.getMergeVariables());
newSettings.setShowDebugLineNumbers(settings.getShowDebugLineNumbers());
}
return newSettings;
}
}

View File

@ -7,10 +7,10 @@ import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
@ -20,23 +20,20 @@ import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rtextarea.RTextScrollPane;
import org.fife.ui.rtextarea.SearchContext;
import org.fife.ui.rtextarea.SearchEngine;
public class FindBox extends JDialog{
/**
*
*/
public class FindBox extends JDialog {
private static final long serialVersionUID = -4125409760166690462L;
JCheckBox mcase;
JCheckBox regex;
JCheckBox wholew;
JCheckBox reverse;
JButton findButton;
JTextField textField;
Model base;
private JCheckBox mcase;
private JCheckBox regex;
private JCheckBox wholew;
private JCheckBox reverse;
private JButton findButton;
private JTextField textField;
private MainWindow mainWindow;
public void showFindBox() {
this.setVisible(true);
this.textField.requestFocus();
@ -46,118 +43,111 @@ public class FindBox extends JDialog{
this.setVisible(false);
}
public FindBox(Model base) {
this.base = base;
public FindBox(MainWindow mainWindow) {
this.mainWindow = mainWindow;
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
this.setHideOnEscapeButton();
JLabel label = new JLabel("Find What:");
textField = new JTextField();
int pos = base.house.getSelectedIndex();
if(pos>=0){
RTextScrollPane co = (RTextScrollPane) base.house.getComponentAt(pos);
RSyntaxTextArea pane = (RSyntaxTextArea) co.getViewport().getView();
JLabel label = new JLabel("Find What:");
textField = new JTextField();
RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea();
if (pane != null) {
textField.setText(pane.getSelectedText());
}
mcase = new JCheckBox("Match Case");
regex = new JCheckBox("Regex");
wholew = new JCheckBox("Whole Words");
reverse = new JCheckBox("Search Backwards");
findButton = new JButton("Find");
findButton.addActionListener(new FindButton());
this.getRootPane().setDefaultButton(findButton);
mcase.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
regex.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
wholew.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
reverse.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
mcase = new JCheckBox("Match Case");
regex = new JCheckBox("Regex");
wholew = new JCheckBox("Whole Words");
reverse = new JCheckBox("Search Backwards");
findButton = new JButton("Find");
findButton.addActionListener(new FindButton());
this.getRootPane().setDefaultButton(findButton);
mcase.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
regex.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
wholew.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
reverse.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Dimension center = new Dimension((int)(screenSize.width*0.35),
final Dimension center = new Dimension((int) (screenSize.width * 0.35),
Math.min((int) (screenSize.height * 0.20), 200));
final int x = (int) (center.width * 0.2);
final int y = (int) (center.height * 0.2);
this.setBounds(x, y, center.width, center.height);
this.setResizable(false);
GroupLayout layout = new GroupLayout(getRootPane());
getRootPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addComponent(label)
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(textField)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(mcase)
.addComponent(wholew))
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(regex)
.addComponent(reverse))))
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(findButton))
);
layout.linkSize(SwingConstants.HORIZONTAL, findButton);
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(label)
.addComponent(textField)
.addComponent(findButton))
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(mcase)
.addComponent(regex))
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(wholew)
.addComponent(reverse))))
);
GroupLayout layout = new GroupLayout(getRootPane());
getRootPane().setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(true);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addComponent(label)
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(textField)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(mcase)
.addComponent(wholew))
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(regex)
.addComponent(reverse))))
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addComponent(findButton))
);
layout.linkSize(SwingConstants.HORIZONTAL, findButton);
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(label)
.addComponent(textField)
.addComponent(findButton))
.addGroup(layout.createParallelGroup(Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(mcase)
.addComponent(regex))
.addGroup(layout.createParallelGroup(Alignment.BASELINE)
.addComponent(wholew)
.addComponent(reverse))))
);
this.adjustWindowPositionBySavedState();
this.setSaveWindowPositionOnClosing();
this.setName("Find");
this.setName("Find");
this.setTitle("Find");
this.setVisible(true);
}
private class FindButton extends AbstractAction{
/**
*
*/
this.setVisible(true);
}
private class FindButton extends AbstractAction {
private static final long serialVersionUID = 75954129199541874L;
@Override
public void actionPerformed(ActionEvent event) {
int pos = base.house.getSelectedIndex();
if (pos < 0) {
base.label.setText("No open tab");
if (textField.getText().length() == 0)
return;
}
RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea();
if (pane == null)
return;
SearchContext context = new SearchContext();
if (textField.getText().length() == 0)
return;
RTextScrollPane co = (RTextScrollPane) base.house.getComponentAt(pos);
RSyntaxTextArea pane = (RSyntaxTextArea) co.getViewport().getView();
context.setSearchFor(textField.getText());
context.setMatchCase(mcase.isSelected());
context.setRegularExpression(regex.isSelected());
context.setSearchForward(!reverse.isSelected());
context.setWholeWord(wholew.isSelected());
if (!SearchEngine.find(pane, context)) {
pane.setSelectionStart(0);
pane.setSelectionEnd(0);
}
context.setSearchFor(textField.getText());
context.setMatchCase(mcase.isSelected());
context.setRegularExpression(regex.isSelected());
context.setSearchForward(!reverse.isSelected());
context.setWholeWord(wholew.isSelected());
if (!SearchEngine.find(pane, context)) {
pane.setSelectionStart(0);
pane.setSelectionEnd(0);
}
}
}
private void setHideOnEscapeButton() {
Action escapeAction = new AbstractAction() {
private static final long serialVersionUID = 1L;
@ -172,7 +162,7 @@ public class FindBox extends JDialog{
this.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeKeyStroke, "ESCAPE");
this.getRootPane().getActionMap().put("ESCAPE", escapeAction);
}
private void adjustWindowPositionBySavedState() {
WindowPosition windowPosition = ConfigSaver.getLoadedInstance().getFindWindowPosition();

View File

@ -0,0 +1,26 @@
package com.modcrafting.luyten;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
/**
* Starter, the main class
*/
public class Luyten {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
MainWindow mainWindow = new MainWindow();
mainWindow.setVisible(true);
}
});
}
}

View File

@ -0,0 +1,332 @@
package com.modcrafting.luyten;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ButtonModel;
import javax.swing.JCheckBox;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
import javax.swing.text.DefaultEditorKit;
import com.strobel.decompiler.DecompilerSettings;
import com.strobel.decompiler.languages.Language;
import com.strobel.decompiler.languages.Languages;
/**
* Main menu (only MainWindow should be called from here)
*/
public class MainMenuBar extends JMenuBar {
private static final long serialVersionUID = 1L;
private final MainWindow mainWindow;
private final Map<String, Language> languageLookup = new HashMap<String, Language>();
private JCheckBox flattenSwitchBlocks;
private JCheckBox forceExplicitImports;
private JCheckBox forceExplicitTypes;
private JCheckBox showSyntheticMembers;
private JCheckBox excludeNestedTypes;
private JCheckBox retainRedundantCasts;
private JCheckBox showDebugInfo;
private JRadioButtonMenuItem java;
private JRadioButtonMenuItem bytecode;
private JRadioButtonMenuItem bytecodeAST;
private ButtonGroup languagesGroup;
private DecompilerSettings settings;
private LuytenPreferences luytenPrefs;
public MainMenuBar(MainWindow mainWnd) {
this.mainWindow = mainWnd;
ConfigSaver configSaver = ConfigSaver.getLoadedInstance();
settings = configSaver.getDecompilerSettings();
luytenPrefs = configSaver.getLuytenPreferences();
JMenu fileMenu = new JMenu("File");
JMenuItem menuItem = new JMenuItem("Open File...");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainWindow.onOpenFileMenu();
}
});
fileMenu.add(menuItem);
fileMenu.addSeparator();
menuItem = new JMenuItem("Close");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, ActionEvent.CTRL_MASK));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainWindow.onCloseFileMenu();
}
});
fileMenu.add(menuItem);
fileMenu.addSeparator();
menuItem = new JMenuItem("Save As...");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainWindow.onSaveAsMenu();
}
});
fileMenu.add(menuItem);
menuItem = new JMenuItem("Save All...");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainWindow.onSaveAllMenu();
}
});
fileMenu.add(menuItem);
fileMenu.addSeparator();
menuItem = new JMenuItem("Recent Files");
menuItem.setEnabled(false);
fileMenu.add(menuItem);
fileMenu.addSeparator();
menuItem = new JMenuItem("Exit");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainWindow.onExitMenu();
}
});
fileMenu.add(menuItem);
this.add(fileMenu);
fileMenu = new JMenu("Edit");
menuItem = new JMenuItem("Cut");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));
menuItem.setEnabled(false);
fileMenu.add(menuItem);
menuItem = new JMenuItem("Copy");
menuItem.addActionListener(new DefaultEditorKit.CopyAction());
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
fileMenu.add(menuItem);
menuItem = new JMenuItem("Paste");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK));
menuItem.setEnabled(false);
fileMenu.add(menuItem);
fileMenu.addSeparator();
menuItem = new JMenuItem("Select All");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainWindow.onSelectAllMenu();
}
});
fileMenu.add(menuItem);
fileMenu.addSeparator();
menuItem = new JMenuItem("Find...");
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK));
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainWindow.onFindMenu();
}
});
fileMenu.add(menuItem);
this.add(fileMenu);
fileMenu = new JMenu("Themes");
languagesGroup = new ButtonGroup();
JRadioButtonMenuItem a = new JRadioButtonMenuItem(new ThemeAction("Default", "default.xml"));
a.setSelected("default.xml".equals(luytenPrefs.getThemeXml()));
languagesGroup.add(a);
fileMenu.add(a);
a = new JRadioButtonMenuItem(new ThemeAction("Dark", "dark.xml"));
a.setSelected("dark.xml".equals(luytenPrefs.getThemeXml()));
languagesGroup.add(a);
fileMenu.add(a);
a = new JRadioButtonMenuItem(new ThemeAction("Eclipse", "eclipse.xml"));
a.setSelected("eclipse.xml".equals(luytenPrefs.getThemeXml()));
languagesGroup.add(a);
fileMenu.add(a);
a = new JRadioButtonMenuItem(new ThemeAction("Visual Studio", "vs.xml"));
a.setSelected("vs.xml".equals(luytenPrefs.getThemeXml()));
languagesGroup.add(a);
fileMenu.add(a);
this.add(fileMenu);
fileMenu = new JMenu("Settings");
ActionListener settingsChanged = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new Thread() {
@Override
public void run() {
populateSettingsFromSettingsMenu();
mainWindow.onSettingsChanged();
}
}.start();
}
};
flattenSwitchBlocks = new JCheckBox("Flatten Switch Blocks");
flattenSwitchBlocks.setSelected(settings.getFlattenSwitchBlocks());
flattenSwitchBlocks.addActionListener(settingsChanged);
fileMenu.add(flattenSwitchBlocks);
forceExplicitImports = new JCheckBox("Force Explicit Imports");
forceExplicitImports.setSelected(settings.getForceExplicitImports());
forceExplicitImports.addActionListener(settingsChanged);
fileMenu.add(forceExplicitImports);
forceExplicitTypes = new JCheckBox("Force Explicit Types");
forceExplicitTypes.setSelected(settings.getForceExplicitTypeArguments());
forceExplicitTypes.addActionListener(settingsChanged);
fileMenu.add(forceExplicitTypes);
showSyntheticMembers = new JCheckBox("Show Synthetic Members");
showSyntheticMembers.setSelected(settings.getShowSyntheticMembers());
showSyntheticMembers.addActionListener(settingsChanged);
fileMenu.add(showSyntheticMembers);
excludeNestedTypes = new JCheckBox("Exclude Nested Types");
excludeNestedTypes.setSelected(settings.getExcludeNestedTypes());
excludeNestedTypes.addActionListener(settingsChanged);
fileMenu.add(excludeNestedTypes);
retainRedundantCasts = new JCheckBox("Retain Redundant Casts");
retainRedundantCasts.setSelected(settings.getRetainRedundantCasts());
retainRedundantCasts.addActionListener(settingsChanged);
fileMenu.add(retainRedundantCasts);
JMenu debugSettingsMenu = new JMenu("Debug Settings");
showDebugInfo = new JCheckBox("Include Error Diagnostics");
showDebugInfo.setSelected(settings.getIncludeErrorDiagnostics());
showDebugInfo.addActionListener(settingsChanged);
debugSettingsMenu.add(showDebugInfo);
fileMenu.add(debugSettingsMenu);
fileMenu.addSeparator();
languageLookup.put(Languages.java().getName(), Languages.java());
languageLookup.put(Languages.bytecode().getName(), Languages.bytecode());
languageLookup.put(Languages.bytecodeAst().getName(), Languages.bytecodeAst());
languagesGroup = new ButtonGroup();
java = new JRadioButtonMenuItem(Languages.java().getName());
java.getModel().setActionCommand(Languages.java().getName());
java.setSelected(Languages.java().getName().equals(settings.getLanguage().getName()));
languagesGroup.add(java);
fileMenu.add(java);
bytecode = new JRadioButtonMenuItem(Languages.bytecode().getName());
bytecode.getModel().setActionCommand(Languages.bytecode().getName());
bytecode.setSelected(Languages.bytecode().getName().equals(settings.getLanguage().getName()));
languagesGroup.add(bytecode);
fileMenu.add(bytecode);
bytecodeAST = new JRadioButtonMenuItem(Languages.bytecodeAst().getName());
bytecodeAST.getModel().setActionCommand(Languages.bytecodeAst().getName());
bytecodeAST.setSelected(Languages.bytecodeAst().getName().equals(settings.getLanguage().getName()));
languagesGroup.add(bytecodeAST);
fileMenu.add(bytecodeAST);
JMenu debugLanguagesMenu = new JMenu("Debug Languages");
for (final Language language : Languages.debug()) {
final JRadioButtonMenuItem m = new JRadioButtonMenuItem(language.getName());
m.getModel().setActionCommand(language.getName());
m.setSelected(language.getName().equals(settings.getLanguage().getName()));
languagesGroup.add(m);
debugLanguagesMenu.add(m);
languageLookup.put(language.getName(), language);
}
for (AbstractButton button : Collections.list(languagesGroup.getElements())) {
button.addActionListener(settingsChanged);
}
fileMenu.add(debugLanguagesMenu);
this.add(fileMenu);
fileMenu = new JMenu("Help");
menuItem = new JMenuItem("Legal");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
mainWindow.onLegalMenu();
}
});
fileMenu.add(menuItem);
menuItem = new JMenuItem("About");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(null,
"Luyten Gui \n" +
"by Deathmarine\n\n" +
"Powered By\nProcyon\n" +
"(c) 2013 Mike Strobel\n\n" +
"RSyntaxTextArea\n" +
"(c) 2012 Robert Futrell\n" +
"All rights reserved.");
}
});
fileMenu.add(menuItem);
this.add(fileMenu);
}
private void populateSettingsFromSettingsMenu() {
// synchronized: do not disturb decompiler at work (synchronize every time before run decompiler)
synchronized (settings) {
settings.setFlattenSwitchBlocks(flattenSwitchBlocks.isSelected());
settings.setForceExplicitImports(forceExplicitImports.isSelected());
settings.setShowSyntheticMembers(showSyntheticMembers.isSelected());
settings.setExcludeNestedTypes(excludeNestedTypes.isSelected());
settings.setForceExplicitTypeArguments(forceExplicitTypes.isSelected());
settings.setRetainRedundantCasts(retainRedundantCasts.isSelected());
settings.setIncludeErrorDiagnostics(showDebugInfo.isSelected());
//
// Note: You shouldn't ever need to set this. It's only for languages that support catch
// blocks without an exception variable. Java doesn't allow this. I think Scala does.
//
// settings.setAlwaysGenerateExceptionVariableForCatchBlocks(true);
//
final ButtonModel selectedLanguage = languagesGroup.getSelection();
if (selectedLanguage != null) {
final Language language = languageLookup.get(selectedLanguage.getActionCommand());
if (language != null)
settings.setLanguage(language);
}
if (java.isSelected()) {
settings.setLanguage(Languages.java());
} else if (bytecode.isSelected()) {
settings.setLanguage(Languages.bytecode());
} else if (bytecodeAST.isSelected()) {
settings.setLanguage(Languages.bytecodeAst());
}
}
}
private class ThemeAction extends AbstractAction {
private static final long serialVersionUID = -6618680171943723199L;
private String xml;
public ThemeAction(String name, String xml) {
putValue(NAME, name);
this.xml = xml;
}
@Override
public void actionPerformed(ActionEvent e) {
luytenPrefs.setThemeXml(xml);
mainWindow.onThemesChanged();
}
}
}

View File

@ -0,0 +1,294 @@
package com.modcrafting.luyten;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.dnd.DropTarget;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.border.BevelBorder;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
/**
* Dispatcher
*/
public class MainWindow extends JFrame {
private static final long serialVersionUID = 1L;
private Model model;
private JProgressBar bar;
private JLabel label;
private FindBox findBox;
private ConfigSaver configSaver;
private WindowPosition windowPosition;
private LuytenPreferences luytenPrefs;
private FileDialog fileDialog;
private FileSaver fileSaver;
public MainWindow() {
configSaver = ConfigSaver.getLoadedInstance();
windowPosition = configSaver.getMainWindowPosition();
luytenPrefs = configSaver.getLuytenPreferences();
MainMenuBar mainMenuBar = new MainMenuBar(this);
this.setJMenuBar(mainMenuBar);
this.adjustWindowPositionBySavedState();
this.setHideFindBoxOnMainWindowFocus();
this.setQuitOnWindowClosing();
this.setTitle("Luyten");
JPanel pane = new JPanel();
pane.setBorder(new BevelBorder(BevelBorder.LOWERED));
pane.setPreferredSize(new Dimension(this.getWidth(), 24));
pane.setLayout(new BoxLayout(pane, BoxLayout.X_AXIS));
JPanel panel1 = new JPanel();
label = new JLabel(" ");
label.setHorizontalAlignment(JLabel.LEFT);
panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
panel1.setBorder(new BevelBorder(BevelBorder.LOWERED));
panel1.setPreferredSize(new Dimension(this.getWidth() / 2, 20));
panel1.add(label);
pane.add(panel1);
panel1 = new JPanel();
bar = new JProgressBar();
bar.setIndeterminate(true);
bar.setOpaque(false);
bar.setVisible(false);
panel1.setLayout(new BoxLayout(panel1, BoxLayout.X_AXIS));
panel1.setPreferredSize(new Dimension(this.getWidth() / 2, 20));
panel1.add(bar);
pane.add(panel1);
model = new Model(this);
this.getContentPane().add(model);
this.add(pane, BorderLayout.SOUTH);
try {
DropTarget dt = new DropTarget();
dt.addDropTargetListener(new DropListener(this));
this.setDropTarget(dt);
} catch (Exception e) {
e.printStackTrace();
}
fileDialog = new FileDialog(this);
fileSaver = new FileSaver(bar, label);
}
public void onOpenFileMenu() {
File selectedFile = fileDialog.doOpenDialog();
if (selectedFile != null) {
this.getModel().loadFile(selectedFile);
}
}
public void onCloseFileMenu() {
this.getModel().closeFile();
}
public void onSaveAsMenu() {
RSyntaxTextArea pane = this.getModel().getCurrentTextArea();
if (pane == null)
return;
String tabTitle = this.getModel().getCurrentTabTitle();
if (tabTitle == null)
return;
String recommendedFileName = tabTitle.replace(".class", ".java");
File selectedFile = fileDialog.doSaveDialog(recommendedFileName);
if (selectedFile != null) {
fileSaver.saveText(pane.getText(), selectedFile);
}
}
public void onSaveAllMenu() {
File openedFile = this.getModel().getOpenedFile();
if (openedFile == null)
return;
String fileName = openedFile.getName();
if (fileName.endsWith(".class")) {
fileName = fileName.replace(".class", ".java");
} else if (fileName.toLowerCase().endsWith(".jar")) {
fileName = "decompiled-" + fileName.replaceAll("\\.[jJ][aA][rR]", ".zip");
} else {
fileName = "saved-" + fileName;
}
File selectedFileToSave = fileDialog.doSaveAllDialog(fileName);
if (selectedFileToSave != null) {
fileSaver.saveAllDecompiled(openedFile, selectedFileToSave);
}
}
public void onExitMenu() {
quit();
}
public void onSelectAllMenu() {
try {
RSyntaxTextArea pane = this.getModel().getCurrentTextArea();
if (pane != null) {
pane.requestFocusInWindow();
pane.setSelectionStart(0);
pane.setSelectionEnd(pane.getText().length());
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void onFindMenu() {
try {
RSyntaxTextArea pane = this.getModel().getCurrentTextArea();
if (pane != null) {
if (findBox == null)
findBox = new FindBox(this);
findBox.showFindBox();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void onLegalMenu() {
new Thread() {
public void run() {
try {
bar.setVisible(true);
String legalStr = getLegalStr();
MainWindow.this.getModel().showLegal(legalStr);
} finally {
bar.setVisible(false);
}
}
}.start();
}
private String getLegalStr() {
StringBuilder sb = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(getClass()
.getResourceAsStream("/distfiles/Procyon.License.txt")));
String line;
while ((line = reader.readLine()) != null)
sb.append(line).append("\n");
sb.append("\n\n\n\n\n");
reader = new BufferedReader(new InputStreamReader(getClass()
.getResourceAsStream("/distfiles/RSyntaxTextArea.License.txt")));
while ((line = reader.readLine()) != null)
sb.append(line).append("\n");
} catch (IOException e) {
e.printStackTrace();
}
return sb.toString();
}
public void onThemesChanged() {
this.getModel().changeTheme(luytenPrefs.getThemeXml());
}
public void onSettingsChanged() {}
public void onFileDropped(File file) {
if (file != null) {
this.getModel().loadFile(file);
}
}
private void adjustWindowPositionBySavedState() {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
if (!windowPosition.isSavedWindowPositionValid()) {
final Dimension center = new Dimension((int) (screenSize.width * 0.75), (int) (screenSize.height * 0.75));
final int x = (int) (center.width * 0.2);
final int y = (int) (center.height * 0.2);
this.setBounds(x, y, center.width, center.height);
} else if (windowPosition.isFullScreen()) {
int heightMinusTray = screenSize.height;
if (screenSize.height > 30)
heightMinusTray -= 30;
this.setBounds(0, 0, screenSize.width, heightMinusTray);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
this.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
if (MainWindow.this.getExtendedState() != JFrame.MAXIMIZED_BOTH) {
windowPosition.setFullScreen(false);
if (windowPosition.isSavedWindowPositionValid()) {
MainWindow.this.setBounds(windowPosition.getWindowX(), windowPosition.getWindowY(),
windowPosition.getWindowWidth(), windowPosition.getWindowHeight());
}
MainWindow.this.removeComponentListener(this);
}
}
});
} else {
this.setBounds(windowPosition.getWindowX(), windowPosition.getWindowY(),
windowPosition.getWindowWidth(), windowPosition.getWindowHeight());
}
}
private void setHideFindBoxOnMainWindowFocus() {
this.addWindowFocusListener(new WindowAdapter() {
@Override
public void windowGainedFocus(WindowEvent e) {
if (findBox != null && findBox.isVisible()) {
findBox.setVisible(false);
}
}
});
}
private void setQuitOnWindowClosing() {
this.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
quit();
}
});
}
private void quit() {
try {
windowPosition.readPositionFromWindow(this);
configSaver.saveConfig();
} catch (Exception exc) {
exc.printStackTrace();
} finally {
try {
this.dispose();
} finally {
System.exit(0);
}
}
}
public Model getModel() {
return model;
}
public JProgressBar getBar() {
return bar;
}
public JLabel getLabel() {
return label;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -8,7 +8,7 @@ import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.fife.ui.rtextarea.RTextScrollPane;
public class OpenFile implements SyntaxConstants{
public class OpenFile implements SyntaxConstants {
public static final HashSet<String> WELL_KNOWN_TEXT_FILE_EXTENSIONS = new HashSet<>(Arrays.asList(
".java", ".xml", ".rss", ".project", ".classpath", ".h", ".sql", ".js", ".php", ".php5",
@ -20,8 +20,8 @@ public class OpenFile implements SyntaxConstants{
RSyntaxTextArea textArea;
String name;
private String path;
public OpenFile(String name, String path, String contents, Theme theme){
public OpenFile(String name, String path, String contents, Theme theme) {
this.name = name;
this.path = path;
textArea = new RSyntaxTextArea(25, 70);
@ -32,51 +32,51 @@ public class OpenFile implements SyntaxConstants{
textArea.setEditable(false);
textArea.setAntiAliasingEnabled(true);
textArea.setCodeFoldingEnabled(true);
if(name.toLowerCase().endsWith(".class")
if (name.toLowerCase().endsWith(".class")
|| name.toLowerCase().endsWith(".java"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_JAVA);
else if(name.toLowerCase().endsWith(".xml")
else if (name.toLowerCase().endsWith(".xml")
|| name.toLowerCase().endsWith(".rss")
|| name.toLowerCase().endsWith(".project")
|| name.toLowerCase().endsWith(".classpath"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_XML);
else if(name.toLowerCase().endsWith(".h"))
else if (name.toLowerCase().endsWith(".h"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_C);
else if(name.toLowerCase().endsWith(".sql"))
else if (name.toLowerCase().endsWith(".sql"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_SQL);
else if(name.toLowerCase().endsWith(".js"))
else if (name.toLowerCase().endsWith(".js"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_JAVASCRIPT);
else if(name.toLowerCase().endsWith(".php")
else if (name.toLowerCase().endsWith(".php")
|| name.toLowerCase().endsWith(".php5")
|| name.toLowerCase().endsWith(".phtml"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_PHP);
else if(name.toLowerCase().endsWith(".html")
else if (name.toLowerCase().endsWith(".html")
|| name.toLowerCase().endsWith(".htm")
|| name.toLowerCase().endsWith(".xhtm")
|| name.toLowerCase().endsWith(".xhtml"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_HTML);
else if(name.toLowerCase().endsWith(".js"))
else if (name.toLowerCase().endsWith(".js"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_JAVASCRIPT);
else if(name.toLowerCase().endsWith(".lua"))
else if (name.toLowerCase().endsWith(".lua"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_LUA);
else if(name.toLowerCase().endsWith(".bat"))
else if (name.toLowerCase().endsWith(".bat"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_WINDOWS_BATCH);
else if(name.toLowerCase().endsWith(".pl"))
else if (name.toLowerCase().endsWith(".pl"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_PERL);
else if(name.toLowerCase().endsWith(".sh"))
else if (name.toLowerCase().endsWith(".sh"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_UNIX_SHELL);
else if(name.toLowerCase().endsWith(".css"))
else if (name.toLowerCase().endsWith(".css"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_CSS);
else if(name.toLowerCase().endsWith(".json"))
else if (name.toLowerCase().endsWith(".json"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_JSON);
else if(name.toLowerCase().endsWith(".txt"))
else if (name.toLowerCase().endsWith(".txt"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_NONE);
else if(name.toLowerCase().endsWith(".rb"))
else if (name.toLowerCase().endsWith(".rb"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_RUBY);
else if(name.toLowerCase().endsWith(".make")
else if (name.toLowerCase().endsWith(".make")
|| name.toLowerCase().endsWith(".mak"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_MAKEFILE);
else if(name.toLowerCase().endsWith(".py"))
else if (name.toLowerCase().endsWith(".py"))
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_PYTHON);
else
textArea.setSyntaxEditingStyle(SYNTAX_STYLE_PROPERTIES_FILE);
@ -85,7 +85,7 @@ public class OpenFile implements SyntaxConstants{
textArea.setText(contents);
theme.apply(textArea);
}
public void setContent(String content) {
textArea.setText(content);
}

View File

@ -7,7 +7,6 @@ public class TooLargeFileException extends Exception {
private long size;
public TooLargeFileException(long size) {
super();
this.size = size;
}