Lines 45-50
Link Here
|
45 |
|
45 |
|
46 |
package org.netbeans.modules.jumpto.file; |
46 |
package org.netbeans.modules.jumpto.file; |
47 |
|
47 |
|
|
|
48 |
import java.awt.BorderLayout; |
49 |
import java.awt.Color; |
50 |
import java.awt.Component; |
51 |
import java.awt.Container; |
48 |
import java.awt.Dialog; |
52 |
import java.awt.Dialog; |
49 |
import java.awt.Dimension; |
53 |
import java.awt.Dimension; |
50 |
import java.awt.Rectangle; |
54 |
import java.awt.Rectangle; |
Lines 56-62
Link Here
|
56 |
import java.util.ArrayList; |
60 |
import java.util.ArrayList; |
57 |
import java.util.Collection; |
61 |
import java.util.Collection; |
58 |
import java.util.Collections; |
62 |
import java.util.Collections; |
|
|
63 |
import java.util.Comparator; |
59 |
import java.util.Enumeration; |
64 |
import java.util.Enumeration; |
|
|
65 |
import java.util.LinkedList; |
60 |
import java.util.List; |
66 |
import java.util.List; |
61 |
import java.util.logging.Level; |
67 |
import java.util.logging.Level; |
62 |
import java.util.logging.Logger; |
68 |
import java.util.logging.Logger; |
Lines 64-75
Link Here
|
64 |
import java.util.regex.Pattern; |
70 |
import java.util.regex.Pattern; |
65 |
import java.util.regex.PatternSyntaxException; |
71 |
import java.util.regex.PatternSyntaxException; |
66 |
import javax.swing.AbstractAction; |
72 |
import javax.swing.AbstractAction; |
|
|
73 |
import javax.swing.DefaultListCellRenderer; |
67 |
import javax.swing.DefaultListModel; |
74 |
import javax.swing.DefaultListModel; |
|
|
75 |
import javax.swing.Icon; |
76 |
import javax.swing.ImageIcon; |
68 |
import javax.swing.JButton; |
77 |
import javax.swing.JButton; |
|
|
78 |
import javax.swing.JLabel; |
69 |
import javax.swing.JList; |
79 |
import javax.swing.JList; |
|
|
80 |
import javax.swing.JPanel; |
81 |
import javax.swing.JViewport; |
70 |
import javax.swing.ListCellRenderer; |
82 |
import javax.swing.ListCellRenderer; |
71 |
import javax.swing.ListModel; |
83 |
import javax.swing.ListModel; |
|
|
84 |
import javax.swing.SwingConstants; |
72 |
import javax.swing.SwingUtilities; |
85 |
import javax.swing.SwingUtilities; |
|
|
86 |
import javax.swing.event.ChangeEvent; |
87 |
import javax.swing.event.ChangeListener; |
73 |
import org.netbeans.api.project.FileOwnerQuery; |
88 |
import org.netbeans.api.project.FileOwnerQuery; |
74 |
import org.netbeans.api.project.Project; |
89 |
import org.netbeans.api.project.Project; |
75 |
import org.netbeans.api.project.ProjectUtils; |
90 |
import org.netbeans.api.project.ProjectUtils; |
Lines 80-85
Link Here
|
80 |
import org.netbeans.modules.jumpto.type.Models; |
95 |
import org.netbeans.modules.jumpto.type.Models; |
81 |
import org.netbeans.modules.parsing.spi.indexing.support.IndexResult; |
96 |
import org.netbeans.modules.parsing.spi.indexing.support.IndexResult; |
82 |
import org.netbeans.modules.parsing.spi.indexing.support.QuerySupport; |
97 |
import org.netbeans.modules.parsing.spi.indexing.support.QuerySupport; |
|
|
98 |
import org.netbeans.spi.jumpto.file.FileProvider; |
99 |
import org.netbeans.spi.jumpto.file.FileProviderFactory; |
100 |
import org.netbeans.spi.jumpto.type.SearchType; |
83 |
import org.openide.DialogDescriptor; |
101 |
import org.openide.DialogDescriptor; |
84 |
import org.openide.DialogDisplayer; |
102 |
import org.openide.DialogDisplayer; |
85 |
import org.openide.awt.Mnemonics; |
103 |
import org.openide.awt.Mnemonics; |
Lines 87-92
Link Here
|
87 |
import org.openide.filesystems.FileUtil; |
105 |
import org.openide.filesystems.FileUtil; |
88 |
import org.openide.loaders.DataObject; |
106 |
import org.openide.loaders.DataObject; |
89 |
import org.openide.util.HelpCtx; |
107 |
import org.openide.util.HelpCtx; |
|
|
108 |
import org.openide.util.ImageUtilities; |
90 |
import org.openide.util.Lookup; |
109 |
import org.openide.util.Lookup; |
91 |
import org.openide.util.NbBundle; |
110 |
import org.openide.util.NbBundle; |
92 |
import org.openide.util.RequestProcessor; |
111 |
import org.openide.util.RequestProcessor; |
Lines 109-114
Link Here
|
109 |
private JButton openBtn; |
128 |
private JButton openBtn; |
110 |
private FileSearchPanel panel; |
129 |
private FileSearchPanel panel; |
111 |
private Dimension initialDimension; |
130 |
private Dimension initialDimension; |
|
|
131 |
private Iterable<? extends FileProvider> providers; |
112 |
|
132 |
|
113 |
public FileSearchAction() { |
133 |
public FileSearchAction() { |
114 |
super( NbBundle.getMessage(FileSearchAction.class, "CTL_FileSearchAction") ); |
134 |
super( NbBundle.getMessage(FileSearchAction.class, "CTL_FileSearchAction") ); |
Lines 135-141
Link Here
|
135 |
|
155 |
|
136 |
|
156 |
|
137 |
public ListCellRenderer getListCellRenderer( JList list ) { |
157 |
public ListCellRenderer getListCellRenderer( JList list ) { |
138 |
return new FileDescription.Renderer( list ); |
158 |
return new Renderer( list ); |
139 |
} |
159 |
} |
140 |
|
160 |
|
141 |
|
161 |
|
Lines 205-235
Link Here
|
205 |
|
225 |
|
206 |
private FileDescription[] getSelectedFiles() { |
226 |
private FileDescription[] getSelectedFiles() { |
207 |
FileDescription[] result = null; |
227 |
FileDescription[] result = null; |
208 |
// try { |
228 |
panel = new FileSearchPanel(this, findCurrentProject()); |
209 |
panel = new FileSearchPanel(this, findCurrentProject()); |
229 |
dialog = createDialog(panel); |
210 |
dialog = createDialog(panel); |
230 |
dialog.setVisible(true); |
211 |
|
231 |
result = panel.getSelectedFiles(); |
212 |
// Node[] arr = TopComponent.getRegistry ().getActivatedNodes(); |
|
|
213 |
// String initSearchText = null; |
214 |
// if (arr.length > 0) { |
215 |
// EditorCookie ec = arr[0].getCookie (EditorCookie.class); |
216 |
// if (ec != null) { |
217 |
// JEditorPane[] openedPanes = ec.getOpenedPanes (); |
218 |
// if (openedPanes != null) { |
219 |
// initSearchText = org.netbeans.editor.Utilities.getSelectionOrIdentifier(openedPanes [0]); |
220 |
// if (initSearchText != null && org.openide.util.Utilities.isJavaIdentifier(initSearchText)) { |
221 |
// panel.setInitialText(initSearchText); |
222 |
// } |
223 |
// } |
224 |
// } |
225 |
// } |
226 |
|
227 |
dialog.setVisible(true); |
228 |
result = panel.getSelectedFiles(); |
229 |
|
230 |
// } catch (IOException ex) { |
231 |
// ErrorManager.getDefault().notify(ex); |
232 |
// } |
233 |
return result; |
232 |
return result; |
234 |
} |
233 |
} |
235 |
|
234 |
|
Lines 306-316
Link Here
|
306 |
// } |
305 |
// } |
307 |
|
306 |
|
308 |
private void cleanup() { |
307 |
private void cleanup() { |
309 |
//System.out.println("CLEANUP"); |
|
|
310 |
//Thread.dumpStack(); |
311 |
|
308 |
|
312 |
if ( dialog != null ) { // Closing event for some reson sent twice |
309 |
if ( dialog != null ) { // Closing event for some reson sent twice |
313 |
|
310 |
//Free SPI |
|
|
311 |
synchronized (this) { |
312 |
providers = null; |
313 |
} |
314 |
// Save dialog size only when changed |
314 |
// Save dialog size only when changed |
315 |
final int currentWidth = dialog.getWidth(); |
315 |
final int currentWidth = dialog.getWidth(); |
316 |
final int currentHeight = dialog.getHeight(); |
316 |
final int currentHeight = dialog.getHeight(); |
Lines 323-330
Link Here
|
323 |
dialog.dispose(); |
323 |
dialog.dispose(); |
324 |
this.dialog = null; |
324 |
this.dialog = null; |
325 |
//GoToTypeAction.this.cache = null; |
325 |
//GoToTypeAction.this.cache = null; |
326 |
|
|
|
327 |
FileSearchOptions.flush(); |
326 |
FileSearchOptions.flush(); |
|
|
327 |
} |
328 |
} |
329 |
|
330 |
private Iterable<? extends FileProvider> getProviders() { |
331 |
synchronized (this) { |
332 |
if (providers != null) { |
333 |
return providers; |
334 |
} |
335 |
} |
336 |
final List<FileProvider> result = new LinkedList<FileProvider>(); |
337 |
for (FileProviderFactory fpf : Lookup.getDefault().lookupAll(FileProviderFactory.class)) { |
338 |
result.add(fpf.createFileProvider()); |
339 |
} |
340 |
synchronized (this) { |
341 |
if (providers == null) { |
342 |
providers = Collections.unmodifiableList(result); |
343 |
} |
344 |
return providers; |
328 |
} |
345 |
} |
329 |
} |
346 |
} |
330 |
|
347 |
|
Lines 339-344
Link Here
|
339 |
private class Worker implements Runnable { |
356 |
private class Worker implements Runnable { |
340 |
|
357 |
|
341 |
private volatile boolean isCanceled = false; |
358 |
private volatile boolean isCanceled = false; |
|
|
359 |
private volatile FileProvider currentProvider; |
342 |
|
360 |
|
343 |
private final String text; |
361 |
private final String text; |
344 |
private final QuerySupport.Kind searchType; |
362 |
private final QuerySupport.Kind searchType; |
Lines 391-398
Link Here
|
391 |
if ( panel.time != -1 ) { |
409 |
if ( panel.time != -1 ) { |
392 |
LOGGER.fine( "Worker for text " + text + " canceled after " + ( System.currentTimeMillis() - createTime ) + " ms." ); |
410 |
LOGGER.fine( "Worker for text " + text + " canceled after " + ( System.currentTimeMillis() - createTime ) + " ms." ); |
393 |
} |
411 |
} |
|
|
412 |
FileProvider provider; |
394 |
synchronized (this) { |
413 |
synchronized (this) { |
395 |
isCanceled = true; |
414 |
isCanceled = true; |
|
|
415 |
provider = currentProvider; |
416 |
} |
417 |
if (provider != null) { |
418 |
provider.cancel(); |
396 |
} |
419 |
} |
397 |
} |
420 |
} |
398 |
|
421 |
|
Lines 402-413
Link Here
|
402 |
case CASE_INSENSITIVE_PREFIX: |
425 |
case CASE_INSENSITIVE_PREFIX: |
403 |
case CASE_INSENSITIVE_REGEXP: |
426 |
case CASE_INSENSITIVE_REGEXP: |
404 |
searchField = FileIndexer.FIELD_CASE_INSENSITIVE_NAME; break; |
427 |
searchField = FileIndexer.FIELD_CASE_INSENSITIVE_NAME; break; |
405 |
|
|
|
406 |
default: |
428 |
default: |
407 |
searchField = FileIndexer.FIELD_NAME; break; |
429 |
searchField = FileIndexer.FIELD_NAME; break; |
408 |
} |
430 |
} |
409 |
|
431 |
|
410 |
Collection<? extends FileObject> roots = QuerySupport.findRoots((Project) null, null, Collections.<String>emptyList(), Collections.<String>emptyList()); |
432 |
final Collection<FileObject> roots = new ArrayList<FileObject>(QuerySupport.findRoots((Project) null, null, Collections.<String>emptyList(), Collections.<String>emptyList())); |
411 |
try { |
433 |
try { |
412 |
QuerySupport q = QuerySupport.forRoots(FileIndexer.ID, FileIndexer.VERSION, roots.toArray(new FileObject [roots.size()])); |
434 |
QuerySupport q = QuerySupport.forRoots(FileIndexer.ID, FileIndexer.VERSION, roots.toArray(new FileObject [roots.size()])); |
413 |
Collection<? extends IndexResult> results = q.query(searchField, text, searchType); |
435 |
Collection<? extends IndexResult> results = q.query(searchField, text, searchType); |
Lines 430-447
Link Here
|
430 |
files.add(fd); |
452 |
files.add(fd); |
431 |
LOGGER.finer("Found: " + file.getPath() + ", project=" + project + ", currentProject=" + currentProject + ", preferred=" + preferred); |
453 |
LOGGER.finer("Found: " + file.getPath() + ", project=" + project + ", currentProject=" + currentProject + ", preferred=" + preferred); |
432 |
} |
454 |
} |
|
|
455 |
if (isCanceled) { |
456 |
return files; |
457 |
} |
458 |
|
459 |
final Project[] projects = OpenProjects.getDefault().getOpenProjects(); |
460 |
final List<FileObject> sgRoots = new LinkedList<FileObject>(); |
461 |
for (Project p : projects) { |
462 |
for (SourceGroup group: ProjectUtils.getSources(p).getSourceGroups(Sources.TYPE_GENERIC)) { |
463 |
sgRoots.add(group.getRootFolder()); |
464 |
} |
465 |
} |
466 |
//Ask GTF providers |
467 |
final FileProvider.Context ctx = FileProviderAccessor.getInstance().createContext(text, toJumpToSearchType(searchType), currentProject); |
468 |
final FileProvider.Result fpR = FileProviderAccessor.getInstance().createResult(files,new String[1], ctx); |
469 |
for (FileProvider provider : getProviders()) { |
470 |
currentProvider = provider; |
471 |
try { |
472 |
for (FileObject root : sgRoots) { |
473 |
FileProviderAccessor.getInstance().setRoot(ctx, root); |
474 |
boolean recognized = provider.computeFiles(ctx, fpR); |
475 |
if (recognized) { |
476 |
roots.add(root); |
477 |
} |
478 |
} |
479 |
} finally { |
480 |
currentProvider = null; |
481 |
if (isCanceled) { |
482 |
return files; |
483 |
} |
484 |
} |
485 |
} |
486 |
|
433 |
//PENDING Now we have to search folders which not included in Search API |
487 |
//PENDING Now we have to search folders which not included in Search API |
434 |
Project[] projects = OpenProjects.getDefault().getOpenProjects(); |
488 |
Collection <FileObject> allFolders = new ArrayList<FileObject>(); |
435 |
Enumeration <? extends FileObject> projectFolders; |
|
|
436 |
Collection <? extends FileObject> allFolders = new ArrayList<FileObject>(); |
437 |
final FileObjectFilter[] filters = new FileObjectFilter[]{SearchInfoFactory.VISIBILITY_FILTER, SearchInfoFactory.SHARABILITY_FILTER}; |
489 |
final FileObjectFilter[] filters = new FileObjectFilter[]{SearchInfoFactory.VISIBILITY_FILTER, SearchInfoFactory.SHARABILITY_FILTER}; |
438 |
for (Project p : projects) { |
490 |
for (FileObject root : sgRoots) { |
439 |
Sources s = ProjectUtils.getSources(p); |
491 |
allFolders = searchSources(root, allFolders, roots, filters); |
440 |
SourceGroup[] groups = s.getSourceGroups(Sources.TYPE_GENERIC); |
|
|
441 |
for (SourceGroup group: groups) { |
442 |
FileObject root = group.getRootFolder(); |
443 |
allFolders = searchSources(root, allFolders, roots, filters); |
444 |
} |
445 |
} |
492 |
} |
446 |
//Looking for matching files in all found folders |
493 |
//Looking for matching files in all found folders |
447 |
for (FileObject folder: allFolders) { |
494 |
for (FileObject folder: allFolders) { |
Lines 467-473
Link Here
|
467 |
} |
514 |
} |
468 |
} |
515 |
} |
469 |
} |
516 |
} |
470 |
Collections.sort(files, new FileDescription.FDComarator(panel.isPreferedProject(), panel.isCaseSensitive())); |
517 |
Collections.sort(files, new FDComarator(panel.isPreferedProject(), panel.isCaseSensitive())); |
471 |
return files; |
518 |
return files; |
472 |
} catch (PatternSyntaxException pse) { |
519 |
} catch (PatternSyntaxException pse) { |
473 |
return Collections.<FileDescription>emptyList(); |
520 |
return Collections.<FileDescription>emptyList(); |
Lines 475-528
Link Here
|
475 |
LOGGER.log(Level.WARNING, null, ioe); |
522 |
LOGGER.log(Level.WARNING, null, ioe); |
476 |
return Collections.<FileDescription>emptyList(); |
523 |
return Collections.<FileDescription>emptyList(); |
477 |
} |
524 |
} |
|
|
525 |
} |
478 |
|
526 |
|
479 |
|
527 |
private SearchType toJumpToSearchType(final QuerySupport.Kind searchType) { |
480 |
// // TODO: Search twice, first for current project, then for all projects |
528 |
switch (searchType) { |
481 |
// List<TypeDescriptor> items; |
529 |
case CAMEL_CASE: |
482 |
// // Multiple providers: merge results |
530 |
case CASE_INSENSITIVE_CAMEL_CASE: |
483 |
// items = new ArrayList<TypeDescriptor>(128); |
531 |
return org.netbeans.spi.jumpto.type.SearchType.CAMEL_CASE; |
484 |
// String[] message = new String[1]; |
532 |
case CASE_INSENSITIVE_PREFIX: |
485 |
// TypeProvider.Context context = TypeProviderAccessor.DEFAULT.createContext(null, text, nameKind); |
533 |
return org.netbeans.spi.jumpto.type.SearchType.CASE_INSENSITIVE_PREFIX; |
486 |
// TypeProvider.Result result = TypeProviderAccessor.DEFAULT.createResult(items, message); |
534 |
case CASE_INSENSITIVE_REGEXP: |
487 |
// if (typeProviders == null) { |
535 |
return org.netbeans.spi.jumpto.type.SearchType.CASE_INSENSITIVE_REGEXP; |
488 |
// typeProviders = Lookup.getDefault().lookupAll(TypeProvider.class); |
536 |
case EXACT: |
489 |
// } |
537 |
return org.netbeans.spi.jumpto.type.SearchType.EXACT_NAME; |
490 |
// for (TypeProvider provider : typeProviders) { |
538 |
case PREFIX: |
491 |
// if (isCanceled) { |
539 |
return org.netbeans.spi.jumpto.type.SearchType.PREFIX; |
492 |
// return null; |
540 |
case REGEXP: |
493 |
// } |
541 |
return org.netbeans.spi.jumpto.type.SearchType.REGEXP; |
494 |
// current = provider; |
542 |
default: |
495 |
// long start = System.currentTimeMillis(); |
543 |
throw new IllegalArgumentException(); |
496 |
// try { |
544 |
} |
497 |
// LOGGER.fine("Calling TypeProvider: " + provider); |
|
|
498 |
// provider.computeTypeNames(context, result); |
499 |
// } finally { |
500 |
// current = null; |
501 |
// } |
502 |
// long delta = System.currentTimeMillis() - start; |
503 |
// LOGGER.fine("Provider '" + provider.getDisplayName() + "' took " + delta + " ms."); |
504 |
// |
505 |
// } |
506 |
// if ( !isCanceled ) { |
507 |
// //time = System.currentTimeMillis(); |
508 |
// Collections.sort(items, new TypeComparator()); |
509 |
// panel.setWarning(message[0]); |
510 |
// //sort += System.currentTimeMillis() - time; |
511 |
// //LOGGER.fine("PERF - " + " GSS: " + gss + " GSB " + gsb + " CP: " + cp + " SFB: " + sfb + " GTN: " + gtn + " ADD: " + add + " SORT: " + sort ); |
512 |
// return items; |
513 |
// } |
514 |
// else { |
515 |
// return null; |
516 |
// } |
517 |
} |
545 |
} |
518 |
} // End of Worker class |
546 |
} // End of Worker class |
519 |
|
547 |
|
520 |
private Collection<? extends FileObject> searchSources(FileObject root, Collection<? extends FileObject> result, Collection<? extends FileObject> exclude, FileObjectFilter[] filters) { |
548 |
private Collection<FileObject> searchSources(FileObject root, Collection<FileObject> result, Collection<? extends FileObject> exclude, FileObjectFilter[] filters) { |
521 |
if (root.getChildren().length == 0 || exclude.contains(root) || !checkAgainstFilters(root, filters)) { |
549 |
if (root.getChildren().length == 0 || exclude.contains(root) || !checkAgainstFilters(root, filters)) { |
522 |
return result; |
550 |
return result; |
523 |
} else { |
551 |
} else { |
524 |
// if (!exclude.contains(root)) { |
552 |
// if (!exclude.contains(root)) { |
525 |
((Collection<FileObject>)result).add(root); |
553 |
result.add(root); |
526 |
Enumeration<? extends FileObject> subFolders = root.getFolders(false); |
554 |
Enumeration<? extends FileObject> subFolders = root.getFolders(false); |
527 |
while (subFolders.hasMoreElements()) { |
555 |
while (subFolders.hasMoreElements()) { |
528 |
searchSources(subFolders.nextElement(), result, exclude, filters); |
556 |
searchSources(subFolders.nextElement(), result, exclude, filters); |
Lines 681-687
Link Here
|
681 |
panel.setSelectedFile(); |
709 |
panel.setSelectedFile(); |
682 |
} |
710 |
} |
683 |
} |
711 |
} |
684 |
|
|
|
685 |
} |
712 |
} |
686 |
|
713 |
|
|
|
714 |
//Inner classes |
715 |
public static class FDComarator implements Comparator<FileDescription> { |
716 |
|
717 |
private boolean usePrefered; |
718 |
private boolean caseSensitive; |
719 |
|
720 |
public FDComarator(boolean usePrefered, boolean caseSensitive ) { |
721 |
this.usePrefered = usePrefered; |
722 |
this.caseSensitive = caseSensitive; |
723 |
} |
724 |
|
725 |
public int compare(FileDescription o1, FileDescription o2) { |
726 |
|
727 |
// If prefered prefer prefered |
728 |
if ( usePrefered ) { |
729 |
if ( o1.isFromCurrentProject() && !o2.isFromCurrentProject()) { |
730 |
return -1; |
731 |
} |
732 |
if ( !o1.isFromCurrentProject() && o2.isFromCurrentProject()) { |
733 |
return 1; |
734 |
} |
735 |
} |
736 |
|
737 |
// File name |
738 |
int cmpr = compareStrings( o1.getFileName(), o2.getFileName(), caseSensitive ); |
739 |
if ( cmpr != 0 ) { |
740 |
return cmpr; |
741 |
} |
742 |
|
743 |
// Project name |
744 |
cmpr = compareStrings( o1.getProjectName(), o2.getProjectName(), caseSensitive ); |
745 |
if ( cmpr != 0 ) { |
746 |
return cmpr; |
747 |
} |
748 |
|
749 |
// Relative location |
750 |
cmpr = compareStrings( o1.getOwnerPath(), o2.getOwnerPath(), caseSensitive ); |
751 |
|
752 |
return cmpr; |
753 |
|
754 |
} |
755 |
|
756 |
private int compareStrings(String s1, String s2, boolean caseSensitive) { |
757 |
if( s1 == null ) { |
758 |
s1 = ""; //NOI18N |
759 |
} |
760 |
if ( s2 == null ) { |
761 |
s2 = ""; //NOI18N |
762 |
} |
763 |
|
764 |
|
765 |
return caseSensitive ? s1.compareTo( s2 ) : s1.compareToIgnoreCase( s2 ); |
766 |
} |
767 |
} |
768 |
|
769 |
private static class RendererComponent extends JPanel { |
770 |
private FileDescription fd; |
771 |
|
772 |
void setDescription(FileDescription fd) { |
773 |
this.fd = fd; |
774 |
putClientProperty(TOOL_TIP_TEXT_KEY, null); |
775 |
} |
776 |
|
777 |
@Override |
778 |
public String getToolTipText() { |
779 |
String text = (String) getClientProperty(TOOL_TIP_TEXT_KEY); |
780 |
if( text == null ) { |
781 |
if( fd != null) { |
782 |
text = FileUtil.getFileDisplayName(fd.getFileObject()); |
783 |
} |
784 |
putClientProperty(TOOL_TIP_TEXT_KEY, text); |
785 |
} |
786 |
return text; |
787 |
} |
788 |
} |
789 |
|
790 |
public static class Renderer extends DefaultListCellRenderer implements ChangeListener { |
791 |
|
792 |
public static Icon WAIT_ICON = ImageUtilities.loadImageIcon("org/netbeans/modules/jumpto/resources/wait.gif", false); // NOI18N |
793 |
|
794 |
private RendererComponent rendererComponent; |
795 |
private JLabel jlName = new JLabel(); |
796 |
private JLabel jlPath = new JLabel(); |
797 |
private JLabel jlPrj = new JLabel(); |
798 |
private int DARKER_COLOR_COMPONENT = 5; |
799 |
private int LIGHTER_COLOR_COMPONENT = 80; |
800 |
private Color fgColor; |
801 |
private Color fgColorLighter; |
802 |
private Color bgColor; |
803 |
private Color bgColorDarker; |
804 |
private Color bgSelectionColor; |
805 |
private Color fgSelectionColor; |
806 |
private Color bgColorGreener; |
807 |
private Color bgColorDarkerGreener; |
808 |
|
809 |
private JList jList; |
810 |
|
811 |
private boolean colorPrefered; |
812 |
|
813 |
public Renderer( JList list ) { |
814 |
|
815 |
jList = list; |
816 |
|
817 |
Container container = list.getParent(); |
818 |
if ( container instanceof JViewport ) { |
819 |
((JViewport)container).addChangeListener(this); |
820 |
stateChanged(new ChangeEvent(container)); |
821 |
} |
822 |
|
823 |
rendererComponent = new RendererComponent(); |
824 |
rendererComponent.setLayout(new BorderLayout()); |
825 |
rendererComponent.add( jlName, BorderLayout.WEST ); |
826 |
rendererComponent.add( jlPath, BorderLayout.CENTER); |
827 |
rendererComponent.add( jlPrj, BorderLayout.EAST ); |
828 |
|
829 |
|
830 |
jlName.setOpaque(false); |
831 |
jlPath.setOpaque(false); |
832 |
jlPrj.setOpaque(false); |
833 |
|
834 |
jlName.setFont(list.getFont()); |
835 |
jlPath.setFont(list.getFont()); |
836 |
jlPrj.setFont(list.getFont()); |
837 |
|
838 |
|
839 |
jlPrj.setHorizontalAlignment(RIGHT); |
840 |
jlPrj.setHorizontalTextPosition(LEFT); |
841 |
|
842 |
// setFont( list.getFont() ); |
843 |
fgColor = list.getForeground(); |
844 |
fgColorLighter = new Color( |
845 |
Math.min( 255, fgColor.getRed() + LIGHTER_COLOR_COMPONENT), |
846 |
Math.min( 255, fgColor.getGreen() + LIGHTER_COLOR_COMPONENT), |
847 |
Math.min( 255, fgColor.getBlue() + LIGHTER_COLOR_COMPONENT) |
848 |
); |
849 |
|
850 |
bgColor = list.getBackground(); |
851 |
bgColorDarker = new Color( |
852 |
Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT), |
853 |
Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT), |
854 |
Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT) |
855 |
); |
856 |
bgSelectionColor = list.getSelectionBackground(); |
857 |
fgSelectionColor = list.getSelectionForeground(); |
858 |
|
859 |
|
860 |
bgColorGreener = new Color( |
861 |
Math.abs(bgColor.getRed() - 20), |
862 |
Math.min(255, bgColor.getGreen() + 10 ), |
863 |
Math.abs(bgColor.getBlue() - 20) ); |
864 |
|
865 |
|
866 |
bgColorDarkerGreener = new Color( |
867 |
Math.abs(bgColorDarker.getRed() - 35), |
868 |
Math.min(255, bgColorDarker.getGreen() + 5 ), |
869 |
Math.abs(bgColorDarker.getBlue() - 35) ); |
870 |
} |
871 |
|
872 |
public @Override Component getListCellRendererComponent( JList list, |
873 |
Object value, |
874 |
int index, |
875 |
boolean isSelected, |
876 |
boolean hasFocus) { |
877 |
|
878 |
// System.out.println("Renderer for index " + index ); |
879 |
|
880 |
int height = list.getFixedCellHeight(); |
881 |
int width = list.getFixedCellWidth() - 1; |
882 |
|
883 |
width = width < 200 ? 200 : width; |
884 |
|
885 |
// System.out.println("w, h " + width + ", " + height ); |
886 |
|
887 |
Dimension size = new Dimension( width, height ); |
888 |
rendererComponent.setMaximumSize(size); |
889 |
rendererComponent.setPreferredSize(size); |
890 |
|
891 |
if ( isSelected ) { |
892 |
jlName.setForeground(fgSelectionColor); |
893 |
jlPath.setForeground(fgSelectionColor); |
894 |
jlPrj.setForeground(fgSelectionColor); |
895 |
rendererComponent.setBackground(bgSelectionColor); |
896 |
} |
897 |
else { |
898 |
jlName.setForeground(fgColor); |
899 |
jlPath.setForeground(fgColorLighter); |
900 |
jlPrj.setForeground(fgColor); |
901 |
rendererComponent.setBackground( index % 2 == 0 ? bgColor : bgColorDarker ); |
902 |
} |
903 |
|
904 |
if ( value instanceof FileDescription ) { |
905 |
FileDescription fd = (FileDescription)value; |
906 |
jlName.setIcon(fd.getIcon()); |
907 |
jlName.setText(fd.getFileName()); |
908 |
jlPath.setIcon(null); |
909 |
jlPath.setHorizontalAlignment(SwingConstants.LEFT); |
910 |
jlPath.setText(fd.getOwnerPath().length() > 0 ? " (" + fd.getOwnerPath() + ")" : " ()"); //NOI18N |
911 |
jlPrj.setText(fd.getProjectName()); |
912 |
jlPrj.setIcon(fd.getProjectIcon()); |
913 |
if ( !isSelected ) { |
914 |
rendererComponent.setBackground( index % 2 == 0 ? |
915 |
( fd.isFromCurrentProject() && colorPrefered ? bgColorGreener : bgColor ) : |
916 |
( fd.isFromCurrentProject() && colorPrefered ? bgColorDarkerGreener : bgColorDarker ) ); |
917 |
} |
918 |
rendererComponent.setDescription(fd); |
919 |
} |
920 |
else { |
921 |
jlName.setText( "" ); // NOI18M |
922 |
jlName.setIcon(null); |
923 |
jlPath.setIcon(Renderer.WAIT_ICON); |
924 |
jlPath.setHorizontalAlignment(SwingConstants.CENTER); |
925 |
jlPath.setText( value.toString() ); |
926 |
jlPrj.setIcon(null); |
927 |
jlPrj.setText( "" ); // NOI18N |
928 |
} |
929 |
|
930 |
return rendererComponent; |
931 |
} |
932 |
|
933 |
@Override |
934 |
public void stateChanged(ChangeEvent event) { |
935 |
|
936 |
JViewport jv = (JViewport)event.getSource(); |
937 |
|
938 |
jlName.setText( "Sample" ); // NOI18N |
939 |
jlName.setIcon( new ImageIcon() ); |
940 |
|
941 |
jList.setFixedCellHeight(jlName.getPreferredSize().height); |
942 |
jList.setFixedCellWidth(jv.getExtentSize().width); |
943 |
} |
944 |
|
945 |
public void setColorPrefered( boolean colorPrefered ) { |
946 |
this.colorPrefered = colorPrefered; |
947 |
} |
948 |
|
949 |
} |
687 |
} |
950 |
} |