Skip to content

添加 JFXRadioButton 源码#5559

Merged
Glavo merged 1 commit intoHMCL-dev:mainfrom
Glavo:radio-button
Feb 17, 2026
Merged

添加 JFXRadioButton 源码#5559
Glavo merged 1 commit intoHMCL-dev:mainfrom
Glavo:radio-button

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Feb 17, 2026

No description provided.

@Glavo Glavo requested a review from Copilot February 17, 2026 15:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +2 to +17
* 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.
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该文件的许可证头声明为 Apache Software Foundation (ASF),但类位于 com.jfoenix 命名空间,看起来是引入第三方(JFoenix)源码。建议改为与上游来源一致的版权/许可证头(或项目统一的 third-party header),并在需要时补充对应 NOTICE/来源信息,避免误署名或许可证信息不一致。

Suggested change
* 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.

Copilot uses AI. Check for mistakes.
Comment on lines +33 to +37
/// JFXRadioButton is the material design implementation of a radio button.
///
/// @author Bashir Elias & Shadi Shaheen
/// @version 1.0
/// @since 2016-03-09
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用了 /// 风格注释(虽能编译,但不是 JavaDoc),工具链(Javadoc、IDE 文档、静态检查)通常无法识别为 API 文档。建议将这些注释改为标准 JavaDoc(/** ... */),并将 @author/@since 等标签放入 JavaDoc 块中。

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +64
/// 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
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用了 /// 风格注释(虽能编译,但不是 JavaDoc),工具链(Javadoc、IDE 文档、静态检查)通常无法识别为 API 文档。建议将这些注释改为标准 JavaDoc(/** ... */),并将 @author/@since 等标签放入 JavaDoc 块中。

Copilot uses AI. Check for mistakes.
this.selectedColorProperty().set(selectedColor);
}

/// default color used when the radio button is not selected
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里使用了 /// 风格注释(虽能编译,但不是 JavaDoc),工具链(Javadoc、IDE 文档、静态检查)通常无法识别为 API 文档。建议将这些注释改为标准 JavaDoc(/** ... */),并将 @author/@since 等标签放入 JavaDoc 块中。

Copilot uses AI. Check for mistakes.
package com.jfoenix.controls;

import com.jfoenix.skins.JFXRadioButtonSkin;
import javafx.css.*;
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议避免 javafx.css.* 通配符导入,改为显式导入实际使用的类型(如 CssMetaData, Styleable, StyleableObjectProperty, StyleableProperty, SimpleStyleableObjectProperty 等),以提升可读性并减少与代码风格/Checkstyle 规则冲突的风险。

Suggested change
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;

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +107
"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) {
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unSelectedColor / getUnSelectedColor() 这种大小写不符合常见 Java/JavaFX 属性命名约定(通常为 unselectedColor)。这会影响可读性,并可能影响依赖 JavaBeans 命名规则的场景(例如某些 FXML/反射绑定、属性编辑器等)。建议统一改为 unselectedColor(字段、property 方法、getter/setter 以及 SimpleStyleableObjectProperty 中的属性名字符串)。

Suggested change
"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) {

Copilot uses AI. Check for mistakes.
Comment on lines +97 to +107
"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) {
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unSelectedColor / getUnSelectedColor() 这种大小写不符合常见 Java/JavaFX 属性命名约定(通常为 unselectedColor)。这会影响可读性,并可能影响依赖 JavaBeans 命名规则的场景(例如某些 FXML/反射绑定、属性编辑器等)。建议统一改为 unselectedColor(字段、property 方法、getter/setter 以及 SimpleStyleableObjectProperty 中的属性名字符串)。

Suggested change
"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) {

Copilot uses AI. Check for mistakes.
ColorConverter.getInstance(), DEFAULT_UNSELECTED_COLOR) {
@Override
public boolean isSettable(JFXRadioButton control) {
return control.unSelectedColor == null || !control.unSelectedColor.isBound();
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unSelectedColor / getUnSelectedColor() 这种大小写不符合常见 Java/JavaFX 属性命名约定(通常为 unselectedColor)。这会影响可读性,并可能影响依赖 JavaBeans 命名规则的场景(例如某些 FXML/反射绑定、属性编辑器等)。建议统一改为 unselectedColor(字段、property 方法、getter/setter 以及 SimpleStyleableObjectProperty 中的属性名字符串)。

Copilot uses AI. Check for mistakes.

@Override
public StyleableProperty<Color> getStyleableProperty(JFXRadioButton control) {
return control.unSelectedColorProperty();
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unSelectedColor / getUnSelectedColor() 这种大小写不符合常见 Java/JavaFX 属性命名约定(通常为 unselectedColor)。这会影响可读性,并可能影响依赖 JavaBeans 命名规则的场景(例如某些 FXML/反射绑定、属性编辑器等)。建议统一改为 unselectedColor(字段、property 方法、getter/setter 以及 SimpleStyleableObjectProperty 中的属性名字符串)。

Copilot uses AI. Check for mistakes.
SELECTED_COLOR,
UNSELECTED_COLOR
);
CHILD_STYLEABLES = List.copyOf(styleables);
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List.copyOf(...) 需要 JDK 10+。如果项目的 source/target 仍包含 JDK 8/9(不少 JavaFX 项目仍会这样配置),这里会直接编译失败。为保持更广泛的兼容性,建议改为 Collections.unmodifiableList(new ArrayList<>(styleables))(或使用现有项目中惯用的不可变列表构造方式)。

Suggested change
CHILD_STYLEABLES = List.copyOf(styleables);
CHILD_STYLEABLES = Collections.unmodifiableList(new ArrayList<>(styleables));

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit ffb1300 into HMCL-dev:main Feb 17, 2026
7 of 8 checks passed
@Glavo Glavo deleted the radio-button branch February 17, 2026 15:50
Glavo added a commit to Glavo/HMCL that referenced this pull request Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants