KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > editor > fold > FoldHierarchyTestEnv


1 package org.netbeans.modules.editor.fold;
2
3 import javax.swing.JEditorPane JavaDoc;
4 import javax.swing.text.AbstractDocument JavaDoc;
5 import org.netbeans.api.editor.fold.FoldHierarchy;
6 import org.netbeans.spi.editor.fold.FoldManagerFactory;
7
8 /*
9  * FoldHierarchyExecutionTest.java
10  * JUnit based test
11  *
12  * Created on June 27, 2004, 1:03 AM
13  */

14
15
16 /**
17  *
18  * @author mmetelka
19  */

20 class FoldHierarchyTestEnv {
21     
22     private JEditorPane JavaDoc pane;
23     
24     FoldHierarchyTestEnv(FoldManagerFactory factory) {
25         this(new FoldManagerFactory[] { factory });
26     }
27
28     FoldHierarchyTestEnv(FoldManagerFactory[] factories) {
29         pane = new JEditorPane JavaDoc();
30         assert (getMimeType() != null);
31
32         FoldManagerFactoryProvider.setForceCustomProvider(true);
33         FoldManagerFactoryProvider provider = FoldManagerFactoryProvider.getDefault();
34         assert (provider instanceof CustomProvider)
35             : "setForceCustomProvider(true) did not ensure CustomProvider use"; // NOI18N
36

37         CustomProvider customProvider = (CustomProvider)provider;
38         customProvider.removeAllFactories(); // cleanup all registered factories
39
customProvider.registerFactories(getMimeType(), factories);
40     }
41
42     public JEditorPane JavaDoc getPane() {
43         return pane;
44     }
45     
46     public AbstractDocument JavaDoc getDocument() {
47         return (AbstractDocument JavaDoc)getPane().getDocument();
48     }
49     
50     public String JavaDoc getMimeType() {
51         return pane.getEditorKit().getContentType();
52     }
53     
54     public FoldHierarchy getHierarchy() {
55         FoldHierarchy hierarchy = FoldHierarchy.get(getPane());
56         assert (hierarchy != null);
57         return hierarchy;
58     }
59     
60 }
61
Popular Tags