Skip to content

Commit

Permalink
feat(gui): save the class tree width and restore it upon jadx-gui sta…
Browse files Browse the repository at this point in the history
…rt (PR #606)
  • Loading branch information
jpstotz authored and skylot committed May 6, 2019
1 parent 7ac0b9f commit 65818dc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 5 deletions.
18 changes: 17 additions & 1 deletion jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package jadx.gui.settings;

import java.awt.*;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Window;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand Down Expand Up @@ -55,6 +58,10 @@ public class JadxSettings extends JadxCLIArgs {

private Map<String, WindowLocation> windowPos = new HashMap<>();
private int mainWindowExtendedState = JFrame.NORMAL;
/**
* UI setting: the width of the tree showing the classes, resources, ...
*/
private int treeWidth = 130;

private int settingsVersion = 0;

Expand Down Expand Up @@ -305,6 +312,15 @@ public void setExportAsGradleProject(boolean exportAsGradleProject) {
this.exportAsGradleProject = exportAsGradleProject;
}

public int getTreeWidth() {
return treeWidth;
}

public void setTreeWidth(int treeWidth) {
this.treeWidth = treeWidth;
partialSync(settings -> settings.treeWidth = JadxSettings.this.treeWidth);
}

public Font getFont() {
if (fontStr.isEmpty()) {
return DEFAULT_FONT;
Expand Down
42 changes: 38 additions & 4 deletions jadx-gui/src/main/java/jadx/gui/ui/MainWindow.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package jadx.gui.ui;

import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.DisplayMode;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.event.ActionEvent;
Expand All @@ -23,7 +29,27 @@
import java.util.Timer;
import java.util.TimerTask;

import javax.swing.*;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.ProgressMonitor;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import javax.swing.event.TreeExpansionEvent;
Expand Down Expand Up @@ -102,6 +128,7 @@ public class MainWindow extends JFrame {
private transient Action saveProjectAction;

private JPanel mainPanel;
private JSplitPane splitPane;

private JTree tree;
private DefaultTreeModel treeModel;
Expand Down Expand Up @@ -140,6 +167,7 @@ public MainWindow(JadxSettings settings) {
public void init() {
pack();
setLocationAndPosition();
splitPane.setDividerLocation(settings.getTreeWidth());
heapUsageBar.setVisible(settings.isShowHeapUsageBar());
setVisible(true);
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
Expand Down Expand Up @@ -772,8 +800,9 @@ public void actionPerformed(ActionEvent e) {
}

private void initUI() {
setMinimumSize(new Dimension(200, 150));
mainPanel = new JPanel(new BorderLayout());
JSplitPane splitPane = new JSplitPane();
splitPane = new JSplitPane();
splitPane.setResizeWeight(SPLIT_PANE_RESIZE_WEIGHT);
mainPanel.add(splitPane);

Expand Down Expand Up @@ -840,11 +869,15 @@ public void treeWillCollapse(TreeExpansionEvent event) {
progressPane = new ProgressPanel(this, true);

JPanel leftPane = new JPanel(new BorderLayout());
leftPane.add(new JScrollPane(tree), BorderLayout.CENTER);
JScrollPane treeScrollPane = new JScrollPane(tree);
treeScrollPane.setMinimumSize(new Dimension(100, 150));

leftPane.add(treeScrollPane, BorderLayout.CENTER);
leftPane.add(progressPane, BorderLayout.PAGE_END);
splitPane.setLeftComponent(leftPane);

tabbedPane = new TabbedPane(this);
tabbedPane.setMinimumSize(new Dimension(150, 150));
splitPane.setRightComponent(tabbedPane);

new DropTarget(this, DnDConstants.ACTION_COPY, new MainDropTarget(this));
Expand Down Expand Up @@ -931,6 +964,7 @@ private void closeWindow() {
if (!ensureProjectIsSaved()) {
return;
}
settings.setTreeWidth(splitPane.getDividerLocation());
settings.saveWindowPos(this);
settings.setMainWindowExtendedState(getExtendedState());
cancelBackgroundJobs();
Expand Down

0 comments on commit 65818dc

Please sign in to comment.