Skip to content

Commit

Permalink
Define common parameter for node anchoring in DatabaseChangeDetailsView
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-cremieux committed Jun 19, 2024
1 parent 4a86a6f commit eb057ae
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,5 +13,31 @@
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit eb057ae

Please sign in to comment.