Skip to content

重构 SchematicsPage 以使用 ListCell 展示元素#5276

Merged
Glavo merged 6 commits into
HMCL-dev:mainfrom
Glavo:schematics
Jan 21, 2026
Merged

重构 SchematicsPage 以使用 ListCell 展示元素#5276
Glavo merged 6 commits into
HMCL-dev:mainfrom
Glavo:schematics

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented Jan 21, 2026

No description provided.

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

This pull request refactors the SchematicsPage to use a custom ListCell for displaying items instead of having each Item extend Control with its own Skin. This is a cleaner architectural approach that follows JavaFX best practices.

Changes:

  • Converted Item from a Control class to a sealed class implementing Comparable
  • Removed the ItemSkin class and replaced it with a ListCell-based Cell class
  • Added getImage() method to LitematicFileItem to support preview images
  • Updated SchematicsPageSkin to provide the custom Cell via createListCell override

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/SchematicsPage.java Outdated
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

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

abstract class Item extends Control implements Comparable<Item> {
abstract sealed class Item implements Comparable<Item> {
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The sealed class Item is missing a permits clause. Sealed classes in Java must explicitly list the classes that are allowed to extend them using the permits keyword. Add permits BackItem, DirItem, LitematicFileItem to specify which inner classes can extend this sealed class.

Suggested change
abstract sealed class Item implements Comparable<Item> {
abstract sealed class Item implements Comparable<Item> permits BackItem, DirItem, LitematicFileItem {

Copilot uses AI. Check for mistakes.
Comment on lines +632 to +655
if (empty || item == null) {
setGraphic(null);
center.setTitle("");
center.setSubtitle("");
} else {
if (item instanceof LitematicFileItem fileItem && fileItem.getImage() != null) {
iconImageView.setImage(fileItem.getImage());
left.getChildren().setAll(iconImageView);
} else {
iconSVG.setContent(item.getIcon().getPath());
left.getChildren().setAll(iconSVGWrapper);
}

center.setTitle(item.getName());
center.setSubtitle(item.getDescription());

Path path = item.getPath();
if (path != null) {
tooltip.setText(FileUtils.getAbsolutePath(path));
FXUtils.installSlowTooltip(left, tooltip);
} else {
tooltip.setText("");
Tooltip.uninstall(left, tooltip);
}
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The tooltip is being installed and uninstalled repeatedly in updateItem, which can cause memory leaks and performance issues. The tooltip should be installed once in the constructor (similar to the WorldListCell pattern at line 254 in WorldListPage.java), and only the text should be updated in updateItem. When the item is empty or has no path, set the tooltip text to an empty string instead of uninstalling it. Additionally, ensure that tooltip.setText is called in the empty branch at line 635 to clear the tooltip text when the cell is reused.

Copilot uses AI. Check for mistakes.
@Glavo Glavo merged commit 20249ec into HMCL-dev:main Jan 21, 2026
8 checks passed
@Glavo Glavo deleted the schematics branch January 21, 2026 14:04
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