1 19 20 package org.netbeans.spi.editor.fold; 21 22 import javax.swing.text.BadLocationException ; 23 import org.netbeans.api.editor.fold.Fold; 24 import org.netbeans.api.editor.fold.FoldHierarchy; 25 import org.netbeans.api.editor.fold.FoldType; 26 import org.netbeans.modules.editor.fold.FoldHierarchyTransactionImpl; 27 import org.netbeans.modules.editor.fold.FoldOperationImpl; 28 import org.netbeans.modules.editor.fold.SpiPackageAccessor; 29 30 31 48 49 public final class FoldOperation { 50 51 private static boolean spiPackageAccessorRegistered; 52 53 static { 54 ensureSpiAccessorRegistered(); 55 } 56 57 private static void ensureSpiAccessorRegistered() { 58 if (!spiPackageAccessorRegistered) { 59 spiPackageAccessorRegistered = true; 60 SpiPackageAccessor.register(new SpiPackageAccessorImpl()); 61 } 62 } 63 64 private final FoldOperationImpl impl; 65 66 private FoldOperation(FoldOperationImpl impl) { 67 this.impl = impl; 68 } 69 70 71 106 public Fold addToHierarchy(FoldType type, String description, boolean collapsed, 107 int startOffset, int endOffset, int startGuardedLength, int endGuardedLength, 108 Object extraInfo, FoldHierarchyTransaction transaction) 109 throws BadLocationException { 110 Fold fold = impl.createFold(type, description, collapsed, 111 startOffset, endOffset, startGuardedLength, endGuardedLength, 112 extraInfo 113 ); 114 impl.addToHierarchy(fold, transaction.getImpl()); 115 return fold; 116 } 117 118 140 public static boolean isBoundsValid(int startOffset, int endOffset, 141 int startGuardedLength, int endGuardedLength) { 142 return (startOffset < endOffset) 143 && (startGuardedLength >= 0) 144 && (endGuardedLength >= 0) 145 && ((startOffset + startGuardedLength) <= (endOffset -endGuardedLength)); 146 } 147 148 155 public void removeFromHierarchy(Fold fold, FoldHierarchyTransaction transaction) { 156 impl.removeFromHierarchy(fold, transaction.getImpl()); 157 } 158 159 165 public Object getExtraInfo(Fold fold) { 166 return impl.getExtraInfo(fold); 167 } 168 169 177 public boolean isStartDamaged(Fold fold) { 178 return impl.isStartDamaged(fold); 179 } 180 181 189 public boolean isEndDamaged(Fold fold) { 190 return impl.isEndDamaged(fold); 191 } 192 193 208 public FoldHierarchyTransaction openTransaction() { 209 return impl.openTransaction().getTransaction(); 210 } 211 212 218 public boolean isAddedOrBlocked(Fold fold) { 219 return impl.isAddedOrBlocked(fold); 220 } 221 222 225 public boolean isBlocked(Fold fold) { 226 return impl.isBlocked(fold); 227 } 228 229 232 public FoldHierarchy getHierarchy() { 233 return impl.getHierarchy(); 234 } 235 236 public boolean isReleased() { 237 return impl.isReleased(); 238 } 239 240 241 private static final class SpiPackageAccessorImpl extends SpiPackageAccessor { 242 243 public FoldHierarchyTransaction createFoldHierarchyTransaction( 244 FoldHierarchyTransactionImpl impl) { 245 return new FoldHierarchyTransaction(impl); 246 } 247 248 public FoldHierarchyTransactionImpl getImpl(FoldHierarchyTransaction transaction) { 249 return transaction.getImpl(); 250 } 251 252 public FoldOperation createFoldOperation(FoldOperationImpl impl) { 253 return new FoldOperation(impl); 254 } 255 256 } 257 } 258 | Popular Tags |