当前位置: 首页>>代码示例>>Java>>正文


Java ScrollType.CENTER_DOWN属性代码示例

本文整理汇总了Java中com.intellij.openapi.editor.ScrollType.CENTER_DOWN属性的典型用法代码示例。如果您正苦于以下问题:Java ScrollType.CENTER_DOWN属性的具体用法?Java ScrollType.CENTER_DOWN怎么用?Java ScrollType.CENTER_DOWN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.intellij.openapi.editor.ScrollType的用法示例。


在下文中一共展示了ScrollType.CENTER_DOWN属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: navigateToError

static void navigateToError(Project project, final Editor editor, HighlightInfo info) {
  int oldOffset = editor.getCaretModel().getOffset();

  final int offset = getNavigationPositionFor(info, editor.getDocument());
  final int endOffset = info.getActualEndOffset();

  final ScrollingModel scrollingModel = editor.getScrollingModel();
  if (offset != oldOffset) {
    ScrollType scrollType = offset > oldOffset ? ScrollType.CENTER_DOWN : ScrollType.CENTER_UP;
    editor.getSelectionModel().removeSelection();
    editor.getCaretModel().removeSecondaryCarets();
    editor.getCaretModel().moveToOffset(offset);
    scrollingModel.scrollToCaret(scrollType);
  }

  scrollingModel.runActionOnScrollingFinished(
    new Runnable(){
      @Override
      public void run() {
        int maxOffset = editor.getDocument().getTextLength() - 1;
        if (maxOffset == -1) return;
        scrollingModel.scrollTo(editor.offsetToLogicalPosition(Math.min(maxOffset, endOffset)), ScrollType.MAKE_VISIBLE);
        scrollingModel.scrollTo(editor.offsetToLogicalPosition(Math.min(maxOffset, offset)), ScrollType.MAKE_VISIBLE);
      }
    }
  );

  IdeDocumentHistory.getInstance(project).includeCurrentCommandAsNavigation();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:GotoNextErrorHandler.java

示例2: calcOffsetsToScroll

private Point calcOffsetsToScroll(LogicalPosition pos, ScrollType scrollType, Rectangle viewRect) {
  Point targetLocation = myEditor.logicalPositionToXY(pos);

  if (myEditor.getSettings().isRefrainFromScrolling() && viewRect.contains(targetLocation)) {
    if (scrollType == ScrollType.CENTER ||
        scrollType == ScrollType.CENTER_DOWN ||
        scrollType == ScrollType.CENTER_UP) {
      scrollType = ScrollType.RELATIVE;
    }
  }

  int spaceWidth = EditorUtil.getSpaceWidth(Font.PLAIN, myEditor);
  int xInsets = myEditor.getSettings().getAdditionalColumnsCount() * spaceWidth;

  int hOffset = scrollType == ScrollType.CENTER ||
                scrollType == ScrollType.CENTER_DOWN ||
                scrollType == ScrollType.CENTER_UP ? 0 : viewRect.x;
  if (targetLocation.x < hOffset) {
    int inset = 4 * spaceWidth;
    if (scrollType == ScrollType.MAKE_VISIBLE && targetLocation.x < viewRect.width - inset) {
      // if we need to scroll to the left to make target position visible, 
      // let's scroll to the leftmost position (if that will make caret visible)
      hOffset = 0;
    }
    else {
      hOffset = Math.max(0, targetLocation.x - inset);
    }
  }
  else if (targetLocation.x >= hOffset + viewRect.width) {
    hOffset = targetLocation.x - Math.max(0, viewRect.width - xInsets);
  }

  // the following code tries to keeps 1 line above and 1 line below if available in viewRect
  int lineHeight = myEditor.getLineHeight();
  int scrollUpBy = viewRect.y - targetLocation.y + (viewRect.height > lineHeight ? lineHeight : 0);
  int scrollDownBy = targetLocation.y - viewRect.y - Math.max(0, viewRect.height - 2 * lineHeight);
  int centerPosition = targetLocation.y - viewRect.height / 3;

  int vOffset = viewRect.y;
  if (scrollType == ScrollType.CENTER) {
    vOffset = centerPosition;
  }
  else if (scrollType == ScrollType.CENTER_UP) {
    if (scrollUpBy > 0 || scrollDownBy > 0 || vOffset > centerPosition) {
      vOffset = centerPosition;
    }
  }
  else if (scrollType == ScrollType.CENTER_DOWN) {
    if (scrollUpBy > 0 || scrollDownBy > 0 || vOffset < centerPosition) {
      vOffset = centerPosition;
    }
  }
  else if (scrollType == ScrollType.RELATIVE) {
    if (scrollUpBy > 0) {
      vOffset = viewRect.y - scrollUpBy;
    }
    else if (scrollDownBy > 0) {
      vOffset = viewRect.y + scrollDownBy;
    }
  }
  else if (scrollType == ScrollType.MAKE_VISIBLE) {
    if (scrollUpBy > 0 || scrollDownBy > 0) {
      vOffset = centerPosition;
    }
  }

  JScrollPane scrollPane = myEditor.getScrollPane();
  hOffset = Math.max(0, hOffset);
  vOffset = Math.max(0, vOffset);
  hOffset = Math.min(scrollPane.getHorizontalScrollBar().getMaximum() - getExtent(scrollPane.getHorizontalScrollBar()), hOffset);
  vOffset = Math.min(scrollPane.getVerticalScrollBar().getMaximum() - getExtent(scrollPane.getVerticalScrollBar()), vOffset);

  return new Point(hOffset, vOffset);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:74,代码来源:ScrollingModelImpl.java


注:本文中的com.intellij.openapi.editor.ScrollType.CENTER_DOWN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。