mirror of
https://github.com/deathmarine/Luyten.git
synced 2025-02-06 06:16:27 +00:00
Add ability to open multiple jars in same window
This commit is contained in:
parent
7e63d5a47a
commit
1c644178ce
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>us.deathmarine</groupId>
|
||||
<artifactId>luyten</artifactId>
|
||||
<version>0.5.4</version>
|
||||
<version>0.6.0</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fifesoft</groupId>
|
||||
|
@ -65,11 +65,14 @@ public class FindAllBox extends JDialog {
|
||||
|
||||
private Thread tmp_thread;
|
||||
|
||||
private MainWindow mainWindow;
|
||||
|
||||
public FindAllBox(final MainWindow mainWindow) {
|
||||
this.setDefaultCloseOperation(HIDE_ON_CLOSE);
|
||||
this.setHideOnEscapeButton();
|
||||
|
||||
progressBar = new JProgressBar(0, 100);
|
||||
this.mainWindow = mainWindow;
|
||||
|
||||
JLabel label = new JLabel("Find What:");
|
||||
textField = new JTextField();
|
||||
@ -99,7 +102,7 @@ public class FindAllBox extends JDialog {
|
||||
String internalName = StringUtilities.removeRight(entryName, ".class");
|
||||
TypeReference type = Model.metadataSystem.lookupType(internalName);
|
||||
try {
|
||||
mainWindow.getModel().extractClassToTextPane(type, array[array.length - 1], entryName,
|
||||
mainWindow.getSelectedModel().extractClassToTextPane(type, array[array.length - 1], entryName,
|
||||
null);
|
||||
} catch (Exception e) {
|
||||
Luyten.showExceptionDialog("Exception!", e);
|
||||
@ -107,8 +110,8 @@ public class FindAllBox extends JDialog {
|
||||
|
||||
} else {
|
||||
try {
|
||||
JarFile jfile = new JarFile(MainWindow.model.getOpenedFile());
|
||||
mainWindow.getModel().extractSimpleFileEntryToTextPane(
|
||||
JarFile jfile = new JarFile(mainWindow.getSelectedModel().getOpenedFile());
|
||||
mainWindow.getSelectedModel().extractSimpleFileEntryToTextPane(
|
||||
jfile.getInputStream(jfile.getEntry(entryName)), array[array.length - 1],
|
||||
entryName);
|
||||
jfile.close();
|
||||
@ -196,7 +199,7 @@ public class FindAllBox extends JDialog {
|
||||
classesList.clear();
|
||||
ConfigSaver configSaver = ConfigSaver.getLoadedInstance();
|
||||
DecompilerSettings settings = configSaver.getDecompilerSettings();
|
||||
File inFile = MainWindow.model.getOpenedFile();
|
||||
File inFile = mainWindow.getSelectedModel().getOpenedFile();
|
||||
boolean filter = ConfigSaver.getLoadedInstance().getLuytenPreferences()
|
||||
.isFilterOutInnerClassEntries();
|
||||
try {
|
||||
|
@ -54,7 +54,7 @@ public class FindBox extends JDialog {
|
||||
JLabel label = new JLabel("Find What:");
|
||||
textField = new JTextField();
|
||||
|
||||
RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea();
|
||||
RSyntaxTextArea pane = mainWindow.getSelectedModel().getCurrentTextArea();
|
||||
if (pane != null) {
|
||||
textField.setText(pane.getSelectedText());
|
||||
}
|
||||
@ -132,7 +132,7 @@ public class FindBox extends JDialog {
|
||||
if (textField.getText().length() == 0)
|
||||
return;
|
||||
|
||||
RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea();
|
||||
RSyntaxTextArea pane = mainWindow.getSelectedModel().getCurrentTextArea();
|
||||
if (pane == null)
|
||||
return;
|
||||
|
||||
@ -207,7 +207,7 @@ public class FindBox extends JDialog {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (textField.getText().length() == 0)
|
||||
return;
|
||||
RSyntaxTextArea pane = mainWindow.getModel().getCurrentTextArea();
|
||||
RSyntaxTextArea pane = mainWindow.getSelectedModel().getCurrentTextArea();
|
||||
if (pane == null)
|
||||
return;
|
||||
SearchContext context = new SearchContext();
|
||||
|
@ -75,7 +75,7 @@ public class Luyten {
|
||||
if (mainWindow != null) {
|
||||
synchronized (pendingFiles) {
|
||||
for (File f : pendingFiles) {
|
||||
mainWindow.getModel().loadFile(f);
|
||||
mainWindow.loadNewFile(f);
|
||||
}
|
||||
pendingFiles.clear();
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class MainMenuBar extends JMenuBar {
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
mainWindow.getModel().loadFile(file);
|
||||
mainWindow.loadNewFile(file);
|
||||
}
|
||||
});
|
||||
recentFiles.add(menuItem);
|
||||
@ -196,12 +196,12 @@ public class MainMenuBar extends JMenuBar {
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JTabbedPane house = mainWindow.getModel().house;
|
||||
JTabbedPane house = mainWindow.getSelectedModel().house;
|
||||
|
||||
if (e.getModifiers() != 2 || house.getTabCount() == 0)
|
||||
mainWindow.onCloseFileMenu();
|
||||
else {
|
||||
mainWindow.getModel().closeOpenTab(house.getSelectedIndex());
|
||||
mainWindow.getSelectedModel().closeOpenTab(house.getSelectedIndex());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -15,20 +15,15 @@ import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.BevelBorder;
|
||||
import javax.swing.plaf.basic.BasicTabbedPaneUI;
|
||||
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||
|
||||
@ -39,6 +34,7 @@ public class MainWindow extends JFrame {
|
||||
private static final long serialVersionUID = 5265556630724988013L;
|
||||
|
||||
private static final String TITLE = "Luyten";
|
||||
private static final String DEFAULT_TAB = "#DEFAULT";
|
||||
|
||||
public static Model model;
|
||||
private JProgressBar bar;
|
||||
@ -50,13 +46,16 @@ public class MainWindow extends JFrame {
|
||||
private LuytenPreferences luytenPrefs;
|
||||
private FileDialog fileDialog;
|
||||
private FileSaver fileSaver;
|
||||
private JTabbedPane jarsTabbedPane;
|
||||
private List<Model> jarModels;
|
||||
public MainMenuBar mainMenuBar;
|
||||
|
||||
public MainWindow(File fileFromCommandLine) {
|
||||
configSaver = ConfigSaver.getLoadedInstance();
|
||||
windowPosition = configSaver.getMainWindowPosition();
|
||||
luytenPrefs = configSaver.getLuytenPreferences();
|
||||
|
||||
|
||||
jarModels = new ArrayList<>();
|
||||
mainMenuBar = new MainMenuBar(this);
|
||||
this.setJMenuBar(mainMenuBar);
|
||||
|
||||
@ -85,7 +84,18 @@ public class MainWindow extends JFrame {
|
||||
panel2.add(bar);
|
||||
|
||||
model = new Model(this);
|
||||
this.getContentPane().add(model);
|
||||
jarsTabbedPane = new JTabbedPane(SwingConstants.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
|
||||
jarsTabbedPane.setUI(new BasicTabbedPaneUI() {
|
||||
@Override
|
||||
protected int calculateTabAreaHeight(int tab_placement, int run_count, int max_tab_height) {
|
||||
if (jarsTabbedPane.indexOfTab(DEFAULT_TAB) == -1)
|
||||
return super.calculateTabAreaHeight(tab_placement, run_count, max_tab_height);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
jarsTabbedPane.addTab("#DEFAULT", model);
|
||||
this.getContentPane().add(jarsTabbedPane);
|
||||
|
||||
JSplitPane spt = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panel1, panel2) {
|
||||
private static final long serialVersionUID = 2189946972124687305L;
|
||||
@ -133,24 +143,58 @@ public class MainWindow extends JFrame {
|
||||
if(RecentFiles.load() > 0) mainMenuBar.updateRecentFiles();
|
||||
}
|
||||
|
||||
private void createDefaultTab() {
|
||||
jarsTabbedPane.addTab(DEFAULT_TAB, new Model(this));
|
||||
}
|
||||
|
||||
private void removeDefaultTab() {
|
||||
jarsTabbedPane.remove(jarsTabbedPane.indexOfTab(DEFAULT_TAB));
|
||||
}
|
||||
|
||||
public void onOpenFileMenu() {
|
||||
File selectedFile = fileDialog.doOpenDialog();
|
||||
if (selectedFile != null) {
|
||||
System.out.println("[Open]: Opening " + selectedFile.getAbsolutePath());
|
||||
|
||||
this.getModel().loadFile(selectedFile);
|
||||
this.loadNewFile(selectedFile);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadNewFile(final File file) {
|
||||
Model jarModel = new Model(this);
|
||||
jarModel.loadFile(file);
|
||||
jarModels.add(jarModel);
|
||||
jarsTabbedPane.addTab(file.getName(), jarModel);
|
||||
jarsTabbedPane.setSelectedComponent(jarModel);
|
||||
|
||||
final String tabName = file.getName();
|
||||
int index = jarsTabbedPane.indexOfTab(tabName);
|
||||
Model.Tab tabUI = new Model.Tab(tabName, new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
int index = jarsTabbedPane.indexOfTab(tabName);
|
||||
jarsTabbedPane.remove(index);
|
||||
if (jarsTabbedPane.getTabCount() == 0) {
|
||||
createDefaultTab();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
jarsTabbedPane.setTabComponentAt(index, tabUI);
|
||||
if (jarsTabbedPane.indexOfTab(DEFAULT_TAB) != -1 && jarsTabbedPane.getTabCount() > 1) {
|
||||
removeDefaultTab();
|
||||
}
|
||||
}
|
||||
|
||||
public void onCloseFileMenu() {
|
||||
this.getModel().closeFile();
|
||||
this.getSelectedModel().closeFile();
|
||||
jarModels.remove(getSelectedModel());
|
||||
}
|
||||
|
||||
public void onSaveAsMenu() {
|
||||
RSyntaxTextArea pane = this.getModel().getCurrentTextArea();
|
||||
RSyntaxTextArea pane = this.getSelectedModel().getCurrentTextArea();
|
||||
if (pane == null)
|
||||
return;
|
||||
String tabTitle = this.getModel().getCurrentTabTitle();
|
||||
String tabTitle = this.getSelectedModel().getCurrentTabTitle();
|
||||
if (tabTitle == null)
|
||||
return;
|
||||
|
||||
@ -162,7 +206,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
public void onSaveAllMenu() {
|
||||
File openedFile = this.getModel().getOpenedFile();
|
||||
File openedFile = this.getSelectedModel().getOpenedFile();
|
||||
if (openedFile == null)
|
||||
return;
|
||||
|
||||
@ -187,7 +231,7 @@ public class MainWindow extends JFrame {
|
||||
|
||||
public void onSelectAllMenu() {
|
||||
try {
|
||||
RSyntaxTextArea pane = this.getModel().getCurrentTextArea();
|
||||
RSyntaxTextArea pane = this.getSelectedModel().getCurrentTextArea();
|
||||
if (pane != null) {
|
||||
pane.requestFocusInWindow();
|
||||
pane.setSelectionStart(0);
|
||||
@ -200,7 +244,7 @@ public class MainWindow extends JFrame {
|
||||
|
||||
public void onFindMenu() {
|
||||
try {
|
||||
RSyntaxTextArea pane = this.getModel().getCurrentTextArea();
|
||||
RSyntaxTextArea pane = this.getSelectedModel().getCurrentTextArea();
|
||||
if (pane != null) {
|
||||
if (findBox == null)
|
||||
findBox = new FindBox(this);
|
||||
@ -229,7 +273,7 @@ public class MainWindow extends JFrame {
|
||||
bar.setVisible(true);
|
||||
bar.setIndeterminate(true);
|
||||
String legalStr = getLegalStr();
|
||||
MainWindow.this.getModel().showLegal(legalStr);
|
||||
getSelectedModel().showLegal(legalStr);
|
||||
} finally {
|
||||
bar.setIndeterminate(false);
|
||||
bar.setVisible(false);
|
||||
@ -251,7 +295,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
myCL = myCL.getParent();
|
||||
}
|
||||
MainWindow.this.getModel().show("Debug", sb.toString());
|
||||
this.getSelectedModel().show("Debug", sb.toString());
|
||||
} finally {
|
||||
bar.setIndeterminate(false);
|
||||
bar.setVisible(false);
|
||||
@ -295,21 +339,27 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
public void onThemesChanged() {
|
||||
this.getModel().changeTheme(luytenPrefs.getThemeXml());
|
||||
luytenPrefs.setFont_size(this.getModel().getTheme().baseFont.getSize());
|
||||
for (Model jarModel : jarModels) {
|
||||
jarModel.changeTheme(luytenPrefs.getThemeXml());
|
||||
luytenPrefs.setFont_size(jarModel.getTheme().baseFont.getSize());
|
||||
}
|
||||
}
|
||||
|
||||
public void onSettingsChanged() {
|
||||
this.getModel().updateOpenClasses();
|
||||
for (Model jarModel : jarModels) {
|
||||
jarModel.updateOpenClasses();
|
||||
}
|
||||
}
|
||||
|
||||
public void onTreeSettingsChanged() {
|
||||
this.getModel().updateTree();
|
||||
for (Model jarModel : jarModels) {
|
||||
jarModel.updateTree();
|
||||
}
|
||||
}
|
||||
|
||||
public void onFileDropped(File file) {
|
||||
if (file != null) {
|
||||
this.getModel().loadFile(file);
|
||||
this.loadNewFile(file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,7 +376,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
|
||||
public void onNavigationRequest(String uniqueStr) {
|
||||
this.getModel().navigateTo(uniqueStr);
|
||||
this.getSelectedModel().navigateTo(uniqueStr);
|
||||
}
|
||||
|
||||
private void adjustWindowPositionBySavedState() {
|
||||
@ -426,8 +476,8 @@ public class MainWindow extends JFrame {
|
||||
mainComponent.getActionMap().put("ESCAPE", escapeAction);
|
||||
}
|
||||
|
||||
public Model getModel() {
|
||||
return model;
|
||||
public Model getSelectedModel() {
|
||||
return (Model) jarsTabbedPane.getSelectedComponent();
|
||||
}
|
||||
|
||||
public JProgressBar getBar() {
|
||||
|
@ -5,12 +5,7 @@ import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -28,6 +23,7 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
@ -213,8 +209,14 @@ public class Model extends JSplitPane {
|
||||
house.addTab(title, rTextScrollPane);
|
||||
index = house.indexOfComponent(rTextScrollPane);
|
||||
house.setSelectedIndex(index);
|
||||
Tab ct = new Tab(title);
|
||||
ct.getButton().addMouseListener(new CloseTab(title));
|
||||
Tab ct = new Tab(title, new Callable<Void>() {
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
int index = house.indexOfTab(title);
|
||||
closeOpenTab(index);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
house.setTabComponentAt(index, ct);
|
||||
} else {
|
||||
house.setSelectedIndex(index);
|
||||
@ -586,25 +588,28 @@ public class Model extends JSplitPane {
|
||||
}
|
||||
}
|
||||
|
||||
private class Tab extends JPanel {
|
||||
private static final long serialVersionUID = -514663009333644974L;
|
||||
public static class Tab extends JPanel {
|
||||
private JLabel tabTitle;
|
||||
private JLabel closeButton = new JLabel(new ImageIcon(
|
||||
Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/icon_close.png"))));
|
||||
private JLabel tabTitle = new JLabel();
|
||||
private String title = "";
|
||||
|
||||
public Tab(String t) {
|
||||
public Tab(String title, final Callable<Void> onCloseTabAction) {
|
||||
super(new GridBagLayout());
|
||||
this.setOpaque(false);
|
||||
|
||||
this.title = t;
|
||||
this.tabTitle = new JLabel(title);
|
||||
|
||||
this.createTab();
|
||||
}
|
||||
|
||||
public JLabel getButton() {
|
||||
return this.closeButton;
|
||||
closeButton.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
try {
|
||||
if (onCloseTabAction != null) {
|
||||
onCloseTabAction.call();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Luyten.showExceptionDialog("Exception!", ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void createTab() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user