├── .gitignore
├── README.md
├── pom.xml
└── src
└── main
├── java
└── com
│ └── mvp
│ └── java
│ ├── Main.java
│ ├── controllers
│ ├── ConsoleTabController.java
│ ├── LoggerTabController.java
│ └── MainController.java
│ └── services
│ └── MissionsService.java
└── resources
├── application.properties
├── fxml
├── ConsoleTab.fxml
├── LoggerTab.fxml
└── Main.fxml
├── outline
└── specs
├── Apollo
├── Shuttle
└── Skylab
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.jar
8 | *.war
9 | *.ear
10 |
11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
12 | hs_err_pid*
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # javaFX-multiple-controllers-tutorial
2 |
3 | Tutorial covering how to have multiple JavaFX Controllers communicate with each other through a TabPane demo.
4 |
5 | The Java FX views are generated via Scene Builder in FXML files.
6 | The demo covers best design principles in GUI design by separating different tabs into separate FXML files
7 | with their own respective Controllers.
8 |
9 | Special attention is put on the 3 main points to remember when incorporating multiple controllers into your design.
10 |
11 | You can watch the YouTube Tutorial "JavaFX Multiple Controllers" https://youtu.be/osIRfgHTfyg
12 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.mvp.java
7 | javaFX_SepControllersTutorial
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | javaFX_SepControllersTutorial
12 | Mission Desciptions
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.3.5.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | 1.8
24 |
25 |
26 |
27 |
28 | org.springframework.boot
29 | spring-boot-starter-security
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter-test
35 | test
36 |
37 |
38 |
39 | org.testfx
40 | testfx-core
41 | 4.0.1-alpha
42 | test
43 |
44 |
45 |
46 | org.testfx
47 | testfx-junit
48 | 4.0.1-alpha
49 | test
50 |
51 |
52 |
53 |
54 |
55 |
56 | org.springframework.boot
57 | spring-boot-maven-plugin
58 |
59 |
60 | org.apache.maven.plugins
61 | maven-compiler-plugin
62 | 2.3.2
63 |
64 | true
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/src/main/java/com/mvp/java/Main.java:
--------------------------------------------------------------------------------
1 | package com.mvp.java;
2 |
3 | import javafx.application.Application;
4 | import javafx.fxml.FXMLLoader;
5 | import javafx.scene.Parent;
6 | import javafx.scene.Scene;
7 | import javafx.stage.Stage;
8 |
9 | public class Main extends Application {
10 |
11 | private Parent rootNode;
12 |
13 | public static void main(final String[] args) {
14 | Application.launch(args);
15 | }
16 |
17 | @Override
18 | public void init() throws Exception {
19 | FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/Main.fxml"));
20 | rootNode = fxmlLoader.load();
21 | }
22 |
23 | @Override
24 | public void start(Stage stage) throws Exception {
25 | stage.setScene(new Scene(rootNode));
26 | stage.show();
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/src/main/java/com/mvp/java/controllers/ConsoleTabController.java:
--------------------------------------------------------------------------------
1 | package com.mvp.java.controllers;
2 |
3 | import com.mvp.java.services.MissionsService;
4 | import java.io.IOException;
5 | import java.io.PrintWriter;
6 | import java.io.StringWriter;
7 | import javafx.collections.FXCollections;
8 | import javafx.collections.ObservableList;
9 | import javafx.fxml.FXML;
10 | import javafx.scene.control.ListView;
11 | import javafx.scene.control.TextArea;
12 | import javafx.scene.input.MouseEvent;
13 |
14 | public class ConsoleTabController {
15 |
16 | @FXML private TextArea missionOverviewText;
17 | @FXML private ListView missionsList;
18 |
19 | private final MissionsService service = new MissionsService();
20 | private MainController mainController;
21 |
22 | public void injectMainController(MainController mainController){
23 | this.mainController = mainController;
24 | }
25 |
26 | public void initialize() {
27 | ObservableList missions = FXCollections.observableArrayList("Apollo", "Shuttle", "Skylab");
28 | missionsList.setItems(missions);
29 | }
30 |
31 | @FXML
32 | private void onMouseClicked(MouseEvent event) {
33 | missionOverviewText.clear();
34 | final String selectedItem = missionsList.getSelectionModel().getSelectedItem();
35 | if (selectedItem == null) {
36 | return;
37 | }
38 | missionOverviewText.positionCaret(0);
39 | missionOverviewText.appendText(getInfo(selectedItem));
40 | }
41 |
42 | public String getInfo(String selectedItem) {
43 | PrintWriter stackTraceWriter = new PrintWriter(new StringWriter());
44 | String missionInfo = null ;
45 |
46 | try {
47 | missionInfo = service.getMissionInfo(selectedItem);
48 | getLog().appendText("Sucessfully retrieved mission info for " + selectedItem + "\n");
49 | } catch (IOException exception) {
50 | exception.printStackTrace (stackTraceWriter);
51 | getLog().appendText(stackTraceWriter.toString() + "\n");
52 | }
53 |
54 | return missionInfo;
55 | }
56 |
57 | public TextArea getMissionOverviewText() {
58 | return missionOverviewText;
59 | }
60 |
61 | public ListView getMissionsList() {
62 | return missionsList;
63 | }
64 |
65 | private TextArea getLog(){
66 | return mainController.getVisualLog();
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/mvp/java/controllers/LoggerTabController.java:
--------------------------------------------------------------------------------
1 | package com.mvp.java.controllers;
2 |
3 | import javafx.fxml.FXML;
4 | import javafx.scene.control.TextArea;
5 | import javafx.scene.layout.VBox;
6 |
7 | public class LoggerTabController {
8 |
9 | @FXML private VBox loggerTab;
10 | @FXML private TextArea loggerTxtArea;
11 |
12 | public TextArea getLoggerTxtArea() {
13 | return loggerTxtArea;
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/main/java/com/mvp/java/controllers/MainController.java:
--------------------------------------------------------------------------------
1 | package com.mvp.java.controllers;
2 |
3 | import javafx.fxml.FXML;
4 | import javafx.scene.control.TextArea;
5 |
6 | public class MainController {
7 |
8 | @FXML private ConsoleTabController consoleTabController;
9 | @FXML private LoggerTabController loggerTabController;
10 |
11 | public TextArea getVisualLog() {
12 | return loggerTabController.getLoggerTxtArea();
13 | }
14 |
15 | @FXML private void initialize() {
16 | consoleTabController.injectMainController(this);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/main/java/com/mvp/java/services/MissionsService.java:
--------------------------------------------------------------------------------
1 | package com.mvp.java.services;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.InputStreamReader;
7 |
8 | public class MissionsService {
9 |
10 | private final String specsPath = "/specs/";
11 |
12 | public String getMissionInfo(String missionName) throws IOException {
13 | final StringBuilder fileContents = new StringBuilder(2000);
14 | final InputStream is = this.getClass().getResourceAsStream(specsPath + missionName);
15 |
16 | try (BufferedReader br = new BufferedReader(new InputStreamReader(is));) {
17 | String line;
18 | while ((line = br.readLine()) != null) {
19 | fileContents.append(line).append("\n");
20 | }
21 | }
22 | return fileContents.toString();
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mvpjava/javaFX-multiple-controllers-tutorial/326d0a6d315d76dd4fb0e4a0f3c0902a63e570dd/src/main/resources/application.properties
--------------------------------------------------------------------------------
/src/main/resources/fxml/ConsoleTab.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/src/main/resources/fxml/LoggerTab.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/src/main/resources/fxml/Main.fxml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/main/resources/outline:
--------------------------------------------------------------------------------
1 | Java FX 8 - Communication between Controllers
2 | ===================================================
3 | Will Cover ...
4 |
5 | - Tabbed Demo that concentrates on setting this up
6 |
7 | - Cover the gotcha's!
8 | - fx:id for Components
9 | - fx:id for include
10 | - @FXML on Controllers
11 |
12 | - Some annoying issues ...
13 |
14 | - Follow up Questions ...
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/src/main/resources/specs/Apollo:
--------------------------------------------------------------------------------
1 | Apollo (spacecraft)
2 | ================================================
3 | The Apollo spacecraft was composed of three parts designed to accomplish the American Apollo
4 | program's goal of landing astronauts on the Moon by the end of the 1960s and returning them
5 | safely to Earth. The expendable (single-use) spacecraft consisted of a combined
6 | Command/Service Module (CSM) and a Lunar Module (LM).
7 |
8 | Two additional components
9 | complemented the spacecraft stack for space vehicle assembly: a Spacecraft
10 | Lunar Module Adapter (SLA) designed to shield the LM from the aerodynamic
11 | stress of launch, and to connect the CSM to the Saturn launch vehicle;
12 | and a Launch Escape System (LES) to carry the crew in the Command Module safely away from
13 | the launch vehicle in the event of a launch emergency.
14 |
15 | The design was based on the Lunar Orbit Rendezvous approach: two docked spacecraft were sent
16 | to the Moon and went into lunar orbit. While the LM separated and landed, the CSM remained
17 | in orbit. After the lunar excursion, the two craft rendezvoused and docked in lunar orbit,
18 | and the CSM returned the crew to Earth. The Command Module was the only part of the space
19 | vehicle that returned with the crew to the Earth's surface.
20 |
21 |
22 | Specifications
23 |
24 | Length minus BPC: 32 ft 6 in (9.92 m)
25 | Length with BPC: 39 ft 5 in (12.02 m)
26 | Diameter: 2 ft 2 in (0.66 m)
27 | Total mass: 9,200 pounds (4,200 kg)
28 | Thrust, 36,000 ft: 147,000 pounds-force (650 kN)
29 | Thrust, maximum: 200,000 pounds-force (890 kN)
30 | Burn time: 4.0 seconds
--------------------------------------------------------------------------------
/src/main/resources/specs/Shuttle:
--------------------------------------------------------------------------------
1 | the Shuttle
2 | ===========
3 |
4 | Since 1981, NASA space shuttles have been rocketing from the Florida coast into
5 | Earth orbit. The five orbiters — Columbia, Challenger, Discovery, Atlantis and
6 | Endeavour — have flown more than 130 times, carrying over 350 people into space
7 | and travelling more than half a billion miles, more than enough to reach Jupiter.
8 |
9 |
10 | SPECIFICATIONS
11 |
12 | First launch: 12-Apr-1981
13 | Number launches: 114 to end-2005
14 | Launch sites: KSC pads 39A/39B
15 | Principal uses: US manned capability to beyond 2010 (four reuseable Orbiter fleet), 25,000 kg payload delivery to LEO, satellite retrieval/in situ repair, short-duration science platform, Space Station assembly/servicing
16 | Vehicle success rate: 98.25% to end-2005
17 | Performance:
18 | LEO (204 km, 28.45o): 21,140 kg OV-102, 24,950 kg OV-103/104/105; each additional
19 | 1 km altitude reduces capacity by 25 kg, each crewmember beyond 5-person size
20 | reduces capacity by 230 kg into basic orbit
21 | LEO (204 km, 57o): 14,800 kg OV-102, 18,600 kg OV-103/104/105 (57o is usually the
22 | highest inclination flown from Florida, but dog-legging provides access to higher angles)
23 | LEO (204 km, 98o Sun-synchronous VAFB): 13,426 kg OV-103/104/105, assuming use if
24 | Advanced Solid Rocket Motors. Neither VAFB nor ASRM will be used
25 | Molniya (925 x 39,450 km, 63o): 3,563 kg using IUS via 222 km, 57o parking orbit
26 | Crossrange: 2,040 km max; 1,020-1,300 km used operationally by NASA
--------------------------------------------------------------------------------
/src/main/resources/specs/Skylab:
--------------------------------------------------------------------------------
1 | Skylab
2 | ======
3 |
4 | Skylab was a space station launched and operated by NASA and was the United
5 | States' first space station. Skylab orbited Earth from 1973 to 1979, and
6 | included a workshop, a solar observatory, and other systems. It was launched
7 | unmanned by a modified Saturn V rocket, with a weight of 170,000 pounds
8 | (77,111 kg).[1] Three manned expeditions to the station, conducted between
9 | May 1973 and February 1974 using the Apollo Command/Service Module (CSM) atop
10 | the smaller Saturn IB, each delivered a three-astronaut crew. On the last two
11 | manned missions, an additional Apollo / Saturn IB stood by ready to rescue the
12 | crew in orbit if it was needed.
13 |
14 | Specifications
15 |
16 | Crew Size: 3. Orbital Storage: 730 days. Habitable Volume: 361.00 m3. RCS
17 | Coarse No x Thrust: Reaction wheels. Electric System: 11.00 average kW.
18 |
19 | Gross mass: 76,295 kg (168,201 lb).
20 | Height: 36.12 m (118.50 ft).
21 | Span: 21.00 m (68.00 ft).
22 | First Launch: 1973.05.14.
23 | Number: 1 .
24 |
--------------------------------------------------------------------------------