Add option for whether the name of the containing file should be shown in the tab title

Fix bug with closing tabs
Fix bug with updating tab names when changing show container name option
This commit is contained in:
afffsdd 2015-12-24 20:01:21 -05:00
parent 090d3f7f29
commit 3aee5e5c3d
5 changed files with 28 additions and 11 deletions

View File

@ -119,8 +119,6 @@ public class ClassViewer extends Viewer {
return splitter;
}
String name;
String container;
JSplitPane sp;
JSplitPane sp2;
public List<Decompiler> decompilers = Arrays.asList(null, null, null);
@ -321,7 +319,7 @@ public class ClassViewer extends Viewer {
this.name = name;
this.container = container;
this.cn = cn;
this.setName(name + "(" + container + ")");
updateName();
this.setLayout(new BorderLayout());
this.sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, panels.get(0), panels.get(1));

View File

@ -50,8 +50,6 @@ public class FileViewer extends Viewer {
private static final long serialVersionUID = 6103372882168257164L;
String name;
String container;
private byte[] contents;
RSyntaxTextArea panelArea = new RSyntaxTextArea();
JPanel panel = new JPanel(new BorderLayout());
@ -194,7 +192,7 @@ public class FileViewer extends Viewer {
this.name = name;
this.container = container;
this.contents = contents;
this.setName(name);
updateName();
this.setLayout(new BorderLayout());
this.add(panel2, BorderLayout.CENTER);

View File

@ -205,6 +205,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
public final ButtonGroup panelGroup1 = new ButtonGroup();
public final ButtonGroup panelGroup2 = new ButtonGroup();
public final ButtonGroup panelGroup3 = new ButtonGroup();
public final JCheckBox mnShowContainer = new JCheckBox("Show Containing File's Name");
private final JMenuItem mntmSetOpitonalLibrary = new JMenuItem("Set Optional Library Folder");
private final JMenuItem mntmPingback = new JMenuItem("Pingback");
private final JMenu mnFontSize = new JMenu("Font Size");
@ -1225,10 +1226,25 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
fontSpinner.setSize(new Dimension(42, 20));
fontSpinner.setModel(new SpinnerNumberModel(12, 1, null, 1));
viewMenu.add(mnFontSize);
mnFontSize.add(fontSpinner);
viewMenu.add(mnShowContainer);
mnShowContainer.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
JTabbedPane tabs = workPane.tabs;
Component[] components = tabs.getComponents();
for (int i = 0; i < components.length; i++) {
Component c = components[i];
if (c instanceof Viewer) {
((Viewer) c).updateName();
int idx = tabs.indexOfComponent(c);
tabs.setTabComponentAt(idx, new TabbedPane(c.getName(), tabs));
workPane.tabs.setTitleAt(idx, c.getName());
}
}
}
});
panelGroup1.setSelected(allDecompilersRev.get(panelGroup1).get(Decompiler.JDGUI).getModel(), true);
panelGroup2.setSelected(allDecompilersRev.get(panelGroup2).get(Decompiler.BYTECODE).getModel(), true);
panelGroup3.setSelected(allDecompilersRev.get(panelGroup3).get(null).getModel(), true);

View File

@ -1,6 +1,7 @@
package the.bytecode.club.bytecodeviewer.gui;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import javax.swing.*;
@ -26,7 +27,11 @@ public abstract class Viewer extends JPanel {
public ClassNode cn;
public String name;
public String container;
private static final long serialVersionUID = -2965538493489119191L;
public void updateName() {
this.setName(name + (BytecodeViewer.viewer.mnShowContainer.isSelected() ? "(" + container + ")" : ""));
}
}

View File

@ -86,11 +86,11 @@ public class WorkPane extends VisibleComponent implements ActionListener {
final Component c = e.getChild();
if (c instanceof ClassViewer) {
ClassViewer cv = (ClassViewer) c;
workingOn.remove(cv.name + "$" + cv.name);
workingOn.remove(cv.container + "$" + cv.name);
}
if (c instanceof FileViewer) {
FileViewer fv = (FileViewer) c;
workingOn.remove(fv.name + "$" + fv.name);
workingOn.remove(fv.container + "$" + fv.name);
}
}