Skip to content

Commit 9033449

Browse files
authored
Merge pull request #171 from Dokyeongyun/ft-220223-resourceBaseDir
Ft 220223 resource base dir
2 parents 3b2136e + e5b12c4 commit 9033449

16 files changed

+165
-92
lines changed
Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
11
package root.applications;
22

3-
import java.io.File;
4-
53
import javafx.application.Application;
6-
import javafx.fxml.FXMLLoader;
4+
import javafx.scene.Parent;
75
import javafx.scene.Scene;
8-
import javafx.scene.layout.AnchorPane;
9-
import javafx.scene.text.Font;
106
import javafx.stage.Stage;
117
import root.core.repository.constracts.PropertyRepository;
128
import root.core.repository.implement.PropertyRepositoryImpl;
9+
import root.javafx.Controller.HomeController;
10+
import root.javafx.Controller.LeftMenuController;
11+
import root.javafx.DI.DependencyInjection;
1312

1413
public class Program extends Application {
1514

15+
public static Stage stage;
16+
1617
PropertyRepository propRepo = PropertyRepositoryImpl.getInstance();
1718

1819
@Override
1920
public void start(Stage primaryStage) throws Exception {
2021

22+
stage = primaryStage;
23+
24+
setUpDependecyInjector();
25+
2126
// configuration load
2227
propRepo.loadCombinedConfiguration();
2328

2429
// fxml load
2530
System.setProperty("prism.lcdtext", "false"); // ¾ÈƼ¾Ù¸®¾î½Ì (Font ºÎµå·´°Ô)
2631

27-
String[] fontFiles = new File("./src/main/resources/font").list();
28-
for(String font : fontFiles) {
29-
Font.loadFont(getClass().getResourceAsStream("./src/main/resources/font/" + font), 10);
30-
}
31-
32-
FXMLLoader homeloader = new FXMLLoader();
33-
homeloader.setLocation(getClass().getResource("/fxml/Home.fxml"));
34-
AnchorPane homePane = homeloader.load();
35-
36-
Scene scene = new Scene(homePane, 1200, 650);
37-
scene.getStylesheets().add(getClass().getResource("/css/javaFx.css").toExternalForm());
38-
32+
Parent root = DependencyInjection.load("/fxml/Home.fxml");
3933
primaryStage.setTitle("DB Monitoring Window Program");
40-
primaryStage.setScene(scene);
34+
primaryStage.setScene(new Scene(root, 1200, 650));
4135
primaryStage.show();
42-
4336
}
4437

4538
public static void main(String[] args) {
39+
if(System.getProperty("resourceBaseDir") == null) {
40+
System.setProperty("resourceBaseDir", "");
41+
}
42+
4643
launch(args);
4744
}
45+
46+
private void setUpDependecyInjector() {
47+
// save the factory in the injector
48+
DependencyInjection.addInjectionMethod(HomeController.class, param -> {return new HomeController();});
49+
DependencyInjection.addInjectionMethod(LeftMenuController.class, param -> {return new LeftMenuController();});
50+
}
4851
}

src/main/java/root/core/batch/DBCheckBatch.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public DBCheckBatch(DBCheckUsecase dbCheckUsecase) {
1212
public void startBatchArchiveUsageCheck() {
1313
try {
1414
this.dbCheckUsecase.printArchiveUsageCheck();
15-
this.dbCheckUsecase.writeExcelArchiveUsageCheck();
15+
// this.dbCheckUsecase.writeExcelArchiveUsageCheck();
1616
this.dbCheckUsecase.writeCsvArchiveUsage();
1717
}catch(Exception e) {
1818
e.printStackTrace();
Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,23 @@
11
package root.javafx.Controller;
22

33
import java.io.IOException;
4-
import java.net.URL;
5-
import java.util.ResourceBundle;
64

75
import com.jfoenix.controls.JFXButton;
86

97
import javafx.event.ActionEvent;
108
import javafx.fxml.FXML;
11-
import javafx.fxml.FXMLLoader;
12-
import javafx.fxml.Initializable;
13-
import javafx.scene.Parent;
14-
import javafx.scene.Scene;
159
import javafx.scene.layout.AnchorPane;
16-
import javafx.stage.Stage;
10+
import root.javafx.DI.DependencyInjection;
11+
import root.utils.SceneUtils;
12+
13+
public class HomeController {
14+
15+
@FXML
16+
AnchorPane rootAnchorPane;
17+
@FXML
18+
JFXButton startBtn;
1719

18-
public class HomeController implements Initializable {
19-
20-
@FXML AnchorPane rootAnchorPane;
21-
@FXML JFXButton startBtn;
22-
23-
@Override
24-
public void initialize(URL location, ResourceBundle resources) {
25-
}
26-
2720
public void goMainStage(ActionEvent e) throws IOException {
28-
Scene originalScene = rootAnchorPane.getScene();
29-
Parent root = FXMLLoader.load(getClass().getResource("/fxml/RunMenu.fxml"));
30-
Scene scene = new Scene(root, originalScene.getWidth(), originalScene.getHeight());
31-
Stage primaryStage = (Stage) startBtn.getScene().getWindow();
32-
primaryStage.setScene(scene);
21+
SceneUtils.movePage(DependencyInjection.load("/fxml/RunMenu.fxml"));
3322
}
3423
}

src/main/java/root/javafx/Controller/LeftMenuController.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44

55
import javafx.event.ActionEvent;
66
import javafx.fxml.FXML;
7-
import javafx.fxml.FXMLLoader;
8-
import javafx.scene.Node;
9-
import javafx.scene.Parent;
10-
import javafx.scene.Scene;
117
import javafx.scene.control.Button;
12-
import javafx.stage.Stage;
8+
import root.javafx.DI.DependencyInjection;
9+
import root.utils.SceneUtils;
1310

1411
public class LeftMenuController {
12+
1513
// Left SplitPane Region
1614
@FXML Button homeBtn;
1715
@FXML Button settingMenuBtn;
@@ -23,11 +21,7 @@ public class LeftMenuController {
2321
* @throws IOException
2422
*/
2523
public void goHomeStage(ActionEvent e) throws IOException {
26-
Scene originalScene = homeBtn.getScene();
27-
Parent home = FXMLLoader.load(getClass().getResource("/fxml/Home.fxml"));
28-
Scene homeScene = new Scene(home, originalScene.getWidth(), originalScene.getHeight());
29-
Stage primaryStage = (Stage) homeBtn.getScene().getWindow();
30-
primaryStage.setScene(homeScene);
24+
SceneUtils.movePage(DependencyInjection.load("/fxml/Home.fxml"));
3125
}
3226

3327
/**
@@ -36,24 +30,17 @@ public void goHomeStage(ActionEvent e) throws IOException {
3630
* @throws IOException
3731
*/
3832
public void goSettingMenu(ActionEvent e) throws IOException {
39-
Scene originalScene = homeBtn.getScene();
40-
Parent parent = FXMLLoader.load(getClass().getResource("/fxml/SettingMenu.fxml"));
41-
Scene newScene = new Scene(parent, originalScene.getWidth(), originalScene.getHeight());
42-
Stage primaryStage = (Stage)((Node) e.getSource()).getScene().getWindow();
43-
primaryStage.setScene(newScene);
33+
SceneUtils.movePage(DependencyInjection.load("/fxml/SettingMenu.fxml"));
4434
}
4535

4636
/**
4737
* 실행 메뉴로 이동한다.
38+
*
4839
* @param e
4940
* @throws IOException
5041
*/
5142
public void goRunMenu(ActionEvent e) throws IOException {
52-
Scene originalScene = homeBtn.getScene();
53-
Parent parent = FXMLLoader.load(getClass().getResource("/fxml/RunMenu.fxml"));
54-
Scene newScene = new Scene(parent, originalScene.getWidth(), originalScene.getHeight());
55-
Stage primaryStage = (Stage)((Node) e.getSource()).getScene().getWindow();
56-
primaryStage.setScene(newScene);
43+
SceneUtils.movePage(DependencyInjection.load("/fxml/RunMenu.fxml"));
5744
}
5845

5946
public void goMenu2(ActionEvent e) {

src/main/java/root/javafx/Controller/MainController.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88

99
import javafx.event.ActionEvent;
1010
import javafx.fxml.FXML;
11-
import javafx.fxml.FXMLLoader;
1211
import javafx.fxml.Initializable;
1312
import javafx.geometry.Pos;
14-
import javafx.scene.Parent;
15-
import javafx.scene.Scene;
1613
import javafx.scene.control.Button;
1714
import javafx.scene.control.Label;
1815
import javafx.scene.layout.ColumnConstraints;
@@ -21,9 +18,10 @@
2118
import javafx.scene.layout.StackPane;
2219
import javafx.scene.layout.VBox;
2320
import javafx.scene.text.TextAlignment;
24-
import javafx.stage.Stage;
2521
import root.core.repository.constracts.PropertyRepository;
2622
import root.core.repository.implement.PropertyRepositoryImpl;
23+
import root.javafx.DI.DependencyInjection;
24+
import root.utils.SceneUtils;
2725

2826
public class MainController implements Initializable {
2927

@@ -60,10 +58,7 @@ public void initialize(URL location, ResourceBundle resources) {
6058
}
6159

6260
public void goHomeStage(ActionEvent e) throws IOException {
63-
Parent root = FXMLLoader.load(getClass().getResource("/fxml/Home.fxml"));
64-
Scene scene = new Scene(root);
65-
Stage primaryStage = (Stage) homeBtn.getScene().getWindow();
66-
primaryStage.setScene(scene);
61+
SceneUtils.movePage(DependencyInjection.load("/fxml/Home.fxml"));
6762
}
6863

6964
public void setToggleDefaultValue() {

src/main/java/root/javafx/Controller/MonitoringAPController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import root.javafx.CustomView.UsageUI.UsageUI;
4545
import root.javafx.CustomView.UsageUI.UsageUIFactory;
4646
import root.javafx.CustomView.prequencyUI.PrequencyButton;
47+
import root.javafx.DI.DependencyInjection;
4748
import root.utils.AlertUtils;
4849
import root.utils.DateUtils;
4950
import root.utils.UnitUtils.FileSize;
@@ -98,7 +99,7 @@ public MonitoringAPController(Class<T> clazz) {
9899

99100
try {
100101
this.clazz = clazz;
101-
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/MonitoringAP.fxml"));
102+
FXMLLoader loader = DependencyInjection.getLoader("/fxml/MonitoringAP.fxml");
102103
loader.setController(this);
103104
loader.setRoot(this);
104105
loader.load();

src/main/java/root/javafx/Controller/SettingMenuController.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,13 @@ public void showMonitoringPresetPopup(ActionEvent e) {
183183
// ICON
184184
presetInputDialog.setGraphic(new FontAwesomeIconView(FontAwesomeIcon.PENCIL, "30"));
185185
// CSS
186-
presetInputDialog.getDialogPane().getStylesheets()
187-
.add(getClass().getResource("/css/dialog.css").toExternalForm());
186+
presetInputDialog.getDialogPane().getStylesheets().add(
187+
getClass().getResource(System.getProperty("resourceBaseDir") + "/css/dialog.css").toExternalForm());
188188
presetInputDialog.getDialogPane().getStyleClass().add("textInputDialog");
189189
// Dialog ICON
190190
Stage stage = (Stage) presetInputDialog.getDialogPane().getScene().getWindow();
191-
stage.getIcons().add(new Image(this.getClass().getResource("/image/add_icon.png").toString()));
191+
stage.getIcons().add(new Image(
192+
this.getClass().getResource(System.getProperty("resourceBaseDir") + "/image/add_icon.png").toString()));
192193
// Button Custom
193194
ButtonType okButton = new ButtonType("입력", ButtonData.OK_DONE);
194195
presetInputDialog.getDialogPane().getButtonTypes().removeAll(ButtonType.OK, ButtonType.CANCEL);
@@ -624,12 +625,13 @@ public void createNewConfigFile(ActionEvent e) {
624625
// ICON
625626
configInputDialog.setGraphic(new FontAwesomeIconView(FontAwesomeIcon.PENCIL, "30"));
626627
// CSS
627-
configInputDialog.getDialogPane().getStylesheets()
628-
.add(getClass().getResource("/css/dialog.css").toExternalForm());
628+
configInputDialog.getDialogPane().getStylesheets().add(
629+
getClass().getResource(System.getProperty("resourceBaseDir") + "/css/dialog.css").toExternalForm());
629630
configInputDialog.getDialogPane().getStyleClass().add("textInputDialog");
630631
// Dialog ICON
631632
Stage stage = (Stage) configInputDialog.getDialogPane().getScene().getWindow();
632-
stage.getIcons().add(new Image(this.getClass().getResource("/image/add_icon.png").toString()));
633+
stage.getIcons().add(new Image(
634+
this.getClass().getResource(System.getProperty("resourceBaseDir") + "/image/add_icon.png").toString()));
633635
// Button Custom
634636
ButtonType okButton = new ButtonType("입력", ButtonData.OK_DONE);
635637
configInputDialog.getDialogPane().getButtonTypes().removeAll(ButtonType.OK, ButtonType.CANCEL);

src/main/java/root/javafx/CustomView/AlertLogListViewCell.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import javafx.scene.control.ListCell;
1111
import javafx.scene.layout.AnchorPane;
1212
import root.core.domain.Log;
13+
import root.javafx.DI.DependencyInjection;
1314

1415
public class AlertLogListViewCell extends ListCell<Log> {
1516
private FXMLLoader loader;
@@ -27,14 +28,13 @@ protected void updateItem(Log log, boolean empty) {
2728
setGraphic(null);
2829
} else {
2930
if (loader == null) {
30-
loader = new FXMLLoader(getClass().getResource("/fxml/AlertLogListViewCell.fxml"));
31-
loader.setController(this);
32-
33-
try {
34-
loader.load();
35-
} catch (IOException e) {
36-
e.printStackTrace();
37-
}
31+
FXMLLoader loader = DependencyInjection.getLoader("/fxml/AlertLogListViewCell.fxml");
32+
loader.setController(this);
33+
try {
34+
loader.load();
35+
} catch (IOException e) {
36+
e.printStackTrace();
37+
}
3838
}
3939

4040
logTimeLabel.setText(log.getLogTimeStamp());

src/main/java/root/javafx/CustomView/ConnectionInfoVBox.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
import javafx.scene.text.Text;
2626
import lombok.AllArgsConstructor;
2727
import lombok.Data;
28+
import root.javafx.DI.DependencyInjection;
2829
import root.javafx.Service.ConnectionTestService;
2930
import root.utils.AlertUtils;
31+
import root.utils.SceneUtils;
3032

3133
public class ConnectionInfoVBox<T> extends VBox {
3234

@@ -65,12 +67,12 @@ public class ConnectionInfoVBox<T> extends VBox {
6567
private ConnInfoAPMap connInfoAPMap = new ConnInfoAPMap();
6668

6769
private long connInfoIdx = -1;
68-
70+
6971
public ConnectionInfoVBox(ConnInfoControl<T> connInfoControl) {
7072
this.connInfoControl = connInfoControl;
7173

7274
try {
73-
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/ConnectionInfoVBox.fxml"));
75+
FXMLLoader loader = DependencyInjection.getLoader("/fxml/ConnectionInfoVBox.fxml");
7476
loader.setController(this);
7577
loader.setRoot(this);
7678
loader.load();

src/main/java/root/javafx/CustomView/DBConnectionInfoAnchorPane.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import root.core.domain.JdbcConnectionInfo;
2020
import root.core.repository.constracts.PropertyRepository;
2121
import root.core.repository.implement.PropertyRepositoryImpl;
22+
import root.javafx.DI.DependencyInjection;
2223

2324
public class DBConnectionInfoAnchorPane extends ConnectionInfoAP {
2425

@@ -51,7 +52,7 @@ public class DBConnectionInfoAnchorPane extends ConnectionInfoAP {
5152

5253
public DBConnectionInfoAnchorPane() {
5354
try {
54-
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DBConnectionInfoAnchorPane.fxml"));
55+
FXMLLoader loader = DependencyInjection.getLoader("/fxml/DBConnectionInfoAnchorPane.fxml");
5556
loader.setController(this);
5657
loader.setRoot(this);
5758
loader.load();

0 commit comments

Comments
 (0)