Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #72: Background cleanup for code blocks #73

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) + "}" +
Expand All @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 4 additions & 9 deletions src/main/java/com/devoxx/genie/ui/util/DevoxxGenieColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}