Skip to content

Commit

Permalink
10 - Adding new tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandervalach committed Apr 3, 2020
1 parent aa52d60 commit 5c587a1
Show file tree
Hide file tree
Showing 28 changed files with 971 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 10 - Adding tracks/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions 10 - Adding tracks/.idea/ant.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions 10 - Adding tracks/.idea/artifacts/JavaFXApp.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions 10 - Adding tracks/.idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions 10 - Adding tracks/.idea/description.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 10 - Adding tracks/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions 10 - Adding tracks/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions 10 - Adding tracks/.idea/libraries/jfxrt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions 10 - Adding tracks/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 10 - Adding tracks/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions 10 - Adding tracks/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 10 - Adding tracks/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions 10 - Adding tracks/10 - Adding tracks.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jfxrt" level="project" />
</component>
</module>
79 changes: 79 additions & 0 deletions 10 - Adding tracks/src/controller/BaseController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package controller;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.layout.GridPane;
import model.Identity;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ResourceBundle;

public abstract class BaseController implements Initializable {

@FXML
protected GridPane app;

protected Identity identity;

protected String viewURL;
protected String rootURL;

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
identity = Identity.getInstance();

// Na začiatku si načítame URL
viewURL = System.getProperty("user.dir") + "/src/view/";
rootURL = System.getProperty("user.dir");
}

/**
* Logs out user
*/
protected void logout() {
identity.logOut();
identity = Identity.getInstance();
switchScene( "login");
}

/**
* Switches between different scenes
* @param view scene to be viewed
* */
public void switchScene(String view) {
/*
if (identity != null) {
System.out.println("Identity: " + identity.getUsername());
} else {
System.out.println("No identity");
}
*/

try {
// Odstránime obsah view, ktorý je momentálne zobrazený
app.getChildren().clear();

// Absolútna URL k danému fxml súboru
URL fxmlURL = getLocation(view);

// Vymeníme za nový obsah
app.getChildren().add(FXMLLoader.load(fxmlURL));
} catch (IOException e) {
e.printStackTrace();
}
}

protected URL getLocation (String view) throws MalformedURLException {
return Paths.get(viewURL + view + ".fxml").toUri().toURL();
}

protected boolean fileExists (String url) {
File file = new File(url);
return file.exists();
}
}
34 changes: 34 additions & 0 deletions 10 - Adding tracks/src/controller/DashboardController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package controller;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import model.InfoDialog;

import java.net.URL;
import java.util.ResourceBundle;

public class DashboardController extends BaseController {
@FXML
private Button tracks;

@FXML
private Button logout;

// private InfoDialog infoDialog;

public DashboardController () {
// infoDialog = new InfoDialog();
}

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
super.initialize(url, resourceBundle);

tracks.defaultButtonProperty().bind(tracks.focusedProperty());
logout.defaultButtonProperty().bind(logout.focusedProperty());

tracks.setOnAction((e) -> { this.switchScene("tracks/all"); });
logout.setOnAction((e) -> { this.logout(); });
}
}
Loading

0 comments on commit 5c587a1

Please sign in to comment.