Skip to content

Commit

Permalink
Merge pull request #450 from devoxx/issue-447
Browse files Browse the repository at this point in the history
Fix #447 : Broken UI elements on Windows/Linux fixed
  • Loading branch information
stephanj authored Jan 27, 2025
2 parents defe30e + 3e8f038 commit 57d81ef
Show file tree
Hide file tree
Showing 19 changed files with 206 additions and 268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void fileOpened(@NotNull FileEditorManager source, @NotNull VirtualFile f
return;
}
addFileBtn.setEnabled(true);
// addFileBtn.setToolTipText("Select file(s) for prompt context");
addFileBtn.setToolTipText("Select file(s) for prompt context");
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public FileEntryComponent(Project project, @NotNull VirtualFile file, FileRemove
add(removeButton, BorderLayout.EAST);

// Set tooltip for the entire component
// setToolTipText(tooltipText);
setToolTipText(tooltipText);

// Set preferred size
setPreferredSize(new Dimension(0, 25));
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/com/devoxx/genie/ui/component/InputSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public InputSwitch(String label, String tooltip) {
textLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0));

// Set tooltip for both components
// textLabel.setToolTipText(tooltip);
// switchButton.setToolTipText(tooltip);
textLabel.setToolTipText(tooltip);
switchButton.setToolTipText(tooltip);

// Initialize timer
timer = new Timer(0, new MyActionListener());
Expand Down Expand Up @@ -161,12 +161,12 @@ public void setSelected(boolean selected) {
runEvent();
}

// @Override
// public void setToolTipText(String text) {
// super.setToolTipText(text);
// textLabel.setToolTipText(text);
// switchButton.setToolTipText(text);
// }
@Override
public void setToolTipText(String text) {
super.setToolTipText(text);
textLabel.setToolTipText(text);
switchButton.setToolTipText(text);
}

private class MyActionListener implements ActionListener {
@Override
Expand Down Expand Up @@ -194,4 +194,4 @@ public void actionPerformed(ActionEvent ae) {
}
}
}
}
}
79 changes: 0 additions & 79 deletions src/main/java/com/devoxx/genie/ui/component/JHoverButton.java

This file was deleted.

90 changes: 90 additions & 0 deletions src/main/java/com/devoxx/genie/ui/component/button/ButtonUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.devoxx.genie.ui.component.button;

import com.intellij.ui.scale.JBUIScale;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.function.Consumer;

import static com.devoxx.genie.ui.util.DevoxxGenieColorsUtil.HOVER_BG_COLOR;
import static com.devoxx.genie.ui.util.DevoxxGenieColorsUtil.TRANSPARENT_COLOR;

public class ButtonUtil {

// Set minimum size for buttons to prevent them from becoming too small
private final static Dimension minSize = new Dimension(100, 30);
private final static Dimension maxSize = new Dimension(200, 30);

public static @NotNull JButton createActionButton(String label,
@NotNull Consumer<ActionEvent> actionListener) {
return createActionButton(label, null, "", actionListener);
}

public static @NotNull JButton createActionButton(Icon icon,
@NotNull Consumer<ActionEvent> actionListener) {
return createActionButton("", icon, "", actionListener);
}

public static @NotNull JButton createActionButton(Icon icon,
String tooltipText,
@NotNull Consumer<ActionEvent> actionListener) {
return createActionButton("", icon, tooltipText, actionListener);
}

public static @NotNull JButton createActionButton(String label,
Icon icon,
@NotNull Consumer<ActionEvent> actionListener) {
return createActionButton(label, icon, "", actionListener);
}

public static @NotNull JButton createActionButton(String label,
Icon icon,
String tooltipText,
@NotNull Consumer<ActionEvent> actionListener) {
JButton button = new JButton(label);
if (icon != null) {
button.setIcon(icon);
}
button.setToolTipText(tooltipText);
button.setBorder(BorderFactory.createEmptyBorder());
button.addMouseListener(new ButtonHoverEffect(button));
button.addActionListener(actionListener::accept);
button.setMinimumSize(minSize);
button.setMaximumSize(maxSize);
button.setContentAreaFilled(false);
button.setOpaque(true);

if (label == null || label.isEmpty()) {
int fontSize = (int) JBUIScale.scale(14f) + 6;
button.setPreferredSize(new Dimension(fontSize, 30));
}

return button;
}

static class ButtonHoverEffect extends MouseAdapter {
private final JButton button;
private final Color originalColor;

public ButtonHoverEffect(@NotNull JButton button) {
this.button = button;
this.originalColor = button.getBackground();
this.button.setBackground(TRANSPARENT_COLOR);
}

@Override
public void mouseEntered(MouseEvent e) {
button.setBackground(HOVER_BG_COLOR);
}

@Override
public void mouseExited(MouseEvent e) {
button.setBackground(originalColor);
}
}

}
54 changes: 8 additions & 46 deletions src/main/java/com/devoxx/genie/ui/panel/ActionButtonsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.devoxx.genie.ui.DevoxxGenieToolWindowContent;
import com.devoxx.genie.ui.EditorFileButtonManager;
import com.devoxx.genie.ui.component.ContextPopupMenu;
import com.devoxx.genie.ui.component.JHoverButton;
import com.devoxx.genie.ui.component.TokenUsageBar;
import com.devoxx.genie.ui.component.input.PromptInputArea;
import com.devoxx.genie.ui.listener.GlowingListener;
Expand All @@ -35,6 +34,7 @@
import java.util.List;

import static com.devoxx.genie.model.Constant.*;
import static com.devoxx.genie.ui.component.button.ButtonUtil.createActionButton;
import static com.devoxx.genie.ui.util.DevoxxGenieIconsUtil.*;

public class ActionButtonsPanel extends JPanel
Expand All @@ -54,10 +54,6 @@ public class ActionButtonsPanel extends JPanel

private final JPanel calcProjectPanel = createCalcProjectPanel();

// Set minimum size for buttons to prevent them from becoming too small
private final Dimension minSize = new Dimension(100, 30);
private final Dimension maxSize = new Dimension(200, 30);

private final PromptInputArea promptInputArea;
private final TokenUsageBar tokenUsageBar = createTokenUsageBar();

Expand All @@ -74,7 +70,6 @@ public ActionButtonsPanel(Project project,
ComboBox<LanguageModel> modelNameComboBox,
DevoxxGenieToolWindowContent devoxxGenieToolWindowContent) {
setLayout(new BorderLayout());
// setBorder(JBUI.Borders.empty(10));

// Initialize fields and components
this.project = project;
Expand Down Expand Up @@ -106,10 +101,10 @@ private void setupUI() {
}

private void createButtons() {
submitBtn = createSubmitButton();
addFileBtn = createAddFileButton();
addProjectBtn = createAddProjectButton();
calcTokenCostBtn = createCalcTokenCostButton();
submitBtn = createActionButton(SubmitIcon, this::onSubmitPrompt);
addFileBtn = createActionButton(AddFileIcon, this::selectFilesForPromptContext);
addProjectBtn = createActionButton(ADD_PROJECT_TO_CONTEXT, AddFileIcon, this::handleProjectContext);
calcTokenCostBtn = createActionButton(CALC_TOKENS_COST, CalculateIcon, e -> controller.calculateTokensAndCost());
}

private @NotNull JPanel createButtonPanel() {
Expand Down Expand Up @@ -138,22 +133,6 @@ private void createButtons() {
return progressPanel;
}

private @NotNull JButton createCalcTokenCostButton() {
JButton button = new JHoverButton(CALC_TOKENS_COST, CalculateIcon, true);
button.addActionListener(e -> controller.calculateTokensAndCost());
button.setMinimumSize(minSize);
button.setMaximumSize(maxSize);
return button;
}

private @NotNull JButton createAddProjectButton() {
JButton button = new JHoverButton(ADD_PROJECT_TO_CONTEXT, AddFileIcon, true);
button.addActionListener(this::handleProjectContext);
button.setMinimumSize(minSize);
button.setMaximumSize(maxSize);
return button;
}

private void handleProjectContext(ActionEvent e) {
if (projectContextController.isProjectContextAdded()) {
confirmProjectContextRemoval();
Expand All @@ -162,23 +141,6 @@ private void handleProjectContext(ActionEvent e) {
}
}

private @NotNull JButton createAddFileButton() {
JButton button = new JHoverButton(AddFileIcon, false);
button.addActionListener(this::selectFilesForPromptContext);
button.setMinimumSize(minSize);
button.setMaximumSize(maxSize);
return button;
}

private @NotNull JButton createSubmitButton() {
JButton button = new JHoverButton(SubmitIcon, false);
button.setActionCommand(Constant.SUBMIT_ACTION);
button.addActionListener(this::onSubmitPrompt);
button.setMinimumSize(minSize);
button.setMaximumSize(maxSize);
return button;
}

/**
* Add files to the prompt context.
*/
Expand Down Expand Up @@ -237,7 +199,7 @@ public void disableButtons() {
public void disableSubmitBtn() {
ApplicationManager.getApplication().invokeLater(() -> {
submitBtn.setIcon(StopIcon);
// submitBtn.setToolTipText(PROMPT_IS_RUNNING_PLEASE_BE_PATIENT);
submitBtn.setToolTipText(PROMPT_IS_RUNNING_PLEASE_BE_PATIENT);
});
}

Expand All @@ -263,7 +225,7 @@ public void updateAddProjectButton(boolean isProjectContextAdded, int tokenCount
private void setAddProjectButton(Icon addFileIcon, String addProjectToContext, String addEntireProjectToPromptContext) {
addProjectBtn.setIcon(addFileIcon);
addProjectBtn.setText(addProjectToContext);
// addProjectBtn.setToolTipText(addEntireProjectToPromptContext);
addProjectBtn.setToolTipText(addEntireProjectToPromptContext);
}

public void setAddProjectButtonEnabled(boolean enabled) {
Expand Down Expand Up @@ -346,4 +308,4 @@ public void onTokenCalculationComplete(String message) {
NotificationUtil.sendNotification(project, message);

}
}
}
Loading

0 comments on commit 57d81ef

Please sign in to comment.