支持动态修改窗口标题setWindowTitle、窗口图标setIcon、窗口可拖拽拖放setDragAndResize的接口
This commit is contained in:
@@ -6,6 +6,6 @@ package cn.edu.scau.biubiusuisui.function;
|
||||
* @date 2019/7/27 1:54
|
||||
* @since JavaFX2.0 JDK1.8
|
||||
*/
|
||||
public interface Draggale {
|
||||
public interface Draggable {
|
||||
|
||||
}
|
||||
@@ -22,44 +22,28 @@ import java.net.URL;
|
||||
* @since JavaFX2.0 JDK1.8
|
||||
*/
|
||||
public class FXWindowParser {
|
||||
private static IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(FXWindowParser.class);
|
||||
private static final IFXPlusLogger logger = FXPlusLoggerFactory.getLogger(FXWindowParser.class);
|
||||
|
||||
public void parse(Stage stage, FXBaseController fxControllerProxy, FXWindow fxWindow) {
|
||||
logger.info("parsing @FXWindow of class: " + fxControllerProxy.getName());
|
||||
|
||||
// 处理 title
|
||||
stage.setTitle(fxWindow.title());
|
||||
fxControllerProxy.setWindowTitle(fxWindow.title());
|
||||
|
||||
// 处理 icon
|
||||
if (!"".equals(fxWindow.icon())) {
|
||||
try {
|
||||
URL iconUrl = new FileUtil().getFilePathFromResources(fxWindow.icon());
|
||||
if (iconUrl != null) {
|
||||
if (new File(StringUtil.getRootPath(iconUrl)).exists()) {
|
||||
stage.getIcons().add(new Image(fxWindow.icon()));
|
||||
} else {
|
||||
logger.warn("the icon file has not existed");
|
||||
}
|
||||
} else {
|
||||
logger.warn("the icon file has not existed");
|
||||
}
|
||||
} catch (ProtocolNotSupport protocolNotSupport) {
|
||||
logger.error(protocolNotSupport.getMessage(), protocolNotSupport);
|
||||
protocolNotSupport.printStackTrace();
|
||||
}
|
||||
fxControllerProxy.setIcon(fxWindow.icon());
|
||||
|
||||
// 处理draggable和resizable
|
||||
if (fxWindow.draggable() || fxWindow.resizable()) {
|
||||
fxControllerProxy.setDragAndResize(fxWindow.draggable(), fxWindow.resizable());
|
||||
}
|
||||
|
||||
// fxWindow的resizable默认为false
|
||||
if (fxWindow.resizable()) {
|
||||
stage.setResizable(true);
|
||||
fxControllerProxy.setDragAndResize(fxWindow.draggable(), true);
|
||||
}
|
||||
|
||||
// 处理draggable和resizable
|
||||
if (fxWindow.draggable() || fxWindow.resizable()) {
|
||||
EventHandler dragWindowHandler = new DragWindowHandlerImpl(stage, fxWindow.minWidth(), fxWindow.minHeight(), fxControllerProxy, fxWindow.draggable(), fxWindow.resizable());
|
||||
fxControllerProxy.setOnMousePressed(dragWindowHandler);
|
||||
fxControllerProxy.setOnMouseDragged(dragWindowHandler);
|
||||
fxControllerProxy.setOnMouseMoved(dragWindowHandler);
|
||||
}
|
||||
|
||||
// 处理style
|
||||
stage.initStyle(fxWindow.style());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user