From 1fb2f04202e1a5554d290fe316c1521355ece9dd Mon Sep 17 00:00:00 2001 From: delvh Date: Sun, 28 Jun 2020 22:44:34 +0200 Subject: [PATCH] Finished implementing ClearableTextField (IMPORTANT! read description) in order to use SceneBuilder further, you have to import the attached JAR "CustomComponents.jar" into the SceneBuilder. If you don't do this, Scenebuilder no longer can load FXML files that depend on a custom component. If you are implementing another custom component, feel free to add it to the jar. Note however that SceneBuilder cannot load any components that rely on libraries other than the standard Java library or the JavaFX standard. Meaning that even if you are referencing another Envoy file, the component will not be importable. Because of this, the ClearableTextField is also present only in a slimmed down version, as SceneBuilder additionally has problems when dealing with loading resources. --- .../envoy/client/ui/ClearableTextField.java | 143 +++--------------- .../ui/controller/ContactSearchScene.java | 1 + .../ui/controller/GroupCreationScene.java | 1 + src/main/other/CustomComponents.jar | Bin 0 -> 5744 bytes 4 files changed, 27 insertions(+), 118 deletions(-) create mode 100644 src/main/other/CustomComponents.jar diff --git a/src/main/java/envoy/client/ui/ClearableTextField.java b/src/main/java/envoy/client/ui/ClearableTextField.java index adc5f94..2a4dcfb 100644 --- a/src/main/java/envoy/client/ui/ClearableTextField.java +++ b/src/main/java/envoy/client/ui/ClearableTextField.java @@ -1,16 +1,14 @@ package envoy.client.ui; -import javafx.beans.property.IntegerProperty; import javafx.beans.property.ObjectProperty; import javafx.beans.property.StringProperty; -import javafx.geometry.Insets; -import javafx.geometry.Pos; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; import javafx.scene.control.*; import javafx.scene.image.ImageView; import javafx.scene.layout.Background; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; -import javafx.scene.text.Font; import envoy.client.data.Settings; @@ -25,7 +23,6 @@ import envoy.client.data.Settings; * @author Leon Hofmeister * @since Envoy Client v0.1-beta */ -@SuppressWarnings("javadoc") public class ClearableTextField extends GridPane { private final TextField textField; @@ -56,6 +53,7 @@ public class ClearableTextField extends GridPane { Settings.getInstance().getCurrentTheme().equals("dark") ? "/icons/clear_button_white.png" : "/icons/clear_button_black.png", size))); clearButton.setOnAction(e -> textField.clear()); + clearButton.setFocusTraversable(false); clearButton.getStyleClass().clear(); clearButton.setBackground(Background.EMPTY); // Adding the two elements to the GridPane @@ -64,17 +62,11 @@ public class ClearableTextField extends GridPane { // Setting the percent - widths of the two columns. // Used to locate the button on the right. final var columnConstraints = new ColumnConstraints(); - columnConstraints.setPercentWidth(85); + columnConstraints.setPercentWidth(90); getColumnConstraints().add(columnConstraints); final var columnConstraints2 = new ColumnConstraints(); - columnConstraints2.setPercentWidth(15); - columnConstraints2.setPrefWidth(size); + columnConstraints2.setPercentWidth(10); getColumnConstraints().add(columnConstraints2); - setAlignment(Pos.CENTER); - setHgap(10); - setVgap(10); - setPadding(new Insets(5, 5, 5, 5)); - setMargin(clearButton, new Insets(5)); } /** @@ -84,169 +76,84 @@ public class ClearableTextField extends GridPane { public TextField getTextField() { return textField; } /** - * @return - * @see javafx.scene.control.TextInputControl#fontProperty() + * This method offers the freedom to perform custom actions when the + * {@code clearButton} has been pressed. + *

+ * The default is + * e -> {clearableTextField.getTextField().clear();} + * + * @param onClearButtonAction the action that should be performed * @since Envoy Client v0.1-beta */ - public final ObjectProperty fontProperty() { return textField.fontProperty(); } + public void setClearButtonListener(EventHandler onClearButtonAction) { clearButton.setOnAction(onClearButtonAction); } /** - * @return - * @see javafx.scene.control.TextField#prefColumnCountProperty() - * @since Envoy Client v0.1-beta - */ - public final IntegerProperty prefColumnCountProperty() { return textField.prefColumnCountProperty(); } - - /** - * @return - * @see javafx.scene.control.TextField#getPrefColumnCount() - * @since Envoy Client v0.1-beta - */ - public final int getPrefColumnCount() { return textField.getPrefColumnCount(); } - - /** - * @param value - * @see javafx.scene.control.TextField#setPrefColumnCount(int) - * @since Envoy Client v0.1-beta - */ - public final void setPrefColumnCount(int value) { textField.setPrefColumnCount(value); } - - /** - * @return - * @see javafx.scene.control.Control#skinProperty() - * @since Envoy Client v0.1-beta - */ - public final ObjectProperty> skinProperty() { return textField.skinProperty(); } - - /** - * @param value - * @see javafx.scene.control.TextInputControl#setFont(javafx.scene.text.Font) - * @since Envoy Client v0.1-beta - */ - public final void setFont(Font value) { textField.setFont(value); } - - /** - * @return - * @see javafx.scene.control.TextInputControl#getFont() - * @since Envoy Client v0.1-beta - */ - public final Font getFont() { return textField.getFont(); } - - /** - * @return + * @return the current property of the prompt text * @see javafx.scene.control.TextInputControl#promptTextProperty() * @since Envoy Client v0.1-beta */ public final StringProperty promptTextProperty() { return textField.promptTextProperty(); } /** - * @return + * @return the current prompt text * @see javafx.scene.control.TextInputControl#getPromptText() * @since Envoy Client v0.1-beta */ public final String getPromptText() { return textField.getPromptText(); } /** - * @param value + * @param value the prompt text to display * @see javafx.scene.control.TextInputControl#setPromptText(java.lang.String) * @since Envoy Client v0.1-beta */ public final void setPromptText(String value) { textField.setPromptText(value); } /** - * @return - * @see javafx.scene.control.TextInputControl#getText() - * @since Envoy Client v0.1-beta - */ - public final String getText() { return textField.getText(); } - - /** - * @param value - * @see javafx.scene.control.TextInputControl#setText(java.lang.String) - * @since Envoy Client v0.1-beta - */ - public final void setText(String value) { textField.setText(value); } - - /** - * @return - * @see javafx.scene.control.TextInputControl#textProperty() - * @since Envoy Client v0.1-beta - */ - public final StringProperty textProperty() { return textField.textProperty(); } - - /** - * @param value - * @see javafx.scene.control.TextInputControl#setEditable(boolean) - * @since Envoy Client v0.1-beta - */ - public final void setEditable(boolean value) { textField.setEditable(value); } - - /** - * @return + * @return the current property of the tooltip * @see javafx.scene.control.Control#tooltipProperty() * @since Envoy Client v0.1-beta */ public final ObjectProperty tooltipProperty() { return textField.tooltipProperty(); } /** - * @param value + * @param value the new tooltip * @see javafx.scene.control.Control#setTooltip(javafx.scene.control.Tooltip) * @since Envoy Client v0.1-beta */ public final void setTooltip(Tooltip value) { textField.setTooltip(value); } /** - * @return + * @return the current tooltip * @see javafx.scene.control.Control#getTooltip() * @since Envoy Client v0.1-beta */ public final Tooltip getTooltip() { return textField.getTooltip(); } /** - * @return + * @return the current property of the context menu * @see javafx.scene.control.Control#contextMenuProperty() * @since Envoy Client v0.1-beta */ public final ObjectProperty contextMenuProperty() { return textField.contextMenuProperty(); } /** - * @param value + * @param value the new context menu * @see javafx.scene.control.Control#setContextMenu(javafx.scene.control.ContextMenu) * @since Envoy Client v0.1-beta */ public final void setContextMenu(ContextMenu value) { textField.setContextMenu(value); } /** - * @return + * @return the current context menu * @see javafx.scene.control.Control#getContextMenu() * @since Envoy Client v0.1-beta */ public final ContextMenu getContextMenu() { return textField.getContextMenu(); } /** - * @param minWidth - * @param minHeight - * @see javafx.scene.layout.Region#setMinSize(double, double) + * @param value whether this ClearableTextField should be editable + * @see javafx.scene.control.TextInputControl#setEditable(boolean) * @since Envoy Client v0.1-beta */ - @Override - public void setMinSize(double minWidth, double minHeight) { textField.setMinSize(minWidth, minHeight); } - - /** - * @param prefWidth - * @param prefHeight - * @see javafx.scene.layout.Region#setPrefSize(double, double) - * @since Envoy Client v0.1-beta - */ - @Override - public void setPrefSize(double prefWidth, double prefHeight) { textField.setPrefSize(prefWidth, prefHeight); } - - /** - * @param maxWidth - * @param maxHeight - * @see javafx.scene.layout.Region#setMaxSize(double, double) - * @since Envoy Client v0.1-beta - */ - @Override - public void setMaxSize(double maxWidth, double maxHeight) { textField.setMaxSize(maxWidth, maxHeight); } + public final void setEditable(boolean value) { textField.setEditable(value); } } diff --git a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java index 743759c..1260f1d 100644 --- a/src/main/java/envoy/client/ui/controller/ContactSearchScene.java +++ b/src/main/java/envoy/client/ui/controller/ContactSearchScene.java @@ -59,6 +59,7 @@ public class ContactSearchScene { @FXML private void initialize() { contactList.setCellFactory(e -> new ContactListCell()); + searchBar.setClearButtonListener(e -> { searchBar.getTextField().clear(); contactList.getItems().clear(); }); eventBus.register(ContactSearchResult.class, response -> Platform.runLater(() -> { contactList.getItems().clear(); contactList.getItems().addAll(response.get()); })); } diff --git a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java index 484d207..52c46ae 100644 --- a/src/main/java/envoy/client/ui/controller/GroupCreationScene.java +++ b/src/main/java/envoy/client/ui/controller/GroupCreationScene.java @@ -44,6 +44,7 @@ public class GroupCreationScene { private void initialize() { contactList.setCellFactory(e -> new ContactListCell()); contactList.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); + groupNameField.setClearButtonListener(e -> { groupNameField.getTextField().clear(); createButton.setDisable(true); }); } /** diff --git a/src/main/other/CustomComponents.jar b/src/main/other/CustomComponents.jar new file mode 100644 index 0000000000000000000000000000000000000000..083f070fb5d2efcae1888c0cbade774c359c9ad7 GIT binary patch literal 5744 zcma)A1yCGax*Z6E3~m7icV{4Ya1AoJ6Kn_&Ah^4`1)abE3Bd{Ot^+}WyG!r{O9+HO zfKA?3y+6CPZ{L5qx~jXn>fEk->pSQBj;87ZG!g(NCMEzJxT*>G10(=6fSQ7?47akn zB1BC_U0G2xQhzVRK>uo3r0Pm z{6$6a>(>0=1wj9{0Nbyx)=pl|zK~}QcGgZF5KlXZoP#yY4QAww|43}TF3vD|_-S`vq6x@9QYxgn7>1b}nqY~0ctZpqd7dX>qFCvk zKZ*b6LnW8w;qjhS|m4N7Qjoev=04w&fK_Nj-HQQKNBr zb6D-p6(hp8`<&m#c8Nklk;|~S;*&m0M7V9$y4WSx)yv>D)~%of&0fM0*Z`B`=VU}f zv54pmH66YZ`Sy;0mK)sA>V(#+aQpRR3WT^UMU0oa?&-1g`Whnli75hr$%XKCmcFdYw^uFes#e7_JY+reG0#n@JPQG+&WGX_O9VMst|!;>U%;= zKDba~R>Rmtja?z>3}Smcy~I{KrL1TA1fE?79A<0Q)Cmi1&{;(KKJ$Q^Fvh!$f$E7K z)#SWmXFD6ui6~f2EVr@dR)x(OMZGn$zcx-5jploq5ce6Z(5{+;J}8*dKlD1~j7c3c z0<*qdu9D5fEaSxsL3I_MhZ9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