-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualiseDirectories.java
More file actions
89 lines (73 loc) · 2.47 KB
/
VisualiseDirectories.java
File metadata and controls
89 lines (73 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
class VisualiseDirectories{
public static void main(String[] args){
JFrame window = new JFrame("FileMap");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Find the number of Folders here and use them to set the rows and columns
String str = System.getProperty("user.dir");
FileStruct fs = new FileStruct();
ArrayList<FileTree> dirs = fs.getFilePath(str);
/////////////////////////////////////////////////////////
//Put all this into a function to make the code cleaner
int minLvl = dirs.get(dirs.size()-1).getLevel();
int maxLvl = 0;
Hashtable<Integer, Integer> levelCounters = new Hashtable<Integer, Integer>();
for (int i=0; i<dirs.size(); i++){
int lvl = dirs.get(i).getLevel();
if (lvl > maxLvl){
maxLvl = lvl;
}
Integer n = levelCounters.get(lvl);
if (n != null){
levelCounters.put(lvl, n+1);
} else{
levelCounters.put(lvl, 1);
}
}
int maxWidth=0;
for (Integer key: levelCounters.keySet()){
if (levelCounters.get(key)>maxWidth){
maxWidth = levelCounters.get(key);
}
}
//////////////////////////////////////////////////
/////////////////////////////////////////////////
//Sets the frames up
int rows = maxLvl-minLvl+1;
int j = maxWidth;
JPanel[][] panelHolder = new JPanel[rows][j];
window.setLayout(new GridLayout(rows,j));
for(int m = 0; m < rows; m++) {
for(int n = 0; n < j; n++) {
panelHolder[m][n] = new JPanel();
window.add(panelHolder[m][n]);
}
}
int currentPos[] = new int[levelCounters.size()];
for (int i=0; i<dirs.size(); i++){
int lvl = dirs.get(i).getLevel();
int inc = maxWidth/(levelCounters.get(lvl));
int inc2 = (maxWidth%levelCounters.get(lvl)) / 2;
//System.out.println((double)maxWidth/levelCounters.get(lvl));
lvl -= minLvl;
int pos = currentPos[lvl];
String parent = dirs.get(i).getParent();
String[] parentRoot = parent.split("/");
panelHolder[lvl][pos].add(new JLabel(parentRoot[parentRoot.length-1]));
currentPos[lvl]+=1;
}
//Center the values
//Make the font bigger
//Draw lines/arrows between each folder
//Set the background to white
//Add in a save as image option
//TODO
// Find a way to organise each level to match up the the children near it (or would this already be organised based on the recursive nature of the algorithm)?
window.pack();
window.setVisible(true);
}
}