Conversation
There was a problem hiding this comment.
Pull request overview
添加 JFXRadioButton 源码以支持 material design 风格的单选按钮,并暴露可通过 CSS 配置的选中/未选中颜色属性。
Changes:
- 新增
JFXRadioButton控件类并绑定自定义JFXRadioButtonSkin - 新增可样式化属性
-jfx-selected-color/-jfx-unselected-color - 注册并暴露控件的 CSS meta-data 列表
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. |
There was a problem hiding this comment.
该文件的许可证头声明为 Apache Software Foundation (ASF),但类位于 com.jfoenix 命名空间,看起来是引入第三方(JFoenix)源码。建议改为与上游来源一致的版权/许可证头(或项目统一的 third-party header),并在需要时补充对应 NOTICE/来源信息,避免误署名或许可证信息不一致。
| * Licensed to the Apache Software Foundation (ASF) under one | |
| * or more contributor license agreements. See the NOTICE file | |
| * distributed with this work for additional information | |
| * regarding copyright ownership. The ASF licenses this file | |
| * to you under the Apache License, Version 2.0 (the | |
| * "License"); you may not use this file except in compliance | |
| * with the License. You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, | |
| * software distributed under the License is distributed on an | |
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| * KIND, either express or implied. See the License for the | |
| * specific language governing permissions and limitations | |
| * under the License. | |
| * Licensed under the Apache License, Version 2.0 (the "License"); | |
| * you may not use this file except in compliance with the License. | |
| * You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. |
| /// JFXRadioButton is the material design implementation of a radio button. | ||
| /// | ||
| /// @author Bashir Elias & Shadi Shaheen | ||
| /// @version 1.0 | ||
| /// @since 2016-03-09 |
There was a problem hiding this comment.
这里使用了 /// 风格注释(虽能编译,但不是 JavaDoc),工具链(Javadoc、IDE 文档、静态检查)通常无法识别为 API 文档。建议将这些注释改为标准 JavaDoc(/** ... */),并将 @author/@since 等标签放入 JavaDoc 块中。
| /// Initialize the style class to 'jfx-radio-button'. | ||
| /// | ||
| /// This is the selector class from which CSS can be used to style | ||
| /// this control. | ||
| private static final String DEFAULT_STYLE_CLASS = "jfx-radio-button"; | ||
|
|
||
| /// default color used when the radio button is selected |
There was a problem hiding this comment.
这里使用了 /// 风格注释(虽能编译,但不是 JavaDoc),工具链(Javadoc、IDE 文档、静态检查)通常无法识别为 API 文档。建议将这些注释改为标准 JavaDoc(/** ... */),并将 @author/@since 等标签放入 JavaDoc 块中。
| this.selectedColorProperty().set(selectedColor); | ||
| } | ||
|
|
||
| /// default color used when the radio button is not selected |
There was a problem hiding this comment.
这里使用了 /// 风格注释(虽能编译,但不是 JavaDoc),工具链(Javadoc、IDE 文档、静态检查)通常无法识别为 API 文档。建议将这些注释改为标准 JavaDoc(/** ... */),并将 @author/@since 等标签放入 JavaDoc 块中。
| package com.jfoenix.controls; | ||
|
|
||
| import com.jfoenix.skins.JFXRadioButtonSkin; | ||
| import javafx.css.*; |
There was a problem hiding this comment.
建议避免 javafx.css.* 通配符导入,改为显式导入实际使用的类型(如 CssMetaData, Styleable, StyleableObjectProperty, StyleableProperty, SimpleStyleableObjectProperty 等),以提升可读性并减少与代码风格/Checkstyle 规则冲突的风险。
| import javafx.css.*; | |
| import javafx.css.CssMetaData; | |
| import javafx.css.PseudoClass; | |
| import javafx.css.Styleable; | |
| import javafx.css.StyleableBooleanProperty; | |
| import javafx.css.StyleableDoubleProperty; | |
| import javafx.css.StyleableIntegerProperty; | |
| import javafx.css.StyleableObjectProperty; | |
| import javafx.css.StyleableProperty; | |
| import javafx.css.StyleableStringProperty; | |
| import javafx.css.SimpleStyleableObjectProperty; |
| "unSelectedColor", | ||
| DEFAULT_UNSELECTED_COLOR); | ||
| } | ||
| return this.unSelectedColor; | ||
| } | ||
|
|
||
| public final Color getUnSelectedColor() { | ||
| return unSelectedColor == null ? DEFAULT_UNSELECTED_COLOR : this.unSelectedColorProperty().get(); | ||
| } | ||
|
|
||
| public final void setUnSelectedColor(final Color unSelectedColor) { |
There was a problem hiding this comment.
unSelectedColor / getUnSelectedColor() 这种大小写不符合常见 Java/JavaFX 属性命名约定(通常为 unselectedColor)。这会影响可读性,并可能影响依赖 JavaBeans 命名规则的场景(例如某些 FXML/反射绑定、属性编辑器等)。建议统一改为 unselectedColor(字段、property 方法、getter/setter 以及 SimpleStyleableObjectProperty 中的属性名字符串)。
| "unSelectedColor", | |
| DEFAULT_UNSELECTED_COLOR); | |
| } | |
| return this.unSelectedColor; | |
| } | |
| public final Color getUnSelectedColor() { | |
| return unSelectedColor == null ? DEFAULT_UNSELECTED_COLOR : this.unSelectedColorProperty().get(); | |
| } | |
| public final void setUnSelectedColor(final Color unSelectedColor) { | |
| "unselectedColor", | |
| DEFAULT_UNSELECTED_COLOR); | |
| } | |
| return this.unSelectedColor; | |
| } | |
| public final Color getUnselectedColor() { | |
| return unSelectedColor == null ? DEFAULT_UNSELECTED_COLOR : this.unSelectedColorProperty().get(); | |
| } | |
| public final void setUnselectedColor(final Color unSelectedColor) { |
| "unSelectedColor", | ||
| DEFAULT_UNSELECTED_COLOR); | ||
| } | ||
| return this.unSelectedColor; | ||
| } | ||
|
|
||
| public final Color getUnSelectedColor() { | ||
| return unSelectedColor == null ? DEFAULT_UNSELECTED_COLOR : this.unSelectedColorProperty().get(); | ||
| } | ||
|
|
||
| public final void setUnSelectedColor(final Color unSelectedColor) { |
There was a problem hiding this comment.
unSelectedColor / getUnSelectedColor() 这种大小写不符合常见 Java/JavaFX 属性命名约定(通常为 unselectedColor)。这会影响可读性,并可能影响依赖 JavaBeans 命名规则的场景(例如某些 FXML/反射绑定、属性编辑器等)。建议统一改为 unselectedColor(字段、property 方法、getter/setter 以及 SimpleStyleableObjectProperty 中的属性名字符串)。
| "unSelectedColor", | |
| DEFAULT_UNSELECTED_COLOR); | |
| } | |
| return this.unSelectedColor; | |
| } | |
| public final Color getUnSelectedColor() { | |
| return unSelectedColor == null ? DEFAULT_UNSELECTED_COLOR : this.unSelectedColorProperty().get(); | |
| } | |
| public final void setUnSelectedColor(final Color unSelectedColor) { | |
| "unselectedColor", | |
| DEFAULT_UNSELECTED_COLOR); | |
| } | |
| return this.unSelectedColor; | |
| } | |
| public final Color getUnselectedColor() { | |
| return unSelectedColor == null ? DEFAULT_UNSELECTED_COLOR : this.unSelectedColorProperty().get(); | |
| } | |
| public final void setUnselectedColor(final Color unSelectedColor) { |
| ColorConverter.getInstance(), DEFAULT_UNSELECTED_COLOR) { | ||
| @Override | ||
| public boolean isSettable(JFXRadioButton control) { | ||
| return control.unSelectedColor == null || !control.unSelectedColor.isBound(); |
There was a problem hiding this comment.
unSelectedColor / getUnSelectedColor() 这种大小写不符合常见 Java/JavaFX 属性命名约定(通常为 unselectedColor)。这会影响可读性,并可能影响依赖 JavaBeans 命名规则的场景(例如某些 FXML/反射绑定、属性编辑器等)。建议统一改为 unselectedColor(字段、property 方法、getter/setter 以及 SimpleStyleableObjectProperty 中的属性名字符串)。
|
|
||
| @Override | ||
| public StyleableProperty<Color> getStyleableProperty(JFXRadioButton control) { | ||
| return control.unSelectedColorProperty(); |
There was a problem hiding this comment.
unSelectedColor / getUnSelectedColor() 这种大小写不符合常见 Java/JavaFX 属性命名约定(通常为 unselectedColor)。这会影响可读性,并可能影响依赖 JavaBeans 命名规则的场景(例如某些 FXML/反射绑定、属性编辑器等)。建议统一改为 unselectedColor(字段、property 方法、getter/setter 以及 SimpleStyleableObjectProperty 中的属性名字符串)。
| SELECTED_COLOR, | ||
| UNSELECTED_COLOR | ||
| ); | ||
| CHILD_STYLEABLES = List.copyOf(styleables); |
There was a problem hiding this comment.
List.copyOf(...) 需要 JDK 10+。如果项目的 source/target 仍包含 JDK 8/9(不少 JavaFX 项目仍会这样配置),这里会直接编译失败。为保持更广泛的兼容性,建议改为 Collections.unmodifiableList(new ArrayList<>(styleables))(或使用现有项目中惯用的不可变列表构造方式)。
| CHILD_STYLEABLES = List.copyOf(styleables); | |
| CHILD_STYLEABLES = Collections.unmodifiableList(new ArrayList<>(styleables)); |
No description provided.