Skip to content

Commit fea7864

Browse files
Added code bashing image (#346)
1 parent 5ce6be5 commit fea7864

File tree

1 file changed

+35
-2
lines changed
  • src/main/java/com/checkmarx/intellij/tool/window/results/tree/nodes

1 file changed

+35
-2
lines changed

src/main/java/com/checkmarx/intellij/tool/window/results/tree/nodes/ResultNode.java

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import com.checkmarx.intellij.tool.window.FileNode;
1717
import com.checkmarx.intellij.tool.window.Severity;
1818
import com.intellij.icons.AllIcons;
19+
import com.intellij.ide.ui.LafManager;
20+
import com.intellij.ide.ui.LafManagerListener;
1921
import com.intellij.notification.NotificationType;
2022
import com.intellij.openapi.application.ApplicationManager;
2123
import com.intellij.openapi.diagnostic.Logger;
@@ -33,6 +35,7 @@
3335
import com.intellij.ui.components.JBScrollPane;
3436
import com.intellij.ui.components.JBTabbedPane;
3537
import com.intellij.ui.components.labels.BoldLabel;
38+
import com.intellij.util.messages.MessageBusConnection;
3639
import com.intellij.util.ui.JBUI;
3740
import lombok.EqualsAndHashCode;
3841
import lombok.Getter;
@@ -474,7 +477,18 @@ private JPanel buildDetailsPanel(@NotNull Runnable runnableDraw, Runnable runnab
474477

475478
if (result.getType().equals(CxConstants.SAST)) {
476479
//Creating codebashing label
477-
JLabel codebashing = new JLabel("<html>Learn more at <font color='#F36A22'><b>>_</b></font>codebashing</html>");
480+
JLabel codebashing = new JLabel();
481+
updateCodebashingImage(codebashing); // Set the initial image
482+
483+
// listener to detect theme changes
484+
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
485+
connection.subscribe(LafManagerListener.TOPIC, new LafManagerListener() {
486+
@Override
487+
public void lookAndFeelChanged(LafManager source) {
488+
updateCodebashingImage(codebashing);
489+
}
490+
});
491+
478492
codebashing.setCursor(new Cursor(Cursor.HAND_CURSOR));
479493
codebashing.setToolTipText(String.format("Learn more about %s using Checkmarx's eLearning platform ", result.getData().getQueryName()));
480494
codebashing.addMouseListener(new MouseAdapter() {
@@ -490,7 +504,6 @@ public void mouseClicked(MouseEvent e) {
490504

491505
details.add(header, "span, growx, wrap");
492506
details.add(new JSeparator(), "span, growx, wrap");
493-
494507
boolean triageEnabled = !result.getType().equals(Constants.SCAN_TYPE_SCA);
495508
//Panel with triage form, not available to sca type
496509
JPanel triageForm = new JPanel(new MigLayout("fillx"));
@@ -1103,4 +1116,24 @@ public void generateCodeSamples(@NotNull LearnMore learnMore, JPanel panel) {
11031116
"wrap, gapbottom 3, gapleft 0");
11041117
}
11051118
}
1119+
1120+
// Method to update the image based on the current theme of the IDE
1121+
private void updateCodebashingImage(JLabel codebashing) {
1122+
ImageIcon icon;
1123+
if (UIManager.getColor("Panel.background").getRed() > 128) {
1124+
// Light theme
1125+
icon = new ImageIcon(getClass().getResource("/icons/codebashing_light.png"));
1126+
} else {
1127+
// Dark theme
1128+
icon = new ImageIcon(getClass().getResource("/icons/codebashing_dark.png"));
1129+
}
1130+
Image scaledImage = icon.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH);
1131+
ImageIcon scaledIcon = new ImageIcon(scaledImage);
1132+
1133+
// Update the JLabel with the new image
1134+
codebashing.setIcon(scaledIcon);
1135+
codebashing.setText("Learn more at ");
1136+
codebashing.setHorizontalTextPosition(SwingConstants.LEFT);
1137+
codebashing.setVerticalTextPosition(SwingConstants.CENTER);
1138+
}
11061139
}

0 commit comments

Comments
 (0)