Browse Source

New fixes, new bugs

Veloe 4 years ago
parent
commit
7bb5318089

BIN
out/production/JavaFxApplication/com/moviesdb/Controller.class


BIN
out/production/JavaFxApplication/com/moviesdb/Main.class


+ 6 - 4
out/production/JavaFxApplication/com/moviesdb/test2.fxml

@@ -55,7 +55,7 @@
 
 <VBox prefHeight="600.0" prefWidth="900.0" style="-fx-background-color: #121212;" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.moviesdb.Controller">
   <children>
-    <MenuBar style="-fx-background-color: #121212;" VBox.vgrow="NEVER">
+    <MenuBar minWidth="1000.0" style="-fx-background-color: #121212;" VBox.vgrow="NEVER">
       <menus>
         <Menu mnemonicParsing="false" text="File">
           <items>
@@ -126,7 +126,7 @@
                         <Color red="0.624" green="0.624" blue="0.624" fx:id="x21" />
                      </textFill>
                   </Label>
-                  <ScrollPane fx:id="scrollPane" hbarPolicy="NEVER" layoutX="14.0" layoutY="41.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="499.0" prefWidth="463.0" style="-fx-background-color: transparent; -fx-border-color: #212121;" vbarPolicy="NEVER" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="41.0">
+                  <ScrollPane fx:id="scrollPane" hbarPolicy="NEVER" layoutX="14.0" layoutY="48.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="400.0" prefHeight="471.0" prefWidth="858.0" style="-fx-background-color: transparent; -fx-border-color: #212121;" vbarPolicy="NEVER" AnchorPane.bottomAnchor="31.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="48.0">
                      <styleClass>
                         <String fx:value="split-pane" />
                         <String fx:value="split-pane-divider" />
@@ -144,14 +144,16 @@
                         </GridPane>
                      </content>
                   </ScrollPane>
-                  <Label alignment="CENTER" layoutX="502.0" layoutY="14.0" onMouseClicked="#openFilter" style="&#10;" text="Advanced search" textAlignment="CENTER" wrapText="false" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
+                  <Label alignment="CENTER" layoutX="11.0" layoutY="520.0" onMouseClicked="#openFilter" style="&#10;" text="Advanced search?" textAlignment="CENTER" wrapText="false" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="11.0">
                      <font>
-                        <Font size="18.0" fx:id="x111" />
+                        <Font size="16.0" fx:id="x111" />
                      </font>
                      <textFill>
                         <Color red="0.624" green="0.624" blue="0.624" fx:id="x211" />
                      </textFill>
                   </Label>
+                  <TextField layoutX="515.0" layoutY="14.0" prefHeight="27.0" prefWidth="302.0" style="-fx-background-color: #212121; -fx-border-color: #121212; -fx-text-fill: #9f9f9f;" AnchorPane.leftAnchor="515.0" AnchorPane.rightAnchor="63.0" />
+                  <Label layoutX="827.0" layoutY="19.0" text="Button" textFill="#9f9f9f" AnchorPane.rightAnchor="17.0" />
                </children>
             </AnchorPane>
         <AnchorPane fx:id="detailsPane" maxWidth="0.0" minWidth="0.0" prefWidth="0.0" style="-fx-background-color: #212121;" SplitPane.resizableWithParent="false">

+ 59 - 21
src/com/moviesdb/Controller.java

@@ -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++;
+            }
         }
     }
 

+ 46 - 10
src/com/moviesdb/DataBaseConnector.java

@@ -12,7 +12,7 @@ public class DataBaseConnector {
     public void initConnection(String ui_user, String ui_pass) {
         try {
             // connect way #2
-            String url = "jdbc:mysql://192.168.192.1/moviesdb";
+            String url = "jdbc:mysql://192.168.1.119/moviesdb";
             String user = ui_user;
             String password = ui_pass;
             user = "Veloe";
@@ -30,10 +30,14 @@ public class DataBaseConnector {
         }
     }
 
-    public Movie getMovieInfo(int movieId) {
+
+
+    public Movie getMovieInfo(int movieId)
+    {
         Movie resultedMovie = new Movie();
 
-        try {
+        try
+        {
             Statement statement = conn.createStatement();
             String req = "SELECT * FROM Movies WHERE id = " + movieId + ";";
             ResultSet rs = statement.executeQuery(req);
@@ -50,19 +54,51 @@ public class DataBaseConnector {
                 resultedMovie.setDirector(rs.getString("director"));
                 resultedMovie.setCover(rs.getString("image_link"));
             }
-
-        } catch (SQLException ex) {
+        }
+        catch (SQLException ex) {
             //exception
-
             ex.printStackTrace();
         }
+        return  resultedMovie;
+    }
 
+    public Movie[] getMovies()
+    {
+        Movie[] resultedMovies;
 
+        try
+        {
+            Statement statement = conn.prepareStatement("SELECT * FROM Movies;", ResultSet.TYPE_SCROLL_SENSITIVE,
+                    ResultSet.CONCUR_UPDATABLE);
+            String req = "SELECT * FROM Movies;";
+            ResultSet rs = statement.executeQuery(req);
+            rs.last();
+            int Count = rs.getRow();
+            resultedMovies = new Movie[Count];
+            rs.first();
+            for (int i = 0; i < Count; i++)
+            {
+                resultedMovies[i] = new Movie();
+                resultedMovies[i].setId(rs.getInt("id"));
+                resultedMovies[i].setName(rs.getString("name"));
+                resultedMovies[i].setGenre(rs.getString("genre"));
+                resultedMovies[i].setDescription(rs.getString("description"));
+                resultedMovies[i].setDuration(rs.getString("duration"));
+                resultedMovies[i].setRating(rs.getString("user_rating"));
+                resultedMovies[i].setYear(rs.getString("year"));
+                resultedMovies[i].setStudio(rs.getString("studio"));
+                resultedMovies[i].setDirector(rs.getString("director"));
+                resultedMovies[i].setCover(rs.getString("image_link"));
+                rs.next();
+            }
 
-       ;
-
-
-        return  resultedMovie;
+        }
+        catch (SQLException ex) {
+            //exception
+            ex.printStackTrace();
+            resultedMovies = null;
+        }
+        return  resultedMovies;
     }
 
 

+ 14 - 0
src/com/moviesdb/Main.java

@@ -1,6 +1,8 @@
 package com.moviesdb;
 
 import javafx.application.Application;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
 import javafx.event.EventHandler;
 import javafx.fxml.FXMLLoader;
 import javafx.scene.Parent;
@@ -26,6 +28,18 @@ public class Main extends Application {
                 controller.loadPosters();
             }
         });
+
+        primaryStage.widthProperty().addListener(new ChangeListener<Number>() {
+            @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) {
+                controller.gridResize();
+            }
+        });
+        primaryStage.heightProperty().addListener(new ChangeListener<Number>() {
+            @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
+                controller.gridResize();
+            }
+        });
+
         primaryStage.show();
 
     }

+ 6 - 4
src/com/moviesdb/test2.fxml

@@ -55,7 +55,7 @@
 
 <VBox prefHeight="600.0" prefWidth="900.0" style="-fx-background-color: #121212;" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.moviesdb.Controller">
   <children>
-    <MenuBar style="-fx-background-color: #121212;" VBox.vgrow="NEVER">
+    <MenuBar minWidth="1000.0" style="-fx-background-color: #121212;" VBox.vgrow="NEVER">
       <menus>
         <Menu mnemonicParsing="false" text="File">
           <items>
@@ -126,7 +126,7 @@
                         <Color red="0.624" green="0.624" blue="0.624" fx:id="x21" />
                      </textFill>
                   </Label>
-                  <ScrollPane fx:id="scrollPane" hbarPolicy="NEVER" layoutX="14.0" layoutY="41.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="499.0" prefWidth="463.0" style="-fx-background-color: transparent; -fx-border-color: #212121;" vbarPolicy="NEVER" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="41.0">
+                  <ScrollPane fx:id="scrollPane" hbarPolicy="NEVER" layoutX="14.0" layoutY="48.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="400.0" prefHeight="471.0" prefWidth="858.0" style="-fx-background-color: transparent; -fx-border-color: #212121;" vbarPolicy="NEVER" AnchorPane.bottomAnchor="31.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="8.0" AnchorPane.topAnchor="48.0">
                      <styleClass>
                         <String fx:value="split-pane" />
                         <String fx:value="split-pane-divider" />
@@ -144,14 +144,16 @@
                         </GridPane>
                      </content>
                   </ScrollPane>
-                  <Label alignment="CENTER" layoutX="502.0" layoutY="14.0" onMouseClicked="#openFilter" style="&#10;" text="Advanced search" textAlignment="CENTER" wrapText="false" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
+                  <Label alignment="CENTER" layoutX="11.0" layoutY="520.0" onMouseClicked="#openFilter" style="&#10;" text="Advanced search?" textAlignment="CENTER" wrapText="false" AnchorPane.bottomAnchor="5.0" AnchorPane.leftAnchor="11.0">
                      <font>
-                        <Font size="18.0" fx:id="x111" />
+                        <Font size="16.0" fx:id="x111" />
                      </font>
                      <textFill>
                         <Color red="0.624" green="0.624" blue="0.624" fx:id="x211" />
                      </textFill>
                   </Label>
+                  <TextField layoutX="515.0" layoutY="14.0" prefHeight="27.0" prefWidth="302.0" style="-fx-background-color: #212121; -fx-border-color: #121212; -fx-text-fill: #9f9f9f;" AnchorPane.leftAnchor="515.0" AnchorPane.rightAnchor="63.0" />
+                  <Label layoutX="827.0" layoutY="19.0" text="Button" textFill="#9f9f9f" AnchorPane.rightAnchor="17.0" />
                </children>
             </AnchorPane>
         <AnchorPane fx:id="detailsPane" maxWidth="0.0" minWidth="0.0" prefWidth="0.0" style="-fx-background-color: #212121;" SplitPane.resizableWithParent="false">