|
@@ -1,5 +1,6 @@
|
|
|
package com.moviesdb;
|
|
|
|
|
|
+import com.sun.javafx.collections.MappingChange;
|
|
|
import javafx.fxml.FXML;
|
|
|
import javafx.geometry.HPos;
|
|
|
import javafx.geometry.Pos;
|
|
@@ -19,6 +20,8 @@ import com.moviesdb.DataBaseConnector;
|
|
|
|
|
|
import java.awt.event.MouseEvent;
|
|
|
import java.time.chrono.AbstractChronology;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
public class Controller {
|
|
|
@FXML
|
|
@@ -38,8 +41,9 @@ public class Controller {
|
|
|
@FXML
|
|
|
AnchorPane filterPane;
|
|
|
|
|
|
-
|
|
|
- Label[] movies;
|
|
|
+ Map<Label, Movie> map;
|
|
|
+ Label[] labelsMovies;
|
|
|
+ Movie[] movies;
|
|
|
Movie my_movie;
|
|
|
DataBaseConnector my_connector;
|
|
|
|
|
@@ -51,21 +55,27 @@ public class Controller {
|
|
|
|
|
|
public void loadPosters()
|
|
|
{
|
|
|
- detailsPane.setMinWidth(300);
|
|
|
+ //detailsPane.setMinWidth(300);
|
|
|
//get movies array
|
|
|
- movies = new Label[10];
|
|
|
- //change grid size for number of movies
|
|
|
- for (int i = 0; i < 10; i++)
|
|
|
+ movies = my_connector.getMovies();
|
|
|
+ labelsMovies = new Label[movies.length];
|
|
|
+
|
|
|
+ map = new LinkedHashMap<Label, Movie>();
|
|
|
+ //
|
|
|
+ for (int i = 0; i < movies.length; i++)
|
|
|
{
|
|
|
- movies[i] = new Label();
|
|
|
- ImageView image = new ImageView(new Image(getClass().getResourceAsStream("pic.jpg")));
|
|
|
+ labelsMovies[i] = new Label();
|
|
|
+ ImageView image = new ImageView(movies[i].cover());
|
|
|
+
|
|
|
+ map.put(labelsMovies[i], movies[i]);
|
|
|
+
|
|
|
image.setFitHeight(222);
|
|
|
image.setFitWidth(150);
|
|
|
- movies[i].setGraphic(image);
|
|
|
- GridPane.setValignment(movies[i], VPos.CENTER);
|
|
|
- GridPane.setHalignment(movies[i], HPos.CENTER);
|
|
|
- Label movie = movies[i];
|
|
|
- movies[i].setOnMouseClicked(e-> {
|
|
|
+ labelsMovies[i].setGraphic(image);
|
|
|
+ GridPane.setValignment(labelsMovies[i], VPos.CENTER);
|
|
|
+ GridPane.setHalignment(labelsMovies[i], HPos.CENTER);
|
|
|
+ Label movie = labelsMovies[i];
|
|
|
+ labelsMovies[i].setOnMouseClicked(e-> {
|
|
|
openDetails(movie);
|
|
|
});
|
|
|
}
|
|
@@ -74,12 +84,12 @@ public class Controller {
|
|
|
moviesGrid.getChildren().clear();
|
|
|
//moviesGrid.setAlignment(Pos.CENTER);
|
|
|
//fill grid by movies
|
|
|
- moviesGrid.addRow(0, movies[0], movies[1]);
|
|
|
- moviesGrid.addRow(1,movies[4],movies[5]);
|
|
|
- moviesGrid.addRow(2, movies[6],movies[7]);
|
|
|
+ moviesGrid.addRow(0, labelsMovies[0], labelsMovies[1]);
|
|
|
//moviesGrid.minHeight(moviesGrid.getMinHeight() + 222);
|
|
|
moviesGrid.setPrefWidth(browserPane.getWidth()-26);
|
|
|
- moviesGrid.setPrefHeight(moviesGrid.getHeight()+222);
|
|
|
+ moviesGrid.setMinHeight(scrollPane.getHeight());
|
|
|
+ gridResize();
|
|
|
+ //moviesGrid.setPrefHeight(moviesGrid.getHeight());
|
|
|
|
|
|
|
|
|
}
|
|
@@ -100,8 +110,8 @@ public class Controller {
|
|
|
//detailsPicPane.getChildren().clear();
|
|
|
|
|
|
detailsPane.setMinWidth(300);
|
|
|
-
|
|
|
- my_movie= my_connector.getMovieInfo(1);
|
|
|
+ my_movie = map.get(e);
|
|
|
+ //my_movie= my_connector.getMovieInfo(1);
|
|
|
|
|
|
//detailsContent.Text(my_movie.name() + "\n" + my_movie.year() + "\n" + my_movie.duration() + "\n" + my_movie.genre() + "\n" + my_movie.description());
|
|
|
Text info = new Text("Name:\n " + my_movie.name() + "\n" +
|
|
@@ -132,7 +142,7 @@ public class Controller {
|
|
|
scrollPane.setPrefWidth(browserPane.getWidth()-300);
|
|
|
scrollPane.setPrefHeight(browserPane.getHeight());
|
|
|
moviesGrid.setPrefWidth(browserPane.getWidth() -300);
|
|
|
- moviesGrid.setPrefHeight(browserPane.getHeight());
|
|
|
+ //moviesGrid.setPrefHeight(browserPane.getHeight());
|
|
|
//loadPosters();
|
|
|
|
|
|
}
|
|
@@ -146,7 +156,7 @@ public class Controller {
|
|
|
scrollPane.setPrefWidth(browserPane.getWidth()+300);
|
|
|
scrollPane.setPrefHeight(browserPane.getHeight());
|
|
|
moviesGrid.setPrefWidth(browserPane.getWidth()+300);
|
|
|
- moviesGrid.setPrefHeight(browserPane.getHeight());
|
|
|
+ //moviesGrid.setPrefHeight(browserPane.getHeight());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -171,6 +181,7 @@ public class Controller {
|
|
|
scrollPane.setPrefHeight(browserPane.getHeight());
|
|
|
moviesGrid.setPrefWidth(browserPane.getWidth() -300);
|
|
|
moviesGrid.setPrefHeight(browserPane.getHeight());
|
|
|
+ //gridResize();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -183,6 +194,33 @@ public class Controller {
|
|
|
scrollPane.setPrefHeight(browserPane.getHeight());
|
|
|
moviesGrid.setPrefWidth(browserPane.getWidth()+300);
|
|
|
moviesGrid.setPrefHeight(browserPane.getHeight());
|
|
|
+ //gridResize();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void gridResize()
|
|
|
+ {
|
|
|
+ int colsAdd = ((int)scrollPane.getWidth())/200 - 2;
|
|
|
+ int cols = colsAdd + 2;
|
|
|
+
|
|
|
+ int rows = movies.length / cols + 1;
|
|
|
+ if (242*rows<scrollPane.getHeight())
|
|
|
+ moviesGrid.setMinHeight(scrollPane.getHeight());
|
|
|
+ else
|
|
|
+ moviesGrid.setMinHeight(242*rows);
|
|
|
+ moviesGrid.setMaxWidth(scrollPane.getWidth());
|
|
|
+ moviesGrid.setPrefWidth(scrollPane.getWidth());
|
|
|
+ moviesGrid.getChildren().clear();
|
|
|
+ int k = 0;
|
|
|
+ for(int i = 0; i < rows; i++)
|
|
|
+ {
|
|
|
+ for (int j = 0; j < cols; j++)
|
|
|
+ {
|
|
|
+ moviesGrid.add(labelsMovies[k],j,i);
|
|
|
+ if(k == movies.length - 1)
|
|
|
+ break;
|
|
|
+ k++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|