Skip to content

Commit

Permalink
GH-328 normalize popup size relative to page size. (#332)
Browse files Browse the repository at this point in the history
Co-authored-by: Patrick Corless <patrick.corless@arterys.com>
  • Loading branch information
pcorless and Patrick Corless committed Jan 25, 2024
1 parent 048ec0a commit a286485
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,12 @@ public void mouseReleased(MouseEvent e) {
annotation.setRectangle(rectangle);
annotation.setBorderStyle(borderStyle);

AffineTransform pageTransform = getToPageSpaceTransform();
AffineTransform toPageSpaceTransform = getToPageSpaceTransform();
AffineTransform pageTransform = getPageTransform();

// pass outline shapes and bounds to create the highlight shapes
annotation.setBBox(new Rectangle(0, 0, tBbox.width, tBbox.height));
annotation.resetAppearanceStream(pageTransform);
annotation.resetAppearanceStream(toPageSpaceTransform);

// create the annotation object.
MarkupAnnotationComponent comp = (MarkupAnnotationComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ public void createTextMarkupAnnotation(ArrayList<Shape> highlightBounds) {

Rectangle tBbox = convertToPageSpace(highlightBounds, highlightPath);

AffineTransform pageTransform = getToPageSpaceTransform();
AffineTransform toPageSpaceTransform = getToPageSpaceTransform();
AffineTransform pageTransform = getPageTransform();

// create annotations types that that are rectangle based;
// create annotations types that are rectangle based;
// which is actually just link annotations
annotation = (TextMarkupAnnotation)
AnnotationFactory.buildAnnotation(
Expand All @@ -182,7 +183,7 @@ public void createTextMarkupAnnotation(ArrayList<Shape> highlightBounds) {
annotation.setMarkupPath(highlightPath);
annotation.setBBox(tBbox);
// finalized the appearance properties.
annotation.resetAppearanceStream(pageTransform);
annotation.resetAppearanceStream(toPageSpaceTransform);

// create new annotation given the general path
MarkupAnnotationComponent comp = (MarkupAnnotationComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,12 @@ protected void buildInkAnnotation() {
annotation.setInkPath(tInkPath);
annotation.setOpacity(opacity);

AffineTransform pageTransform = getToPageSpaceTransform();
AffineTransform toPageSpaceTransform = getToPageSpaceTransform();
AffineTransform pageTransform = getPageTransform();

// pass outline shapes and bounds to create the highlight shapes
annotation.setBBox(tBbox);
annotation.resetAppearanceStream(pageTransform);
annotation.resetAppearanceStream(toPageSpaceTransform);

// create the annotation object.
MarkupAnnotationComponent comp = (MarkupAnnotationComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ public void mouseReleased(MouseEvent e) {
annotation.setInteriorColor(internalColor);
annotation.setOpacity(opacity);

AffineTransform pageTransform = getToPageSpaceTransform();
AffineTransform toPageSpaceTransform = getToPageSpaceTransform();
AffineTransform pageTransform = getPageTransform();

// setup the markup properties.
annotation.setContents(annotation.getSubType().toString());
Expand All @@ -202,7 +203,7 @@ public void mouseReleased(MouseEvent e) {

// pass outline shapes and bounds to create the highlight shapes
annotation.setBBox(tBbox);
annotation.resetAppearanceStream(pageTransform);
annotation.resetAppearanceStream(toPageSpaceTransform);

// create the annotation object.
MarkupAnnotationComponent comp = (MarkupAnnotationComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,12 @@ public void mouseReleased(MouseEvent e) {
annotation.setRectangle(rectangle);
annotation.setBorderStyle(borderStyle);

AffineTransform pageTransform = getToPageSpaceTransform();
AffineTransform toPageSpaceTransform = getToPageSpaceTransform();
AffineTransform pageTransform = getPageTransform();

// pass outline shapes and bounds to create the highlight shapes
annotation.setBBox(new Rectangle(0, 0, tBbox.width, tBbox.height));
annotation.resetAppearanceStream(pageTransform);
annotation.resetAppearanceStream(toPageSpaceTransform);

// create the annotation object.
MarkupAnnotationComponent comp = (MarkupAnnotationComponent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,11 @@ public static PopupAnnotation createPopupAnnotation(Library library, Rectangle b

public void mouseReleased(MouseEvent e) {

AffineTransform pageTransform = getToPageSpaceTransform();
AffineTransform pageInverseTransform = getPageTransform();
AffineTransform toPageSpaceTransform = getToPageSpaceTransform();
AffineTransform pageTransform = getPageTransform();
Dimension scaledSize = new Dimension(
(int) Math.abs(ICON_SIZE.width * pageInverseTransform.getScaleX()),
(int) Math.abs(ICON_SIZE.height * pageInverseTransform.getScaleY()));
(int) Math.abs(ICON_SIZE.width * pageTransform.getScaleX()),
(int) Math.abs(ICON_SIZE.height * pageTransform.getScaleY()));

// convert bbox and start and end line points.
Rectangle bBox = new Rectangle(e.getX(), e.getY(), scaledSize.width, scaledSize.height);
Expand All @@ -192,7 +192,7 @@ public void mouseReleased(MouseEvent e) {
// text annotation are special as the annotation has fixed size.
TextAnnotation markupAnnotation =
createTextAnnotationInstance(documentViewController.getDocument().getPageTree().getLibrary(),
tBbox, pageTransform);
tBbox, toPageSpaceTransform);

// create the annotation object.
MarkupAnnotationComponent comp = (MarkupAnnotationComponent)
Expand All @@ -206,12 +206,12 @@ public void mouseReleased(MouseEvent e) {
// add them to the container, using absolute positioning.
documentViewController.addNewAnnotation(comp);

// setup the popup so that it will show near the annotation.
// set up the popup so that it will show near the annotation.
PopupAnnotationComponent popupAnnotationComponent = comp.getPopupAnnotationComponent();
popupAnnotationComponent.setBoundsRelativeToParent(
e.getX() + scaledSize.width / 2,
e.getY() + scaledSize.height / 2,
pageInverseTransform);
e.getX() + bBox.width / 2,
e.getY() + bBox.height / 2,
pageTransform);
popupAnnotationComponent.setVisible(true);
popupAnnotationComponent.getAnnotation().setOpen(true);
popupAnnotationComponent.focusTextArea();
Expand Down

0 comments on commit a286485

Please sign in to comment.