将 JFXToggleButton 更新至 MD3 风格#6131
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the JFXToggleButton and its skin to implement Material Design 3 switch specifications. It introduces new styleable properties for touch target size and track shape while maintaining legacy size scaling for backward compatibility. The JFXToggleButtonSkin has been completely rewritten to support M3 visuals, including state layers and ripples, using standard JavaFX Timeline animations. Review feedback suggests using primitive boolean types for the disableVisualFocus and disableAnimation property accessors instead of boxed Boolean types to align with JavaFX best practices and eliminate unnecessary null checks.
| public final Boolean isDisableVisualFocus() { | ||
| return disableVisualFocus != null && disableVisualFocus.get(); | ||
| } | ||
|
|
||
| public StyleableObjectProperty<Paint> unToggleLineColorProperty() { | ||
| return this.untoggleLineColor; | ||
| /// Sets whether focus state layers should be hidden. | ||
| public final void setDisableVisualFocus(Boolean disabled) { | ||
| disableVisualFocusProperty().set(Objects.requireNonNull(disabled, "disabled")); | ||
| } |
There was a problem hiding this comment.
The methods isDisableVisualFocus and setDisableVisualFocus use the boxed Boolean type. In JavaFX, it is standard practice to use the primitive boolean type for property getters and setters to avoid unnecessary boxing/unboxing and to prevent potential null values where they are not expected. Using boolean also eliminates the need for Objects.requireNonNull in the setter.
| public final Boolean isDisableVisualFocus() { | |
| return disableVisualFocus != null && disableVisualFocus.get(); | |
| } | |
| public StyleableObjectProperty<Paint> unToggleLineColorProperty() { | |
| return this.untoggleLineColor; | |
| /// Sets whether focus state layers should be hidden. | |
| public final void setDisableVisualFocus(Boolean disabled) { | |
| disableVisualFocusProperty().set(Objects.requireNonNull(disabled, "disabled")); | |
| } | |
| /// Returns whether focus state layers are hidden. | |
| public final boolean isDisableVisualFocus() { | |
| return disableVisualFocus != null && disableVisualFocus.get(); | |
| } | |
| /// Sets whether focus state layers should be hidden. | |
| public final void setDisableVisualFocus(boolean disabled) { | |
| disableVisualFocusProperty().set(disabled); | |
| } |
| public final Boolean isDisableAnimation() { | ||
| return disableAnimation != null ? disableAnimation.get() : !AnimationUtils.isAnimationEnabled(); | ||
| } | ||
|
|
||
| public StyleableDoubleProperty sizeProperty() { | ||
| return this.size; | ||
| /// Sets whether switch animations should be disabled. | ||
| public final void setDisableAnimation(Boolean disabled) { | ||
| disableAnimationProperty().set(Objects.requireNonNull(disabled, "disabled")); | ||
| } |
There was a problem hiding this comment.
Similar to disableVisualFocus, the isDisableAnimation and setDisableAnimation methods should use the primitive boolean type instead of the boxed Boolean type to align with JavaFX best practices and simplify the implementation.
| public final Boolean isDisableAnimation() { | |
| return disableAnimation != null ? disableAnimation.get() : !AnimationUtils.isAnimationEnabled(); | |
| } | |
| public StyleableDoubleProperty sizeProperty() { | |
| return this.size; | |
| /// Sets whether switch animations should be disabled. | |
| public final void setDisableAnimation(Boolean disabled) { | |
| disableAnimationProperty().set(Objects.requireNonNull(disabled, "disabled")); | |
| } | |
| /// Returns whether switch animations are disabled. | |
| public final boolean isDisableAnimation() { | |
| return disableAnimation != null ? disableAnimation.get() : !AnimationUtils.isAnimationEnabled(); | |
| } | |
| /// Sets whether switch animations should be disabled. | |
| public final void setDisableAnimation(boolean disabled) { | |
| disableAnimationProperty().set(disabled); | |
| } |
No description provided.