Exemplo n.º 1
0
 void pairDraw(GC gc, StyledRegion sr, int start, int end) {
   if (start > text.getCharCount() || end > text.getCharCount()) return;
   if (gc != null) {
     Point left = text.getLocationAtOffset(start);
     Point right = text.getLocationAtOffset(end);
     if (sr != null) {
       if (highlightStyle == HLS_XOR) {
         int resultColor = sr.fore ^ cm.getColor(text.getBackground());
         if (text.getLineAtOffset(text.getCaretOffset()) == text.getLineAtOffset(start)
             && horzCross
             && horzCrossColor != null
             && ((StyledRegion) horzCrossColor).bback)
           resultColor = sr.fore ^ ((StyledRegion) horzCrossColor).back;
         Color color = cm.getColor(sr.bfore, resultColor);
         gc.setBackground(color);
         gc.setXORMode(true);
         gc.fillRectangle(left.x, left.y, right.x - left.x, gc.getFontMetrics().getHeight());
       } else if (highlightStyle == HLS_OUTLINE) {
         Color color = cm.getColor(sr.bfore, sr.fore);
         gc.setForeground(color);
         gc.drawRectangle(
             left.x, left.y, right.x - left.x - 1, gc.getFontMetrics().getHeight() - 1);
       } else if (highlightStyle == HLS_OUTLINE2) {
         Color color = cm.getColor(sr.bfore, sr.fore);
         gc.setForeground(color);
         gc.setLineWidth(2);
         gc.drawRectangle(
             left.x + 1, left.y + 1, right.x - left.x - 2, gc.getFontMetrics().getHeight() - 2);
       }
     }
   } else {
     text.redrawRange(start, end - start, true);
   }
 }
Exemplo n.º 2
0
 /** Moves caret to the position of currently active pair. */
 public boolean matchPair() {
   if (currentPair == null) return false;
   int caret = text.getCaretOffset();
   int lno = text.getLineAtOffset(caret);
   PairMatch cp = baseEditor.getPairMatch(lno, caret - text.getOffsetAtLine(lno));
   baseEditor.searchGlobalPair(cp);
   if (cp.end == null) return false;
   if (cp.topPosition) text.setSelection(text.getOffsetAtLine(cp.eline) + cp.end.end);
   else text.setSelection(text.getOffsetAtLine(cp.eline) + cp.end.start);
   return true;
 }
Exemplo n.º 3
0
 public void stateChanged() {
   backParserDelay = true;
   int curLine = text.getLineAtOffset(text.getCaretOffset());
   if (lineHighlighting && text.getSelectionRange().y != 0) {
     lineHighlighting = false;
     drawLine(prevLine);
     pairsHighlighting = false;
     pairsDraw(null, currentPair);
     return;
   }
   if (text.getSelectionRange().y != 0) return;
   if (!lineHighlighting) {
     // drawing current line
     lineHighlighting = true;
     drawLine(curLine);
   } else if (curLine != prevLine) {
     drawLine(prevLine);
     drawLine(curLine);
     prevLine = curLine;
   }
   // drawing current pairs
   if (!pairsHighlighting) {
     pairsHighlighting = true;
     pairsDraw(null, currentPair);
   } else {
     int lineOffset = text.getOffsetAtLine(curLine);
     PairMatch newmatch = baseEditor.getPairMatch(curLine, text.getCaretOffset() - lineOffset);
     if (newmatch != null) baseEditor.searchLocalPair(newmatch);
     if ((newmatch == null && currentPair != null)
         || (newmatch != null && !newmatch.equals(currentPair))) {
       pairsDraw(null, currentPair);
       pairsDraw(null, newmatch);
     }
     currentPair = newmatch;
   }
 }