Search in sources :

Example 21 with Consumer

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();
    }
}
Also used : RegistryValue(com.intellij.openapi.util.registry.RegistryValue) UIUtil(com.intellij.util.ui.UIUtil) Point2D(java.awt.geom.Point2D) com.intellij.openapi.editor(com.intellij.openapi.editor) EditorUtil(com.intellij.openapi.editor.ex.util.EditorUtil) Rectangle2D(java.awt.geom.Rectangle2D) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) JBUI(com.intellij.util.ui.JBUI) HighlighterLayer(com.intellij.openapi.editor.markup.HighlighterLayer) EffectType(com.intellij.openapi.editor.markup.EffectType) Disposer(com.intellij.openapi.util.Disposer) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) IterationState(com.intellij.openapi.editor.impl.view.IterationState) FontLayoutService(com.intellij.openapi.editor.impl.view.FontLayoutService) EditorTextField(com.intellij.ui.EditorTextField) BufferedImage(java.awt.image.BufferedImage) HighlighterTargetArea(com.intellij.openapi.editor.markup.HighlighterTargetArea) java.awt(java.awt) VolatileImage(java.awt.image.VolatileImage) EditorUIUtil(com.intellij.openapi.editor.ex.util.EditorUIUtil) List(java.util.List) EditorColors(com.intellij.openapi.editor.colors.EditorColors) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) Gray(com.intellij.ui.Gray) JBColor(com.intellij.ui.JBColor) Consumer(com.intellij.util.Consumer) javax.swing(javax.swing) Rectangle2D(java.awt.geom.Rectangle2D) LexerEditorHighlighter(com.intellij.openapi.editor.ex.util.LexerEditorHighlighter) Point2D(java.awt.geom.Point2D) FontLayoutService(com.intellij.openapi.editor.impl.view.FontLayoutService) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes)

Example 22 with Consumer

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;
}
Also used : Project(com.intellij.openapi.project.Project) ToolWindow(com.intellij.openapi.wm.ToolWindow) Consumer(com.intellij.util.Consumer) AsyncResult(com.intellij.openapi.util.AsyncResult)

Example 23 with Consumer

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;
}
Also used : ActionCallback(com.intellij.openapi.util.ActionCallback) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) Consumer(com.intellij.util.Consumer) AsyncResult(com.intellij.openapi.util.AsyncResult)

Example 24 with Consumer

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;
}
Also used : Disposable(com.intellij.openapi.Disposable) Project(com.intellij.openapi.project.Project) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) Consumer(com.intellij.util.Consumer) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) AsyncResult(com.intellij.openapi.util.AsyncResult)

Example 25 with Consumer

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();
            }
        });
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) AccessibleContextUtil(com.intellij.util.ui.accessibility.AccessibleContextUtil) Wrapper(com.intellij.ui.components.panels.Wrapper) AllIcons(com.intellij.icons.AllIcons) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Area(java.awt.geom.Area) Rectangle2D(java.awt.geom.Rectangle2D) HashSet(com.intellij.util.containers.HashSet) FocusRequestor(com.intellij.openapi.wm.FocusRequestor) ShadowBorderPainter(com.intellij.openapi.ui.impl.ShadowBorderPainter) Balloon(com.intellij.openapi.ui.popup.Balloon) RGBImageFilter(java.awt.image.RGBImageFilter) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) IdeGlassPaneUtil(com.intellij.openapi.wm.IdeGlassPaneUtil) NonOpaquePanel(com.intellij.ui.components.panels.NonOpaquePanel) BufferedImage(java.awt.image.BufferedImage) com.intellij.ide(com.intellij.ide) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) com.intellij.util.ui(com.intellij.util.ui) java.awt.event(java.awt.event) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) ApplicationManager(com.intellij.openapi.application.ApplicationManager) EmptyBorder(javax.swing.border.EmptyBorder) Registry(com.intellij.openapi.util.registry.Registry) GeneralPath(java.awt.geom.GeneralPath) NotNull(org.jetbrains.annotations.NotNull) RelativePoint(com.intellij.ui.awt.RelativePoint) ImageFilter(java.awt.image.ImageFilter) Consumer(com.intellij.util.Consumer) DataContext(com.intellij.openapi.actionSystem.DataContext) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) ScreenReader(com.intellij.util.ui.accessibility.ScreenReader) ActionManager(com.intellij.openapi.actionSystem.ActionManager) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) JdkConstants(org.intellij.lang.annotations.JdkConstants) JBPopupListener(com.intellij.openapi.ui.popup.JBPopupListener) AnAction(com.intellij.openapi.actionSystem.AnAction) java.awt(java.awt) MnemonicHelper(com.intellij.openapi.MnemonicHelper) ObjectUtils(com.intellij.util.ObjectUtils) IdeGlassPaneEx(com.intellij.openapi.wm.impl.IdeGlassPaneEx) Collections(java.util.Collections) Alarm(com.intellij.util.Alarm) javax.swing(javax.swing) NotNull(org.jetbrains.annotations.NotNull) List(java.util.List) EmptyBorder(javax.swing.border.EmptyBorder)

Aggregations

Consumer (com.intellij.util.Consumer)59 NotNull (org.jetbrains.annotations.NotNull)41 Project (com.intellij.openapi.project.Project)37 Nullable (org.jetbrains.annotations.Nullable)33 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 List (java.util.List)22 ApplicationManager (com.intellij.openapi.application.ApplicationManager)17 StringUtil (com.intellij.openapi.util.text.StringUtil)17 javax.swing (javax.swing)16 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 Logger (com.intellij.openapi.diagnostic.Logger)14 Module (com.intellij.openapi.module.Module)12 java.awt (java.awt)12 Pair (com.intellij.openapi.util.Pair)11 java.util (java.util)11 File (java.io.File)10 Collection (java.util.Collection)10 PsiElement (com.intellij.psi.PsiElement)9 PsiFile (com.intellij.psi.PsiFile)9 DataContext (com.intellij.openapi.actionSystem.DataContext)8