Java Code Examples for com.intellij.openapi.util.Pair#pair()

The following examples show how to use com.intellij.openapi.util.Pair#pair() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EditorSizeManager.java    From consulo with Apache License 2.0 6 votes vote down vote up
private Pair<Integer, Integer> calculateTextPreferredWidth(int startVisualLine, int endVisualLine) {
  if (checkDirty()) return Pair.pair(1, 0);
  assertValidState();
  VisualLinesIterator iterator = new VisualLinesIterator(myEditor, startVisualLine);
  int maxWidth = 0;
  int largestLineNumber = 0;
  if (startVisualLine == 0 && iterator.atEnd()) {
    maxWidth += myView.getPrefixTextWidthInPixels();
  }
  while (!iterator.atEnd()) {
    int width = getVisualLineWidth(iterator, true);
    if (width > maxWidth) {
      maxWidth = width;
      largestLineNumber = iterator.getVisualLine();
    }
    if (iterator.getVisualLine() >= endVisualLine) break;
    iterator.advance();
  }
  return Pair.create(maxWidth, largestLineNumber);
}
 
Example 2
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Returned Point is in layered pane coordinate system.
 * Second value is a {@link HintManager.PositionFlags position flag}.
 */
static Pair<Point, Short> chooseBestHintPosition(Editor editor, VisualPosition pos, LightweightHint hint, short preferredPosition, boolean showLookupHint) {
  if (ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isHeadlessEnvironment()) return Pair.pair(new Point(), HintManager.DEFAULT);

  HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl();
  Dimension hintSize = hint.getComponent().getPreferredSize();
  JComponent editorComponent = editor.getComponent();
  JLayeredPane layeredPane = editorComponent.getRootPane().getLayeredPane();

  Point p1;
  Point p2;
  if (showLookupHint) {
    p1 = hintManager.getHintPosition(hint, editor, HintManager.UNDER);
    p2 = hintManager.getHintPosition(hint, editor, HintManager.ABOVE);
  }
  else {
    p1 = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.UNDER);
    p2 = HintManagerImpl.getHintPosition(hint, editor, pos, HintManager.ABOVE);
  }

  boolean p1Ok = p1.y + hintSize.height < layeredPane.getHeight();
  boolean p2Ok = p2.y >= 0;

  if (!showLookupHint) {
    if (preferredPosition != HintManager.DEFAULT) {
      if (preferredPosition == HintManager.ABOVE) {
        if (p2Ok) return new Pair<>(p2, HintManager.ABOVE);
      }
      else if (preferredPosition == HintManager.UNDER) {
        if (p1Ok) return new Pair<>(p1, HintManager.UNDER);
      }
    }
  }
  if (p1Ok) return new Pair<>(p1, HintManager.UNDER);
  if (p2Ok) return new Pair<>(p2, HintManager.ABOVE);

  int underSpace = layeredPane.getHeight() - p1.y;
  int aboveSpace = p2.y;
  return aboveSpace > underSpace ? new Pair<>(new Point(p2.x, 0), HintManager.UNDER) : new Pair<>(p1, HintManager.ABOVE);
}
 
Example 3
Source File: LineMarkerActionWrapper.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private DataContext wrapContext(DataContext dataContext) {
  Pair<PsiElement, MyDataContext> pair = DataManager.getInstance().loadFromDataContext(dataContext, LOCATION_WRAPPER);
  if (pair == null || pair.first != myElement) {
    pair = Pair.pair(myElement, new MyDataContext(dataContext));
    DataManager.getInstance().saveInDataContext(dataContext, LOCATION_WRAPPER, pair);
  }
  return pair.second;
}