|
1 | 1 | package javafx;
|
2 | 2 |
|
3 |
| -import javafx.annotation.LoadView; |
| 3 | +import javafx.annotation.Load; |
4 | 4 | import javafx.annotation.MouseClicked;
|
5 | 5 | import javafx.scene.control.Control;
|
6 | 6 | import javafx.scene.layout.Pane;
|
7 | 7 |
|
8 | 8 | import java.lang.annotation.Annotation;
|
9 |
| -import java.lang.reflect.Constructor; |
10 | 9 | import java.lang.reflect.Field;
|
11 | 10 | import java.lang.reflect.InvocationTargetException;
|
12 | 11 | import java.lang.reflect.Method;
|
13 | 12 |
|
14 | 13 | import static javafx.utils.CommonUtil.checkNotNull;
|
15 | 14 |
|
16 | 15 | /**
|
17 |
| - * FXML注解初始化类,通过继承本接口的实现类可以轻松地使用注解 {@link javafx.annotation.LoadView}初始化界面而不需要写冗长的初始化代码 |
| 16 | + * FXML注解初始化类,通过继承本接口的实现类可以轻松地使用注解 {@link Load}初始化界面而不需要写冗长的初始化代码 |
18 | 17 | *
|
19 | 18 | * 注意:
|
20 | 19 | * <ol>
|
|
23 | 22 | * </ol>
|
24 | 23 | *
|
25 | 24 | * @author Nandem on 2017/3/13.
|
26 |
| - * @see javafx.annotation.LoadView |
| 25 | + * @see Load |
27 | 26 | */
|
28 | 27 | public interface EasyInitialization
|
29 | 28 | {
|
@@ -112,31 +111,34 @@ default void loadUI()
|
112 | 111 |
|
113 | 112 | try
|
114 | 113 | {
|
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 | + |
117 | 118 | LoadUIUtil.load(uiPath, this);
|
| 119 | + |
| 120 | + if(!cssPath.equals("")) |
| 121 | + { |
| 122 | + loadCss(cssPath); |
| 123 | + } |
118 | 124 | }
|
119 | 125 | catch(Exception e)
|
120 | 126 | {
|
121 | 127 | //如果没有Load注解,什么都不做,他可能自己去加载
|
122 | 128 | }
|
| 129 | + } |
123 | 130 |
|
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(); |
140 | 142 | }
|
141 | 143 |
|
142 | 144 | default void initialize()
|
|
0 commit comments