Skip to content

Commit

Permalink
Added wrapper around each country flag to add a border to each flag f…
Browse files Browse the repository at this point in the history
…or stronger contrast.
  • Loading branch information
dlemmermann committed Nov 12, 2023
1 parent 5d5fdbc commit 047108a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.StackPane;
import javafx.util.Callback;
import org.kordamp.ikonli.bootstrapicons.BootstrapIcons;
import org.kordamp.ikonli.javafx.FontIcon;
Expand Down Expand Up @@ -102,8 +103,13 @@ public PhoneNumberField() {
imageView.setFitHeight(24);
imageView.setFitWidth(24);
imageView.setPreserveRatio(true);
imageView.getStyleClass().add("flag-image-view");
Optional.ofNullable(FLAG_IMAGES.get(code)).ifPresent(imageView::setImage);
return imageView;

StackPane wrapper = new StackPane(imageView);
wrapper.getStyleClass().add("flag-wrapper");

return wrapper;
}

return new FontIcon(BootstrapIcons.GLOBE2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Bounds;
import javafx.scene.Node;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
import javafx.scene.control.Skin;
Expand Down Expand Up @@ -119,7 +118,7 @@ public PhoneNumberEditor(TextField textField) {
StackPane flagBox = new StackPane();
flagBox.getStyleClass().add("flag-box");

Runnable flagUpdater = () -> flagBox.getChildren().setAll(getCountryCodeFlagView(getSkinnable().getCountryCallingCode()));
Runnable flagUpdater = () -> flagBox.getChildren().setAll(getSkinnable().getCountryCodeViewFactory().call(getSkinnable().getCountryCallingCode()));
getSkinnable().countryCallingCodeProperty().addListener(obs -> flagUpdater.run());
getSkinnable().countryCodeViewFactoryProperty().addListener(obs -> flagUpdater.run());
flagUpdater.run();
Expand Down Expand Up @@ -170,15 +169,15 @@ public String getUserAgentStylesheet() {
}

@Override
protected void updateItem(PhoneNumberField.CountryCallingCode item, boolean empty) {
super.updateItem(item, empty);
protected void updateItem(PhoneNumberField.CountryCallingCode code, boolean empty) {
super.updateItem(code, empty);

int index = -1;

if (item != null && !empty) {
setText(new Locale("en", item.iso2Code()).getDisplayCountry());
setGraphic(getCountryCodeFlagView(item));
index = getSkinnable().getPreferredCountryCodes().indexOf(item);
if (code != null && !empty) {
setText(new Locale("en", code.iso2Code()).getDisplayCountry());
setGraphic(getSkinnable().getCountryCodeViewFactory().call(code));
index = getSkinnable().getPreferredCountryCodes().indexOf(code);
} else {
setText(null);
setGraphic(null);
Expand All @@ -196,10 +195,5 @@ protected void updateItem(PhoneNumberField.CountryCallingCode item, boolean empt
getStyleClass().remove("last");
}
}

}

private Node getCountryCodeFlagView(PhoneNumberField.CountryCallingCode code) {
return getSkinnable().getCountryCodeViewFactory().call(code);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@
-fx-alignment: center;
}

.country-calling-code-cell {
.phone-number-field > .combo-box .list-view .country-calling-code-cell {
-fx-padding: 5px;
}

.phone-number-field > .combo-box .list-view .country-calling-code-cell.preferred {
-fx-font-weight: bold;
}

.phone-number-field > .combo-box .list-view .country-calling-code-cell .flag-wrapper {
-fx-padding: 1px;
-fx-background-color: -fx-selection-bar-text;
}

0 comments on commit 047108a

Please sign in to comment.