1 19 20 package org.netbeans.modules.editor.guards; 21 22 import java.util.logging.Level ; 23 import java.util.logging.Logger ; 24 import javax.swing.text.BadLocationException ; 25 import javax.swing.text.Position ; 26 import javax.swing.text.StyledDocument ; 27 28 32 public final class SimpleSectionImpl extends GuardedSectionImpl { 33 34 private PositionBounds bounds; 35 36 41 SimpleSectionImpl(String name, PositionBounds bounds, GuardedSectionsImpl guards) { 42 super(name, guards); 43 this.bounds = bounds; 44 } 45 46 50 public void setText(String text) { 51 setText(bounds, text, true); 52 } 53 54 void markGuarded(StyledDocument doc) { 55 markGuarded(doc, bounds, true); 56 } 57 58 62 void unmarkGuarded(StyledDocument doc) { 63 markGuarded(doc, bounds, false); 64 } 65 66 public Position getCaretPosition() { 67 return bounds.getBegin(); 68 } 69 70 public String getText() { 71 String text = ""; try { 73 text = bounds.getText(); 74 } catch (BadLocationException ex) { 75 Logger.getLogger("guards").log(Level.ALL, null, ex); 77 } 78 return text; 79 } 80 81 95 96 public Position getEndPosition() { 97 return bounds.getEnd(); 98 } 99 100 public boolean contains(Position pos, boolean allowHoles) { 101 return bounds.getBegin().getOffset() <= pos.getOffset() && 102 bounds.getEnd().getOffset() >= pos.getOffset(); 103 } 104 105 public Position getStartPosition() { 106 return bounds.getBegin(); 107 } 108 109 public void resolvePositions() throws BadLocationException { 110 bounds.resolvePositions(); 111 } 112 } 113 | Popular Tags |