1 19 20 package org.netbeans.api.editor.guards; 21 22 import javax.swing.text.BadLocationException ; 23 import javax.swing.text.Position ; 24 import javax.swing.text.StyledDocument ; 25 import org.netbeans.modules.editor.guards.GuardedSectionImpl; 26 import org.netbeans.modules.editor.guards.GuardedSectionsImpl; 27 import org.netbeans.modules.editor.guards.GuardsAccessor; 28 import org.netbeans.modules.editor.guards.InteriorSectionImpl; 29 import org.netbeans.modules.editor.guards.SimpleSectionImpl; 30 31 37 public final class GuardedSectionManager { 38 39 44 public static GuardedSectionManager getInstance(StyledDocument doc) { 45 return (GuardedSectionManager) doc.getProperty(GuardedSectionManager.class); 46 } 47 48 54 public SimpleSection findSimpleSection(String name) { 55 GuardedSection s = impl.findSection(name); 56 return (s instanceof SimpleSection) ? (SimpleSection) s : null; 57 } 58 59 65 public InteriorSection findInteriorSection(String name) { 66 GuardedSection s = impl.findSection(name); 67 return (s instanceof InteriorSection) ? (InteriorSection) s : null; 68 } 69 70 83 public SimpleSection createSimpleSection(Position pos, String name) 84 throws IllegalArgumentException , BadLocationException { 85 return impl.createSimpleSection(pos, name); 86 } 87 88 101 public InteriorSection createInteriorSection(Position pos, String name) 102 throws IllegalArgumentException , BadLocationException { 103 return impl.createInteriorSection(pos, name); 104 } 105 106 109 public Iterable <GuardedSection> getGuardedSections() { 110 return impl.getGuardedSections(); 111 } 112 113 115 117 static { 118 GuardsAccessor.DEFAULT = new GuardsAccessor() { 119 public GuardedSectionManager createGuardedSections(GuardedSectionsImpl impl) { 120 return new GuardedSectionManager(impl); 121 } 122 123 public SimpleSection createSimpleSection(SimpleSectionImpl impl) { 124 return new SimpleSection(impl); 125 } 126 127 public InteriorSection createInteriorSection(InteriorSectionImpl impl) { 128 return new InteriorSection(impl); 129 } 130 131 public GuardedSectionImpl getImpl(GuardedSection gs) { 132 return gs.getImpl(); 133 } 134 135 }; 136 } 137 138 139 private GuardedSectionManager(GuardedSectionsImpl impl) { 140 this.impl = impl; 141 } 142 143 private final GuardedSectionsImpl impl; 144 145 } 146 | Popular Tags |