PaintListener createPaintListenerPrompt()

in plugin/src/software/aws/toolkits/eclipse/amazonq/inlineChat/InlineChatUIManager.java [255:308]


    PaintListener createPaintListenerPrompt(final StyledText widget, final int offset, final String promptText, final boolean isDarkTheme) {
        return new PaintListener() {
            @Override
            public void paintControl(final PaintEvent event) {
                try {
                    int indentedOffset = calculateIndentOffset(widget, offset);
                    Point location = widget.getLocationAtOffset(indentedOffset);
                    Point textExtent = event.gc.textExtent(promptText);

                    // Check if selection is atop the editor
                    Rectangle clientArea = widget.getClientArea();
                    boolean hasSpaceAbove = (location.y - widget.getLineHeight() * 2) >= clientArea.y;

                    // If space above, draw above. Otherwise draw over the selected line
                    if (hasSpaceAbove) {
                        location.y -= widget.getLineHeight() * 2;
                    }
                    // If no space above, keep location.y as is

                    Color backgroundColor;
                    Color textColor;

                    // Toggle color based on editor theme
                    if (isDarkTheme) {
                        backgroundColor = new Color(Display.getCurrent(), 100, 100, 100);
                        textColor = new Color(Display.getCurrent(), 255, 255, 255);
                    } else {
                        backgroundColor = new Color(Display.getCurrent(), 230, 230, 230);
                        textColor = new Color(Display.getCurrent(), 0, 0, 0);
                    }

                    try {
                        // Draw background
                        event.gc.setBackground(backgroundColor);
                        event.gc.fillRectangle(location.x, location.y, textExtent.x + 10, textExtent.y + 10);

                        // Draw text
                        event.gc.setForeground(textColor);
                        event.gc.drawText(promptText, location.x + 5, location.y + 5, false);
                    } finally {
                        backgroundColor.dispose();
                        textColor.dispose();
                    }
                } catch (Exception e) {
                    Activator.getLogger().error("Exception rendering paint control: " + e.getMessage(), e);
                    if (widget != null) {
                        widget.removePaintListener(this);
                        widget.redraw();
                    }
                }
            }
        };

    }