Skip to content

Commit

Permalink
Changed Right button to a combo box
Browse files Browse the repository at this point in the history
  • Loading branch information
andromeda-224 committed Feb 20, 2025
1 parent 7ff0bde commit 18f9d79
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@
package au.gov.asd.tac.constellation.utilities.gui.field;

import au.gov.asd.tac.constellation.utilities.gui.field.framework.ConstellationInputListener;
import au.gov.asd.tac.constellation.utilities.gui.field.framework.ConstellationInputConstants;
import au.gov.asd.tac.constellation.utilities.gui.field.framework.Button.ButtonType;
import au.gov.asd.tac.constellation.utilities.text.SeparatorConstants;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import javafx.event.EventHandler;
import javafx.scene.control.CheckBox;
import javafx.scene.control.CustomMenuItem;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.input.MouseEvent;
import au.gov.asd.tac.constellation.utilities.gui.field.framework.AutoCompleteSupport;
import au.gov.asd.tac.constellation.utilities.gui.field.framework.ChoiceInputField;
import au.gov.asd.tac.constellation.utilities.gui.field.framework.ConstellationInput;
import au.gov.asd.tac.constellation.utilities.gui.field.framework.ConstellationInputDropDown;
import au.gov.asd.tac.constellation.utilities.gui.field.framework.InfoWindowSupport;
import au.gov.asd.tac.constellation.utilities.gui.field.framework.RightButtonSupport;
Expand Down Expand Up @@ -59,6 +57,8 @@ public final class MultiChoiceInput<C extends Object>
extends ChoiceInputField<List<C>, C>
implements RightButtonSupport, AutoCompleteSupport {

private ChoiceInputDropDown choiceInputDropDown;

public MultiChoiceInput() {
initialiseDepedantComponents();
}
Expand Down Expand Up @@ -208,7 +208,7 @@ public boolean isValidContent() {
public List<MenuItem> getLocalMenuItems() {
final List<MenuItem> items = new ArrayList();

final MenuItem choose = new MenuItem("Select Choice");
final MenuItem choose = new MenuItem("Show Choices...");
choose.setOnAction(value -> executeRightButtonAction());
items.add(choose);

Expand All @@ -220,18 +220,25 @@ public List<MenuItem> getLocalMenuItems() {
@Override
public RightButton getRightButton() {
RightButton button = new RightButton(
new Label(ConstellationInputConstants.SELECT_BUTTON_LABEL), ButtonType.DROPDOWN) {
new Label(""), ButtonType.DROPDOWN) {

@Override
public EventHandler<? super MouseEvent> action() {
return event -> executeRightButtonAction();
}
};
public void show() {
// show our menu instead
executeRightButtonAction();
}
};
return button;
}

@Override
public void executeRightButtonAction() {
showDropDown(new ChoiceInputDropDown(this));
if (choiceInputDropDown == null) {
choiceInputDropDown = new ChoiceInputDropDown(this);
showDropDown(choiceInputDropDown);
} else {
choiceInputDropDown = null;
}
}
// </editor-fold>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,49 @@
*/
package au.gov.asd.tac.constellation.utilities.gui.field.framework;

import au.gov.asd.tac.constellation.utilities.javafx.JavafxStyleManager;
import javafx.beans.property.DoubleProperty;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.geometry.Insets;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.layout.Region;

/**
*
* @author capricornunicorn123
* @author andromeda-224
*/
public abstract class Button extends StackPane {

private final int endCellPrefWidth = 50;
private final int defaultCellHeight = 22;

private final Color dkButtonColor = Color.color(0.11, 0.35, 0.65);
private final Color dkOptionColor = Color.color(0.4, 0.4, 0.4);

private final Color ltButtonColor = Color.color(0.19, 0.5, 0.97);
private final Color ltOptionColor = Color.color(0.255, 0.568, 0.91);

private final Rectangle background = new Rectangle(endCellPrefWidth, defaultCellHeight);
public abstract class Button extends ComboBox {

private final ButtonType btnType;
private Region arrowBtn = null ;

public Button(final Label label, final ButtonType type) {
final Color color = switch (type){
case POPUP -> JavafxStyleManager.isDarkTheme() ? dkButtonColor : ltButtonColor;
default -> JavafxStyleManager.isDarkTheme() ? dkOptionColor : ltOptionColor;
};
background.setFill(color);
background.setArcHeight(7);
background.setOnMouseEntered(event -> background.setFill(color.brighter()));
background.setOnMouseExited(event -> background.setFill(color));
background.setOnMouseClicked(action());
label.setMouseTransparent(true);
label.setPrefWidth(endCellPrefWidth);
label.setAlignment(Pos.CENTER);
label.setStyle("-fx-text-fill: white;");

this.getChildren().addAll(background, label);
btnType = type;
if (!label.getText().isEmpty()) {
this.setValue(label.getText());
}
}

public DoubleProperty getHeightProperty(){
return background.heightProperty();
@Override
protected void layoutChildren() {
super.layoutChildren();
// don't display arrow if not dropdown
if (arrowBtn == null && !btnType.equals(ButtonType.DROPDOWN)) {
arrowBtn = (Region)lookup(".arrow-button");
arrowBtn.setMaxSize(0,0);
arrowBtn.setMinSize(0,0);
arrowBtn.setPadding(new Insets(0));

Region arrow = (Region)lookup(".arrow");
arrow.setMaxSize(0,0);
arrow.setMinSize(0,0);
arrow.setPadding(new Insets(0));

// Call again the super method to relayout with the new bounds.
super.layoutChildren();
}
}

public abstract EventHandler<? super MouseEvent> action();


public enum ButtonType{
POPUP,
DROPDOWN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import au.gov.asd.tac.constellation.utilities.gui.field.framework.RightButtonSupport.RightButton;
import com.fasterxml.jackson.core.io.NumberInput;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.control.TextInputControl;
import javafx.scene.effect.ColorInput;

Expand Down Expand Up @@ -148,9 +149,6 @@ public abstract class ConstellationInput<T> extends StackPane implements
private boolean isValid = true;
private boolean focused = false;

final Color fieldColor = Color.color(51 / 255D, 51 / 255D, 51 / 255D);
final Color invalidColor = Color.color(238 / 255D, 66 / 255D, 49 / 255D);

public ConstellationInput() {
this(TextType.SINGLELINE);
}
Expand Down Expand Up @@ -179,16 +177,16 @@ public ConstellationInput(final TextType type) {
});
textArea.setContextMenu(contextMenu);
textArea.setMinHeight(defaultCellHeight);
textArea.setPadding(new Insets(0, 5, 0, 0));
}

// <editor-fold defaultstate="collapsed" desc="Local Private Methods">
/**
* Builds out the three layers to a ConstellationInput. Each of these layers
* needs to have their height bound to the height of a TextArea to ensure
* appropriate resizing with contained text. The first layer is the
* background layer, a {@link Rectangle} which acts a a shape to provide the
* fill color to an input field. When a field becomes invalid, it should be
* this rectangle that changes color. The second Layer is the interactable
* background layer, a {@link Rectangle} which acts as a shape to provide the
* fill color to an input field. The second Layer is the interactable
* content layer a {@link HBox} that hosts all of the "clickable" UI
* components. This layer need to have a clipping mask that this the same
* size as the foreground to enable smooth corners. The third layer is the
Expand All @@ -200,11 +198,11 @@ private void buildInputFieldLayers(final ConstellationTextArea textArea) {
interactableContentLayer.setAlignment(Pos.TOP_CENTER);
HBox.setHgrow(interactableContentLayer, Priority.ALWAYS);

final Rectangle backgroundLayer = new Rectangle();
backgroundLayer.setArcWidth(corner);
backgroundLayer.setArcHeight(corner);
backgroundLayer.setFill(Color.TRANSPARENT);
backgroundLayer.widthProperty().bind(interactableContentLayer.widthProperty());
// final Rectangle backgroundLayer = new Rectangle();
// backgroundLayer.setArcWidth(corner);
// backgroundLayer.setArcHeight(corner);
// backgroundLayer.setFill(Color.TRANSPARENT);
// backgroundLayer.widthProperty().bind(interactableContentLayer.widthProperty());

final Rectangle interactableContentClipingMask = new Rectangle();
interactableContentClipingMask.setArcWidth(corner);
Expand All @@ -219,9 +217,9 @@ private void buildInputFieldLayers(final ConstellationTextArea textArea) {
foregroundLayer.setMouseTransparent(true);
foregroundLayer.widthProperty().bind(interactableContentLayer.widthProperty());

textArea.bindHeightProperty(foregroundLayer, backgroundLayer, interactableContentClipingMask);
textArea.bindHeightProperty(foregroundLayer, interactableContentClipingMask);

getChildren().addAll(backgroundLayer, interactableContentLayer, foregroundLayer);
getChildren().addAll(interactableContentLayer, foregroundLayer);
}

/**
Expand All @@ -243,7 +241,6 @@ protected void initialiseDepedantComponents() {
if (this instanceof LeftButtonSupport leftButton) {
final LeftButton button = leftButton.getLeftButton();
if (button != null) {
button.getHeightProperty().bind(textArea.heightProperty());
interactableContent.getChildren().addFirst(button);
this.createWidthListener(button);
}
Expand All @@ -260,8 +257,6 @@ protected void initialiseDepedantComponents() {
// Add Right Button
if (this instanceof RightButtonSupport rightButton) {
final RightButton button = rightButton.getRightButton();
button.getHeightProperty().bind(textArea.heightProperty());

interactableContent.getChildren().add(button);
this.createWidthListener(button);
}
Expand Down Expand Up @@ -585,16 +580,14 @@ private void setValid(final boolean fieldValidity) {

/**
* Responsible for updating the color of the background of an input field.
* Uses a boolean parameter to override the expression of validty in some
* Uses a boolean parameter to override the expression of validity in some
* cases. Typically the isValid attribute will be passed in to ensure that
* the input field reflects the validity of its contents.
*/
private void updateFieldValidityVisuals(final boolean valid) {
if (valid) {
getBackgroundShape().setFill(fieldColor);
textArea.getStyleClass().remove("invalid-input");
} else {
getBackgroundShape().setFill(invalidColor);
textArea.getStyleClass().add("invalid-input");
}
}
Expand Down

0 comments on commit 18f9d79

Please sign in to comment.