Skip to content

Commit

Permalink
Added Web CSS for javafx-graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
salmonb committed Mar 31, 2024
1 parent 31588ff commit f88ebe9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.TextAlignment;
Expand Down Expand Up @@ -112,7 +111,7 @@ public Property<TextAlignment> textAlignmentProperty() {
return textAlignmentProperty;
}

private final Property<Paint> textFillProperty = new SimpleObjectProperty<>(Color.BLACK);
private final Property<Paint> textFillProperty = new SimpleObjectProperty<>(/* null for CSS */);

@Override
public Property<Paint> textFillProperty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import javafx.scene.control.Button;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;

/**
Expand Down Expand Up @@ -50,8 +49,6 @@ public ButtonSkin(Button button) {
registerChangeListener(button.fontProperty(), "FONT");
registerChangeListener(button.paddingProperty(), "PADDING");
}
// Setting text color to gray when disabled (normal text fill otherwise)
getSkinnable().disabledProperty().addListener((observable, oldValue, disabled) -> getSkinnable().setTextFill(disabled ? Color.GRAY : getSkinnable().getTextFill()));
}

private boolean paddingExplicitlySetByUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,20 +335,6 @@ public String getName() {
return disabled;
}

private void updateDisabled() {
boolean isDisabled = false; //isDisable();
if (!isDisabled) {
isDisabled = getParent() != null ? getParent().isDisabled() :
false ; //getSubScene() != null && getSubScene().isDisabled();
}
setDisabled(isDisabled);
/*
if (this instanceof SubScene) {
((SubScene)this).getRoot().setDisabled(isDisabled);
}
*/
}

public final void setDisable(boolean value) {
disableProperty().setValue(value);
}
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.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;

/**
Expand All @@ -22,7 +21,7 @@ public abstract class Shape extends Node implements
HasStrokeMiterLimitProperty,
HasStrokeDashOffsetProperty {

private final ObjectProperty<Paint> fillProperty = new SimpleObjectProperty<>(Color.BLACK);
private final ObjectProperty<Paint> fillProperty = new SimpleObjectProperty<>(/* null for CSS */);
@Override
public ObjectProperty<Paint> fillProperty() {
return fillProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public abstract class HtmlSvgNodePeer
<E extends Element, N extends Node, NB extends NodePeerBase<N, NB, NM>, NM extends NodePeerMixin<N, NB, NM>>
extends NodePeerImpl<N, NB, NM> {

private static final String DISABLED_CSS_CLASS = "disabled";

private final E element;
private Element container;
private boolean containerInvisible;
Expand Down Expand Up @@ -523,7 +525,6 @@ public void updateAllNodeTransforms(List<Transform> localToParentTransforms) {
setElementAttribute("transform", isSvg ? SvgTransforms.toSvgTransforms(localToParentTransforms) : HtmlTransforms.toHtmlTransforms(localToParentTransforms));
}


@Override
public boolean isTreeVisible() {
if (container instanceof HTMLElement)
Expand Down Expand Up @@ -576,7 +577,16 @@ public void updateOpacity(Double opacity) {

@Override
public void updateDisabled(Boolean disabled) {
setElementAttribute(getElement(),"disabled", Booleans.isTrue(disabled) ? "disabled" : null);
// Here we just tag/untag the element with "disabled" css class, so the disabled appearance can be managed by CSS.
DOMTokenList classList = getElement().classList;
boolean disabledCssClassPresent = classList.contains(DISABLED_CSS_CLASS);
if (Booleans.isTrue(disabled)) {
if (!disabledCssClassPresent)
classList.add(DISABLED_CSS_CLASS);
} else {
if (disabledCssClassPresent)
classList.remove(DISABLED_CSS_CLASS);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.disabled -fx-text {
color: gray;
}

0 comments on commit f88ebe9

Please sign in to comment.