Skip to content

Commit

Permalink
Use Annotation rather than playing with JEditorPane
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaroslav Tulach committed Feb 2, 2025
1 parent 9ee80e5 commit c4f059d
Showing 1 changed file with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

package org.graalvm.visualizer.source.impl.ui;

import javax.swing.JEditorPane;
import org.graalvm.visualizer.source.Location;
import org.graalvm.visualizer.source.ui.Trackable;
import org.netbeans.api.actions.Openable;
Expand All @@ -39,6 +38,7 @@
import javax.swing.text.JTextComponent;
import javax.swing.text.StyledDocument;
import org.openide.text.Annotatable;
import org.openide.text.Annotation;
import org.openide.text.NbDocument;
import org.openide.util.Mutex;
import org.openide.util.Task;
Expand Down Expand Up @@ -92,23 +92,8 @@ public void run() {
line.show(Line.ShowOpenType.REUSE, focus ? Line.ShowVisibilityType.FRONT : Line.ShowVisibilityType.FRONT);
} else if (select instanceof Line.Part) {
Line.Part part = (Line.Part) select;

part.getLine().show(Line.ShowOpenType.REUSE, focus ? Line.ShowVisibilityType.FRONT : Line.ShowVisibilityType.FRONT);
Mutex.EVENT.postReadRequest(() -> {
// later
int line = part.getLine().getLineNumber();
int startLineOffset = NbDocument.findLineOffset(doc, line);
int startOffset = startLineOffset + part.getColumn();
int endOffset = startLineOffset + part.getLength();
final JEditorPane[] panes = cake.getOpenedPanes();
if (panes != null) {
for (JEditorPane p : panes) {
p.select(startOffset, endOffset);
}
} else {
cake.open();
}
});
CurrentNodeAnnotation.INSTANCE.attach(part);
} else {
// neither line nor offsets
cake.open();
Expand Down Expand Up @@ -182,4 +167,21 @@ private static Line findLine(Line.Set lines, int line) {
return null;
}
}

private static final class CurrentNodeAnnotation extends Annotation {
static final Annotation INSTANCE = new CurrentNodeAnnotation();

private CurrentNodeAnnotation() {
}

@Override
public String getAnnotationType() {
return "NodePositionCurrent";
}

@Override
public String getShortDescription() {
return "Representing a node";
}
}
}

0 comments on commit c4f059d

Please sign in to comment.