예제 #1
0
 /**
  * Draw the given line range.
  *
  * @param gc
  * @param startLine first line number
  * @param endLine last line number (inclusive)
  * @param x the X-coordinate of the drawing range
  * @param w the width of the drawing range
  */
 private void drawLineRange(GC gc, int startLine, int endLine, int x, int w) {
   final int viewPortWidth = fTextWidget.getClientArea().width;
   for (int line = startLine; line <= endLine; line++) {
     int lineOffset = fTextWidget.getOffsetAtLine(line);
     // line end offset including line delimiter
     int lineEndOffset;
     if (line < fTextWidget.getLineCount() - 1) {
       lineEndOffset = fTextWidget.getOffsetAtLine(line + 1);
     } else {
       lineEndOffset = fTextWidget.getCharCount();
     }
     // line length excluding line delimiter
     int lineLength = lineEndOffset - lineOffset;
     while (lineLength > 0) {
       char c = fTextWidget.getTextRange(lineOffset + lineLength - 1, 1).charAt(0);
       if (c != '\r' && c != '\n') {
         break;
       }
       --lineLength;
     }
     // compute coordinates of last character on line
     Point endOfLine = fTextWidget.getLocationAtOffset(lineOffset + lineLength);
     if (x - endOfLine.x > viewPortWidth) {
       // line is not visible
       continue;
     }
     // Y-coordinate of line
     int y = fTextWidget.getLinePixel(line);
     // compute first visible char offset
     int startOffset;
     try {
       startOffset = fTextWidget.getOffsetAtLocation(new Point(x, y)) - 1;
       if (startOffset - 2 <= lineOffset) {
         startOffset = lineOffset;
       }
     } catch (IllegalArgumentException iae) {
       startOffset = lineOffset;
     }
     // compute last visible char offset
     int endOffset;
     if (x + w >= endOfLine.x) {
       // line end is visible
       endOffset = lineEndOffset;
     } else {
       try {
         endOffset = fTextWidget.getOffsetAtLocation(new Point(x + w - 1, y)) + 1;
         if (endOffset + 2 >= lineEndOffset) {
           endOffset = lineEndOffset;
         }
       } catch (IllegalArgumentException iae) {
         endOffset = lineEndOffset;
       }
     }
     // draw character range
     if (endOffset > startOffset) {
       drawCharRange(gc, startOffset, endOffset);
     }
   }
 }
예제 #2
0
 void drawLine(int lno) {
   if (lno < 0 || lno >= text.getLineCount()) return;
   int y = text.getLocationAtOffset(text.getOffsetAtLine(lno)).y;
   int height = 0;
   if (text.getLineCount() > lno + 1)
     height = text.getLocationAtOffset(text.getOffsetAtLine(lno + 1)).y - y;
   else height = text.getLocationAtOffset(text.getCharCount()).y + text.getLineHeight();
   int width = text.getClientArea().width + text.getHorizontalPixel();
   text.redraw(0, y, width, height, false);
 }
예제 #3
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;
 }
예제 #4
0
 void pairsDraw(GC gc, PairMatch pm) {
   if (pm == null) return;
   if (pm.start != null) {
     if (pm.sline >= text.getLineCount()) return;
     int lineOffset = text.getOffsetAtLine(pm.sline);
     pairDraw(
         gc, (StyledRegion) pm.start.rdef, pm.start.start + lineOffset, pm.start.end + lineOffset);
   }
   if (pm.end != null) {
     if (pm.eline >= text.getLineCount()) return;
     int lineOffset = text.getOffsetAtLine(pm.eline);
     pairDraw(gc, (StyledRegion) pm.end.rdef, pm.end.start + lineOffset, pm.end.end + lineOffset);
   }
 }
예제 #5
0
 void redrawFrom(int lno) {
   if (lno < 0 || lno >= text.getLineCount()) return;
   int y = text.getLocationAtOffset(text.getOffsetAtLine(lno)).y;
   int height = text.getClientArea().height - y;
   int width = text.getClientArea().width + text.getHorizontalPixel();
   text.redraw(0, y, width, height, false);
 }
예제 #6
0
 /**
  * Checks whether a (tab key) event should be consumed.
  *
  * @param inWidget StyledText
  * @return boolean <code>true</code> if the actual line has a bullet AND the cursor is at the
  *     beginning of the line.
  */
 private boolean consumeTabKey(final StyledText inWidget) {
   final int lPosition = inWidget.getCaretOffset();
   final int lLine = inWidget.getLineAtOffset(lPosition);
   if (inWidget.getLineBullet(lLine) != null && lPosition == inWidget.getOffsetAtLine(lLine)) {
     return true;
   }
   return false;
 }
 protected void setLastRulerMouseLocation(ISourceViewer viewer, int line) {
   // set last mouse activity in order to get the correct context menu
   if (fCompositeRuler != null) {
     StyledText st = viewer.getTextWidget();
     if (st != null && !st.isDisposed()) {
       if (viewer instanceof ITextViewerExtension5) {
         int widgetLine = ((ITextViewerExtension5) viewer).modelLine2WidgetLine(line);
         Point loc = st.getLocationAtOffset(st.getOffsetAtLine(widgetLine));
         fCompositeRuler.setLocationOfLastMouseButtonActivity(0, loc.y);
       } else if (viewer instanceof TextViewer) {
         // TODO remove once TextViewer implements the extension
         int widgetLine = ((TextViewer) viewer).modelLine2WidgetLine(line);
         Point loc = st.getLocationAtOffset(st.getOffsetAtLine(widgetLine));
         fCompositeRuler.setLocationOfLastMouseButtonActivity(0, loc.y);
       }
     }
   }
 }
예제 #8
0
    @Override
    public void verifyKey(VerifyEvent event) {
      StyledText styledText = (StyledText) event.widget;

      if (event.keyCode == '\r' || event.keyCode == '\n')
        if ((event.stateMask & SWT.SHIFT) != 0) {
          //   toggle paragraph end character
          event.doit = false;
          int index = styledText.getLineAtOffset(styledText.getCaretOffset());
          String line = styledText.getLine(index);
          if (line.length() > 0)
            if (line.charAt(line.length() - 1) != PARAGRAPH_END)
              styledText.replaceTextRange(
                  styledText.getOffsetAtLine(index),
                  line.length(),
                  line + Character.toString(PARAGRAPH_END));
            else
              styledText.replaceTextRange(
                  styledText.getOffsetAtLine(index),
                  line.length(),
                  line.substring(0, line.length() - 1));
          return;
        } else {
          //   play page bell
          int index = styledText.getLineAtOffset(styledText.getCaretOffset());
          if (index == prevLine + 1 && index % linesPerPage == pageMarginBell - 2)
            if (!pageMarginClip.isActive()) {
              pageMarginClip.setFramePosition(0);
              pageMarginClip.start();
            }
          prevLine = index;
        }

      //   check if using braille entry
      if (brailleEntry) if (event.character > ' ' && event.character < 0x7f) event.doit = false;
    }
예제 #9
0
    @Override
    public void caretMoved(CaretEvent ignored) {
      int caretOffset = source.getCaretOffset();
      int lineIndex = source.getLineAtOffset(caretOffset);
      int lineOffset = source.getOffsetAtLine(lineIndex);

      //   play line margin bell
      if (lineMarginClip != null && lineMarginBell > 0 && caretOffset == prevCaretOffset + 1) {
        if (caretOffset - lineOffset == lineMarginBell)
          if (!lineMarginClip.isActive()) {
            lineMarginClip.setFramePosition(0);
            lineMarginClip.start();
          }
      }

      //   play line end bell
      if (lineEndClip != null && charsPerLine > 0 && caretOffset == prevCaretOffset + 1) {
        if (caretOffset - lineOffset == charsPerLine)
          if (!lineEndClip.isActive()) {
            lineEndClip.setFramePosition(0);
            lineEndClip.start();
          }
      }

      prevCaretOffset = caretOffset;

      //   scroll other text to match current
      if (lineIndex == prevLineIndex) return;
      prevLineIndex = lineIndex;
      if (source != currentText) return;

      int sourceLinePixel = source.getLinePixel(lineIndex);
      int sourceHeight = source.getClientArea().height;
      int sourceLineHeight = source.getLineHeight();

      //   check if have to wait until after paint event
      if (sourceLinePixel < 0 || sourceLinePixel + sourceLineHeight > sourceHeight)
        adjustOtherThread.waitPainted(source, other);
      else adjustOtherThread.adjustOther(source, other);
    }
예제 #10
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;
   }
 }
예제 #11
0
  public void _setWhatsNew() {

    if (sWhatsNew.indexOf("<html") >= 0 || sWhatsNew.indexOf("<HTML") >= 0) {
      BrowserWrapper browser = Utils.createSafeBrowser(cWhatsNew, SWT.NONE);
      if (browser != null) {
        browser.setText(sWhatsNew);
      } else {
        try {
          File tempFile = File.createTempFile("AZU", ".html");
          tempFile.deleteOnExit();
          FileUtil.writeBytesAsFile(tempFile.getAbsolutePath(), sWhatsNew.getBytes("utf8"));
          Utils.launch(tempFile.getAbsolutePath());
          shell.dispose();
          return;
        } catch (IOException e) {
        }
      }
    } else {

      StyledText helpPanel = new StyledText(cWhatsNew, SWT.VERTICAL | SWT.HORIZONTAL);

      helpPanel.setEditable(false);
      try {
        helpPanel.setRedraw(false);
        helpPanel.setWordWrap(false);
        helpPanel.setFont(monospace);

        black = ColorCache.getColor(display, 0, 0, 0);
        white = ColorCache.getColor(display, 255, 255, 255);
        light = ColorCache.getColor(display, 200, 200, 200);
        grey = ColorCache.getColor(display, 50, 50, 50);
        green = ColorCache.getColor(display, 30, 80, 30);
        blue = ColorCache.getColor(display, 20, 20, 80);
        int style;
        boolean setStyle;

        helpPanel.setForeground(grey);

        String[] lines = sWhatsNew.split("\\r?\\n");
        for (int i = 0; i < lines.length; i++) {
          String line = lines[i];

          setStyle = false;
          fg = grey;
          bg = white;
          style = SWT.NORMAL;

          char styleChar;
          String text;

          if (line.length() < 2) {
            styleChar = ' ';
            text = " " + lineSeparator;
          } else {
            styleChar = line.charAt(0);
            text = line.substring(1) + lineSeparator;
          }

          switch (styleChar) {
            case '*':
              text = "  * " + text;
              fg = green;
              setStyle = true;
              break;
            case '+':
              text = "     " + text;
              fg = black;
              bg = light;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '!':
              style = SWT.BOLD;
              setStyle = true;
              break;
            case '@':
              fg = blue;
              setStyle = true;
              break;
            case '$':
              bg = blue;
              fg = white;
              style = SWT.BOLD;
              setStyle = true;
              break;
            case ' ':
              text = "  " + text;
              break;

            default:
              text = styleChar + text;
          }

          helpPanel.append(text);

          if (setStyle) {
            int lineCount = helpPanel.getLineCount() - 1;
            int charCount = helpPanel.getCharCount();
            //          System.out.println("Got Linecount " + lineCount + ", Charcount " +
            // charCount);

            int lineOfs = helpPanel.getOffsetAtLine(lineCount - 1);
            int lineLen = charCount - lineOfs;
            //          System.out.println("Setting Style : " + lineOfs + ", " + lineLen);
            helpPanel.setStyleRange(new StyleRange(lineOfs, lineLen, fg, bg, style));
            helpPanel.setLineBackground(lineCount - 1, 1, bg);
          }
        }

        helpPanel.setRedraw(true);
      } catch (Exception e) {
        System.out.println("Unable to load help contents because:" + e);
        // e.printStackTrace();
      }
    }

    if (labelLoading != null && !labelLoading.isDisposed()) {
      labelLoading.dispose();
    }
    shell.layout(true, true);
  }