Skip to content

Commit fefb70b

Browse files
committed
Proper folder icons
1 parent 70ca268 commit fefb70b

File tree

2 files changed

+16
-35
lines changed

2 files changed

+16
-35
lines changed

src/main/java/club/bytecode/the/jda/gui/navigation/FileNavigationPane.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public FileNode addTreeElement(FileContainer container, FileNode parent) {
225225
if (parent == null)
226226
parent = treeRoot;
227227

228-
FileNode root = new FileNode(container);
228+
FileNode root = new FileNode(container, isJava(container));
229229
parent.add(root);
230230
JDATreeCellRenderer renderer = new JDATreeCellRenderer();
231231
tree.setCellRenderer(renderer);
@@ -234,10 +234,10 @@ public FileNode addTreeElement(FileContainer container, FileNode parent) {
234234
for (final Entry<String, byte[]> entry : container.files.entrySet()) {
235235
String name = entry.getKey();
236236
final String[] spl = name.split("/");
237+
FileNode parentNode = root;
237238
if (spl.length <= 1) {
238-
root.add(new FileNode(name));
239+
root.add(new FileNode(name, parentNode.isJava));
239240
} else {
240-
FileNode parentNode = root;
241241
for (final String s : spl) {
242242
FileNode child = null;
243243
for (int i = 0; i < parentNode.getChildCount(); i++) {
@@ -247,7 +247,7 @@ public FileNode addTreeElement(FileContainer container, FileNode parent) {
247247
}
248248
}
249249
if (child == null) {
250-
child = new FileNode(s);
250+
child = new FileNode(s, parentNode.isJava);
251251
parentNode.add(child);
252252
}
253253
parentNode = child;
@@ -263,6 +263,10 @@ public FileNode addTreeElement(FileContainer container, FileNode parent) {
263263
return root;
264264
}
265265

266+
private boolean isJava(FileContainer container) {
267+
return container.name.endsWith(".java") || container.name.endsWith(".jar") || container.name.endsWith(".class");
268+
}
269+
266270
@SuppressWarnings("rawtypes")
267271
void treeDfs(final TreePath parent, Consumer<TreePath> onPreOrder, Consumer<TreePath> onPostOrder) {
268272
if (onPreOrder != null)
@@ -314,12 +318,17 @@ public void paint(final Graphics g) {
314318

315319
public class FileNode extends DefaultMutableTreeNode {
316320

317-
public final boolean isJava = false;
321+
public final boolean isJava;
318322

319323
private static final long serialVersionUID = -8817777566176729571L;
320324

321-
public FileNode(final Object o) {
325+
public FileNode(final Object o, boolean isJava) {
322326
super(o);
327+
this.isJava = isJava;
328+
}
329+
330+
public FileNode(final Object o) {
331+
this(o, false);
323332
}
324333

325334
@Override

src/main/java/club/bytecode/the/jda/gui/navigation/JDATreeCellRenderer.java

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
5454
nodes.add(node);
5555
totalNodes.add(node);
5656

57-
boolean isJava = false;
58-
boolean finished = false;
59-
60-
while (!finished) { //may cause a clusterfuck with huge files
61-
if (nodes.isEmpty())
62-
finished = true;
63-
else {
64-
TreeNode treeNode = nodes.get(0);
65-
nodes.remove(treeNode);
66-
int children = treeNode.getChildCount();
67-
if (children >= 1)
68-
for (int i = 0; i < children; i++) {
69-
TreeNode child = treeNode.getChildAt(i);
70-
71-
if (!totalNodes.contains(child)) {
72-
nodes.add(child);
73-
totalNodes.add(child);
74-
}
75-
76-
if (child.toString().endsWith(".class"))
77-
isJava = true;
78-
}
79-
80-
if (isJava)
81-
nodes.clear();
82-
}
83-
}
84-
85-
if (isJava)
57+
if (node.isJava)
8658
setIcon(Resources.packagesIcon);
8759
else {
8860
setIcon(Resources.folderIcon);

0 commit comments

Comments
 (0)