Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7edb23

Browse files
committed
1.添加css路径配置。
2.优化逻辑。
1 parent c8905f6 commit f7edb23

File tree

14 files changed

+191
-68
lines changed

14 files changed

+191
-68
lines changed

dist/src/main/java/javafx/EasyInitialization.java

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
package javafx;
22

3-
import javafx.annotation.LoadView;
3+
import javafx.annotation.Load;
44
import javafx.annotation.MouseClicked;
55
import javafx.scene.control.Control;
66
import javafx.scene.layout.Pane;
77

88
import java.lang.annotation.Annotation;
9-
import java.lang.reflect.Constructor;
109
import java.lang.reflect.Field;
1110
import java.lang.reflect.InvocationTargetException;
1211
import java.lang.reflect.Method;
1312

1413
import static javafx.utils.CommonUtil.checkNotNull;
1514

1615
/**
17-
* FXML注解初始化类,通过继承本接口的实现类可以轻松地使用注解 {@link javafx.annotation.LoadView}初始化界面而不需要写冗长的初始化代码
16+
* FXML注解初始化类,通过继承本接口的实现类可以轻松地使用注解 {@link Load}初始化界面而不需要写冗长的初始化代码
1817
*
1918
* 注意:
2019
* <ol>
@@ -23,7 +22,7 @@
2322
* </ol>
2423
*
2524
* @author Nandem on 2017/3/13.
26-
* @see javafx.annotation.LoadView
25+
* @see Load
2726
*/
2827
public interface EasyInitialization
2928
{
@@ -112,31 +111,34 @@ default void loadUI()
112111

113112
try
114113
{
115-
Annotation uiAnnotation = checkNotNull(clazz.getAnnotation(LoadView.class));
116-
String uiPath = ((LoadView) uiAnnotation).path();
114+
Annotation uiAnnotation = checkNotNull(clazz.getAnnotation(Load.class), "请指定界面文件路径");
115+
String uiPath = ((Load) uiAnnotation).view();
116+
String cssPath = ((Load) uiAnnotation).css();
117+
117118
LoadUIUtil.load(uiPath, this);
119+
120+
if(!cssPath.equals(""))
121+
{
122+
loadCss(cssPath);
123+
}
118124
}
119125
catch(Exception e)
120126
{
121127
//如果没有Load注解,什么都不做,他可能自己去加载
122128
}
129+
}
123130

124-
// Constructor[] constructors = clazz.getConstructors();
125-
//
126-
// for(Constructor c : constructors)
127-
// {
128-
// try
129-
// {
130-
// clazz.getAnnotation(Load.class);
131-
// Annotation uiAnnotation = checkNotNull(c.getAnnotation(Load.class));
132-
// String uiPath = ((Load) uiAnnotation).value();
133-
// LoadUIUtil.load(uiPath, this);
134-
// }
135-
// catch(Exception e)
136-
// {
137-
// //如果没有Load注解,什么都不做,他可能自己去加载
138-
// }
139-
// }
131+
default void loadCss(String path)
132+
{
133+
((Pane) this).getStylesheets().add(getClass().getResource(path).toExternalForm());
134+
135+
}
136+
137+
default void beforeInitialize()
138+
{
139+
loadUI();
140+
initEvent();
141+
initialize();
140142
}
141143

142144
default void initialize()

dist/src/main/java/javafx/annotation/LoadView.java renamed to dist/src/main/java/javafx/annotation/Load.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
@Target(ElementType.TYPE)
1818
@Retention(RetentionPolicy.RUNTIME)
1919
@Documented
20-
public @interface LoadView
20+
public @interface Load
2121
{
22-
String path() default "";
22+
String view() default "";
23+
String css() default "";
2324
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package javafx.geometry;
2+
3+
/**
4+
* @author Nandem on 2017/8/6.
5+
*/
6+
public class Point
7+
{
8+
private double x;
9+
private double y;
10+
11+
public Point()
12+
{
13+
this.x = 0.0;
14+
this.y = 0.0;
15+
}
16+
17+
public Point(double x, double y)
18+
{
19+
this.x = x;
20+
this.y = y;
21+
}
22+
23+
public void update(double x, double y)
24+
{
25+
this.x = x;
26+
this.y = y;
27+
}
28+
29+
public void updateX(double x)
30+
{
31+
this.x = x;
32+
}
33+
34+
public void updateY(double y)
35+
{
36+
this.y = y;
37+
}
38+
39+
public double distance(double x1, double y1) {
40+
double a = getX() - x1;
41+
double b = getY() - y1;
42+
return Math.sqrt(a * a + b * b);
43+
}
44+
45+
public double distance(Point point) {
46+
return distance(point.getX(), point.getY());
47+
}
48+
49+
public double getX()
50+
{
51+
return x;
52+
}
53+
54+
public void setX(double x)
55+
{
56+
this.x = x;
57+
}
58+
59+
public double getY()
60+
{
61+
return y;
62+
}
63+
64+
public void setY(double y)
65+
{
66+
this.y = y;
67+
}
68+
}

dist/src/main/java/javafx/scene/layout/EasyAnchorPane.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public abstract class EasyAnchorPane extends AnchorPane implements EasyInitializ
99
{
1010
protected EasyAnchorPane()
1111
{
12-
loadUI();
13-
initEvent();
14-
initialize();
12+
beforeInitialize();
1513
}
1614
}

dist/src/main/java/javafx/scene/layout/EasyBorderPane.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public abstract class EasyBorderPane extends BorderPane implements EasyInitializ
99
{
1010
protected EasyBorderPane()
1111
{
12-
loadUI();
13-
initEvent();
14-
initialize();
12+
beforeInitialize();
1513
}
1614
}

dist/src/main/java/javafx/scene/layout/EasyFlowPane.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public abstract class EasyFlowPane extends FlowPane implements EasyInitializatio
99
{
1010
protected EasyFlowPane()
1111
{
12-
loadUI();
13-
initEvent();
14-
initialize();
12+
beforeInitialize();
1513
}
1614
}

dist/src/main/java/javafx/scene/layout/EasyGridPane.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public abstract class EasyGridPane extends GridPane implements EasyInitializatio
99
{
1010
protected EasyGridPane()
1111
{
12-
loadUI();
13-
initEvent();
14-
initialize();
12+
beforeInitialize();
1513
}
1614
}

dist/src/main/java/javafx/scene/layout/EasyPane.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public abstract class EasyPane extends Pane implements EasyInitialization
99
{
1010
protected EasyPane()
1111
{
12-
loadUI();
13-
initEvent();
14-
initialize();
12+
beforeInitialize();
1513
}
1614
}

dist/src/main/java/javafx/scene/layout/EasyTitledPane.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ public abstract class EasyTitledPane extends TitledPane implements EasyInitializ
1010
{
1111
protected EasyTitledPane()
1212
{
13-
loadUI();
14-
initEvent();
15-
initialize();
13+
beforeInitialize();
1614
}
1715
}

example/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@
2525
<directory>src/main/java</directory>
2626
<includes>
2727
<include>**/*.properties</include>
28+
<include>**/*.css</include>
2829
<include>**/*.fxml</include>
2930
<include>**/*.xml</include>
3031
</includes>
31-
<filtering>false</filtering>
32+
<filtering>true</filtering>
3233
</resource>
3334
</resources>
3435
</build>

0 commit comments

Comments
 (0)