use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class ImmediatePainter method paintImmediately.
private void paintImmediately(final Graphics g, final int offset, final char c2) {
final EditorImpl editor = myEditor;
final Document document = editor.getDocument();
final LexerEditorHighlighter highlighter = (LexerEditorHighlighter) myEditor.getHighlighter();
final EditorSettings settings = editor.getSettings();
final boolean isBlockCursor = editor.isInsertMode() == settings.isBlockCursor();
final int lineHeight = editor.getLineHeight();
final int ascent = editor.getAscent();
final int topOverhang = editor.myView.getTopOverhang();
final int bottomOverhang = editor.myView.getBottomOverhang();
final char c1 = offset == 0 ? ' ' : document.getCharsSequence().charAt(offset - 1);
final List<TextAttributes> attributes = highlighter.getAttributesForPreviousAndTypedChars(document, offset, c2);
updateAttributes(editor, offset, attributes);
final TextAttributes attributes1 = attributes.get(0);
final TextAttributes attributes2 = attributes.get(1);
if (!(canRender(attributes1) && canRender(attributes2))) {
return;
}
FontLayoutService fontLayoutService = FontLayoutService.getInstance();
final float width1 = fontLayoutService.charWidth2D(editor.getFontMetrics(attributes1.getFontType()), c1);
final float width2 = fontLayoutService.charWidth2D(editor.getFontMetrics(attributes2.getFontType()), c2);
final Font font1 = EditorUtil.fontForChar(c1, attributes1.getFontType(), editor).getFont();
final Font font2 = EditorUtil.fontForChar(c1, attributes2.getFontType(), editor).getFont();
final Point2D p2 = editor.offsetToXY(offset, false);
float p2x = (float) p2.getX();
int p2y = (int) p2.getY();
int width1i = (int) (p2x) - (int) (p2x - width1);
int width2i = (int) (p2x + width2) - (int) p2x;
Caret caret = editor.getCaretModel().getPrimaryCaret();
//noinspection ConstantConditions
final int caretWidth = isBlockCursor ? editor.getCaretLocations(false)[0].myWidth : JBUI.scale(caret.getVisualAttributes().getWidth(settings.getLineCursorWidth()));
final float caretShift = isBlockCursor ? 0 : caretWidth == 1 ? 0 : 1 / JBUI.sysScale((Graphics2D) g);
final Rectangle2D caretRectangle = new Rectangle2D.Float((int) (p2x + width2) - caretShift, p2y - topOverhang, caretWidth, lineHeight + topOverhang + bottomOverhang + (isBlockCursor ? -1 : 0));
final Rectangle rectangle1 = new Rectangle((int) (p2x - width1), p2y, width1i, lineHeight);
final Rectangle rectangle2 = new Rectangle((int) p2x, p2y, (int) (width2i + caretWidth - caretShift), lineHeight);
final Consumer<Graphics> painter = graphics -> {
EditorUIUtil.setupAntialiasing(graphics);
fillRect(graphics, rectangle2, attributes2.getBackgroundColor());
drawChar(graphics, c2, p2x, p2y + ascent, font2, attributes2.getForegroundColor());
fillRect(graphics, caretRectangle, getCaretColor(editor));
fillRect(graphics, rectangle1, attributes1.getBackgroundColor());
drawChar(graphics, c1, p2x - width1, p2y + ascent, font1, attributes1.getForegroundColor());
};
final Shape originalClip = g.getClip();
g.setClip(new Rectangle2D.Float((int) p2x - caretShift, p2y, width2i + caretWidth, lineHeight));
if (DOUBLE_BUFFERING.asBoolean()) {
paintWithDoubleBuffering(g, painter);
} else {
painter.consume(g);
}
g.setClip(originalClip);
if (PIPELINE_FLUSH.asBoolean()) {
Toolkit.getDefaultToolkit().sync();
}
if (DEBUG.asBoolean()) {
pause();
}
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class WindowSystemPlaybackCall method waitForToolWindow.
public static AsyncResult<String> waitForToolWindow(final PlaybackContext context, final String id) {
final AsyncResult<String> result = new AsyncResult<>();
findProject().doWhenDone(new Consumer<Project>() {
@Override
public void consume(Project project) {
ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(id);
if (toolWindow == null) {
result.setRejected("Cannot find tool window with id: " + id);
return;
}
toolWindow.getReady(context).doWhenDone(result.createSetDoneRunnable()).doWhenRejected(() -> result.setRejected("Cannot activate tool window with id:" + id));
}
}).doWhenRejected(() -> result.setRejected("Cannot retrieve open project"));
return result;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class CallCommand method _execute.
@Override
protected ActionCallback _execute(final PlaybackContext context) {
final ActionCallback cmdResult = new ActionCallback();
final String cmd = getText().substring(PREFIX.length()).trim();
final int open = cmd.indexOf("(");
if (open == -1) {
context.error("( expected", getLine());
return ActionCallback.DONE;
}
final int close = cmd.lastIndexOf(")");
if (close == -1) {
context.error(") expected", getLine());
return ActionCallback.DONE;
}
final String methodName = cmd.substring(0, open);
String[] args = cmd.substring(open + 1, close).split(",");
final boolean noArgs = args.length == 1 && args[0].length() == 0;
Class[] types = noArgs ? new Class[1] : new Class[args.length + 1];
types[0] = PlaybackContext.class;
for (int i = 1; i < types.length; i++) {
types[i] = String.class;
}
try {
Pair<Method, Class> methodClass = findMethod(context, methodName, types);
if (methodClass == null) {
context.error("No method \"" + methodName + "\" found in facade classes: " + context.getCallClasses(), getLine());
return ActionCallback.REJECTED;
}
Method m = methodClass.getFirst();
if (!m.getReturnType().isAssignableFrom(AsyncResult.class)) {
context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return AsyncResult object", getLine());
return ActionCallback.REJECTED;
}
Object[] actualArgs = noArgs ? new Object[1] : new Object[args.length + 1];
actualArgs[0] = context;
System.arraycopy(args, 0, actualArgs, 1, actualArgs.length - 1);
AsyncResult result = (AsyncResult<String>) m.invoke(null, actualArgs);
if (result == null) {
context.error("Method " + methodClass.getSecond() + ":" + methodName + " must return AsyncResult object, but was null", getLine());
return ActionCallback.REJECTED;
}
result.doWhenDone(new Consumer<String>() {
@Override
public void consume(String s) {
if (s != null) {
context.message(s, getLine());
}
cmdResult.setDone();
}
}).doWhenRejected(s -> {
context.error(s, getLine());
cmdResult.setRejected();
});
} catch (InvocationTargetException ignored) {
context.error("InvocationTargetException while executing command: " + cmd, getLine());
} catch (IllegalAccessException ignored) {
context.error("IllegalAccessException while executing command: " + cmd, getLine());
}
return cmdResult;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class EditorPlaybackCall method waitDaemonForFinish.
public static AsyncResult<String> waitDaemonForFinish(final PlaybackContext context) {
final AsyncResult<String> result = new AsyncResult<>();
final Disposable connection = Disposer.newDisposable();
result.doWhenProcessed(() -> Disposer.dispose(connection));
WindowSystemPlaybackCall.findProject().doWhenDone(new Consumer<Project>() {
@Override
public void consume(Project project) {
final MessageBusConnection bus = project.getMessageBus().connect(connection);
bus.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
@Override
public void daemonFinished() {
context.flushAwtAndRunInEdt(result.createSetDoneRunnable());
}
@Override
public void daemonCancelEventOccurred(@NotNull String reason) {
result.setDone();
}
});
}
}).doWhenRejected(() -> result.setRejected("Cannot find project"));
return result;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class BalloonImpl method createComponent.
private void createComponent() {
myComp = new MyComponent(myContent, this, myShadowBorderProvider != null ? null : myShowPointer ? myPosition.createBorder(this) : getPointlessBorder());
if (myActionProvider == null) {
final Consumer<MouseEvent> listener = event -> {
SwingUtilities.invokeLater(() -> hide());
};
myActionProvider = new ActionProvider() {
private ActionButton myCloseButton;
@NotNull
@Override
public List<ActionButton> createActions() {
myCloseButton = new CloseButton(listener);
return Collections.singletonList(myCloseButton);
}
@Override
public void layout(@NotNull Rectangle lpBounds) {
if (!myCloseButton.isVisible()) {
return;
}
Icon icon = getCloseButton();
int iconWidth = icon.getIconWidth();
int iconHeight = icon.getIconHeight();
Rectangle r = new Rectangle(lpBounds.x + lpBounds.width - iconWidth + (int) (iconWidth * 0.3), lpBounds.y - (int) (iconHeight * 0.3), iconWidth, iconHeight);
Insets border = getShadowBorderInsets();
r.x -= border.left;
r.y -= border.top;
myCloseButton.setBounds(r);
}
};
}
myComp.clear();
myComp.myAlpha = isAnimationEnabled() ? 0f : -1;
myComp.setBorder(new EmptyBorder(getShadowBorderInsets()));
myLayeredPane.add(myComp);
// the second balloon must be over the first one
myLayeredPane.setLayer(myComp, getLayer(), 0);
myPosition.updateBounds(this);
if (myBlockClicks) {
myComp.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
e.consume();
}
@Override
public void mousePressed(MouseEvent e) {
e.consume();
}
@Override
public void mouseReleased(MouseEvent e) {
e.consume();
}
});
}
}
Aggregations