Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新 JFoenix #3415

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 8
# TODO: Java 8
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 8
java-version: 11
java-package: 'jdk+fx'
- name: Build with Gradle
run: ./gradlew build --no-daemon
Expand Down
25 changes: 15 additions & 10 deletions HMCL/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ version = "$versionRoot.$buildNumber"

dependencies {
implementation(project(":HMCLCore"))
implementation("libs:JFoenix")
// implementation("com.jfoenix:jfoenix:9.0.10")
}

fun digest(algorithm: String, bytes: ByteArray): ByteArray = MessageDigest.getInstance(algorithm).digest(bytes)
Expand Down Expand Up @@ -81,21 +81,25 @@ fun attachSignature(jar: File) {
}
}

val java11 = sourceSets.create("java11") {
tasks.checkstyleMain {
exclude("**/com/jfoenix/**")
}

val java9 = sourceSets.create("java9") {
java {
srcDir("src/main/java11")
srcDir("src/main/java9")
}
}

tasks.getByName<JavaCompile>(java11.compileJavaTaskName) {
tasks.getByName<JavaCompile>(java9.compileJavaTaskName) {
if (JavaVersion.current() < JavaVersion.VERSION_11) {
javaCompiler.set(javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(11))
})
}
options.compilerArgs.add("--add-exports=java.base/jdk.internal.loader=ALL-UNNAMED")
sourceCompatibility = "11"
targetCompatibility = "11"
sourceCompatibility = "9"
targetCompatibility = "9"
}

tasks.jar {
Expand All @@ -113,7 +117,7 @@ tasks.getByName<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("sha

minimize {
exclude(dependency("com.google.code.gson:.*:.*"))
exclude(dependency("libs:JFoenix:.*"))
// exclude(dependency("com.jfoenix:.*:.*"))
}

manifest {
Expand All @@ -135,6 +139,7 @@ tasks.getByName<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("sha
"javafx.base/com.sun.javafx.event",
"javafx.base/com.sun.javafx.runtime",
"javafx.graphics/javafx.css",
"javafx.graphics/com.sun.javafx.scene",
"javafx.graphics/com.sun.javafx.stage",
"javafx.graphics/com.sun.prism",
"javafx.controls/com.sun.javafx.scene.control",
Expand Down Expand Up @@ -167,10 +172,10 @@ fun createExecutable(suffix: String, header: String) {
}

tasks.processResources {
into("META-INF/versions/11") {
from(sourceSets["java11"].output)
into("META-INF/versions/9") {
from(java9.output)
}
dependsOn(tasks["java11Classes"])
dependsOn(tasks[java9.classesTaskName])
}

val makeExecutables = tasks.create("makeExecutables") {
Expand Down
35 changes: 35 additions & 0 deletions HMCL/src/main/java/com/jfoenix/adapters/ReflectionHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.
*/

package com.jfoenix.adapters;

import java.lang.reflect.Field;

public final class ReflectionHelper {

public static Field getDeclaredField(Class<?> clazz, String fieldName) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);
return field;
} catch (NoSuchFieldException e) {
throw new InternalError(e);
}
}
}
50 changes: 50 additions & 0 deletions HMCL/src/main/java/com/jfoenix/adapters/VirtualFlowAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2024 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.jfoenix.adapters;

import javafx.scene.Node;
import javafx.scene.control.IndexedCell;
import javafx.scene.control.skin.VirtualFlow;

import java.util.Objects;

public final class VirtualFlowAdapter<T extends IndexedCell<?>> {
@SuppressWarnings("unchecked")
public static <T extends IndexedCell<?>> VirtualFlowAdapter<T> wrap(Node node) {
Objects.requireNonNull(node);
return new VirtualFlowAdapter<>((VirtualFlow<T>) node);
}

private final VirtualFlow<T> flow;

VirtualFlowAdapter(VirtualFlow<T> flow) {
this.flow = flow;
}

public Node getFlow() {
return flow;
}

public int getCellCount() {
return flow.getCellCount();
}

public T getCell(int index) {
return flow.getCell(index);
}
}
2 changes: 2 additions & 0 deletions HMCL/src/main/java/com/jfoenix/adapters/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// TODO: Multi-Release
package com.jfoenix.adapters;
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2024 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.jfoenix.adapters.skins;

import javafx.scene.control.Button;
import javafx.scene.control.skin.ButtonSkin;

public abstract class ButtonSkinAdapter extends ButtonSkin {
public ButtonSkinAdapter(Button control) {
super(control);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2024 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.jfoenix.adapters.skins;

import javafx.beans.value.ObservableValue;
import javafx.scene.control.CheckBox;
import javafx.scene.control.skin.CheckBoxSkin;

public abstract class CheckBoxSkinAdapter extends CheckBoxSkin {
public CheckBoxSkinAdapter(CheckBox control) {
super(control);
}

protected final void __registerChangeListener(ObservableValue<?> property, String key) {
this.registerChangeListener(property, ignored -> __handleControlPropertyChanged(key));
}

protected abstract void __handleControlPropertyChanged(String key);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2024 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.jfoenix.adapters.skins;

import javafx.beans.value.ObservableValue;
import javafx.scene.control.ComboBox;
import javafx.scene.control.skin.ComboBoxListViewSkin;

public abstract class ComboBoxListViewSkinAdapter<T> extends ComboBoxListViewSkin<T> {

public ComboBoxListViewSkinAdapter(ComboBox<T> control) {
super(control);
}

protected final void __registerChangeListener(ObservableValue<?> property, String key) {
this.registerChangeListener(property, ignored -> __handleControlPropertyChanged(key));
}

protected abstract void __handleControlPropertyChanged(String key);

protected final double __snapPositionX(double value) {
return super.snapPositionX(value);
}

protected final double __snapPositionY(double value) {
return super.snapPositionY(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2024 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.jfoenix.adapters.skins;

import com.jfoenix.adapters.VirtualFlowAdapter;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.control.skin.ListViewSkin;
import javafx.scene.control.skin.VirtualFlow;

public class ListViewSkinAdapter<T> extends ListViewSkin<T> {
public ListViewSkinAdapter(ListView<T> control) {
super(control);
}

@SuppressWarnings("unchecked")
protected final VirtualFlowAdapter<ListCell<T>> __getFlow() {
VirtualFlow<ListCell<T>> flow;
try {
// Since JavaFX 10
flow = getVirtualFlow();
} catch (NoSuchMethodError e) {
flow = (VirtualFlow<ListCell<T>>) getChildren().get(0);
}

return VirtualFlowAdapter.wrap(flow);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2024 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.jfoenix.adapters.skins;

import javafx.animation.Animation;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.skin.ProgressBarSkin;
import javafx.scene.control.skin.ProgressIndicatorSkin;

import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;

public abstract class ProgressBarSkinAdapter extends ProgressBarSkin {
private static final VarHandle indeterminateTransitionFieldHandle;

static {
try {
MethodHandles.Lookup lookup = MethodHandles.privateLookupIn(ProgressIndicatorSkin.class, MethodHandles.lookup());
indeterminateTransitionFieldHandle = lookup.findVarHandle(ProgressIndicatorSkin.class, "indeterminateTransition", Animation.class);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new ExceptionInInitializerError(e);
}
}

public ProgressBarSkinAdapter(ProgressBar control) {
super(control);
}

protected final void __registerChangeListener(ObservableValue<?> property, String key) {
this.registerChangeListener(property, ignored -> __handleControlPropertyChanged(key));
}

protected abstract void __handleControlPropertyChanged(String p);

protected Animation __getIndeterminateTransition() {
return (Animation) indeterminateTransitionFieldHandle.get(this);
}

protected void __setIndeterminateTransition(Animation animation) {
indeterminateTransitionFieldHandle.set(this, animation);
}
}
Loading