This commit is contained in:
liwen
2020-10-28 16:36:50 +08:00
commit 5b8021007c
262 changed files with 32530 additions and 0 deletions

View File

@@ -0,0 +1,129 @@
import sun.reflect.ConstructorAccessor;
import sun.reflect.FieldAccessor;
import sun.reflect.ReflectionFactory;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class DynamicEnumUtil {
private static ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();
private static void setFailsafeFieldValue(Field field, Object target, Object value) throws NoSuchFieldException,
IllegalAccessException {
// let's make the field accessible
field.setAccessible(true);
// next we change the modifier in the Field instance to
// not be final anymore, thus tricking reflection into
// letting us modify the static final field
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
int modifiers = modifiersField.getInt(field);
// blank out the final bit in the modifiers int
modifiers &= ~Modifier.FINAL;
modifiersField.setInt(field, modifiers);
FieldAccessor fa = reflectionFactory.newFieldAccessor(field, false);
fa.set(target, value);
}
private static void blankField(Class<?> enumClass, String fieldName) throws NoSuchFieldException,
IllegalAccessException {
for (Field field : Class.class.getDeclaredFields()) {
if (field.getName().contains(fieldName)) {
AccessibleObject.setAccessible(new Field[] { field }, true);
setFailsafeFieldValue(field, enumClass, null);
break;
}
}
}
private static void cleanEnumCache(Class<?> enumClass) throws NoSuchFieldException, IllegalAccessException {
blankField(enumClass, "enumConstantDirectory"); // Sun (Oracle?!?) JDK 1.5/6
blankField(enumClass, "enumConstants"); // IBM JDK
}
private static ConstructorAccessor getConstructorAccessor(Class<?> enumClass, Class<?>[] additionalParameterTypes)
throws NoSuchMethodException {
Class<?>[] parameterTypes = new Class[additionalParameterTypes.length + 2];
parameterTypes[0] = String.class;
parameterTypes[1] = int.class;
System.arraycopy(additionalParameterTypes, 0, parameterTypes, 2, additionalParameterTypes.length);
return reflectionFactory.newConstructorAccessor(enumClass.getDeclaredConstructor(parameterTypes));
}
private static Object makeEnum(Class<?> enumClass, String value, int ordinal, Class<?>[] additionalTypes,
Object[] additionalValues) throws Exception {
Object[] parms = new Object[additionalValues.length + 2];
parms[0] = value;
parms[1] = Integer.valueOf(ordinal);
System.arraycopy(additionalValues, 0, parms, 2, additionalValues.length);
// parms[1] = parms[parms.length-1];
return enumClass.cast(getConstructorAccessor(enumClass, additionalTypes).newInstance(parms));
}
/**
* Add an enum instance to the enum class given as argument
*
* @param <T> the type of the enum (implicit)
* @param enumType the class of the enum to be modified
* @param enumName the name of the new enum instance to be added to the class.
*/
@SuppressWarnings("unchecked")
public static <T extends Enum<?>> T addEnum(Class<T> enumType, String enumName, Class<?>[] additionalTypes, Object[] additionalValues) {
// 0. Sanity checks
if (!Enum.class.isAssignableFrom(enumType)) {
throw new RuntimeException("class " + enumType + " is not an instance of Enum");
}
// 1. Lookup "$VALUES" holder in enum class and get previous enum instances
Field valuesField = null;
Field[] fields = enumType.getDeclaredFields();
for (Field field : fields) {
if (field.getName().contains("$VALUES")) {
valuesField = field;
break;
}
}
AccessibleObject.setAccessible(new Field[] { valuesField }, true);
try {
// 2. Copy it
T[] previousValues = (T[]) valuesField.get(enumType);
List<T> values = new ArrayList<T>(Arrays.asList(previousValues));
// 3. build new enum
T newValue = (T) makeEnum(enumType, enumName, values.size(), additionalTypes, additionalValues);
// 4. add new value
values.add(newValue);
// 5. Set new values field
setFailsafeFieldValue(valuesField, null, values.toArray((T[]) Array.newInstance(enumType, 0)));
// 6. Clean enum cache
cleanEnumCache(enumType);
return newValue;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
public static void main(String[] args) {
}
}

View File

@@ -0,0 +1,43 @@
import javafx.application.Application;
import javafx.geometry.NodeOrientation;
import javafx.geometry.Side;
import javafx.scene.Scene;
import javafx.scene.chart.*;
import javafx.scene.control.Label;
import javafx.stage.Stage;
public class LineChartSample extends Application {
@Override
public void start(Stage stage) {
stage.setTitle("people");
final CategoryAxis xAxis = new CategoryAxis();
final NumberAxis yAxis = new NumberAxis();
xAxis.setLabel("Country");
final BarChart<String, Number> chart =
new BarChart<String, Number>(xAxis, yAxis);
chart.setTitle("people");
XYChart.Series series = new XYChart.Series();
series.setName("flag");
series.getData().add(new XYChart.Data("China", 14.7));
series.getData().add(new XYChart.Data("America", 2.5));
series.getData().add(new XYChart.Data("India", 14));
XYChart.Data data = new XYChart.Data("Russa", 2);
data.setNode(new Label("2aaaaaaaaaaaaa"));
series.getData().add(data);
Scene scene = new Scene(chart, 800, 600);
chart.getData().addAll(series);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}

View File

@@ -0,0 +1,180 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.chart.Axis;
import javafx.scene.chart.LineChart;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Path;
import java.util.ArrayList;
/**
* @description:
* @className: MyStackedAreaChart
* @author: liwen
* @date: 2020/9/9 16:42
*/
public class MyStackedAreaChart<X, Y> extends LineChart<X, Y> {
private Line selectLine;
private Region chartPlotBackground;
private ObservableList<Circle> cirleList;
private Tooltip selectorTooltip;
public MyStackedAreaChart(Axis axis, Axis axis2) {
super(axis, axis2);
init();
registerListeners();
}
public MyStackedAreaChart(Axis axis, Axis axis2, ObservableList data) {
super(axis, axis2, data);
init();
registerListeners();
}
private void init() {
cirleList = FXCollections.observableList(new ArrayList<>());
for (int i = 0; i < getData().size(); i++) {
// Add selector to chart
Circle selector = new Circle();
selector.getStyleClass().addAll("my-chart-symbol","my-chart-symbol"+i);
cirleList.add(selector);
}
chartPlotBackground = getChartPlotBackground();
selectLine = new Line();
selectLine.setStroke(Color.RED);
selectLine.setStrokeWidth(1f);
selectorTooltip = new Tooltip("");
Tooltip.install(selectLine, selectorTooltip);
getChartChildren().add(selectLine);
getChartChildren().addAll(cirleList);
}
public Region getChartPlotBackground() {
if (null == chartPlotBackground) {
for (Node node : lookupAll(".chart-plot-background")) {
if (node instanceof Region) {
chartPlotBackground = (Region) node;
break;
}
}
}
return chartPlotBackground;
}
private void registerListeners() {
setOnMouseMoved(event -> {
final double EVENT_X = event.getX();
final double EVENT_Y = event.getY();
final double CHART_MIN_Y = chartPlotBackground.getBoundsInParent().getMinY();
final double CHART_MAX_Y = chartPlotBackground.getBoundsInParent().getMaxY();
final double shiftX = xSceneShift(chartPlotBackground);
final double shiftY = ySceneShift(chartPlotBackground);
double x = event.getSceneX() - shiftX;
double y = event.getSceneY() - shiftY;
X xValue = getXAxis().getValueForDisplay(x);
double xx = getXAxis().getDisplayPosition(xValue) + shiftX - 5;
if (!chartPlotBackground.getBoundsInParent().contains(EVENT_X, EVENT_Y) || xValue == null) {
selectLine.setVisible(false);
selectorTooltip.hide();
return;
}
StringBuilder tooltipText = new StringBuilder(xValue.toString()).append("\n");
VBox vBox = new VBox();
vBox.setSpacing(5);
for (int i = 0; i < getData().size(); i++) {
Series<X, Y> series = getData().get(i);
series.getNode().getStyle();
Circle circle = cirleList.get(i);
int finalI = i;
series.getData().forEach(xyData -> {
if (xyData.getXValue() == xValue) {
HBox hBox = new HBox();
hBox.setSpacing(5);
Circle cir = new Circle();
cir.getStyleClass().add("my-chart-symbol" + finalI);
cir.setRadius(3);
cir.setStrokeWidth(6);
Label label=new Label(series.getName() + "" + xyData.getYValue());
hBox.setAlignment(Pos.CENTER_LEFT);
hBox.getChildren().addAll(cir, label);
vBox.getChildren().add(hBox);
double xy = getYAxis().getDisplayPosition(xyData.getYValue())+shiftY-5 ;
circle.setCenterX(xx);
circle.setCenterY(xy);
}
});
}
selectLine.setVisible(true);
selectLine.setStartX(xx);
selectLine.setEndX(xx);
selectLine.setStartY(CHART_MIN_Y);
selectLine.setEndY(CHART_MAX_Y);
Point2D tooltipLocation = selectLine.localToScreen(event.getX(), event.getY());
selectorTooltip.setGraphic(vBox);
selectorTooltip.setX(tooltipLocation.getX());
selectorTooltip.setY(tooltipLocation.getY());
selectorTooltip.show(getScene().getWindow());
});
}
/**
* Returns an array of paths where the first entry represents the fill path
* and the second entry represents the stroke path
*
* @param SERIES
* @return an array of paths where [0] == FillPath and [1] == StrokePath
*/
private Path[] getPaths(final Series<X, Y> SERIES) {
if (!getData().contains(SERIES)) {
return null;
}
Node seriesNode = SERIES.getNode();
if (null == seriesNode) {
return null;
}
Group seriesGroup = (Group) seriesNode;
if (seriesGroup.getChildren().isEmpty() || seriesGroup.getChildren().size() < 2) {
return null;
}
return new Path[]{ /* FillPath */ (Path) (seriesGroup).getChildren().get(0),
/* StrokePath */ (Path) (seriesGroup).getChildren().get(1)};
}
private double xSceneShift(Node node) {
return node.getParent() == null ? 0 : node.getBoundsInParent().getMinX() + xSceneShift(node.getParent());
}
private double ySceneShift(Node node) {
return node.getParent() == null ? 0 : node.getBoundsInParent().getMinY() + ySceneShift(node.getParent());
}
}

View File

@@ -0,0 +1,107 @@
import com.jfoenix.assets.JFoenixResources;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
import javafx.scene.shape.Path;
import javafx.stage.Stage;
import java.util.List;
/**
* A sample that displays data in a stacked area chart.
*/
public class StackedAreaChartApp extends Application {
private MyStackedAreaChart chart;
private StackPane pane;
private CategoryAxis xAxis;
private NumberAxis yAxis;
private Circle selector;
private Line selectorLine;
private List<Path> strokePaths;
private Tooltip selectorTooltip;
public MyStackedAreaChart createContent() {
xAxis = new CategoryAxis ();
yAxis = new NumberAxis("Y Values", 0.0d, 30.0d, 2.0d);
ObservableList<XYChart.Series> areaChartData =
FXCollections.observableArrayList(
new XYChart.Series("Series 1",
FXCollections.observableArrayList(
new XYChart.Data("a", 4),
new XYChart.Data("b", 15),
new XYChart.Data("c", 14),
new XYChart.Data("d", 12),
new XYChart.Data("e", 6),
new XYChart.Data("f", 18)
)),
new XYChart.Series("Series 2",
FXCollections.observableArrayList(
new XYChart.Data("a", 26),
new XYChart.Data("b", 5),
new XYChart.Data("c", 10),
new XYChart.Data("d", 16),
new XYChart.Data("e", 9),
new XYChart.Data("f", 13)
)),
new XYChart.Series("Series 3",
FXCollections.observableArrayList(
new XYChart.Data("a", 6),
new XYChart.Data("b", 21),
new XYChart.Data("c", 13),
new XYChart.Data("d", 16),
new XYChart.Data("e", 9),
new XYChart.Data("f", 22)
))
);
chart = new MyStackedAreaChart(xAxis, yAxis, areaChartData);
chart.setCreateSymbols(true);
return chart;
}
private StackPane createPane(){
selectorLine = new Line();
selectorLine.setFill(Color.WHEAT);
selectorLine.setStrokeWidth(5f);
pane = new StackPane();
pane.getChildren().addAll(createContent(),selectorLine);
return pane;
}
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(createContent());
scene.getStylesheets().addAll(JFoenixResources.load("/test.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* Java main for when running without JavaFX launcher
*/
public static void main(String[] args) {
launch(args);
}
}

View File

@@ -0,0 +1,16 @@
public class Test{
public static void main(String[] args) {
int[] a={39,48,57,62,40,51,43,50};
int[] b={9,36,17,5,28,30,24,19};
System.err.println("结果为:");
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < b.length; j++) {
int sum = a[i] + b[j];
int differ = a[i] - b[j];
System.err.println(a[i] +"+"+ b[j]+"="+sum +"\t\t\t"+a[i] +"-"+ b[j]+"="+differ);
}
System.err.println();
}
}
}

View File

@@ -0,0 +1,82 @@
/**
* @description:
* @className: TestFx
* @author: liwen
* @date: 2020/9/11 10:53
*/
import com.epri.fx.client.AppStartup;
import com.epri.fx.client.store.ApplicatonStore;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.svg.SVGGlyph;
import com.jfoenix.svg.SVGGlyphLoader;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIconView;
import de.jensd.fx.glyphs.materialicons.MaterialIcon;
import de.jensd.fx.glyphs.materialicons.MaterialIconView;
import javafx.animation.*;
import javafx.application.Application;
import javafx.geometry.Point3D;
import javafx.scene.DepthTest;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.util.Duration;
import java.io.IOException;
public class TestFx extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
new Thread(() -> {
try {
SVGGlyphLoader.loadGlyphsFont(AppStartup.class.getResourceAsStream("/fonts/icon_font/iconfont.svg"),
ApplicatonStore.ICON_FONT_KEY);
// SVGGlyphLoader.loadGlyphsFont(AppStartup.class.getResourceAsStream("/fonts/icon_font/icon-font-solid.svg"),
// "IconFontSolid.svg");
} catch (IOException ioExc) {
ioExc.printStackTrace();
}
}).start();
JFXButton button = new JFXButton("");
button.setPrefHeight(100);
button.setPrefWidth(200);
button.setRipplerFill(Color.RED);
button.setDepthTest(DepthTest.DISABLE);
SVGGlyph materialIconView= SVGGlyphLoader.getIcoMoonGlyph(ApplicatonStore.ICON_FONT_KEY+".home-outline");
materialIconView.setSize(80);
button.setGraphic(materialIconView);
StackPane stackPane = new StackPane();
stackPane.getChildren().add(button);
button.setRotationAxis(new Point3D(1, 0, 0));
RotateTransition transition1=new RotateTransition(Duration.millis(400),button);
transition1.setByAngle(180);
transition1.setInterpolator(Interpolator.EASE_OUT);
transition1.setOnFinished(event -> {
});
RotateTransition transition2=new RotateTransition(Duration.millis(300),button);
transition2.setByAngle(90);
transition2.setInterpolator(Interpolator.EASE_BOTH);
transition2.setOnFinished(event -> {
});
SequentialTransition sequentialTransition=new SequentialTransition();
sequentialTransition.getChildren().addAll(transition1);
button.setOnMouseEntered(event -> {
sequentialTransition.play();
});
Scene scene = new Scene(stackPane, 1000, 700);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFX Welcome");
primaryStage.show();
}
}

View File

@@ -0,0 +1,49 @@
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public enum YesNoEnum {
YES(1, "yes"),
NO(0, "no");
private Integer value;
private String name;
private static Map<Integer, YesNoEnum> enumMap = new HashMap<>();
static {
// 可以在这里加载枚举的配置文件 比如从 properties 数据库中加载
// 加载完后 使用DynamicEnumUtil.addEnum 动态增加枚举值
// 然后正常使用枚举即可
EnumSet<YesNoEnum> set = EnumSet.allOf(YesNoEnum.class);
for (YesNoEnum each : set) {
// 增加一个缓存 减少对枚举的修改
enumMap.put(each.value, each);
}
}
YesNoEnum(Integer value, String name) {
this.value = value;
this.name = name;
}
public Integer getValue() {
return value;
}
public String getName() {
return name;
}
// 根据关键字段获取枚举值 可以在这里做一些修改 来达到动态添加的效果
public YesNoEnum getEnum(Integer value) {
// 这里可以做一些修改 比如若从 enumMap 中没有取得 则加载配置动态添加
return enumMap.get(value);
}
// 动态添加方法 添加完后加入缓存 减少对枚举的修改
public YesNoEnum addEnum(String enumName, Integer value, String name) {
YesNoEnum yesNoEnum = DynamicEnumUtil.addEnum(YesNoEnum.class, enumName, new Class[]{Integer.class, String.class}, new Object[]{value, name});
enumMap.put(value, yesNoEnum);
return yesNoEnum;
}
}

View File

@@ -0,0 +1,26 @@
/**
* @description:
* @className: ZTest
* @author: liwen
* @date: 2020/9/25 09:29
*/
import com.jfoenix.controls.JFXButton;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class ZTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
Scene scene = new Scene(new JFXButton("aaa"), 1000, 700);
primaryStage.setScene(scene);
primaryStage.setTitle("JavaFX Welcome");
primaryStage.show();
}
}

View File

@@ -0,0 +1,46 @@
.my-chart-symbol0 {
-fx-stroke: CHART_COLOR_1, white;
}
.my-chart-symbol1 {
-fx-stroke: CHART_COLOR_2, white;
}
.my-chart-symbol2 {
-fx-stroke: CHART_COLOR_3, white;
}
.my-chart-symbol3 {
-fx-stroke: CHART_COLOR_4, white;
}
.my-chart-symbol4 {
-fx-stroke: CHART_COLOR_5, white;
}
.my-chart-symbol5 {
-fx-stroke: CHART_COLOR_6, white;
}
.my-chart-symbol6 {
-fx-stroke: CHART_COLOR_7, white;
}
.my-chart-symbol7 {
-fx-stroke: CHART_COLOR_8, white;
}
.my-chart-symbol {
-fx-stroke-width: 10;
-fx-background-size: 10;
}
.series0 {
-fx-background-color: #57b757;
}
.default-color{
-fx-stroke:#9a42c8;
-fx-background-color: #9a42c8;
}

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import javafx.scene.effect.GaussianBlur?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>
<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1">
<children>
<StackPane>
<children>
<ImageView fitHeight="376.0" fitWidth="600.0" nodeOrientation="INHERIT" pickOnBounds="true">
<image>
<Image url="@../../../../../../../../../System/Library/Desktop%20Pictures/Desert%202.jpg" />
</image>
</ImageView>
<VBox prefHeight="200.0" prefWidth="100.0" spacing="10.0">
<children>
<JFXButton buttonType="RAISED" ripplerFill="BLACK" style="-fx-background-color: #aacc33;" />
<JFXButton buttonType="RAISED" ripplerFill="#32ab4d" style="-fx-background-color: #44ff33;" />
<JFXButton buttonType="RAISED" ripplerFill="#32ab4d" style="-fx-background-color: #11aa33;" />
<JFXButton buttonType="RAISED" ripplerFill="#32ab4d" style="-fx-background-color: #44ee33;" />
<JFXButton buttonType="RAISED" ripplerFill="#32ab4d" style="-fx-background-color: #00ee33;" />
<JFXButton buttonType="RAISED" ripplerFill="#32ab4d" style="-fx-background-color: #aaeecc;" />
<JFXButton buttonType="RAISED" ripplerFill="#32ab4d" style="-fx-background-color: #44aa33;" />
</children>
</VBox>
</children>
</StackPane>
<AnchorPane prefHeight="200.0" prefWidth="200.0">
<children>
<ImageView fx:id="leftImageView" fitHeight="400.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<effect>
<GaussianBlur radius="21.0" />
</effect>
</ImageView>
</children>
</AnchorPane>
</children>
</StackPane>