1 22 23 package org.gjt.sp.jedit.buffer; 24 25 import javax.swing.text.Segment ; 26 27 35 public class ExplicitFoldHandler extends FoldHandler 36 { 37 public ExplicitFoldHandler() 39 { 40 super("explicit"); 41 } 43 53 public int getFoldLevel(JEditBuffer buffer, int lineIndex, Segment seg) 54 { 55 if(lineIndex == 0) 56 return 0; 57 else 58 { 59 int foldLevel = buffer.getFoldLevel(lineIndex - 1); 60 61 buffer.getLineText(lineIndex - 1,seg); 62 63 int offset = seg.offset; 64 int count = seg.count; 65 66 int openingBrackets = 0, closingBrackets = 0; 67 for(int i = 0; i < count; i++) 68 { 69 switch(seg.array[offset + i]) 70 { 71 case '{': 72 closingBrackets = 0; 73 openingBrackets++; 74 if(openingBrackets == 3) 75 { 76 foldLevel++; 77 openingBrackets = 0; 78 } 79 break; 80 case '}': 81 openingBrackets = 0; 82 closingBrackets++; 83 if(closingBrackets == 3) 84 { 85 if(foldLevel > 0) 86 foldLevel--; 87 closingBrackets = 0; 88 } 89 break; 90 default: 91 closingBrackets = openingBrackets = 0; 92 break; 93 } 94 } 95 96 return foldLevel; 97 } 98 } } 100 | Popular Tags |