package envoy.client.ui.control; import java.util.function.Consumer; import javafx.geometry.*; import javafx.scene.control.*; import javafx.scene.image.ImageView; import javafx.scene.layout.*; import javafx.scene.shape.Rectangle; import envoy.client.util.IconUtil; import envoy.data.*; /** * Displays an {@link User} as a quick select control which is used in the * quick select list. * * @author Maximilian Käfer * @since Envoy Client v0.3-beta */ public class QuickSelectControl extends VBox { private User user; /** * Creates an instance of the {@code QuickSelectControl}. * * @param user the contact whose data is used to create this instance. * @param action the action to perform when a contact is removed with this control as a parameter * @since Envoy Client v0.3-beta */ public QuickSelectControl(User user, Consumer action) { this.user = user; setPadding(new Insets(1, 0, 0, 0)); setPrefWidth(37); setMaxWidth(37); setMinWidth(37); var stackPane = new StackPane(); stackPane.setAlignment(Pos.TOP_CENTER); // Profile picture var picHold = new VBox(); picHold.setPadding(new Insets(2, 0, 0, 0)); picHold.setPrefHeight(35); picHold.setMaxHeight(35); picHold.setMinHeight(35); var contactProfilePic = new ImageView(IconUtil.loadIconThemeSensitive("user_icon", 32)); final var clip = new Rectangle(); clip.setWidth(32); clip.setHeight(32); clip.setArcHeight(32); clip.setArcWidth(32); contactProfilePic.setClip(clip); picHold.getChildren().add(contactProfilePic); stackPane.getChildren().add(picHold); var hBox = new HBox(); hBox.setPrefHeight(12); hBox.setMaxHeight(12); hBox.setMinHeight(12); var region = new Region(); hBox.getChildren().add(region); HBox.setHgrow(region, Priority.ALWAYS); var removeBtn = new Button(); removeBtn.setPrefSize(12, 12); removeBtn.setMaxSize(12, 12); removeBtn.setMinSize(12, 12); removeBtn.setOnMouseClicked(evt -> action.accept(this)); removeBtn.setId("remove-button"); hBox.getChildren().add(removeBtn); stackPane.getChildren().add(hBox); getChildren().add(stackPane); var nameLabel = new Label(); nameLabel.setPrefSize(35, 20); nameLabel.setMaxSize(35, 20); nameLabel.setMinSize(35, 20); nameLabel.setText(user.getName()); nameLabel.setAlignment(Pos.TOP_CENTER); nameLabel.setPadding(new Insets(0, 5, 0, 0)); getChildren().add(nameLabel); getStyleClass().add("quick-select"); } /** * @return the user whose data is used in this instance * @since Envoy Client v0.3-beta */ public User getUser() { return user; } }