Skip to content

Commit

Permalink
feature(ui): Enable key based navigation on the JBScrollPane of the F…
Browse files Browse the repository at this point in the history
…lameGraph
  • Loading branch information
bric3 committed Feb 6, 2022
1 parent 7b9f05b commit 7d5afcc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/github/bric3/fireplace/FirePlaceMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public static void main(String[] args) {
sysProps.addPropertyChangeListener("text", evt -> CompletableFuture.runAsync(() -> updateContent(sysProps, t -> t.setText(jvmSystemProperties(eventSupplier.get())))));

var jTabbedPane = new JTabbedPane();
jTabbedPane.addTab(SYSTEM_PROPERTIES, JScrollPaneWithButton.create(sysProps));
jTabbedPane.addTab(NATIVE_LIBRARIES, JScrollPaneWithButton.create(nativeLibs));
jTabbedPane.addTab(SYSTEM_PROPERTIES, JScrollPaneWithButton.create(() -> new JScrollPane(sysProps)));
jTabbedPane.addTab(NATIVE_LIBRARIES, JScrollPaneWithButton.create(() -> new JScrollPane(nativeLibs)));
jTabbedPane.addTab(ALLOCATIONS, allocationFlameGraphPanel);
jTabbedPane.addTab(CPU, cpuFlameGraphPanel);
jTabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ public FlameGraph(List<FrameBox<T>> framesSupplier,
ToolTipManager.sharedInstance().registerComponent(canvas);

component = JScrollPaneWithButton.create(
canvas,
scrollPane -> {
() -> {
var scrollPane = new JScrollPane(canvas);
scrollPane.getVerticalScrollBar().setUnitIncrement(16);
scrollPane.getHorizontalScrollBar().setUnitIncrement(16);
new ScrollPaneMouseListener<>(canvas, flameGraphPainter, extractToolTip).install(scrollPane);
new FGMouseInputListener<>(canvas, flameGraphPainter, extractToolTip).install(scrollPane);
new MouseInputListenerWorkaroundForToolTipEnabledComponent(scrollPane).install(canvas);
canvas.linkListenerTo(scrollPane);

return scrollPane;
}
);
}
Expand All @@ -77,14 +79,13 @@ public void requestRepaint() {
canvas.triggerMinimapGeneration();
}


static class ScrollPaneMouseListener<T> implements MouseInputListener {
static class FGMouseInputListener<T> implements MouseInputListener {
private Point pressedPoint;
private FlameGraphCanvas<T> canvas;
private final FlameGraphCanvas<T> canvas;
private final FlameGraphPainter<T> flameGraph;
private final Function<FrameBox<T>, String> extractToolTip;

public ScrollPaneMouseListener(FlameGraphCanvas<T> canvas, FlameGraphPainter<T> flameGraph, Function<FrameBox<T>, String> extractToolTip) {
public FGMouseInputListener(FlameGraphCanvas<T> canvas, FlameGraphPainter<T> flameGraph, Function<FrameBox<T>, String> extractToolTip) {
this.canvas = canvas;
this.flameGraph = flameGraph;
this.extractToolTip = extractToolTip;
Expand Down Expand Up @@ -156,7 +157,12 @@ public void mouseClicked(MouseEvent e) {
}

@Override
public void mouseEntered(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {
// this seems to enable key navigation
if ((e.getComponent() instanceof JScrollPane)) {
e.getComponent().requestFocus();
}
}

@Override
public void mouseExited(MouseEvent e) {
Expand All @@ -165,7 +171,6 @@ public void mouseExited(MouseEvent e) {
flameGraph.stopHover();
scrollPane.repaint();
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.geom.Path2D;
import java.util.function.Consumer;
import java.util.function.Supplier;

public abstract class JScrollPaneWithButton {

public static JLayer<JScrollPane> create(JComponent content, Consumer<JScrollPane> scrollPaneModifier) {
var jScrollPane = new JScrollPane(content);
scrollPaneModifier.accept(jScrollPane);
return new JLayer<>(jScrollPane, new ScrollBackToTopLayerUI(15, 15));
}

public static JLayer<JScrollPane> create(JComponent content) {
return create(content, sp -> {});
public static JLayer<JScrollPane> create(Supplier<JScrollPane> scrollPaneSupplier) {
return new JLayer<>(scrollPaneSupplier.get(),
new ScrollBackToTopLayerUI(15, 15));
}

private static class ScrollBackToTopLayerUI extends LayerUI<JScrollPane> {
Expand Down

0 comments on commit 7d5afcc

Please sign in to comment.