コード例 #1
0
  /**
   * search next text
   *
   * @param widgetText text widget
   * @param widgetFind search text widget
   */
  private void findNext(StyledText widgetText, Text widgetFind) {
    if (!widgetText.isDisposed()) {
      String findText = widgetFind.getText().toLowerCase();
      if (!findText.isEmpty()) {
        // get cursor position
        int cursorIndex = widgetText.getCaretOffset();

        // search
        int offset = -1;
        if (cursorIndex >= 0) {
          String text = widgetText.getText();
          offset =
              (cursorIndex + 1 < text.length())
                  ? text.substring(cursorIndex + 1).toLowerCase().indexOf(findText)
                  : -1;
        }
        if (offset >= 0) {
          int index = cursorIndex + 1 + offset;

          widgetText.setCaretOffset(index);
          widgetText.setSelection(index);
          widgetText.redraw();

          int topIndex = widgetText.getTopIndex();

          widgetLineNumbers.setTopIndex(topIndex);
          widgetVerticalScrollBar.setSelection(topIndex);
        } else {
          Widgets.flash(widgetFind);
        }
      }
    }
  }
コード例 #2
0
 @Override
 public void scrollDown(boolean wholeScreen) {
   int topLine = commandLineText.getTopIndex();
   if (wholeScreen) {
     int bottomLine = commandLineText.getLineIndex(commandLineText.getBounds().y - 1);
     int nLines = bottomLine - topLine;
     commandLineText.setTopIndex(topLine + nLines);
   } else {
     // For some reason, getTopIndex() seems to return the second fully shown line... No +1
     commandLineText.setTopIndex(topLine);
   }
 }
コード例 #3
0
 void updateViewport() {
   baseEditor.lineCountEvent(text.getLineCount());
   int start = 0;
   try {
     start = text.getTopIndex() - 1;
   } catch (Exception e) {
     e.printStackTrace(System.out);
   }
   if (start < 0) start = 0;
   int end = start + text.getClientArea().height / text.getLineHeight();
   baseEditor.visibleTextEvent(start, end - start + 2);
 }
コード例 #4
0
    @Override
    public void paintControl(PaintEvent event) {
      /*   Using event.gc.getFontMetrics().getAverageCharWidth()) was not
          enough on low resolutions, as the rounding to an int seemed
          enough to screw up the right margin, even when using a
          monospaced font (this is the current theory).
      */
      if (charsPerLine != getCharsPerLine()) {
        charsPerLine = getCharsPerLine();
        char buffer[] = new char[charsPerLine];
        for (int i = 0; i < charsPerLine; i++) buffer[i] = 'm';
        rightMargin = event.gc.stringExtent(new String(buffer)).x;
      }

      int lineHeight = source.getLineHeight();
      int drawHeight = source.getClientArea().height;
      int drawWidth = source.getClientArea().width;

      event.gc.setForeground(color);
      event.gc.setBackground(color);

      //   draw right margin
      event.gc.drawLine(rightMargin, 0, rightMargin, drawHeight);

      for (int i = source.getTopIndex(); i < source.getLineCount(); i++) {
        //   draw page lines
        int at = source.getLinePixel(i);
        if (isFirstLineOnPage(i)) event.gc.drawLine(0, at, drawWidth, at);

        //   draw paragraph end markers
        String line = source.getLine(i);
        if (line.length() > 0 && line.charAt(line.length() - 1) == PARAGRAPH_END) {
          Point point = event.gc.stringExtent(line);
          int span = point.y / 2;
          event.gc.fillOval(point.x + span / 2, at + span / 2, span, span);
        }

        //   check if line still visible
        if (at + lineHeight > drawHeight) break;
      }

      adjustOtherThread.notifyPainted(source);
    }