From fdae48a8dbdb3e04443eab7e84fd2568810365bc Mon Sep 17 00:00:00 2001 From: Stephan Janssen Date: Fri, 17 May 2024 17:54:13 +0200 Subject: [PATCH] Fix #72: Background cleanup for code blocks --- .../ui/component/StyleSheetsFactory.java | 14 ++++++---- .../genie/ui/panel/ChatResponsePanel.java | 3 +-- .../genie/ui/processor/BlockProcessor.java | 2 -- .../processor/FencedCodeBlockProcessor.java | 26 +++++-------------- .../genie/ui/util/DevoxxGenieColors.java | 13 +++------- 5 files changed, 20 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/devoxx/genie/ui/component/StyleSheetsFactory.java b/src/main/java/com/devoxx/genie/ui/component/StyleSheetsFactory.java index e6543e9a..cdca91cb 100644 --- a/src/main/java/com/devoxx/genie/ui/component/StyleSheetsFactory.java +++ b/src/main/java/com/devoxx/genie/ui/component/StyleSheetsFactory.java @@ -5,6 +5,8 @@ import com.intellij.util.ui.JBUI; import com.intellij.util.ui.StyleSheetUtil; import com.intellij.util.ui.UIUtil; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.text.html.StyleSheet; @@ -13,17 +15,18 @@ public class StyleSheetsFactory { - public static StyleSheet createCodeStyleSheet() { + @Contract(" -> new") + public static @NotNull StyleSheet createCodeStyleSheet() { return StyleSheetUtil.loadStyleSheet( "code, pre, .pre { " + " font-family: '" + SOURCE_CODE_PRO_FONT + "'; " + " font-size: 14pt;" + - " background-color: black;" + "}" ); } - public static StyleSheet createParagraphStyleSheet() { + @Contract(" -> new") + public static @NotNull StyleSheet createParagraphStyleSheet() { return StyleSheetUtil.loadStyleSheet( "h6 { font-size: " + scaleFontSize(1) + "}" + "h5 { font-size: " + scaleFontSize(2) + "}" + @@ -50,11 +53,12 @@ public static StyleSheet createParagraphStyleSheet() { ); } - private static String scaleFontSize(int increment) { + @Contract("_ -> new") + private static @NotNull String scaleFontSize(int increment) { return Integer.toString(UIManager.getFont("Label.font").getSize() + increment); } - private static String paragraphSpacing() { + private static @NotNull String paragraphSpacing() { return "padding: " + JBUIScale.scale(4) + "px 0 " + JBUIScale.scale(4) + "px 0"; } } diff --git a/src/main/java/com/devoxx/genie/ui/panel/ChatResponsePanel.java b/src/main/java/com/devoxx/genie/ui/panel/ChatResponsePanel.java index b54ac229..f0cd123e 100644 --- a/src/main/java/com/devoxx/genie/ui/panel/ChatResponsePanel.java +++ b/src/main/java/com/devoxx/genie/ui/panel/ChatResponsePanel.java @@ -14,7 +14,6 @@ import java.awt.*; -import static com.devoxx.genie.ui.util.DevoxxGenieColors.PROMPT_BG_COLOR; import static com.devoxx.genie.ui.util.DevoxxGenieFonts.SourceCodeProFontPlan14; public class ChatResponsePanel extends BackgroundPanel { @@ -31,7 +30,7 @@ public ChatResponsePanel(@NotNull ChatMessageContext chatMessageContext) { this.chatMessageContext = chatMessageContext; - add(new ResponseHeaderPanel(chatMessageContext).withBackground(PROMPT_BG_COLOR)); + add(new ResponseHeaderPanel(chatMessageContext)); addResponsePane(chatMessageContext); if (chatMessageContext.hasFiles()) { diff --git a/src/main/java/com/devoxx/genie/ui/processor/BlockProcessor.java b/src/main/java/com/devoxx/genie/ui/processor/BlockProcessor.java index 97ea7e80..df802d7b 100644 --- a/src/main/java/com/devoxx/genie/ui/processor/BlockProcessor.java +++ b/src/main/java/com/devoxx/genie/ui/processor/BlockProcessor.java @@ -31,11 +31,9 @@ public JPanel process() { JEditorPane editorPane = createEditorPane(htmlOutput, StyleSheetsFactory.createParagraphStyleSheet()); editorPane.setOpaque(false); - editorPane.setBackground(PROMPT_BG_COLOR); JPanel panel = new JPanel(new BorderLayout()); panel.setOpaque(false); - panel.setBackground(PROMPT_BG_COLOR); panel.add(editorPane, BorderLayout.CENTER); return panel; } diff --git a/src/main/java/com/devoxx/genie/ui/processor/FencedCodeBlockProcessor.java b/src/main/java/com/devoxx/genie/ui/processor/FencedCodeBlockProcessor.java index 4ac8b9ff..4c5741cd 100644 --- a/src/main/java/com/devoxx/genie/ui/processor/FencedCodeBlockProcessor.java +++ b/src/main/java/com/devoxx/genie/ui/processor/FencedCodeBlockProcessor.java @@ -10,6 +10,7 @@ import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileEditorManager; +import com.intellij.ui.components.JBPanel; import org.commonmark.node.FencedCodeBlock; import org.commonmark.renderer.html.HtmlRenderer; @@ -18,6 +19,8 @@ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.StringSelection; +import static com.devoxx.genie.ui.util.DevoxxGenieColors.CODE_BG_COLOR; +import static com.devoxx.genie.ui.util.DevoxxGenieColors.CODE_BORDER_BG_COLOR; import static com.devoxx.genie.ui.util.DevoxxGenieIcons.CopyIcon; import static com.devoxx.genie.ui.util.DevoxxGenieIcons.InsertCodeIcon; @@ -41,11 +44,12 @@ public JPanel process() { HtmlRenderer htmlRenderer = createHtmlRenderer(chatMessageContext.getProject()); String htmlOutput = htmlRenderer.render(fencedCodeBlock); JEditorPane editorPane = createEditorPane(htmlOutput, StyleSheetsFactory.createCodeStyleSheet()); - editorPane.setBorder(BorderFactory.createLineBorder(Color.BLACK, 4)); + editorPane.setBorder(BorderFactory.createLineBorder(CODE_BORDER_BG_COLOR, 1)); // Initialize the overlay panel and set the OverlayLayout correctly JPanel overlayPanel = new JPanel(new BorderLayout()); - overlayPanel.setBackground(Color.BLACK); + overlayPanel.setBackground(CODE_BG_COLOR); + overlayPanel.setOpaque(true); // Add components to the overlay panel in the correct order overlayPanel.add(editorPane, BorderLayout.CENTER); // Editor pane at the bottom @@ -76,24 +80,6 @@ private JPanel createClipBoardButtonPanel(FencedCodeBlock fencedCodeBlock, JEdit insertButton.setVisible(true); insertButton.setOpaque(true); buttonPanel.add(insertButton); -// -// editorPane.addMouseMotionListener(new MouseAdapter() { -// @Override -// public void mouseMoved(MouseEvent e) { -// copyButton.setVisible(true); -// insertButton.setVisible(true); -// } -// }); -// -// editorPane.addMouseListener(new MouseAdapter() { -// @Override -// public void mouseExited(MouseEvent e) { -// copyButton.setVisible(false); -// insertButton.setVisible(false); -// buttonPanel.revalidate(); -// } -// }); - return buttonPanel; } diff --git a/src/main/java/com/devoxx/genie/ui/util/DevoxxGenieColors.java b/src/main/java/com/devoxx/genie/ui/util/DevoxxGenieColors.java index c5801e12..f81f0499 100644 --- a/src/main/java/com/devoxx/genie/ui/util/DevoxxGenieColors.java +++ b/src/main/java/com/devoxx/genie/ui/util/DevoxxGenieColors.java @@ -11,21 +11,16 @@ public class DevoxxGenieColors { public static final Color GRAY_DARK = Gray._85; // Darker for dark theme if desired public static final Color TRANSPARENT_COLOR = new JBColor(new Color(0, 0, 0, 0), new Color(0, 0, 0, 0)); + public static final Color HOVER_BG_COLOR = new JBColor(new Color(192, 192, 192, 50), new Color(192, 192, 192, 50)); - public static final Color DEFAULT_BG_COLOR = new JBColor(new Color(61, 63, 66), new Color(255, 255, 255)); + public static final Color CODE_BORDER_BG_COLOR = new JBColor(new Color(192, 192, 192, 100), new Color(192, 192, 192, 50)); public static final Color PROMPT_BG_COLOR = new JBColor(new Color(42, 45, 48), new Color(33, 36, 39)); - public static final Color PROMPT_INPUT_BORDER = new JBColor(new Color(37, 150, 190), new Color(28, 141, 181)); - - public static final Color WARNING_BG_COLOR = new JBColor(Color.RED, new Color(255, 69, 0)); // Making dark theme slightly different + public static final Color CODE_BG_COLOR = new JBColor(new Color(211, 211, 211, 100), new Color(10, 10, 10, 100)); - public static final Color INPUT_AREA_BORDER = PROMPT_INPUT_BORDER; // Reuse if same as PROMPT_INPUT_BORDER - - private static final Color LIGHT_GRAY_REGULAR = new Color(56, 59, 64); - private static final Color LIGHT_GRAY_DARK = new Color(45, 48, 52); // Slightly darker for dark theme + public static final Color PROMPT_INPUT_BORDER = new JBColor(new Color(37, 150, 190), new Color(28, 141, 181)); public static final Color GRAY_COLOR = new JBColor(GRAY_REGULAR, GRAY_DARK); - public static final Color LIGHT_GRAY_COLOR = new JBColor(LIGHT_GRAY_REGULAR, LIGHT_GRAY_DARK); }