From 5648718cd3b4c6ca8e539a301ebccb6f152d1848 Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Sat, 27 Jan 2024 08:33:52 +0000 Subject: [PATCH] Attempt to focus on the instruction pointer. --- .../cc/squirreljme/debugger/SequentialPanel.java | 30 ++++++++++++++++++++++ .../cc/squirreljme/debugger/ShownInstruction.java | 12 +++++---- .../java/cc/squirreljme/debugger/ShownMethod.java | 3 ++- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/SequentialPanel.java b/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/SequentialPanel.java index 208c7e4bc1..4a5e090431 100644 --- a/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/SequentialPanel.java +++ b/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/SequentialPanel.java @@ -11,6 +11,7 @@ package cc.squirreljme.debugger; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; +import java.awt.Rectangle; import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JPanel; @@ -141,6 +142,35 @@ public class SequentialPanel } /** + * Look at the given component. + * + * @param __component The component to look at. + * @throws NullPointerException On null arguments. + * @since 2024/01/27 + */ + public void lookAt(JComponent __component) + throws NullPointerException + { + if (__component == null) + throw new NullPointerException("NARG"); + + // If we are using the scroll pane, we need to focus on this + JComponent viewPanel = this.viewPanel; + if (viewPanel instanceof JScrollPane) + { + JScrollPane scroll = (JScrollPane)viewPanel; + + // Scroll here + Rectangle bounds = __component.getBounds(); + /*scroll.scrollRectToVisible(bounds);*/ + scroll.getViewport().scrollRectToVisible(bounds); + + // Make sure the view is updated + Utils.revalidate(scroll); + } + } + + /** * Returns the used panel for this pane. * * @return The used panel. diff --git a/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/ShownInstruction.java b/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/ShownInstruction.java index f1f84107eb..2fb5e7bb89 100644 --- a/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/ShownInstruction.java +++ b/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/ShownInstruction.java @@ -150,16 +150,18 @@ public class ShownInstruction this._args = args; // Request that everything gets updated - Utils.swingInvoke(this::shownUpdate); + Utils.swingInvoke(() -> this.shownUpdate()); } /** * Updates the shown instruction. * + * @return If this is the instruction the pointer is at. * @since 2024/01/21 */ - public void shownUpdate() + public boolean shownUpdate() { + boolean isAt = false; InstructionViewer viewer = this.viewer; // What is our PC address? @@ -178,7 +180,6 @@ public class ShownInstruction // Is there a valid location FrameLocation location = context.getLocation(); - boolean isAt; if (location != null) { if (interpret == FrameLocationInterpret.ADDRESS) @@ -186,8 +187,6 @@ public class ShownInstruction else isAt = (location.index == index); } - else - isAt = false; // Is this the location we are at? if (isAt) @@ -209,5 +208,8 @@ public class ShownInstruction Utils.revalidate(this.address); Utils.revalidate(this.description); Utils.revalidate(this); + + // Are we here? + return isAt; } } diff --git a/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/ShownMethod.java b/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/ShownMethod.java index 248231bc15..4b2dab5fed 100644 --- a/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/ShownMethod.java +++ b/tools/squirreljme-debugger/src/main/java/cc/squirreljme/debugger/ShownMethod.java @@ -147,7 +147,8 @@ public class ShownMethod shownInstructions = this._shownInstructions; if (shownInstructions != null) for (ShownInstruction shown : shownInstructions) - shown.shownUpdate(); + if (shown.shownUpdate()) + this.seqPanel.lookAt(shown); // Repaint Utils.revalidate(this); -- 2.11.4.GIT