Skip to content

Commit

Permalink
fix: Made ColorModel property not null (now with default values).
Browse files Browse the repository at this point in the history
  • Loading branch information
bric3 committed Mar 11, 2024
1 parent 02eb225 commit 54fa280
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import java.util.stream.Collectors.toCollection
import javax.swing.*
import javax.swing.Timer

@OptIn(ExperimentalStdlibApi::class)
class FlamegraphPane : JPanel(BorderLayout()) {
private var jfrFlamegraphView: FlamegraphView<Node>
private var dataApplier: Consumer<FlamegraphView<Node>>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
package io.github.bric3.fireplace.ui.toolkit

import io.github.bric3.fireplace.ui.toolkit.Painter
import java.awt.*
import javax.swing.JPanel

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ public class DimmingFrameColorProvider<T> implements FrameColorProvider<@NotNull
/**
* Single instance to avoid too many allocations, only for the main canvas.
*/
private final ColorModel reusedColorModelForMainCanvas = new ColorModel(null, null);
private final ColorModel reusedColorModelForMainCanvas = new ColorModel();

/**
* Single instance to avoid too many allocations, only for the minimap.
* Since the minimap generation happens on a different thread, it is necessary
* to have a separate instance.
*/
private final ColorModel reusedColorModelForMinimap = new ColorModel(null, null);
private final ColorModel reusedColorModelForMinimap = new ColorModel();

private final ConcurrentHashMap<Color, Color> dimmedColorCache = new ConcurrentHashMap<>();

Expand Down Expand Up @@ -99,7 +99,10 @@ public ColorModel getColors(@NotNull FrameBox<@NotNull T> frame, int flags) {

if (isMinimapMode(flags)) {
// Since minimap rendering can happen in a separate thread, we need to use a separate instance
return reusedColorModelForMinimap.set(backgroundColor, null);
return reusedColorModelForMinimap.set(
backgroundColor,
ColorModel.DEFAULT_FRAME_FOREGROUND_COLOR // fg is unused when rendering minimap
);
}

if (!rootNode && shouldDim(flags)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

import io.github.bric3.fireplace.core.ui.Colors;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.util.Objects;
import java.util.function.Function;
Expand All @@ -31,18 +31,28 @@
@FunctionalInterface
public interface FrameColorProvider<T> {
class ColorModel {
@Nullable
public static Color DEFAULT_FRAME_BACKGROUND_COLOR = UIManager.getColor("Button.background");
public static Color DEFAULT_FRAME_FOREGROUND_COLOR = UIManager.getColor("Button.foreground");

@NotNull
public Color background;
@Nullable
@NotNull
public Color foreground;

/**
* Create a color model with the default colors.
*/
public ColorModel() {
this(DEFAULT_FRAME_BACKGROUND_COLOR, DEFAULT_FRAME_FOREGROUND_COLOR);
}

/**
* Data-structure that hold the computed colors for a frame.
*
* @param background The background color of the frame.
* @param foreground The foreground color of the frame.
*/
public ColorModel(@Nullable Color background, @Nullable Color foreground) {
public ColorModel(@NotNull Color background, @NotNull Color foreground) {
this.background = background;
this.foreground = foreground;
}
Expand All @@ -55,7 +65,7 @@ public ColorModel(@Nullable Color background, @Nullable Color foreground) {
* @return this
*/
@NotNull
public ColorModel set(@Nullable Color background, @Nullable Color foreground) {
public ColorModel set(@NotNull Color background, @NotNull Color foreground) {
this.background = background;
this.foreground = foreground;
return this;
Expand Down Expand Up @@ -90,7 +100,7 @@ public ColorModel copy() {
*/
private final Color highlightedColor = new Color(0xFFFFE771, true);

private final ColorModel reusableDataStructure = new ColorModel(null, null);
private final ColorModel reusableDataStructure = new ColorModel();

@Override
@NotNull
Expand Down

0 comments on commit 54fa280

Please sign in to comment.