diff --git a/src/main/java/the/bytecode/club/jda/JDA.java b/src/main/java/the/bytecode/club/jda/JDA.java index 82c5740..68d7bcc 100644 --- a/src/main/java/the/bytecode/club/jda/JDA.java +++ b/src/main/java/the/bytecode/club/jda/JDA.java @@ -8,8 +8,8 @@ import the.bytecode.club.jda.api.ExceptionUI; import the.bytecode.club.jda.api.Plugin; import the.bytecode.club.jda.api.PluginLoader; -import the.bytecode.club.jda.gui.FileNavigationPane; import the.bytecode.club.jda.gui.MainViewerGUI; +import the.bytecode.club.jda.gui.navigation.FileNavigationPane; import the.bytecode.club.jda.settings.Settings; import javax.swing.*; @@ -152,7 +152,7 @@ private static void onExit() { * @return the currently opened ClassNode */ public static ClassNode getCurrentlyOpenedClassNode() { - return viewer.workPane.getCurrentViewer().cn; + return viewer.FileViewerPane.getCurrentViewer().cn; } public static FileContainer findContainer(String containerName, String fileName) { @@ -702,8 +702,8 @@ public void run() { }; t.start(); } else if ((e.getKeyCode() == KeyEvent.VK_W) && isCtrlDown(e)) { - if (viewer.workPane.getCurrentViewer() != null) - viewer.workPane.tabs.remove(viewer.workPane.getCurrentViewer()); + if (viewer.FileViewerPane.getCurrentViewer() != null) + viewer.FileViewerPane.tabs.remove(viewer.FileViewerPane.getCurrentViewer()); } } } diff --git a/src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java index 1886256..541805e 100644 --- a/src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java @@ -5,6 +5,13 @@ import the.bytecode.club.jda.api.ExceptionUI; import the.bytecode.club.jda.decompilers.Decompiler; import the.bytecode.club.jda.decompilers.Decompilers; +import the.bytecode.club.jda.gui.dialogs.AboutWindow; +import the.bytecode.club.jda.gui.dialogs.FontOptionsDialog; +import the.bytecode.club.jda.gui.dialogs.IntroWindow; +import the.bytecode.club.jda.gui.dialogs.TabbedPane; +import the.bytecode.club.jda.gui.fileviewer.FileViewerPane; +import the.bytecode.club.jda.gui.fileviewer.Viewer; +import the.bytecode.club.jda.gui.navigation.FileNavigationPane; import the.bytecode.club.jda.settings.DecompilerSettings; import the.bytecode.club.jda.settings.IPersistentWindow; import the.bytecode.club.jda.settings.Settings; @@ -44,15 +51,15 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier, IPersis public JDesktopPane desktop; public FileNavigationPane navigator; - public WorkPane workPane; + public FileViewerPane FileViewerPane; public static ArrayList windows = new ArrayList<>(); private final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (Settings.REFRESH_ON_VIEW_CHANGE.getBool()) { - if (workPane.getCurrentViewer() == null) + if (FileViewerPane.getCurrentViewer() == null) return; - workPane.refreshClass.doClick(); + FileViewerPane.refreshClass.doClick(); } } }; @@ -281,7 +288,7 @@ private void initializeMenubar() { mnShowContainer.setSelected(Settings.SHOW_CONTAINER_NAME.getBool()); mnShowContainer.addItemListener(e -> { - JTabbedPane tabs = workPane.tabs; + JTabbedPane tabs = FileViewerPane.tabs; Component[] components = tabs.getComponents(); for (int i = 0; i < components.length; i++) { Component c = components[i]; @@ -289,7 +296,7 @@ private void initializeMenubar() { ((Viewer) c).updateName(); int idx = tabs.indexOfComponent(c); tabs.setTabComponentAt(idx, new TabbedPane(c.getName(), tabs)); - workPane.tabs.setTitleAt(idx, c.getName()); + FileViewerPane.tabs.setTitleAt(idx, c.getName()); } } Settings.SHOW_CONTAINER_NAME.set(mnShowContainer.isSelected()); @@ -310,17 +317,17 @@ public static T getComponent(final Class clazz) { private void initializeWindows() { navigator = new FileNavigationPane(this); - workPane = new WorkPane(this); + FileViewerPane = new FileViewerPane(this); desktop = new JDesktopPane(); setContentPane(desktop); desktop.add(navigator); - desktop.add(workPane); + desktop.add(FileViewerPane); desktop.setDesktopManager(new WorkspaceDesktopManager()); desktop.setBackground(COLOR_DESKTOP_BACKGROUND); windows.add(navigator); - windows.add(workPane); + windows.add(FileViewerPane); } public void resetWindows() { @@ -400,7 +407,7 @@ private JMenu generatePane(int id) { public void closeResources() { navigator.resetWorkspace(); - workPane.resetWorkspace(); + FileViewerPane.resetWorkspace(); } public void setIcon(final boolean busy) { @@ -435,7 +442,7 @@ public void openFile(final String name, String container, byte[] content) { } public void refreshView() { - workPane.refreshClass.doClick(); + FileViewerPane.refreshClass.doClick(); } public void reloadResources() { @@ -525,7 +532,7 @@ private void saveAsRunnableJar() { } private void decompileSaveOpenedClasses() { - if (workPane.getCurrentViewer() == null) { + if (FileViewerPane.getCurrentViewer() == null) { JDA.showMessage("First open a class, jar, or zip file."); return; } diff --git a/src/main/java/the/bytecode/club/jda/gui/PaneUpdaterThread.java b/src/main/java/the/bytecode/club/jda/gui/PaneUpdaterThread.java index 2ad71a6..5252ccd 100644 --- a/src/main/java/the/bytecode/club/jda/gui/PaneUpdaterThread.java +++ b/src/main/java/the/bytecode/club/jda/gui/PaneUpdaterThread.java @@ -6,6 +6,7 @@ import the.bytecode.club.jda.JDA; import the.bytecode.club.jda.api.ExceptionUI; import the.bytecode.club.jda.decompilers.Decompiler; +import the.bytecode.club.jda.gui.fileviewer.ClassViewer; import the.bytecode.club.jda.settings.Settings; import javax.swing.*; diff --git a/src/main/java/the/bytecode/club/jda/gui/AboutWindow.java b/src/main/java/the/bytecode/club/jda/gui/dialogs/AboutWindow.java similarity index 97% rename from src/main/java/the/bytecode/club/jda/gui/AboutWindow.java rename to src/main/java/the/bytecode/club/jda/gui/dialogs/AboutWindow.java index 066b0db..92473ec 100644 --- a/src/main/java/the/bytecode/club/jda/gui/AboutWindow.java +++ b/src/main/java/the/bytecode/club/jda/gui/dialogs/AboutWindow.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.dialogs; import org.apache.commons.io.IOUtils; import the.bytecode.club.jda.JDA; diff --git a/src/main/java/the/bytecode/club/jda/gui/ExportJar.java b/src/main/java/the/bytecode/club/jda/gui/dialogs/ExportJar.java similarity index 97% rename from src/main/java/the/bytecode/club/jda/gui/ExportJar.java rename to src/main/java/the/bytecode/club/jda/gui/dialogs/ExportJar.java index c9ca1ea..64e9010 100644 --- a/src/main/java/the/bytecode/club/jda/gui/ExportJar.java +++ b/src/main/java/the/bytecode/club/jda/gui/dialogs/ExportJar.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.dialogs; import the.bytecode.club.jda.JDA; import the.bytecode.club.jda.JarUtils; diff --git a/src/main/java/the/bytecode/club/jda/gui/FileChooser.java b/src/main/java/the/bytecode/club/jda/gui/dialogs/FileChooser.java similarity index 97% rename from src/main/java/the/bytecode/club/jda/gui/FileChooser.java rename to src/main/java/the/bytecode/club/jda/gui/dialogs/FileChooser.java index 3877742..fbbfa94 100644 --- a/src/main/java/the/bytecode/club/jda/gui/FileChooser.java +++ b/src/main/java/the/bytecode/club/jda/gui/dialogs/FileChooser.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.dialogs; import the.bytecode.club.jda.JDA; import the.bytecode.club.jda.api.ExceptionUI; diff --git a/src/main/java/the/bytecode/club/jda/gui/FontOptionsDialog.java b/src/main/java/the/bytecode/club/jda/gui/dialogs/FontOptionsDialog.java similarity index 97% rename from src/main/java/the/bytecode/club/jda/gui/FontOptionsDialog.java rename to src/main/java/the/bytecode/club/jda/gui/dialogs/FontOptionsDialog.java index 8846dd1..fda165c 100644 --- a/src/main/java/the/bytecode/club/jda/gui/FontOptionsDialog.java +++ b/src/main/java/the/bytecode/club/jda/gui/dialogs/FontOptionsDialog.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.dialogs; import net.miginfocom.swing.MigLayout; import the.bytecode.club.jda.settings.Settings; diff --git a/src/main/java/the/bytecode/club/jda/gui/IntroWindow.java b/src/main/java/the/bytecode/club/jda/gui/dialogs/IntroWindow.java similarity index 97% rename from src/main/java/the/bytecode/club/jda/gui/IntroWindow.java rename to src/main/java/the/bytecode/club/jda/gui/dialogs/IntroWindow.java index 47442c9..19b7208 100644 --- a/src/main/java/the/bytecode/club/jda/gui/IntroWindow.java +++ b/src/main/java/the/bytecode/club/jda/gui/dialogs/IntroWindow.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.dialogs; import org.apache.commons.io.IOUtils; import the.bytecode.club.jda.Resources; diff --git a/src/main/java/the/bytecode/club/jda/gui/SystemErrConsole.java b/src/main/java/the/bytecode/club/jda/gui/dialogs/SystemErrConsole.java similarity index 96% rename from src/main/java/the/bytecode/club/jda/gui/SystemErrConsole.java rename to src/main/java/the/bytecode/club/jda/gui/dialogs/SystemErrConsole.java index da3789f..386d1d8 100644 --- a/src/main/java/the/bytecode/club/jda/gui/SystemErrConsole.java +++ b/src/main/java/the/bytecode/club/jda/gui/dialogs/SystemErrConsole.java @@ -1,7 +1,8 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.dialogs; import the.bytecode.club.jda.JDA; import the.bytecode.club.jda.Resources; +import the.bytecode.club.jda.gui.fileviewer.SearchPanel; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/the/bytecode/club/jda/gui/TabbedPane.java b/src/main/java/the/bytecode/club/jda/gui/dialogs/TabbedPane.java similarity index 99% rename from src/main/java/the/bytecode/club/jda/gui/TabbedPane.java rename to src/main/java/the/bytecode/club/jda/gui/dialogs/TabbedPane.java index d9fa034..24e46eb 100644 --- a/src/main/java/the/bytecode/club/jda/gui/TabbedPane.java +++ b/src/main/java/the/bytecode/club/jda/gui/dialogs/TabbedPane.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.dialogs; import javax.swing.*; import javax.swing.plaf.basic.BasicButtonUI; diff --git a/src/main/java/the/bytecode/club/jda/gui/ClassViewer.java b/src/main/java/the/bytecode/club/jda/gui/fileviewer/ClassViewer.java similarity index 98% rename from src/main/java/the/bytecode/club/jda/gui/ClassViewer.java rename to src/main/java/the/bytecode/club/jda/gui/fileviewer/ClassViewer.java index 4038a82..c5ee426 100644 --- a/src/main/java/the/bytecode/club/jda/gui/ClassViewer.java +++ b/src/main/java/the/bytecode/club/jda/gui/fileviewer/ClassViewer.java @@ -1,9 +1,10 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.fileviewer; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.jda.JDA; import the.bytecode.club.jda.decompilers.Decompiler; +import the.bytecode.club.jda.gui.PaneUpdaterThread; import javax.swing.*; import java.awt.*; diff --git a/src/main/java/the/bytecode/club/jda/gui/FileViewer.java b/src/main/java/the/bytecode/club/jda/gui/fileviewer/FileViewer.java similarity index 99% rename from src/main/java/the/bytecode/club/jda/gui/FileViewer.java rename to src/main/java/the/bytecode/club/jda/gui/fileviewer/FileViewer.java index 3b2ce71..eeffc2b 100644 --- a/src/main/java/the/bytecode/club/jda/gui/FileViewer.java +++ b/src/main/java/the/bytecode/club/jda/gui/fileviewer/FileViewer.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.fileviewer; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.SyntaxConstants; diff --git a/src/main/java/the/bytecode/club/jda/gui/WorkPane.java b/src/main/java/the/bytecode/club/jda/gui/fileviewer/FileViewerPane.java similarity index 93% rename from src/main/java/the/bytecode/club/jda/gui/WorkPane.java rename to src/main/java/the/bytecode/club/jda/gui/fileviewer/FileViewerPane.java index 39d59dd..a7b06b7 100644 --- a/src/main/java/the/bytecode/club/jda/gui/WorkPane.java +++ b/src/main/java/the/bytecode/club/jda/gui/fileviewer/FileViewerPane.java @@ -1,9 +1,13 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.fileviewer; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.jda.FileChangeNotifier; import the.bytecode.club.jda.JDA; import the.bytecode.club.jda.Resources; +import the.bytecode.club.jda.gui.JDAWindow; +import the.bytecode.club.jda.gui.MainViewerGUI; +import the.bytecode.club.jda.gui.dialogs.TabbedPane; +import the.bytecode.club.jda.gui.navigation.FileNavigationPane; import javax.swing.*; import java.awt.*; @@ -20,7 +24,7 @@ * @author WaterWolf */ -public class WorkPane extends JDAWindow implements ActionListener { +public class FileViewerPane extends JDAWindow implements ActionListener { private static final long serialVersionUID = 6542337997679487946L; @@ -28,13 +32,13 @@ public class WorkPane extends JDAWindow implements ActionListener { public JTabbedPane tabs; JPanel buttonPanel; - JButton refreshClass; + public JButton refreshClass; HashMap workingOn = new HashMap<>(); public static int SyntaxFontHeight = 12; - public WorkPane(final FileChangeNotifier fcn) { + public FileViewerPane(final FileChangeNotifier fcn) { super("WorkPanel", "Work Space", Resources.fileNavigatorIcon, (MainViewerGUI) fcn); this.tabs = new JTabbedPane(); diff --git a/src/main/java/the/bytecode/club/jda/gui/SearchPanel.java b/src/main/java/the/bytecode/club/jda/gui/fileviewer/SearchPanel.java similarity index 99% rename from src/main/java/the/bytecode/club/jda/gui/SearchPanel.java rename to src/main/java/the/bytecode/club/jda/gui/fileviewer/SearchPanel.java index b4aec98..7ae1eb1 100644 --- a/src/main/java/the/bytecode/club/jda/gui/SearchPanel.java +++ b/src/main/java/the/bytecode/club/jda/gui/fileviewer/SearchPanel.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.fileviewer; import the.bytecode.club.jda.JDA; import the.bytecode.club.jda.Resources; diff --git a/src/main/java/the/bytecode/club/jda/gui/Viewer.java b/src/main/java/the/bytecode/club/jda/gui/fileviewer/Viewer.java similarity index 90% rename from src/main/java/the/bytecode/club/jda/gui/Viewer.java rename to src/main/java/the/bytecode/club/jda/gui/fileviewer/Viewer.java index a19779d..b32a6a4 100644 --- a/src/main/java/the/bytecode/club/jda/gui/Viewer.java +++ b/src/main/java/the/bytecode/club/jda/gui/fileviewer/Viewer.java @@ -1,4 +1,4 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.fileviewer; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.jda.settings.Settings; diff --git a/src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java b/src/main/java/the/bytecode/club/jda/gui/navigation/FileNavigationPane.java similarity index 72% rename from src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java rename to src/main/java/the/bytecode/club/jda/gui/navigation/FileNavigationPane.java index 79a9288..1e3b34c 100644 --- a/src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java +++ b/src/main/java/the/bytecode/club/jda/gui/navigation/FileNavigationPane.java @@ -1,16 +1,20 @@ -package the.bytecode.club.jda.gui; +package the.bytecode.club.jda.gui.navigation; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.jda.*; +import the.bytecode.club.jda.gui.JDAWindow; +import the.bytecode.club.jda.gui.MainViewerGUI; import javax.swing.*; -import javax.swing.tree.*; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.MutableTreeNode; +import javax.swing.tree.TreeNode; +import javax.swing.tree.TreePath; import java.awt.*; import java.awt.event.*; import java.awt.font.FontRenderContext; import java.awt.geom.Rectangle2D; import java.io.File; -import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Enumeration; @@ -116,7 +120,7 @@ public void mousePressed(MouseEvent e) { openPath(tree.getPathForLocation(e.getX(), e.getY())); } }); - tree.setComponentPopupMenu(new TreeContextMenu()); + tree.setComponentPopupMenu(new TreeContextMenu(this)); tree.setInheritsPopupMenu(true); this.tree.addKeyListener(new KeyListener() { @@ -219,10 +223,9 @@ public void updateTree() { for (FileContainer container : JDA.files) { FileNode root = new FileNode(container.name); treeRoot.add(root); - ImageRenderer renderer = new ImageRenderer(); + JDATreeCellRenderer renderer = new JDATreeCellRenderer(); tree.setCellRenderer(renderer); - if (!container.files.isEmpty()) { for (final Entry entry : container.files.entrySet()) { String name = entry.getKey(); @@ -260,7 +263,7 @@ public void updateTree() { } @SuppressWarnings("rawtypes") - private void treeDfs(final TreePath parent, Consumer onPreOrder, Consumer onPostOrder) { + void treeDfs(final TreePath parent, Consumer onPreOrder, Consumer onPostOrder) { if (onPreOrder != null) onPreOrder.accept(parent); @@ -416,115 +419,4 @@ public void openPath(TreePath path) { } } - /** - * @author http://stackoverflow.com/questions/14968005 - * @author Konloch - */ - public class ImageRenderer extends DefaultTreeCellRenderer { - public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { //called every time there is a pane update, I.E. whenever you expand a folder - - Component ret = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); - - if (value != null && value instanceof FileNode) { - FileNode node = (FileNode) value; - String name = node.toString(); - - if (name.endsWith(".jar")) { - setIcon(Resources.jarIcon); - } else if (name.endsWith(".zip")) { - setIcon(Resources.zipIcon); - } else if (name.endsWith(".bat")) { - setIcon(Resources.batIcon); - } else if (name.endsWith(".sh")) { - setIcon(Resources.shIcon); - } else if (name.endsWith(".cs")) { - setIcon(Resources.csharpIcon); - } else if (name.endsWith(".c") || name.endsWith(".cpp") || name.endsWith(".h")) { - setIcon(Resources.cplusplusIcon); - } else if (name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".bmp") || name.endsWith(".gif")) { - setIcon(Resources.imageIcon); - } else if (name.endsWith(".class")) { - setIcon(Resources.classIcon); - } else if (name.endsWith(".java")) { - setIcon(Resources.javaIcon); - } else if (name.endsWith(".txt") || name.endsWith(".md")) { - setIcon(Resources.textIcon); - } else if (name.equals("decoded resources")) { - setIcon(Resources.decodedIcon); - } else if (name.endsWith(".properties") || name.endsWith(".xml") || name.endsWith(".mf") || name.endsWith(".config") || name.endsWith(".cfg")) { - setIcon(Resources.configIcon); - } else if (node.getChildCount() <= 0) { //random file - setIcon(Resources.fileIcon); - } else { //folder - ArrayList nodes = new ArrayList<>(); - ArrayList totalNodes = new ArrayList<>(); - - nodes.add(node); - totalNodes.add(node); - - boolean isJava = false; - boolean finished = false; - - while (!finished) { //may cause a clusterfuck with huge files - if (nodes.isEmpty()) - finished = true; - else { - TreeNode treeNode = nodes.get(0); - nodes.remove(treeNode); - int children = treeNode.getChildCount(); - if (children >= 1) - for (int i = 0; i < children; i++) { - TreeNode child = treeNode.getChildAt(i); - - if (!totalNodes.contains(child)) { - nodes.add(child); - totalNodes.add(child); - } - - if (child.toString().endsWith(".class")) - isJava = true; - } - - if (isJava) - nodes.clear(); - } - } - - if (isJava) - setIcon(Resources.packagesIcon); - else { - setIcon(Resources.folderIcon); - } - } - } - - return ret; - } - } - - private class TreeContextMenu extends JPopupMenu { - JMenuItem expandAll, collapseAll; - - public TreeContextMenu(){ - add(expandAll = new JMenuItem("Expand All")); - add(collapseAll = new JMenuItem("Collapse All")); - - expandAll.addActionListener(e -> { - if (tree.getSelectionPaths() != null) { - for (TreePath path : tree.getSelectionPaths()) { - treeDfs(path, tree::expandPath, null); - tree.expandPath(path); - } - } - }); - - collapseAll.addActionListener(e -> { - if (tree.getSelectionPaths() != null) { - for (TreePath path : tree.getSelectionPaths()) { - treeDfs(path, null, tree::collapsePath); - } - } - }); - } - } } diff --git a/src/main/java/the/bytecode/club/jda/gui/navigation/JDATreeCellRenderer.java b/src/main/java/the/bytecode/club/jda/gui/navigation/JDATreeCellRenderer.java new file mode 100644 index 0000000..36fe820 --- /dev/null +++ b/src/main/java/the/bytecode/club/jda/gui/navigation/JDATreeCellRenderer.java @@ -0,0 +1,95 @@ +package the.bytecode.club.jda.gui.navigation; + +import the.bytecode.club.jda.Resources; + +import javax.swing.*; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.TreeNode; +import java.awt.*; +import java.util.ArrayList; + +/** + * @author http://stackoverflow.com/questions/14968005 + * @author Konloch + */ +public class JDATreeCellRenderer extends DefaultTreeCellRenderer { + public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { //called every time there is a pane update, I.E. whenever you expand a folder + + Component ret = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus); + + if (value != null && value instanceof FileNavigationPane.FileNode) { + FileNavigationPane.FileNode node = (FileNavigationPane.FileNode) value; + String name = node.toString(); + + if (name.endsWith(".jar")) { + setIcon(Resources.jarIcon); + } else if (name.endsWith(".zip")) { + setIcon(Resources.zipIcon); + } else if (name.endsWith(".bat")) { + setIcon(Resources.batIcon); + } else if (name.endsWith(".sh")) { + setIcon(Resources.shIcon); + } else if (name.endsWith(".cs")) { + setIcon(Resources.csharpIcon); + } else if (name.endsWith(".c") || name.endsWith(".cpp") || name.endsWith(".h")) { + setIcon(Resources.cplusplusIcon); + } else if (name.endsWith(".png") || name.endsWith(".jpg") || name.endsWith(".jpeg") || name.endsWith(".bmp") || name.endsWith(".gif")) { + setIcon(Resources.imageIcon); + } else if (name.endsWith(".class")) { + setIcon(Resources.classIcon); + } else if (name.endsWith(".java")) { + setIcon(Resources.javaIcon); + } else if (name.endsWith(".txt") || name.endsWith(".md")) { + setIcon(Resources.textIcon); + } else if (name.equals("decoded resources")) { + setIcon(Resources.decodedIcon); + } else if (name.endsWith(".properties") || name.endsWith(".xml") || name.endsWith(".mf") || name.endsWith(".config") || name.endsWith(".cfg")) { + setIcon(Resources.configIcon); + } else if (node.getChildCount() <= 0) { //random file + setIcon(Resources.fileIcon); + } else { //folder + ArrayList nodes = new ArrayList<>(); + ArrayList totalNodes = new ArrayList<>(); + + nodes.add(node); + totalNodes.add(node); + + boolean isJava = false; + boolean finished = false; + + while (!finished) { //may cause a clusterfuck with huge files + if (nodes.isEmpty()) + finished = true; + else { + TreeNode treeNode = nodes.get(0); + nodes.remove(treeNode); + int children = treeNode.getChildCount(); + if (children >= 1) + for (int i = 0; i < children; i++) { + TreeNode child = treeNode.getChildAt(i); + + if (!totalNodes.contains(child)) { + nodes.add(child); + totalNodes.add(child); + } + + if (child.toString().endsWith(".class")) + isJava = true; + } + + if (isJava) + nodes.clear(); + } + } + + if (isJava) + setIcon(Resources.packagesIcon); + else { + setIcon(Resources.folderIcon); + } + } + } + + return ret; + } +} diff --git a/src/main/java/the/bytecode/club/jda/gui/navigation/TreeContextMenu.java b/src/main/java/the/bytecode/club/jda/gui/navigation/TreeContextMenu.java new file mode 100644 index 0000000..6d7875b --- /dev/null +++ b/src/main/java/the/bytecode/club/jda/gui/navigation/TreeContextMenu.java @@ -0,0 +1,32 @@ +package the.bytecode.club.jda.gui.navigation; + +import javax.swing.*; +import javax.swing.tree.TreePath; + +class TreeContextMenu extends JPopupMenu { + private FileNavigationPane fileNavigationPane; + JMenuItem expandAll, collapseAll; + + public TreeContextMenu(FileNavigationPane fileNavigationPane){ + this.fileNavigationPane = fileNavigationPane; + add(expandAll = new JMenuItem("Expand All")); + add(collapseAll = new JMenuItem("Collapse All")); + + expandAll.addActionListener(e -> { + if (fileNavigationPane.tree.getSelectionPaths() != null) { + for (TreePath path : fileNavigationPane.tree.getSelectionPaths()) { + fileNavigationPane.treeDfs(path, fileNavigationPane.tree::expandPath, null); + fileNavigationPane.tree.expandPath(path); + } + } + }); + + collapseAll.addActionListener(e -> { + if (fileNavigationPane.tree.getSelectionPaths() != null) { + for (TreePath path : fileNavigationPane.tree.getSelectionPaths()) { + fileNavigationPane.treeDfs(path, null, fileNavigationPane.tree::collapsePath); + } + } + }); + } +}