From 63aa7859d3ccb55a75cc8c0442d8944d0d456388 Mon Sep 17 00:00:00 2001 From: delvh Date: Sat, 27 Jun 2020 15:35:35 +0200 Subject: [PATCH] Added working ClearableTextField additionally designed the clear button icon both in black and white --- .../envoy/client/ui/ClearableTextField.java | 252 ++++++++++++++++++ .../resources/icons/clear_button_black.png | Bin 0 -> 4258 bytes .../resources/icons/clear_button_white.png | Bin 0 -> 3919 bytes 3 files changed, 252 insertions(+) create mode 100644 src/main/java/envoy/client/ui/ClearableTextField.java create mode 100644 src/main/resources/icons/clear_button_black.png create mode 100644 src/main/resources/icons/clear_button_white.png diff --git a/src/main/java/envoy/client/ui/ClearableTextField.java b/src/main/java/envoy/client/ui/ClearableTextField.java new file mode 100644 index 0000000..adc5f94 --- /dev/null +++ b/src/main/java/envoy/client/ui/ClearableTextField.java @@ -0,0 +1,252 @@ +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.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; + +/** + * This class offers a text field that is automatically equipped with a clear + * button. + *

+ * Project: envoy-client
+ * File: ClearableTextField.java
+ * Created: 25.06.2020
+ * + * @author Leon Hofmeister + * @since Envoy Client v0.1-beta + */ +@SuppressWarnings("javadoc") +public class ClearableTextField extends GridPane { + + private final TextField textField; + + private final Button clearButton; + + /** + * Constructs a new {@code ClearableTextField} with no initial text and icon + * size 16. + * + * @since Envoy Client v0.1-beta + */ + public ClearableTextField() { this("", 16); } + + /** + * Constructs a new {@code ClearableTextField} with initial text and a + * predetermined icon size. + * + * @param text the text that should be displayed by default + * @param size the size of the icon + * @since Envoy Client v0.1-beta + */ + public ClearableTextField(String text, int size) { + // initializing the textField and the button + textField = new TextField(text); + clearButton = new Button("", + new ImageView(IconUtil.load( + Settings.getInstance().getCurrentTheme().equals("dark") ? "/icons/clear_button_white.png" : "/icons/clear_button_black.png", + size))); + clearButton.setOnAction(e -> textField.clear()); + clearButton.getStyleClass().clear(); + clearButton.setBackground(Background.EMPTY); + // Adding the two elements to the GridPane + add(textField, 0, 0, 2, 1); + add(clearButton, 1, 0, 1, 1); + // Setting the percent - widths of the two columns. + // Used to locate the button on the right. + final var columnConstraints = new ColumnConstraints(); + columnConstraints.setPercentWidth(85); + getColumnConstraints().add(columnConstraints); + final var columnConstraints2 = new ColumnConstraints(); + columnConstraints2.setPercentWidth(15); + columnConstraints2.setPrefWidth(size); + getColumnConstraints().add(columnConstraints2); + setAlignment(Pos.CENTER); + setHgap(10); + setVgap(10); + setPadding(new Insets(5, 5, 5, 5)); + setMargin(clearButton, new Insets(5)); + } + + /** + * @return the underlying {@code textField} + * @since Envoy Client v0.1-beta + */ + public TextField getTextField() { return textField; } + + /** + * @return + * @see javafx.scene.control.TextInputControl#fontProperty() + * @since Envoy Client v0.1-beta + */ + public final ObjectProperty fontProperty() { return textField.fontProperty(); } + + /** + * @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 + * @see javafx.scene.control.TextInputControl#promptTextProperty() + * @since Envoy Client v0.1-beta + */ + public final StringProperty promptTextProperty() { return textField.promptTextProperty(); } + + /** + * @return + * @see javafx.scene.control.TextInputControl#getPromptText() + * @since Envoy Client v0.1-beta + */ + public final String getPromptText() { return textField.getPromptText(); } + + /** + * @param value + * @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 + * @see javafx.scene.control.Control#tooltipProperty() + * @since Envoy Client v0.1-beta + */ + public final ObjectProperty tooltipProperty() { return textField.tooltipProperty(); } + + /** + * @param value + * @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 + * @see javafx.scene.control.Control#getTooltip() + * @since Envoy Client v0.1-beta + */ + public final Tooltip getTooltip() { return textField.getTooltip(); } + + /** + * @return + * @see javafx.scene.control.Control#contextMenuProperty() + * @since Envoy Client v0.1-beta + */ + public final ObjectProperty contextMenuProperty() { return textField.contextMenuProperty(); } + + /** + * @param value + * @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 + * @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) + * @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); } +} diff --git a/src/main/resources/icons/clear_button_black.png b/src/main/resources/icons/clear_button_black.png new file mode 100644 index 0000000000000000000000000000000000000000..56b8516a2808d37b1c3dcf7e3502e09ad1de7158 GIT binary patch literal 4258 zcmYjVeOOHS+dnf7oe??Huu)NGO0g(pGB%>qgpt%ED-_kD_cV!$Y8v*SypwY0+$`}GHv6Fv%d(* zCmqT^_nu9$Ty@0$@Cv(f1A{HsZ*tpeOS5(zcbM{S>c^$M`DTIBex3GC@;aVj#J?r- zJCNkPd$+B_i=2L^0k_A4D)%2F?{lq;#mCyFHpE3FA(EKHHzUZ5-{j7S>OotHGvc~f zC~g?Rk#1v`hV5L*hG0QD?+RvFPp~_8E@WaywxAE(QW55Sj!VIhKz9q$!+~CousgQ{ zJ%dCa2!Ni#cBune6(C5Dp=nEY=Q5h!f*$jrX^zW2D6Y~7(!IB!_;m^P#Sg-lahL4x z*&715+^7F5Ku$bMv802>E_BKjtS%p7si~TB8p^P`-vtOmAR?h`x&RIK=1P!c%aenP z*c&7-QZ(j}q%q|3D~uT^Ux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5X-deB!5LYB%=k+1 zq`N&=@s_6?l^)Iu_G_f-H_8wNSYn-`kCl626(fQcgu3FSSs=4C2LwyaPUCxCfM3#8 zo4ly{<1(a=Hn5S?aN=w5LfDO$R$CMD1>j*Y+fA)SRK0F3qc;kY-kr9g6xFPNN=SO? zxR#Kw^FZ|e;9K&=SgtmZ$*+T*f5pQU%m09i%HcRH>ny(K97|IQg0|K333lP!H?|U zTM=?!8;LHFM>hQxPk)|c-FhfDCEn`eVd_!)EbE|^xvx^=S*Ku`P$yd|6iYn?}y zRu4=kc0VoHi5%S*vfJc=677buOTHgR8>^mqEV%^zDOAEBM?z|z^A>(YI9kA)R z-)5})2GY_1#MSrz@3RkEwP1)C8@vD2S=%3ZA$nmB*4>o6@LSElRko@MpVu#JA60Jt zqLx<{^PbG4L>Ir}B*T0^Pd}?;Gh=N*;%aZ>M{5+_u+DbnHAi8a3^mcMJ(<_=x_j$R zdm+_+wc{lJCnPPet-ce)+QqQjbYVKqqyL!_?>8vLAMIA00j+snsKuj85E{rHhBkNA zK+G>M)a21ii1q&wzXf9FASTOukcRQ4Y3_I>Z#pq))PZ)r3$29T?b5<^x^J%_Wcv$Gc_ERt zZ_3R{#^~W*35dMmJoQgJf0&?W+D-U;tXl;l--0f0Z0hGzN%M8@^w#~-@~A{3#n)=# zxbw40+i%CD7A5P9rs!W=Cueo8myX6rqtpw6bLj7r{==ctOi#(uR4YiDhDp#1Y#uGZABp#sTvuDTXOjh1p2G($ruh95XMcx znXipqj0x0c;mM^Ge*Gf$#4Al;Wm)GuQnm`P$s wgy`;bK(SpKtf>t?li$*RP{0@VHRBeKEBt>!m;HPW{+@sc-L?q|$bggo2h6-uOaK4? literal 0 HcmV?d00001 diff --git a/src/main/resources/icons/clear_button_white.png b/src/main/resources/icons/clear_button_white.png new file mode 100644 index 0000000000000000000000000000000000000000..e93bd4c6bfb44abc132a6a22825a843c7bf53227 GIT binary patch literal 3919 zcmXw64O~p=8h_7p;;pE2W>89*bNZN&gf`vnY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