Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.web.WebHistory;
import javafx.scene.web.WebView;
import qupath.ui.javadocviewer.gui.components.AutoCompletionTextField;
Expand Down Expand Up @@ -45,8 +44,6 @@ public class JavadocViewer extends BorderPane {
@FXML
private ComboBox<URI> uris;
@FXML
private HBox searchContainer;
@FXML
private AutoCompletionTextField<JavadocEntry> autoCompletionTextField;

/**
Expand Down Expand Up @@ -95,7 +92,7 @@ protected void updateItem(URI item, boolean empty) {
super.updateItem(item, empty);

if (item == null || empty) {
setGraphic(null);
setText(null);
} else {
setText(getName(item));
}
Expand All @@ -107,7 +104,7 @@ protected void updateItem(URI item, boolean empty) {
super.updateItem(item, empty);

if (item == null || empty) {
setGraphic(null);
setText(null);
} else {
setText(getName(item));
}
Expand Down Expand Up @@ -141,7 +138,10 @@ protected void updateItem(URI item, boolean empty) {
.flatMap(List::stream)
.map(javadocElement -> new JavadocEntry(
javadocElement,
() -> webView.getEngine().load(javadocElement.uri().toString())
() -> {
updateSelectedUri(javadocElement.uri());
webView.getEngine().load(javadocElement.uri().toString());
}
))
.filter(javadocEntry -> !CATEGORIES_TO_SKIP.contains(javadocEntry.getCategory()))
.toList());
Expand All @@ -155,13 +155,10 @@ private void setUpListeners() {
));

uris.getSelectionModel().selectedItemProperty().addListener((p, o, n) -> {
if (n != null) {
if (n != null && !webView.getEngine().getLocation().equals(n.toString())) {
webView.getEngine().load(n.toString());
}
});
if (uris.getSelectionModel().getSelectedItem() != null) {
webView.getEngine().load(uris.getSelectionModel().getSelectedItem().toString());
}

// Sometimes, redirection is not automatically performed
// (see https://github.com/qupath/qupath/pull/1513#issuecomment-2095553840)
Expand Down Expand Up @@ -204,6 +201,24 @@ private static String getName(URI uri) {
return name;
}

private void updateSelectedUri(URI uri) {
int maxIndex = Integer.MIN_VALUE;
URI closestUri = null;

for (URI sd: uris.getItems()) {
int index = getNumberOfCommonCharactersFromBeginning(uri.toString(), sd.toString());

if (index > maxIndex) {
maxIndex = index;
closestUri = sd;
}
}

if (closestUri != null) {
uris.getSelectionModel().select(closestUri);
}
}

private static Optional<String> changeLocation(String currentLocation, String newLocation) {
int index = currentLocation.lastIndexOf("/");

Expand All @@ -213,4 +228,16 @@ private static Optional<String> changeLocation(String currentLocation, String ne
return Optional.of(currentLocation.substring(0, currentLocation.lastIndexOf("/")) + "/" + newLocation);
}
}

private static int getNumberOfCommonCharactersFromBeginning(String text1, String text2) {
int n = Math.min(text1.length(), text2.length());

for (int i=0; i<n; i++) {
if (text1.charAt(i) != text2.charAt(i)) {
return i;
}
}

return n;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public void run() {
Scene scene = new Scene(javadocViewer);
stage.setScene(scene);
stage.show();

stage.setMinWidth(javadocViewer.getWidth());
stage.setMinHeight(javadocViewer.getHeight());
}

stage.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,34 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Tooltip?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<?import javafx.scene.control.ToolBar?>
<?import qupath.ui.javadocviewer.gui.components.AutoCompletionTextField?>
<fx:root stylesheets="@styles.css" type="BorderPane" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1">
<top>
<VBox spacing="5.0" BorderPane.alignment="CENTER">
<HBox spacing="4.0">
<padding>
<Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
</padding>
<Button fx:id="back" mnemonicParsing="false" onAction="#onBackClicked" text="&lt;">
<tooltip>
<Tooltip text="%JavadocViewer.back" />
</tooltip>
</Button>
<Button fx:id="forward" mnemonicParsing="false" onAction="#onForwardClicked" text="&gt;">
<tooltip>
<Tooltip text="%JavadocViewer.forward" />
</tooltip>
</Button>
<ComboBox fx:id="uris" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS">
<tooltip>
<Tooltip text="%JavadocViewer.javadocSource" />
</tooltip>
</ComboBox>
</HBox>
<HBox fx:id="searchContainer" alignment="CENTER_RIGHT" spacing="10.0">
<Label text="%JavadocViewer.search" />
<VBox.margin>
<Insets />
</VBox.margin>
<padding>
<Insets left="10.0" right="10.0" />
</padding>
<AutoCompletionTextField fx:id="autoCompletionTextField" prefWidth="400"/>
</HBox>
<BorderPane.margin>
<Insets />
</BorderPane.margin>
<padding>
<Insets bottom="5.0" />
</padding>
</VBox>
</top>

<fx:root stylesheets="@styles.css" type="BorderPane" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<top>
<ToolBar BorderPane.alignment="CENTER">
<padding>
<Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
</padding>
<Button fx:id="back" mnemonicParsing="false" onAction="#onBackClicked" text="&lt;">
<tooltip>
<Tooltip text="%JavadocViewer.back" />
</tooltip>
</Button>
<Button fx:id="forward" mnemonicParsing="false" onAction="#onForwardClicked" text="&gt;">
<tooltip>
<Tooltip text="%JavadocViewer.forward" />
</tooltip>
</Button>
<AutoCompletionTextField fx:id="autoCompletionTextField" promptText="%JavadocViewer.search" maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS"/>
<ComboBox fx:id="uris" maxWidth="200">
<tooltip>
<Tooltip text="%JavadocViewer.javadocSource" />
</tooltip>
</ComboBox>
</ToolBar>
</top>
</fx:root>
Loading