2727
2828@ SuppressWarnings ("serial" )
2929public class FileNavigationPane extends JDAWindow implements FileDrop .Listener {
30- private static final String quickSearchText = "Quick file search (no file extension) " ;
30+ private static final String quickSearchText = "File search" ;
3131
3232 FileChangeNotifier fcn ;
33- JCheckBox exact = new JCheckBox ("Match case" );
33+ JCheckBox matchCase = new JCheckBox ("Match case" );
3434
3535 FileNode treeRoot = new FileNode ("Loaded Files:" );
3636 FileTree tree = new FileTree (treeRoot );
@@ -42,58 +42,7 @@ public void keyPressed(final KeyEvent ke) {
4242 if (ke .getKeyCode () == KeyEvent .VK_ENTER ) {
4343 final String qt = quickSearch .getText ();
4444 quickSearch .setText ("" );
45-
46-
47- String [] path = null ;
48-
49- if (qt .contains ("." )) {
50- path = qt .split ("\\ ." );
51- String [] path2 = new String [path .length ];
52- for (int i = 0 ; i < path .length ; i ++) {
53- path2 [i ] = path [i ];
54- if (i + 2 == path .length ) {
55- path2 [i + 1 ] = "." + path [i + 1 ];
56- }
57- }
58- } else {
59- path = new String []{qt };
60- }
61-
62- FileNode curNode = treeRoot ;
63- if (exact .isSelected ()) {
64- // TODO
65- } else {
66- @ SuppressWarnings ("unchecked" )
67- Enumeration <FileNode > enums = curNode .depthFirstEnumeration ();
68- while (enums != null && enums .hasMoreElements ()) {
69-
70- FileNode node = enums .nextElement ();
71- if (node .isLeaf ()) {
72- if (((String ) (node .getUserObject ())).contains (path [path .length - 1 ])) {
73- TreeNode pathArray [] = node .getPath ();
74- int k = 0 ;
75- StringBuilder fullPath = new StringBuilder ();
76- while (pathArray != null && k < pathArray .length ) {
77- FileNode n = (FileNode ) pathArray [k ];
78- String s = (String ) (n .getUserObject ());
79- fullPath .append (s );
80- if (k ++ != pathArray .length - 1 ) {
81- fullPath .append ("." );
82- }
83- }
84- String fullPathString = fullPath .toString ();
85- if (!fullPathString .equals ("null" ) && fullPathString .contains (qt )) {
86- System .out .println ("Found! " + node );
87- final TreePath pathn = new TreePath (node .getPath ());
88- tree .setSelectionPath (pathn .getParentPath ());
89- tree .setSelectionPath (pathn );
90- tree .makeVisible (pathn );
91- tree .scrollPathToVisible (pathn );
92- }
93- }
94- }
95- }
96- }
45+ quickSearch (qt );
9746 } else if (ke .getKeyCode () == KeyEvent .VK_ESCAPE ) {
9847 tree .grabFocus ();
9948 }
@@ -102,6 +51,56 @@ public void keyPressed(final KeyEvent ke) {
10251 }
10352 };
10453
54+ private void quickSearch (String qt ) {
55+ if (!matchCase .isSelected ())
56+ qt = qt .toLowerCase ();
57+ String [] path = qt .split ("\\ ." );
58+ String searchFilename = path [path .length - 1 ];
59+
60+ FileNode curNode = treeRoot ;
61+ @ SuppressWarnings ("unchecked" )
62+ Enumeration <FileNode > enums = curNode .depthFirstEnumeration ();
63+ while (enums != null && enums .hasMoreElements ()) {
64+ FileNode node = enums .nextElement ();
65+ if (!node .isLeaf ()) {
66+ continue ;
67+ }
68+
69+ // Check filename
70+ String leafFilename = (String ) (node .getUserObject ());
71+ if (!matchCase .isSelected ())
72+ leafFilename = leafFilename .toLowerCase ();
73+ if (!leafFilename .contains (searchFilename )) {
74+ continue ;
75+ }
76+
77+ // Check for path match
78+ TreeNode pathArray [] = node .getPath ();
79+ int k = 0 ;
80+ StringBuilder fullPath = new StringBuilder ();
81+ while (pathArray != null && k < pathArray .length ) {
82+ FileNode n = (FileNode ) pathArray [k ];
83+ String s = (String ) (n .getUserObject ());
84+ fullPath .append (s );
85+ if (k ++ != pathArray .length - 1 ) {
86+ fullPath .append ("." );
87+ }
88+ }
89+ String fullPathString = fullPath .toString ();
90+ if (!matchCase .isSelected ())
91+ fullPathString = fullPathString .toLowerCase ();
92+
93+ if (fullPathString .contains (qt )) { // Match found
94+ final TreePath pathn = new TreePath (node .getPath ());
95+ tree .setSelectionPath (pathn .getParentPath ());
96+ tree .setSelectionPath (pathn );
97+ tree .makeVisible (pathn );
98+ tree .scrollPathToVisible (pathn );
99+ break ;
100+ }
101+ }
102+ }
103+
105104 public FileNavigationPane (final FileChangeNotifier fcn ) {
106105 super ("ClassNavigation" , "File Navigator" , Resources .fileNavigatorIcon , (MainViewerGUI ) fcn );
107106
@@ -167,7 +166,8 @@ public void focusLost(final FocusEvent arg0) {
167166 p2 .setLayout (new BorderLayout ());
168167 p2 .add (quickSearch , BorderLayout .NORTH );
169168 JPanel p3 = new JPanel (new BorderLayout ());
170- p3 .add (exact , BorderLayout .WEST );
169+ matchCase .setSelected (true );
170+ p3 .add (matchCase , BorderLayout .WEST );
171171 JPanel p4 = new JPanel (new BorderLayout ());
172172 p3 .add (p4 , BorderLayout .EAST );
173173 p2 .add (p3 , BorderLayout .SOUTH );
0 commit comments