1 19 20 package org.netbeans.modules.editor.fold; 21 22 import java.util.ArrayList ; 23 import java.util.Collections ; 24 import java.util.HashMap ; 25 import java.util.List ; 26 import java.util.Map ; 27 import javax.swing.text.EditorKit ; 28 import javax.swing.text.JTextComponent ; 29 import org.netbeans.api.editor.fold.FoldHierarchy; 30 import org.netbeans.spi.editor.fold.FoldManagerFactory; 31 32 40 public class CustomProvider extends FoldManagerFactoryProvider { 41 42 private static final String FOLDER_NAME = "FoldManager"; 44 private final Map mime2factoryList = new HashMap (); 45 46 CustomProvider() { 47 } 48 49 59 public void registerFactory(String mimeType, FoldManagerFactory factory) { 60 assert (mimeType != null) && (factory != null); 61 62 synchronized (mime2factoryList) { 63 List factoryList = (List )mime2factoryList.get(mimeType); 64 if (factoryList == null) { 65 factoryList = new ArrayList (); 66 mime2factoryList.put(mimeType, factoryList); 67 } 68 factoryList.add(factory); 69 } 70 } 71 72 76 public void registerFactories(String mimeType, FoldManagerFactory[] factories) { 77 synchronized (mime2factoryList) { 78 for (int i = 0; i < factories.length; i++) { 79 registerFactory(mimeType, factories[i]); 80 } 81 } 82 } 83 84 public void removeAllFactories(String mimeType) { 85 synchronized (mime2factoryList) { 86 mime2factoryList.put(mimeType, null); 87 } 88 } 89 90 public void removeAllFactories() { 91 synchronized (mime2factoryList) { 92 mime2factoryList.clear(); 93 } 94 } 95 96 public List getFactoryList(FoldHierarchy hierarchy) { 97 List factoryList = null; JTextComponent editorComponent = hierarchy.getComponent(); 99 EditorKit kit = editorComponent.getUI().getEditorKit(editorComponent); 100 if (kit != null) { 101 String mimeType = kit.getContentType(); 102 if (mimeType != null) { 103 synchronized (mime2factoryList) { 104 factoryList = (List )mime2factoryList.get(mimeType); 105 } 106 } 107 } 108 109 if (factoryList == null) { 110 return Collections.EMPTY_LIST; 111 } 112 return factoryList; 113 } 114 115 } 116 | Popular Tags |