1 33 34 package edu.rice.cs.util.docnavigation; 35 36 import edu.rice.cs.plt.tuple.Pair; 37 import edu.rice.cs.util.swing.Utilities; 38 39 import java.util.List ; 40 import java.util.*; 41 import java.awt.event.FocusListener ; 42 43 public class AWTContainerNavigatorFactory<ItemT extends INavigatorItem> implements IDocumentNavigatorFactory<ItemT> { 44 45 public AWTContainerNavigatorFactory() { } 46 47 50 public IDocumentNavigator<ItemT> makeListNavigator() { return new JListSortNavigator<ItemT>(); } 51 52 56 public IDocumentNavigator<ItemT> makeTreeNavigator(String path) { return new JTreeSortNavigator<ItemT>(path); } 57 58 63 public IDocumentNavigator<ItemT> makeListNavigator(final IDocumentNavigator<ItemT> parent) { 64 final IDocumentNavigator<ItemT> child = makeListNavigator(); 65 Utilities.invokeLater(new Runnable () { 66 public void run() { 67 migrateNavigatorItems(child, parent); 69 migrateListeners(child, parent); 70 } 71 }); 73 return child; 74 } 75 76 82 public IDocumentNavigator<ItemT> makeTreeNavigator(String name, final IDocumentNavigator<ItemT> parent, 83 final List <Pair<String , INavigatorItemFilter<ItemT>>> l) { 84 85 final IDocumentNavigator<ItemT> child = makeTreeNavigator(name); 86 Utilities.invokeLater(new Runnable () { 87 public void run() { 88 for(Pair<String , INavigatorItemFilter<ItemT>> p: l) { child.addTopLevelGroup(p.first(), p.second()); } 90 migrateNavigatorItems(child, parent); 91 migrateListeners(child, parent); 92 } 93 }); 95 return child; 96 } 97 98 102 private void migrateNavigatorItems(IDocumentNavigator<ItemT> child, IDocumentNavigator<ItemT> parent) { 105 Enumeration<ItemT> enumerator = parent.getDocuments(); 106 while (enumerator.hasMoreElements()) { 107 ItemT navitem = enumerator.nextElement(); 108 child.addDocument(navitem); 109 } 110 parent.clear(); } 112 113 117 private void migrateListeners(IDocumentNavigator<ItemT> child, IDocumentNavigator<ItemT> parent) { 120 for (INavigationListener<? super ItemT> nl: parent.getNavigatorListeners()) child.addNavigationListener(nl); 121 for (FocusListener fl: parent.getFocusListeners()) child.addFocusListener(fl); 122 } 123 } 124 | Popular Tags |