|
@@ -6,6 +6,7 @@ import javafx.fxml.FXML;
|
|
import javafx.geometry.HPos;
|
|
import javafx.geometry.HPos;
|
|
import javafx.geometry.Pos;
|
|
import javafx.geometry.Pos;
|
|
import javafx.geometry.VPos;
|
|
import javafx.geometry.VPos;
|
|
|
|
+import javafx.scene.Node;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.control.*;
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.image.ImageView;
|
|
import javafx.scene.image.ImageView;
|
|
@@ -20,11 +21,16 @@ import com.moviesdb.Movie;
|
|
import javafx.scene.text.Text;
|
|
import javafx.scene.text.Text;
|
|
import javafx.scene.text.TextFlow;
|
|
import javafx.scene.text.TextFlow;
|
|
import com.moviesdb.DataBaseConnector;
|
|
import com.moviesdb.DataBaseConnector;
|
|
|
|
+import javafx.stage.Modality;
|
|
import javafx.stage.Stage;
|
|
import javafx.stage.Stage;
|
|
|
|
+import javafx.scene.Parent;
|
|
|
|
+import javafx.scene.Scene;
|
|
|
|
+import javafx.fxml.FXMLLoader;
|
|
|
|
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.time.chrono.AbstractChronology;
|
|
import java.time.chrono.AbstractChronology;
|
|
-import java.util.LinkedHashMap;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
//For reading properties from .properties file
|
|
//For reading properties from .properties file
|
|
import com.moviesdb.ConnectionParams;
|
|
import com.moviesdb.ConnectionParams;
|
|
|
|
|
|
@@ -47,8 +53,7 @@ public class Controller {
|
|
@FXML
|
|
@FXML
|
|
AnchorPane filterPane;
|
|
AnchorPane filterPane;
|
|
@FXML
|
|
@FXML
|
|
- Label button;
|
|
|
|
-
|
|
|
|
|
|
+ Label button;
|
|
@FXML
|
|
@FXML
|
|
Label minimizeButton;
|
|
Label minimizeButton;
|
|
@FXML
|
|
@FXML
|
|
@@ -58,13 +63,24 @@ public class Controller {
|
|
@FXML
|
|
@FXML
|
|
Label logInButton;
|
|
Label logInButton;
|
|
@FXML
|
|
@FXML
|
|
|
|
+ Button logInButton2;
|
|
|
|
+ @FXML
|
|
MenuBar menuPane;
|
|
MenuBar menuPane;
|
|
|
|
|
|
|
|
+ @FXML
|
|
|
|
+ TextField userTextBox;
|
|
|
|
+ @FXML
|
|
|
|
+ TextField passTextBox;
|
|
|
|
+ @FXML
|
|
|
|
+ TextFlow errorTextBox;
|
|
|
|
+ @FXML
|
|
|
|
+ Label userLabel;
|
|
|
|
+
|
|
Map<Label, Movie> map;
|
|
Map<Label, Movie> map;
|
|
Label[] labelsMovies;
|
|
Label[] labelsMovies;
|
|
Movie[] movies;
|
|
Movie[] movies;
|
|
Movie my_movie;
|
|
Movie my_movie;
|
|
- DataBaseConnector my_connector;
|
|
|
|
|
|
+ public DataBaseConnector my_connector;
|
|
ConnectionParams workParams;
|
|
ConnectionParams workParams;
|
|
|
|
|
|
double xOffset;
|
|
double xOffset;
|
|
@@ -117,8 +133,8 @@ public class Controller {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
|
|
- //TODO change path to connection.properties
|
|
|
|
- workParams = new ConnectionParams("src/com/moviesdb/connection.properties");
|
|
|
|
|
|
+
|
|
|
|
+ workParams = new ConnectionParams("connection.properties");
|
|
if (!workParams.initilized())
|
|
if (!workParams.initilized())
|
|
//TODO this is temporaly handler
|
|
//TODO this is temporaly handler
|
|
System.out.println(workParams.getInitilizeErrCause().toString());
|
|
System.out.println(workParams.getInitilizeErrCause().toString());
|
|
@@ -316,27 +332,84 @@ public class Controller {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void openLoginForm(){
|
|
|
|
- //TODO Followed Must be on some button
|
|
|
|
- if (!newArgLogin())
|
|
|
|
- System.out.println("Login error!");
|
|
|
|
- else
|
|
|
|
- closeLoginForm();
|
|
|
|
|
|
+ public void openLoginForm(){
|
|
|
|
+
|
|
|
|
+ Parent root;
|
|
|
|
+ try {
|
|
|
|
+ FXMLLoader loader = new FXMLLoader();
|
|
|
|
+ loader.setLocation(getClass().getResource("test.fxml"));
|
|
|
|
+ root = loader.load();
|
|
|
|
+ //root = FXMLLoader.load(getClass().getClassLoader().getResource("test.fxml"));
|
|
|
|
+ Stage stage = new Stage();
|
|
|
|
+ stage.initModality(Modality.WINDOW_MODAL);
|
|
|
|
+ stage.initOwner(browserPane.getScene().getWindow());
|
|
|
|
+ stage.setTitle("Log in");
|
|
|
|
+ stage.setScene(new Scene(root, 250, 175));
|
|
|
|
+ stage.show();
|
|
|
|
+ // Hide this current window (if this is what you want)
|
|
|
|
+ //((Node)(event.getSource())).getScene().getWindow().hide();
|
|
|
|
+ }
|
|
|
|
+ catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //if (!newArgLogin())
|
|
|
|
+ // System.out.println("Login error!");
|
|
|
|
+ //else
|
|
|
|
+ // closeLoginForm();
|
|
}
|
|
}
|
|
|
|
|
|
- private void closeLoginForm(){
|
|
|
|
- //TODO Actually closing LoginForm
|
|
|
|
- System.out.println("LoginForm closed");
|
|
|
|
|
|
+ public void closeLoginForm(){
|
|
|
|
+
|
|
|
|
+ Stage stage = (Stage) logInButton2.getScene().getWindow();
|
|
|
|
+ Stage parent = (Stage) stage.getOwner();
|
|
|
|
+ Controller controller = new Controller();
|
|
|
|
+ FXMLLoader loader = (FXMLLoader) parent.getUserData();
|
|
|
|
+ controller = loader.getController();
|
|
|
|
+ //controller.initialize(parent);
|
|
|
|
+ if(controller.newArgLogin(userTextBox.getText(), passTextBox.getText())) {
|
|
|
|
+ stage.close();
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ Text errorMessage = new Text("Incorrect login or password!");
|
|
|
|
+ errorMessage.setStyle("-fx-font-size: 14; -fx-fill: #FF0000;");
|
|
|
|
+ errorTextBox.getChildren().add(errorMessage);
|
|
|
|
+ }
|
|
|
|
+ //System.out.println("LoginForm closed");
|
|
}
|
|
}
|
|
|
|
|
|
- private Boolean newArgLogin(){
|
|
|
|
- //TODO Change Hardcoded values to input fields from LoginForm
|
|
|
|
- ConnectionParams temooralParams = new ConnectionParams("192.168.192.1/moviesdb","Veloe", "Password1*");
|
|
|
|
- if (my_connector.tryConnection(temooralParams)){
|
|
|
|
- workParams = temooralParams;
|
|
|
|
|
|
+ private Boolean newArgLogin(String user, String pass){
|
|
|
|
+
|
|
|
|
+ Properties property = new Properties();
|
|
|
|
+ ConnectionParams temporalParams;
|
|
|
|
+ try {
|
|
|
|
+ FileInputStream fis = new FileInputStream("connection.properties");
|
|
|
|
+ property.load(fis);
|
|
|
|
+ temporalParams = new ConnectionParams(property.getProperty("CONFIG_DEFAULT_HOST"), user, pass);
|
|
|
|
+ }
|
|
|
|
+ catch (IOException ex)
|
|
|
|
+ {
|
|
|
|
+ temporalParams = new ConnectionParams("127.0.0.1/moviesdb", user, pass);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (my_connector.tryConnection(temporalParams)){
|
|
|
|
+ workParams = temporalParams;
|
|
my_connector.initConnection(workParams);
|
|
my_connector.initConnection(workParams);
|
|
|
|
+ setUserName(user);
|
|
return my_connector.initialized();
|
|
return my_connector.initialized();
|
|
}
|
|
}
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ConnectionParams defaultParams = new ConnectionParams("connection.properties");
|
|
|
|
+ setUserName("Guest");
|
|
|
|
+ my_connector.initConnection(defaultParams);
|
|
|
|
+ }
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void setUserName(String name)
|
|
|
|
+ {
|
|
|
|
+ userLabel.setText("Logged in as " + name);
|
|
|
|
+ }
|
|
}
|
|
}
|