Skip to content

Commit

Permalink
Map problem level to unique colors in overlay/paragraph-factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Col-E committed Jun 26, 2024
1 parent 505af81 commit 5c15758
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import jakarta.annotation.Nonnull;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.control.Tooltip;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
Expand Down Expand Up @@ -49,16 +50,31 @@ public void apply(@Nonnull LineContainer container, int paragraph) {
int line = paragraph + 1;
Problem problem = problemTracking.getProblem(line);
if (problem != null) {
ProblemLevel level = problem.getLevel();
Color levelColor = switch (level) {
case ERROR -> Color.RED;
case WARN -> Color.YELLOW;
default -> Color.TURQUOISE;
};
Node graphic = switch (level) {
case ERROR -> new FontIconView(CarbonIcons.ERROR, levelColor);
case WARN -> new FontIconView(CarbonIcons.WARNING_ALT, levelColor);
default -> new FontIconView(CarbonIcons.INFORMATION, levelColor);
};

Rectangle shape = new Rectangle();
shape.widthProperty().bind(container.widthProperty());
shape.heightProperty().bind(container.heightProperty());
shape.setCursor(Cursor.HAND);
shape.setFill(Color.RED);
shape.setFill(levelColor);
shape.setOpacity(0.33);

Tooltip tooltip = new Tooltip(formatTooltipMessage(problem));
tooltip.setGraphic(new FontIconView(CarbonIcons.ERROR, Color.RED));
tooltip.getStyleClass().add("error-text");
tooltip.setGraphic(graphic);
switch (level) {
case ERROR -> tooltip.getStyleClass().add("error-text");
case WARN -> tooltip.getStyleClass().add("warn-text");
}
Tooltip.install(shape, tooltip);
container.addTopLayer(shape);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,27 @@ public ProblemOverlay() {
for (Problem problem : problems) {
// Map level to graphic
ProblemLevel level = problem.getLevel();
Color levelColor = switch (level) {
case ERROR -> Color.RED;
case WARN -> Color.YELLOW;
default -> Color.TURQUOISE;
};
Node graphic = switch (level) {
case ERROR -> new FontIconView(CarbonIcons.ERROR, Color.RED);
case WARN -> new FontIconView(CarbonIcons.WARNING_ALT, Color.YELLOW);
default -> new FontIconView(CarbonIcons.INFORMATION, Color.TURQUOISE);
case ERROR -> new FontIconView(CarbonIcons.ERROR, levelColor);
case WARN -> new FontIconView(CarbonIcons.WARNING_ALT, levelColor);
default -> new FontIconView(CarbonIcons.INFORMATION, levelColor);
};

// Create 'N: Message' layout
// - Exclude line number 'N' when line number is negative
Label messageLabel = new Label(problem.getMessage());
messageLabel.setTextFill(Color.RED);
messageLabel.setTextFill(levelColor);
messageLabel.setMaxWidth(Integer.MAX_VALUE);
int line = problem.getLine();
HBox problemBox;
if (line >= 0) {
Label lineLabel = new Label(String.valueOf(line), graphic);
lineLabel.setTextFill(Color.RED);
lineLabel.setTextFill(levelColor);
lineLabel.getStyleClass().add(Styles.TEXT_BOLD);
problemBox = new HBox(lineLabel, messageLabel);
} else {
Expand Down
5 changes: 4 additions & 1 deletion recaf-ui/src/main/resources/style/tweaks.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@

/* Makes text red, typically for error displays */
.error-text {
-fx-text-fill: red;
-fx-text-fill: red;
}
.warn-text {
-fx-text-fill: yellow;
}

/* Clearly separates filter from the workspace tree */
Expand Down

0 comments on commit 5c15758

Please sign in to comment.