From 8f91bf152fabf18359a5e4ac9d0cf5ecaca42ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Cr=C3=A9mieux?= Date: Sat, 22 Jun 2024 18:45:10 +0200 Subject: [PATCH] Define common parameter for node anchoring in DatabaseChangeDetailsView ref: https://github.com/JabRef/jabref/issues/11220 --- .../gui/collab/DatabaseChangeDetailsView.java | 30 ++++++++++++++++++- .../entrychange/EntryChangeDetailsView.java | 7 +---- .../groupchange/GroupChangeDetailsView.java | 7 +---- .../MetadataChangeDetailsView.java | 6 +--- .../PreambleChangeDetailsView.java | 6 +--- .../stringadd/BibTexStringAddDetailsView.java | 6 +--- .../BibTexStringChangeDetailsView.java | 6 +--- .../BibTexStringDeleteDetailsView.java | 6 +--- .../BibTexStringRenameDetailsView.java | 6 +--- 9 files changed, 37 insertions(+), 43 deletions(-) diff --git a/src/main/java/org/jabref/gui/collab/DatabaseChangeDetailsView.java b/src/main/java/org/jabref/gui/collab/DatabaseChangeDetailsView.java index 7e3d6c18ff5..f1160582e67 100644 --- a/src/main/java/org/jabref/gui/collab/DatabaseChangeDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/DatabaseChangeDetailsView.java @@ -1,5 +1,6 @@ package org.jabref.gui.collab; +import javafx.scene.Node; import javafx.scene.layout.AnchorPane; import org.jabref.gui.collab.entrychange.EntryChangeDetailsView; @@ -12,5 +13,32 @@ import org.jabref.gui.collab.stringdelete.BibTexStringDeleteDetailsView; import org.jabref.gui.collab.stringrename.BibTexStringRenameDetailsView; -public sealed abstract class DatabaseChangeDetailsView extends AnchorPane permits EntryWithPreviewAndSourceDetailsView, GroupChangeDetailsView, MetadataChangeDetailsView, PreambleChangeDetailsView, BibTexStringAddDetailsView, BibTexStringChangeDetailsView, BibTexStringDeleteDetailsView, BibTexStringRenameDetailsView, EntryChangeDetailsView { +public sealed abstract class DatabaseChangeDetailsView extends AnchorPane permits + EntryWithPreviewAndSourceDetailsView, + GroupChangeDetailsView, + MetadataChangeDetailsView, + PreambleChangeDetailsView, + BibTexStringAddDetailsView, + BibTexStringChangeDetailsView, + BibTexStringDeleteDetailsView, + BibTexStringRenameDetailsView, + EntryChangeDetailsView { + + private static Double ANCHOR_PANE_OFFSET = 8D; + + /** + * Set left, top, right, bottom anchors based on common offset parameter for the given child + * and attach it to children. + * + * @param child the child node of the implementation + * @see AnchorPane#getChildren() + * @see javafx.collections.ObservableList#setAll(Object[]) + */ + protected void setAllAnchorsAndAttachChild(Node child) { + setLeftAnchor(child, ANCHOR_PANE_OFFSET); + setTopAnchor(child, ANCHOR_PANE_OFFSET); + setRightAnchor(child, ANCHOR_PANE_OFFSET); + setBottomAnchor(child, ANCHOR_PANE_OFFSET); + this.getChildren().setAll(child); + } } diff --git a/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java b/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java index 4043ac4a920..f2722c5ee49 100644 --- a/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/entrychange/EntryChangeDetailsView.java @@ -72,12 +72,7 @@ public EntryChangeDetailsView(BibEntry oldEntry, SplitPane split = new SplitPane(containerOld, containerNew); split.setOrientation(Orientation.HORIZONTAL); - setLeftAnchor(split, 8d); - setTopAnchor(split, 8d); - setRightAnchor(split, 8d); - setBottomAnchor(split, 8d); - - this.getChildren().add(split); + this.setAllAnchorsAndAttachChild(split); } // Method adapted from: diff --git a/src/main/java/org/jabref/gui/collab/groupchange/GroupChangeDetailsView.java b/src/main/java/org/jabref/gui/collab/groupchange/GroupChangeDetailsView.java index 673c716ce12..de428484f29 100644 --- a/src/main/java/org/jabref/gui/collab/groupchange/GroupChangeDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/groupchange/GroupChangeDetailsView.java @@ -17,11 +17,6 @@ public GroupChangeDetailsView(GroupChange groupChange) { Label label = new Label(labelValue); label.setWrapText(true); - setLeftAnchor(label, 8d); - setTopAnchor(label, 8d); - setRightAnchor(label, 8d); - setBottomAnchor(label, 8d); - - getChildren().setAll(label); + this.setAllAnchorsAndAttachChild(label); } } diff --git a/src/main/java/org/jabref/gui/collab/metedatachange/MetadataChangeDetailsView.java b/src/main/java/org/jabref/gui/collab/metedatachange/MetadataChangeDetailsView.java index 199057036ff..7a6da5205b9 100644 --- a/src/main/java/org/jabref/gui/collab/metedatachange/MetadataChangeDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/metedatachange/MetadataChangeDetailsView.java @@ -25,12 +25,8 @@ public MetadataChangeDetailsView(MetadataChange metadataChange, GlobalCitationKe } ScrollPane scrollPane = new ScrollPane(container); - getChildren().setAll(scrollPane); - setLeftAnchor(scrollPane, 8d); - setTopAnchor(scrollPane, 8d); - setRightAnchor(scrollPane, 8d); - setBottomAnchor(scrollPane, 8d); + this.setAllAnchorsAndAttachChild(scrollPane); } private String getDifferenceString(MetaDataDiff.DifferenceType changeType) { diff --git a/src/main/java/org/jabref/gui/collab/preamblechange/PreambleChangeDetailsView.java b/src/main/java/org/jabref/gui/collab/preamblechange/PreambleChangeDetailsView.java index 8630f62c240..c49182f1d2e 100644 --- a/src/main/java/org/jabref/gui/collab/preamblechange/PreambleChangeDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/preamblechange/PreambleChangeDetailsView.java @@ -27,11 +27,7 @@ public PreambleChangeDetailsView(PreambleChange preambleChange) { } else { container.getChildren().add(new Label(Localization.lang("Value cleared externally"))); } - setLeftAnchor(container, 8d); - setTopAnchor(container, 8d); - setRightAnchor(container, 8d); - setBottomAnchor(container, 8d); - getChildren().setAll(container); + this.setAllAnchorsAndAttachChild(container); } } diff --git a/src/main/java/org/jabref/gui/collab/stringadd/BibTexStringAddDetailsView.java b/src/main/java/org/jabref/gui/collab/stringadd/BibTexStringAddDetailsView.java index 5e34729d108..ffca7b4d7ba 100644 --- a/src/main/java/org/jabref/gui/collab/stringadd/BibTexStringAddDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/stringadd/BibTexStringAddDetailsView.java @@ -17,11 +17,7 @@ public BibTexStringAddDetailsView(BibTexStringAdd stringAdd) { new Label(Localization.lang("Label: %0", stringAdd.getAddedString().getName())), new Label(Localization.lang("Content: %0", stringAdd.getAddedString().getContent())) ); - setLeftAnchor(container, 8d); - setTopAnchor(container, 8d); - setRightAnchor(container, 8d); - setBottomAnchor(container, 8d); - getChildren().setAll(container); + this.setAllAnchorsAndAttachChild(container); } } diff --git a/src/main/java/org/jabref/gui/collab/stringchange/BibTexStringChangeDetailsView.java b/src/main/java/org/jabref/gui/collab/stringchange/BibTexStringChangeDetailsView.java index 58fa700aa2c..880f5661ad8 100644 --- a/src/main/java/org/jabref/gui/collab/stringchange/BibTexStringChangeDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/stringchange/BibTexStringChangeDetailsView.java @@ -19,11 +19,7 @@ public BibTexStringChangeDetailsView(BibTexStringChange stringChange) { ); container.getChildren().add(new Label(Localization.lang("Current content: %0", stringChange.getOldString().getContent()))); - setLeftAnchor(container, 8d); - setTopAnchor(container, 8d); - setRightAnchor(container, 8d); - setBottomAnchor(container, 8d); - getChildren().setAll(container); + this.setAllAnchorsAndAttachChild(container); } } diff --git a/src/main/java/org/jabref/gui/collab/stringdelete/BibTexStringDeleteDetailsView.java b/src/main/java/org/jabref/gui/collab/stringdelete/BibTexStringDeleteDetailsView.java index 2d35145b51d..31a63e5504c 100644 --- a/src/main/java/org/jabref/gui/collab/stringdelete/BibTexStringDeleteDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/stringdelete/BibTexStringDeleteDetailsView.java @@ -17,11 +17,7 @@ public BibTexStringDeleteDetailsView(BibTexStringDelete stringDelete) { new Label(Localization.lang("Label: %0", stringDelete.getDeletedString().getName())), new Label(Localization.lang("Content: %0", stringDelete.getDeletedString().getContent())) ); - setLeftAnchor(container, 8d); - setTopAnchor(container, 8d); - setRightAnchor(container, 8d); - setBottomAnchor(container, 8d); - getChildren().setAll(container); + this.setAllAnchorsAndAttachChild(container); } } diff --git a/src/main/java/org/jabref/gui/collab/stringrename/BibTexStringRenameDetailsView.java b/src/main/java/org/jabref/gui/collab/stringrename/BibTexStringRenameDetailsView.java index b810a1c526e..fa826b08e8f 100644 --- a/src/main/java/org/jabref/gui/collab/stringrename/BibTexStringRenameDetailsView.java +++ b/src/main/java/org/jabref/gui/collab/stringrename/BibTexStringRenameDetailsView.java @@ -8,11 +8,7 @@ public final class BibTexStringRenameDetailsView extends DatabaseChangeDetailsVi public BibTexStringRenameDetailsView(BibTexStringRename stringRename) { Label label = new Label(stringRename.getNewString().getName() + " : " + stringRename.getOldString().getContent()); - setLeftAnchor(label, 8d); - setTopAnchor(label, 8d); - setRightAnchor(label, 8d); - setBottomAnchor(label, 8d); - getChildren().setAll(label); + this.setAllAnchorsAndAttachChild(label); } }