Java 类com.intellij.openapi.ui.TypingTarget 实例源码

项目:intellij-ce-playground    文件:JBViewport.java   
@Override
public void layoutContainer(Container parent) {
  JBViewport viewport = (JBViewport)parent;
  Component view = viewport.getView();
  JBScrollPane scrollPane = UIUtil.getParentOfType(JBScrollPane.class, parent);
  // do not force viewport size on editor component, e.g. EditorTextField and LanguageConsole
  if (view == null || scrollPane == null || view instanceof TypingTarget) {
    super.layoutContainer(parent);
    return;
  }

  Dimension size = doSuperLayoutContainer(viewport);

  Dimension visible = viewport.getExtentSize();
  if (scrollPane.getHorizontalScrollBarPolicy() == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) {
    size.width = visible.width;
  }
  if (scrollPane.getVerticalScrollBarPolicy() == ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER) {
    size.height = visible.height;
  }
  viewport.setViewSize(size);
}
项目:intellij-ce-playground    文件:AlphaNumericTypeCommand.java   
protected ActionCallback type(final PlaybackContext context, final String text) {
  final ActionCallback result = new ActionCallback();

  IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      TypingTarget typingTarget = findTarget(context);
      if (typingTarget != null) {
        typingTarget.type(text).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(new Runnable() {
          public void run() {
            typeByRobot(context.getRobot(), text).notify(result);
          }
        });
      } else {
        typeByRobot(context.getRobot(), text).notify(result);
      }
    }
  });

  return result;
}
项目:intellij-ce-playground    文件:AlphaNumericTypeCommand.java   
@Nullable
public static TypingTarget findTarget(PlaybackContext context) {
  if (!context.isUseTypingTargets()) return null;

  Component each = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

  while (each != null) {
    if (each instanceof TypingTarget) {
      return (TypingTarget)each;
    }

    each = each.getParent();
  }

  return null;
}
项目:tools-idea    文件:AlphaNumericTypeCommand.java   
protected ActionCallback type(final PlaybackContext context, final String text) {
  final ActionCallback result = new ActionCallback();

  IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      TypingTarget typingTarget = findTarget(context);
      if (typingTarget != null) {
        typingTarget.type(text).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(new Runnable() {
          public void run() {
            typeByRobot(context.getRobot(), text).notify(result);
          }
        });
      } else {
        typeByRobot(context.getRobot(), text).notify(result);
      }
    }
  });

  return result;
}
项目:tools-idea    文件:AlphaNumericTypeCommand.java   
@Nullable
public static TypingTarget findTarget(PlaybackContext context) {
  if (!context.isUseTypingTargets()) return null;

  Component each = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

  while (each != null) {
    if (each instanceof TypingTarget) {
      return (TypingTarget)each;
    }

    each = each.getParent();
  }

  return null;
}
项目:consulo    文件:AlphaNumericTypeCommand.java   
protected ActionCallback type(final PlaybackContext context, final String text) {
  final ActionCallback result = new ActionCallback();

  IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      TypingTarget typingTarget = findTarget(context);
      if (typingTarget != null) {
        typingTarget.type(text).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(new Runnable() {
          public void run() {
            typeByRobot(context.getRobot(), text).notify(result);
          }
        });
      } else {
        typeByRobot(context.getRobot(), text).notify(result);
      }
    }
  });

  return result;
}
项目:consulo    文件:AlphaNumericTypeCommand.java   
@Nullable
public static TypingTarget findTarget(PlaybackContext context) {
  if (!context.isUseTypingTargets()) return null;

  Component each = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

  while (each != null) {
    if (each instanceof TypingTarget) {
      return (TypingTarget)each;
    }

    each = each.getParent();
  }

  return null;
}
项目:intellij-ce-playground    文件:KeyCodeTypeCommand.java   
@Override
public ActionCallback _execute(final PlaybackContext context) {
  String text = getText().substring(PREFIX.length()).trim();

  int textDelim = text.indexOf(" ");

  final String codes;
  if (textDelim >= 0) {
    codes = text.substring(0, textDelim);
  } else {
    codes = text;
  }

  final String unicode;
  if (codes.length() + 1 < text.length()) {
    unicode = text.substring(textDelim + 1);
  } else {
    unicode = "";
  }

  final ActionCallback result = new ActionCallback();


  IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      TypingTarget typingTarget = findTarget(context);
      if (typingTarget != null) {
        typingTarget.type(unicode).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(new Runnable() {
          public void run() {
            typeCodes(context, context.getRobot(), codes).notify(result);
          }
        });
      } else {
        typeCodes(context, context.getRobot(), codes).notify(result);
      }
    }
  });

  return result;
}
项目:tools-idea    文件:KeyCodeTypeCommand.java   
@Override
public ActionCallback _execute(final PlaybackContext context) {
  String text = getText().substring(PREFIX.length()).trim();

  int textDelim = text.indexOf(" ");

  final String codes;
  if (textDelim >= 0) {
    codes = text.substring(0, textDelim);
  } else {
    codes = text;
  }

  final String unicode;
  if (codes.length() + 1 < text.length()) {
    unicode = text.substring(textDelim + 1);
  } else {
    unicode = "";
  }

  final ActionCallback result = new ActionCallback();


  IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      TypingTarget typingTarget = findTarget(context);
      if (typingTarget != null) {
        typingTarget.type(unicode).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(new Runnable() {
          public void run() {
            typeCodes(context, context.getRobot(), codes).notify(result);
          }
        });
      } else {
        typeCodes(context, context.getRobot(), codes).notify(result);
      }
    }
  });

  return result;
}
项目:consulo    文件:JBViewport.java   
private static void doLayout(JScrollPane pane, JViewport viewport, Component view) {
  updateBorder(view);

  Dimension actualSize = viewport.getSize();
  Dimension extentSize = viewport.toViewCoordinates(actualSize);
  Dimension viewPreferredSize = view.getPreferredSize();
  Dimension viewSize = new Dimension(viewPreferredSize);
  Point viewPosition = viewport.getViewPosition();

  Scrollable scrollable = null;
  if (view instanceof Scrollable) {
    scrollable = (Scrollable)view;
    if (scrollable.getScrollableTracksViewportWidth()) viewSize.width = actualSize.width;
    if (scrollable.getScrollableTracksViewportHeight()) viewSize.height = actualSize.height;
  }
  // If the new viewport size would leave empty space to the right of the view,
  // right justify the view or left justify the view
  // when the width of the view is smaller than the container.
  int maxX = viewSize.width - extentSize.width;
  if (scrollable == null || pane.getComponentOrientation().isLeftToRight()) {
    if (viewPosition.x > maxX) {
      viewPosition.x = Math.max(0, maxX);
    }
  }
  else {
    viewPosition.x = maxX < 0 ? maxX : Math.max(0, Math.min(maxX, viewPosition.x));
  }
  // If the new viewport size would leave empty space below the view,
  // bottom justify the view or top justify the view
  // when the height of the view is smaller than the container.
  int maxY = viewSize.height - extentSize.height;
  if (viewPosition.y > maxY) {
    viewPosition.y = Math.max(0, maxY);
  }
  // If we haven't been advised about how the viewports size should change wrt to the viewport,
  // i.e. if the view isn't an instance of Scrollable, then adjust the views size as follows.
  if (scrollable == null) {
    // If the origin of the view is showing and the viewport is bigger than the views preferred size,
    // then make the view the same size as the viewport.
    if (viewPosition.x == 0 && actualSize.width > viewPreferredSize.width) viewSize.width = actualSize.width;
    if (viewPosition.y == 0 && actualSize.height > viewPreferredSize.height) viewSize.height = actualSize.height;
  }
  // do not force viewport size on editor component, e.g. EditorTextField and LanguageConsole
  if (!(view instanceof TypingTarget)) {
    if (ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER == pane.getHorizontalScrollBarPolicy()) {
      viewPosition.x = 0;
      viewSize.width = extentSize.width;
    }
    if (ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER == pane.getVerticalScrollBarPolicy()) {
      viewPosition.y = 0;
      viewSize.height = extentSize.height;
    }
  }
  viewport.setViewPosition(viewPosition);
  viewport.setViewSize(viewSize);
}
项目:consulo    文件:KeyCodeTypeCommand.java   
@Override
public ActionCallback _execute(final PlaybackContext context) {
  String text = getText().substring(PREFIX.length()).trim();

  int textDelim = text.indexOf(" ");

  final String codes;
  if (textDelim >= 0) {
    codes = text.substring(0, textDelim);
  } else {
    codes = text;
  }

  final String unicode;
  if (codes.length() + 1 < text.length()) {
    unicode = text.substring(textDelim + 1);
  } else {
    unicode = "";
  }

  final ActionCallback result = new ActionCallback();


  IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(new Runnable() {
    @Override
    public void run() {
      TypingTarget typingTarget = findTarget(context);
      if (typingTarget != null) {
        typingTarget.type(unicode).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(new Runnable() {
          public void run() {
            typeCodes(context, context.getRobot(), codes).notify(result);
          }
        });
      } else {
        typeCodes(context, context.getRobot(), codes).notify(result);
      }
    }
  });

  return result;
}