Skip to content

Commit

Permalink
pcorlessGH-328 Allows setting default width and height of popup and u…
Browse files Browse the repository at this point in the history
…ses the same values for all the annotations
  • Loading branch information
Guillaume Tâche committed Dec 22, 2023
1 parent 12d2762 commit 4f3b56d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void mouseReleased(MouseEvent e) {
// associate popup to location
PopupAnnotationComponent popupAnnotationComponent = comp.getPopupAnnotationComponent();
popupAnnotationComponent.setBoundsRelativeToParent(
bbox.x + (bbox.width / 2), bbox.y + (bbox.height / 2), pageTransform);
bbox.x + (bbox.width / 2), bbox.y + (bbox.height / 2));
popupAnnotationComponent.setVisible(false);
popupAnnotationComponent.getAnnotation().setOpen(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void createTextMarkupAnnotation(ArrayList<Shape> highlightBounds) {
// associate popup to location
PopupAnnotationComponent popupAnnotationComponent = comp.getPopupAnnotationComponent();
popupAnnotationComponent.setBoundsRelativeToParent(
bounds.x + bounds.width / 2, bounds.y + bounds.height / 2, pageTransform);
bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
popupAnnotationComponent.setVisible(false);
popupAnnotationComponent.getAnnotation().setOpen(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ protected void buildInkAnnotation() {
// associate popup to location
PopupAnnotationComponent popupAnnotationComponent = comp.getPopupAnnotationComponent();
popupAnnotationComponent.setBoundsRelativeToParent(
bBox.x + (bBox.width / 2), bBox.y + (bBox.height / 2), pageTransform);
bBox.x + (bBox.width / 2), bBox.y + (bBox.height / 2));
popupAnnotationComponent.setVisible(false);
popupAnnotationComponent.getAnnotation().setOpen(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public void mouseReleased(MouseEvent e) {
// associate popup to location
PopupAnnotationComponent popupAnnotationComponent = comp.getPopupAnnotationComponent();
popupAnnotationComponent.setBoundsRelativeToParent(
bbox.x + (bbox.width / 2), bbox.y + (bbox.height / 2), pageTransform);
bbox.x + (bbox.width / 2), bbox.y + (bbox.height / 2));
popupAnnotationComponent.setVisible(false);
popupAnnotationComponent.getAnnotation().setOpen(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void mouseReleased(MouseEvent e) {
// associate popup to location
PopupAnnotationComponent popupAnnotationComponent = comp.getPopupAnnotationComponent();
popupAnnotationComponent.setBoundsRelativeToParent(
bbox.x + (bbox.width / 2), bbox.y + (bbox.height / 2), pageTransform);
bbox.x + (bbox.width / 2), bbox.y + (bbox.height / 2));
popupAnnotationComponent.setVisible(false);
popupAnnotationComponent.getAnnotation().setOpen(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public void mouseReleased(MouseEvent e) {
PopupAnnotationComponent popupAnnotationComponent = comp.getPopupAnnotationComponent();
popupAnnotationComponent.setBoundsRelativeToParent(
e.getX() + scaledSize.width / 2,
e.getY() + scaledSize.height / 2,
pageInverseTransform);
e.getY() + scaledSize.height / 2
);
popupAnnotationComponent.setVisible(true);
popupAnnotationComponent.getAnnotation().setOpen(true);
popupAnnotationComponent.focusTextArea();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.icepdf.core.pobjects.annotations.MarkupAnnotation;
import org.icepdf.core.pobjects.annotations.PopupAnnotation;
import org.icepdf.core.pobjects.annotations.TextAnnotation;
import org.icepdf.core.util.Defs;
import org.icepdf.core.util.PropertyConstants;
import org.icepdf.core.util.SystemProperties;
import org.icepdf.ri.common.ViewModel;
Expand Down Expand Up @@ -83,8 +84,8 @@ public class PopupAnnotationComponent extends AbstractAnnotationComponent<PopupA
implements TreeSelectionListener, ActionListener, DocumentListener, PropertyChangeListener, MouseWheelListener,
DropTargetListener, PageViewAnnotationComponent {

public static final int DEFAULT_WIDTH = 215;
public static final int DEFAULT_HEIGHT = 150;
public static final int DEFAULT_WIDTH = Defs.sysPropertyInt("org.icepdf.ri.popup.width.default", 215);
public static final int DEFAULT_HEIGHT = Defs.sysPropertyInt("org.icepdf.ri.popup.height.default", 150);
public static final Color backgroundColor = new Color(252, 253, 227);
public static final Dimension BUTTON_SIZE = new Dimension(22, 22);

Expand Down Expand Up @@ -472,12 +473,10 @@ public void focusTextArea() {
textArea.setCaretPosition(textArea.getDocument().getLength());
}

public void setBoundsRelativeToParent(int x, int y, AffineTransform pageInverseTransform) {
public void setBoundsRelativeToParent(int x, int y) {
Rectangle pageBounds = pageViewComponent.getParent().getBounds();
// position the new popup on the icon center.
Rectangle bBox2 = new Rectangle(x, y,
(int) Math.abs(DEFAULT_WIDTH * pageInverseTransform.getScaleX()),
(int) Math.abs(DEFAULT_HEIGHT * pageInverseTransform.getScaleY()));
Rectangle bBox2 = new Rectangle(x, y, Math.abs(DEFAULT_WIDTH), Math.abs(DEFAULT_HEIGHT));

// add page offset
bBox2.x += pageBounds.x;
Expand Down

0 comments on commit 4f3b56d

Please sign in to comment.