Skip to content

Commit 583721d

Browse files
committed
SceneManager in-built for CustomStage and added JavaDoc
1 parent 8ff98ba commit 583721d

File tree

4 files changed

+113
-2
lines changed

4 files changed

+113
-2
lines changed

examples/v1_2_2/StageTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package v1_2_2;
22

33
import javafx.application.Application;
4-
import javafx.scene.image.Image;
54
import javafx.scene.layout.AnchorPane;
6-
import javafx.scene.shape.Circle;
75
import javafx.stage.Stage;
86
import lk.vivoxalabs.customstage.CustomStage;
97
import lk.vivoxalabs.customstage.CustomStageBuilder;

src/main/java/lk/vivoxalabs/customstage/CustomStage.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import javafx.stage.Stage;
66
import lk.vivoxalabs.customstage.tools.NavigationType;
77
import lk.vivoxalabs.customstage.view.controller.CustomStageController;
8+
import lk.vivoxalabs.scenemanager.SceneManager;
89

10+
import java.awt.*;
911
import java.net.URL;
1012

1113
/**
@@ -18,6 +20,11 @@
1820
*/
1921
public class CustomStage extends Stage {
2022
private final CustomStageController _STAGE_CONTROLLER_;
23+
private static final SceneManager DEFAULT_SCENE_MANAGER;
24+
25+
static{
26+
DEFAULT_SCENE_MANAGER = new SceneManager();
27+
}
2128

2229
CustomStage(CustomStageController controller){
2330
_STAGE_CONTROLLER_ = controller;
@@ -105,4 +112,11 @@ public void dynamicDrawerEvent(NavigationType type){
105112
_STAGE_CONTROLLER_.dynamicDrawerEvent(type);
106113
}
107114

115+
/**
116+
* @return the static SceneManager object in CustomStage
117+
*/
118+
public static SceneManager getDefaultSceneManager(){
119+
return DEFAULT_SCENE_MANAGER;
120+
}
121+
108122
}

src/main/java/lk/vivoxalabs/scenemanager/SceneManager.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,43 @@ public String[] getIds(){
7878
return sceneMap.keySet().toArray(new String[]{});
7979
}
8080

81+
/**
82+
* @deprecated Use another "automate" method instead. This does not work unless used with a SceneManager object you have created.
83+
* (Does not work with the defaultSceneManager object provided). <br>
84+
*
85+
* <b>NOTE : {@code CustomStage.getDefaultSceneManager().automate();} will not work </b>
86+
*
87+
* <p>
88+
* When called gets the directory to collect files as the directory of the caller class.
89+
* Ex : If "Foo.class" calls this method, then fxml files available in the same directory as "Foo.class" will be loaded.
90+
* </p>
91+
*
92+
*/
8193
public void automate(){
8294
fileLoader = new FileLoader("fxml",this);
8395
fileLoader.collect();
8496
}
8597

98+
/**
99+
* <p>
100+
* This is used to make the FileLoader eligible to load the given type of files from the directory given in String format.
101+
* </p>
102+
*
103+
* @param dir directory path for fxml files to be loaded from
104+
*/
86105
public void automate(String dir){
87106
fileLoader = new FileLoader(dir,"fxml",this);
88107
fileLoader.collect();
89108
}
90109

110+
/**
111+
* <p>
112+
* This is used to make the FileLoader eligible to load the given type of files from the directory of the URL provides.
113+
* Ex : {@code sceneManager.automate(getClass().getResource("/path/to/file/myfile.fxml")))}
114+
* Will make the FileLoader eligible to load file with ".fxml" extension from the "/path/to/file" directory.
115+
* </p>
116+
* @param url URL of a class to determine the package which needs to be lookup for fxml files to load
117+
*/
91118
public void automate(URL url){
92119
fileLoader = new FileLoader(url,"fxml",this);
93120
fileLoader.collect();

src/main/java/lk/vivoxalabs/scenemanager/tools/FileLoader.java

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,37 @@
1111
import java.util.List;
1212

1313
/**
14+
* This class is used to load all the files in the given package as to the given extension.
15+
*
1416
* @author oshan
17+
* @version 1.0
1518
*/
1619
public class FileLoader {
1720

1821
private SceneManager manager;
1922

2023
private String dir="", ext;
2124

25+
/**
26+
* <p>
27+
* IMPORTANT : <b>
28+
* This DOES NOT GUARANTEE to be executed the way expected and should be avoided unless in testing.
29+
* Use another constructor instead.
30+
* </b>
31+
* Calling this constructor will create a FileLoader object which can load the type of files of the given extension (ext)
32+
* from the same package of the class the constructor was called.
33+
* Ex : If the constructor was called from "Foo.class", this will create a FileLoader which is able to load the specific
34+
* files from the same directory "Foo.class" file is located.
35+
* </p>
36+
*
37+
* <p>
38+
* <b>NOTE :</b> This constructor is specifically created to be used with SceneManager. If used separately, this will not
39+
* work properly and will be unable to load the files. (Since this uses getStackTrace()[3] argument and if called directly,
40+
* it should probably be changed to getStackTrace()[1]).
41+
* </p>
42+
*
43+
* @param ext extension of the type of files needed to be loaded
44+
*/
2245
public FileLoader(String ext) {
2346
this.ext = ext;
2447
try {
@@ -31,11 +54,30 @@ public FileLoader(String ext) {
3154

3255
}
3356

57+
/**
58+
* <p>
59+
* This is same as {@link #FileLoader(String ext)}. The only difference is that this constructor will initialize the
60+
* SceneManager property which can be used later (through the given SceneManager object)
61+
*</p>
62+
*
63+
* @param ext extension of the type of files needed to be loaded
64+
* @param manager SceneManager object which is going to access this FileLoader object
65+
*/
3466
public FileLoader(String ext, SceneManager manager){
3567
this(ext);
3668
this.manager=manager;
3769
}
3870

71+
/**
72+
* <p>
73+
* This is used to make the FileLoader eligible to load the given type of files from the directory of the URL provides.
74+
* Ex : {@code new FileLoader(getClass().getResource("/path/to/file/myfile.fxml")),"fxml")}
75+
* Will make the FileLoader eligible to load file with ".fxml" extension from the "/path/to/file" directory.
76+
* </p>
77+
*
78+
* @param url URL of a class to determine the package which needs to be lookup for files to load
79+
* @param ext extension of the type of files needed to be loaded
80+
*/
3981
public FileLoader(URL url, String ext){
4082
String[] content = url.toString().replace("file:/","").replace("%20"," ").split("/");
4183

@@ -49,21 +91,51 @@ public FileLoader(URL url, String ext){
4991
this.ext = ext;
5092
}
5193

94+
/**
95+
* <p>
96+
* This is same as {@link #FileLoader(URL, String)}. The only difference is that this constructor will initialize the
97+
* SceneManager property which can be used later (through the given SceneManager object)
98+
* </p>
99+
*
100+
* @param url URL of a class to determine the package which needs to be lookup for files to load
101+
* @param ext extension of the type of files needed to be loaded
102+
* @param manager SceneManager object which is going to access this FileLoader object
103+
*/
52104
public FileLoader(URL url, String ext, SceneManager manager){
53105
this(url, ext);
54106
this.manager = manager;
55107
}
56108

109+
/**
110+
* <p>
111+
* This is used to make the FileLoader eligible to load the given type of files from the directory given in String format.
112+
* </p>
113+
*
114+
* @param dir directory path
115+
* @param ext extension of the type of files needed to be loaded
116+
*/
57117
public FileLoader(String dir, String ext) {
58118
this.dir=dir;
59119
this.ext=ext;
60120
}
61121

122+
/**
123+
* See {@link #FileLoader(String, String, SceneManager)}
124+
*
125+
* @param dir directory path
126+
* @param ext extension of the type of files needed to be loaded
127+
* @param manager SceneManager object which is going to access this FileLoader object
128+
*/
62129
public FileLoader(String dir, String ext, SceneManager manager){
63130
this(dir, ext);
64131
this.manager=manager;
65132
}
66133

134+
/**
135+
* Collects the set of files with the given extension and inside the given directory for the FileLoader.
136+
*
137+
* @return the loaded available files.
138+
*/
67139
public List<File> collect(){
68140

69141
List<File> files = new ArrayList<>();

0 commit comments

Comments
 (0)