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.
This commit is contained in:
parent
28fe5cdb27
commit
589353a927
@ -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.
|
||||
* <p>
|
||||
* The default is
|
||||
* <b><code> e -> {clearableTextField.getTextField().clear();}</code></b>
|
||||
*
|
||||
* @param onClearButtonAction the action that should be performed
|
||||
* @since Envoy Client v0.1-beta
|
||||
*/
|
||||
public final ObjectProperty<Font> fontProperty() { return textField.fontProperty(); }
|
||||
public void setClearButtonListener(EventHandler<ActionEvent> 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<Skin<?>> 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<Tooltip> 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<ContextMenu> 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); }
|
||||
}
|
||||
|
@ -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()); }));
|
||||
}
|
||||
|
@ -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); });
|
||||
}
|
||||
|
||||
/**
|
||||
|
BIN
src/main/other/CustomComponents.jar
Normal file
BIN
src/main/other/CustomComponents.jar
Normal file
Binary file not shown.
Reference in New Issue
Block a user