Author: tilman
Date: Tue Aug 25 13:25:15 2026
New Revision: 1937434
Log:
PDFBOX-6240: add a title bar to the popup; swing changes by copilot
Modified:
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Modified:
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
==============================================================================
---
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Tue Aug 25 13:25:11 2026 (r1937433)
+++
pdfbox/trunk/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Tue Aug 25 13:25:15 2026 (r1937434)
@@ -84,6 +84,7 @@ import org.apache.pdfbox.pdmodel.interac
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationFreeText;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationLink;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationMarkup;
import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
import
org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
import
org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDNamedDestination;
@@ -118,6 +119,7 @@ public class PagePane implements ActionL
private final AffineTransform defaultTransform =
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getDefaultConfiguration().getDefaultTransform();
private JWindow hoverWindow;
+ private JLabel hoverTitleLabel;
private JTextArea hoverTextArea;
// more ideas:
@@ -153,6 +155,11 @@ public class PagePane implements ActionL
hoverWindow = new JWindow();
hoverWindow.setAlwaysOnTop(true);
+ hoverTitleLabel = new JLabel("Annotation");
+ hoverTitleLabel.setOpaque(true);
+ hoverTitleLabel.setBackground(new Color(230, 230, 230));
+ hoverTitleLabel.setBorder(BorderFactory.createEmptyBorder(4, 8, 4, 8));
+
hoverTextArea = new JTextArea(4, 24);
hoverTextArea.setEditable(false);
hoverTextArea.setOpaque(true);
@@ -161,7 +168,8 @@ public class PagePane implements ActionL
hoverTextArea.setBorder(BorderFactory.createEmptyBorder(6, 8, 6, 8));
JPanel content = new JPanel(new BorderLayout());
- content.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); //
thin border
+ content.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1));
+ content.add(hoverTitleLabel, BorderLayout.NORTH);
content.add(hoverTextArea, BorderLayout.CENTER);
hoverWindow.setContentPane(content);
@@ -486,6 +494,7 @@ public class PagePane implements ActionL
int y1;
PDRectangle hitRect = null;
String hitText = null;
+ String hitTitle = null;
switch ((RotationMenu.getRotationDegrees() + page.getRotation()) % 360)
{
@@ -529,6 +538,10 @@ public class PagePane implements ActionL
{
hitRect = rectangle;
hitText = contents;
+ if (annotation instanceof PDAnnotationMarkup)
+ {
+ hitTitle = ((PDAnnotationMarkup)
annotation).getTitlePopup();
+ }
}
text += ", " + s;
break;
@@ -540,7 +553,7 @@ public class PagePane implements ActionL
if (hitRect != null)
{
- showHoverPopup(e, hitText);
+ showHoverPopup(e, hitText, hitTitle);
}
else
{
@@ -548,10 +561,19 @@ public class PagePane implements ActionL
}
}
- private void showHoverPopup(MouseEvent e, String text)
+ private void showHoverPopup(MouseEvent e, String text, String title)
{
hoverTextArea.setText(text);
hoverTextArea.setCaretPosition(0);
+ if (title != null && !title.isEmpty())
+ {
+ hoverTitleLabel.setVisible(true);
+ hoverTitleLabel.setText(title);
+ }
+ else
+ {
+ hoverTitleLabel.setVisible(false);
+ }
hoverWindow.pack();
Point screen = e.getLocationOnScreen();