Skip to content

Commit

Permalink
GH-376 add some protection for popup annotations that don't have home.
Browse files Browse the repository at this point in the history
  • Loading branch information
pcorless committed Nov 22, 2024
1 parent 127bccf commit a1190a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public static PopupAnnotation getInstance(Library library,
@Override
protected void renderAppearanceStream(Graphics2D g2d, float rotation, float zoom) {
GraphicsConfiguration graphicsConfiguration = g2d.getDeviceConfiguration();
boolean isPrintingAllowed = getParent().getFlagPrint();

boolean isPrintingAllowed = getParent() != null && getParent().getFlagPrint();
if (graphicsConfiguration.getDevice().getType() == GraphicsDevice.TYPE_PRINTER &&
isOpen() &&
isPrintingAllowed) {
Expand Down Expand Up @@ -179,7 +180,8 @@ private void applyFontScaling(float zoom) {
private void buildPopupPaintables() {

Rectangle2D.Float popupBounds = getUserSpaceRectangle();
Rectangle popupBoundsNormalized = new Rectangle2D.Double(0, 0, popupBounds.width, popupBounds.height).getBounds();
Rectangle popupBoundsNormalized =
new Rectangle2D.Double(0, 0, popupBounds.width, popupBounds.height).getBounds();

popupPaintablesPanel = new JPanel();

Expand Down Expand Up @@ -229,7 +231,8 @@ private void buildPopupPaintables() {
yOffset += comp.getHeight() + padding;
}
// stretch text area.
textArea.setSize((int) (popupBounds.width - (padding * 2)), (int) (popupBounds.height + textArea.getHeight() - yOffset));
textArea.setSize((int) (popupBounds.width - (padding * 2)),
(int) (popupBounds.height + textArea.getHeight() - yOffset));
resetPopupPaintables = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,15 @@ private void refreshTree(JTree tree) {
}

public void buildContextMenu() {
//Create the popup menu.
// Create the popup menu.
MarkupAnnotationComponent comp = (MarkupAnnotationComponent) getAnnotationParentComponent();
contextMenu = new MarkupAnnotationPopupMenu(comp, documentViewController.getParentController(),
getPageViewComponent(), false);
// Add listener to components that can bring up popup menus.
popupListener = new PopupListener(contextMenu);
commentPanel.addMouseListener(popupListener);
if (comp != null) {
contextMenu = new MarkupAnnotationPopupMenu(comp, documentViewController.getParentController(),
getPageViewComponent(), false);
// Add listener to components that can bring up popup menus.
popupListener = new PopupListener(contextMenu);
commentPanel.addMouseListener(popupListener);
}
}

public void replyToSelectedMarkupExecute() {
Expand Down Expand Up @@ -1079,6 +1081,7 @@ private void addAnnotationComponent(Annotation annotation) {
}

protected AnnotationComponent findAnnotationComponent(Annotation annotation) {
if (annotation == null) return null;
return pageViewComponent.getComponentFor(annotation);
}

Expand Down

0 comments on commit a1190a3

Please sign in to comment.