Skip to content

Commit

Permalink
Merge pull request #6 from qupath/expose-text-field
Browse files Browse the repository at this point in the history
Expose text field and JavadocViewer
  • Loading branch information
alanocallaghan authored Jul 24, 2024
2 parents 227df7c + 5ad612e commit 18adc74
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
3 changes: 2 additions & 1 deletion javadocviewer/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
requires javafx.fxml;
requires javafx.web;

opens qupath.ui.javadocviewer.gui.components to javafx.fxml;
opens qupath.ui.javadocviewer.gui.viewer to javafx.fxml;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.web.WebHistory;
Expand Down Expand Up @@ -44,6 +45,8 @@ public class JavadocViewer extends BorderPane {
private ComboBox<URI> uris;
@FXML
private HBox searchContainer;
@FXML
private AutoCompletionTextField<JavadocEntry> autoCompletionTextField;

/**
* Create the javadoc viewer.
Expand All @@ -58,6 +61,14 @@ public JavadocViewer(ReadOnlyStringProperty stylesheet, URI... urisToSearch) thr
setUpListeners();
}

/**
* Set the search text field to an input query.
* @param input The search query string.
*/
public void setSearchInput(String input) {
autoCompletionTextField.setText(input);
}

@FXML
private void onBackClicked(ActionEvent ignoredEvent) {
offset(-1);
Expand Down Expand Up @@ -101,10 +112,6 @@ protected void updateItem(URI item, boolean empty) {
}
});

AutoCompletionTextField<JavadocEntry> search = new AutoCompletionTextField<>();
search.setPrefWidth(400);
searchContainer.getChildren().add(search);

if (stylesheet != null) {
webView.getEngine().userStyleSheetLocationProperty().bind(stylesheet);
}
Expand All @@ -128,7 +135,7 @@ protected void updateItem(URI item, boolean empty) {
);
}

search.getSuggestions().addAll(javadocs.stream()
autoCompletionTextField.getSuggestions().addAll(javadocs.stream()
.map(Javadoc::getElements)
.flatMap(List::stream)
.map(javadocElement -> new JavadocEntry(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ public class JavadocViewerCommand implements Runnable {
private final ReadOnlyStringProperty stylesheet;
private final URI[] urisToSearch;
private Stage stage;
private JavadocViewer javadocViewer;

/**
* Get a reference to the singleton {@link JavadocViewer}
* @return A JavadocViewer, unless the constructor fails, in which case
* a {@link RuntimeException} is thrown.
*/
public JavadocViewer getJavadocViewer() {
if (javadocViewer == null) {
try {
javadocViewer = new JavadocViewer(stylesheet, urisToSearch);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return javadocViewer;
}

/**
* Create the command. This will not create the viewer yet.
Expand All @@ -35,24 +52,21 @@ public JavadocViewerCommand(Stage owner, ReadOnlyStringProperty stylesheet, URI.
@Override
public void run() {
if (stage == null) {
try {
stage = new Stage();
if (owner != null) {
stage.initOwner(owner);
}

JavadocViewer javadocViewer = new JavadocViewer(stylesheet, urisToSearch);
stage = new Stage();
if (owner != null) {
stage.initOwner(owner);
}

Scene scene = new Scene(javadocViewer);
stage.setScene(scene);
stage.show();
javadocViewer = getJavadocViewer();

stage.setMinWidth(javadocViewer.getWidth());
stage.setMinHeight(javadocViewer.getHeight());
Scene scene = new Scene(javadocViewer);
stage.setScene(scene);
stage.show();

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

} catch (IOException e) {
throw new RuntimeException(e);
}
}

stage.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<?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">
Expand Down Expand Up @@ -40,6 +41,7 @@
<padding>
<Insets left="10.0" right="10.0" />
</padding>
<AutoCompletionTextField fx:id="autoCompletionTextField" prefWidth="400"/>
</HBox>
<BorderPane.margin>
<Insets />
Expand Down

0 comments on commit 18adc74

Please sign in to comment.