Browse Source

Fixed moviesGrid size on resizing, add resize func to main window.

Veloe 4 years ago
parent
commit
0ee80e737d

+ 1 - 1
connection.properties

@@ -1,4 +1,4 @@
 
-CONFIG_DEFAULT_HOST = 192.168.1.119/moviesdb
+CONFIG_DEFAULT_HOST = 192.168.2.2/moviesdb
 CONFIG_DEFAULT_USER = Guest
 CONFIG_DEFAULT_PASS = Password1*

+ 136 - 35
src/main/java/com/moviesdb/BrowserController.java

@@ -14,6 +14,7 @@ import javafx.scene.layout.FlowPane;
 import javafx.scene.layout.GridPane;
 import javafx.scene.control.Alert.AlertType;
 
+import javafx.scene.shape.Polyline;
 import javafx.scene.text.Text;
 import javafx.scene.text.TextFlow;
 
@@ -70,6 +71,8 @@ public class BrowserController extends Controller {
             TextFlow errorTextBox;
     @FXML
             Label userLabel;
+    @FXML
+    Polyline resizerPoly;
 
     Map<Label, Movie> map;
     Label[] labelsMovies;
@@ -81,6 +84,15 @@ public class BrowserController extends Controller {
     double xOffset;
     double yOffset;
 
+    int imageWidth = 150;
+    int imageHeight = 222;
+
+    int hGap = 75;
+    int vGap = 25;
+
+    int detailsWidth = 300;
+    int filterWidth = 300;
+
     public void initialize(Stage primaryStage){
         prepare();
         stage = primaryStage;
@@ -101,6 +113,23 @@ public class BrowserController extends Controller {
             }
         });
 
+        resizerPoly.setOnMousePressed(new EventHandler<javafx.scene.input.MouseEvent>() {
+            @Override
+            public void handle(MouseEvent event) {
+                xOffset = primaryStage.getWidth() - event.getScreenX();
+                yOffset = primaryStage.getHeight() - event.getScreenY();
+            }
+        });
+
+        resizerPoly.setOnMouseDragged(new EventHandler<MouseEvent>() {
+            @Override
+            public void handle(MouseEvent event) {
+
+                primaryStage.setWidth(event.getScreenX()  + xOffset);
+                primaryStage.setHeight(event.getScreenY() + yOffset);
+            }
+        });
+
 
         workParams = new ConnectionParams("connection.properties");
         if (!workParams.initilized())
@@ -135,10 +164,10 @@ public class BrowserController extends Controller {
 
                 map.put(labelsMovies[i], movies[i]);
 
-                image.setFitHeight(222);
-                image.setFitWidth(150);
+                image.setFitHeight(imageHeight);
+                image.setFitWidth(imageWidth);
                 labelsMovies[i].setGraphic(image);
-                GridPane.setValignment(labelsMovies[i], VPos.CENTER);
+                GridPane.setValignment(labelsMovies[i], VPos.TOP);
                 GridPane.setHalignment(labelsMovies[i], HPos.CENTER);
                 Label movie = labelsMovies[i];
                 labelsMovies[i].setOnMouseClicked(e -> {
@@ -174,8 +203,11 @@ public class BrowserController extends Controller {
         if (detailsPane.getMinWidth() < 1 || detailsViewingNow != map.get(e).id()) {
             //detailsInfoPane = new AnchorPane();
             //detailsPicPane.getChildren().clear();
+            boolean isOpen = false;
+            if (detailsPane.getMinWidth() > 0)
+                isOpen = true;
 
-            detailsPane.setMinWidth(300);
+            detailsPane.setMinWidth(detailsWidth);
             my_movie = map.get(e);
             detailsViewingNow = my_movie.id();
             //my_movie= my_connector.getMovieInfo(1);
@@ -197,8 +229,8 @@ public class BrowserController extends Controller {
 
 
             ImageView image = new ImageView((my_movie.cover()));
-            image.setFitHeight(222);
-            image.setFitWidth(150);
+            image.setFitHeight(imageHeight);
+            image.setFitWidth(imageWidth);
 
            //movie.
 
@@ -260,14 +292,17 @@ public class BrowserController extends Controller {
                 editMovieButton.setOnMouseClicked(null);
             }
 
-
-            gridResize();
+            if (isOpen)
+                gridResize(scrollPane.getWidth() , detailsPane.getMinWidth());
+            else
+                gridResize((scrollPane.getWidth() - detailsPane.getMinWidth()), detailsPane.getMinWidth());
             //button.setText(Double.toString(browserPane.getWidth()));
 
         }
         else
         {
             //detailsPicPane.getChildren().clear();
+            double oldDetailsWidth = detailsPane.getMinWidth();
             detailsPane.setMinWidth(0);
             detailsPane.setPrefWidth(0);
             detailsPane.setMaxWidth(0);
@@ -277,7 +312,7 @@ public class BrowserController extends Controller {
             //moviesGrid.setPrefWidth(scrollPane.getWidth()+300);
             //moviesGrid.setPrefHeight(browserPane.getHeight());
             //browserPane.setPrefWidth(browserPane.getWidth()+300);
-            gridResize();
+            gridResize(scrollPane.getWidth() + oldDetailsWidth, oldDetailsWidth);
             //button.setText(Double.toString(browserPane.getWidth()));
         }
     }
@@ -294,19 +329,21 @@ public class BrowserController extends Controller {
         if (filterPane.getWidth() < 1)
         {
             //filterPane.maxWidth(300);
-            filterPane.setMinWidth(300);
-            filterPane.setPrefWidth(300);
-            filterPane.setMaxWidth(300);
+            filterPane.setMinWidth(filterWidth);
+            filterPane.setPrefWidth(filterWidth);
+            filterPane.setMaxWidth(filterWidth);
             //loadPosters();
             // 300px is filter window width
             //scrollPane.setPrefWidth(browserPane.getWidth()-300);
             //scrollPane.setPrefHeight(browserPane.getHeight());
             //moviesGrid.setPrefWidth(browserPane.getWidth() -300);
             //moviesGrid.setPrefHeight(browserPane.getHeight());
+            gridResize(scrollPane.getWidth() - filterPane.getWidth(), filterPane.getWidth());
 
         }
         else
         {
+            double oldFilterWidth = filterPane.getWidth();
             filterPane.setMinWidth(0);
             filterPane.setPrefWidth(0);
             filterPane.setMaxWidth(0);
@@ -316,42 +353,106 @@ public class BrowserController extends Controller {
             //scrollPane.setPrefHeight(browserPane.getHeight());
             //moviesGrid.setPrefWidth(scrollPane.getWidth()+300);
             //moviesGrid.setPrefHeight(browserPane.getHeight());
+            gridResize(scrollPane.getWidth() + oldFilterWidth, oldFilterWidth);
+        }
+
+    }
+
+    public void gridResize(double scrollWidth, double influencePaneWidth)
+    {
+        if (!Objects.isNull(movies)) {
+
+            moviesGrid.setAlignment(Pos.TOP_CENTER);
+            moviesGrid.setHgap(hGap);
+            moviesGrid.setVgap(vGap);
+
+            int cols = (((int) scrollWidth) + (int) moviesGrid.getHgap()) / (imageWidth + (int) moviesGrid.getHgap());
+
+            int rows;
+            try {
+                rows = movies.length / cols;
+            }
+            catch (ArithmeticException ex)
+            {
+                cols =  (((int) (scrollWidth + influencePaneWidth)) + (int) moviesGrid.getHgap()) / (imageWidth + (int) moviesGrid.getHgap());
+                rows = movies.length / cols;
+
+            }
+            if (movies.length % cols != 0)
+                rows++;
+
+            if (imageHeight * rows + (moviesGrid.getVgap()*(rows - 1)) < scrollPane.getHeight())
+                moviesGrid.setMinHeight(scrollPane.getHeight());
+            else
+                moviesGrid.setMinHeight(imageHeight * rows + (moviesGrid.getVgap()*(rows - 1)));
+
+            System.out.println("grid height:" + moviesGrid.getHeight() );
+            System.out.println("scroll width:" + scrollWidth );
+            System.out.println("cols: " + cols);
+            System.out.println("rows: " + rows);
+
+            //System.out.println("flow height:" + moviesGrid.getHeight() );
+            moviesGrid.setMaxWidth(scrollWidth);
+            moviesGrid.setPrefWidth(scrollWidth);
+
+            moviesGrid.getChildren().clear();
+            int k = 0;
+            for (int i = 0; i < movies.length; i++) {
+
+                moviesGrid.getChildren().add(labelsMovies[i]);
+
+            }
+            moviesGrid.autosize();
+
         }
-        gridResize();
     }
 
-    public void gridResize()
+    public void gridResize( )
     {
         if (!Objects.isNull(movies)) {
-            int colsAdd = ((int) scrollPane.getWidth()) / 200 - 2;
-            int cols = colsAdd + 2;
 
-            int rows = movies.length / cols + 1;
-            if (242 * rows < scrollPane.getHeight())
+            moviesGrid.setAlignment(Pos.TOP_CENTER);
+            moviesGrid.setHgap(hGap);
+            moviesGrid.setVgap(vGap);
+
+            int cols = (((int) scrollPane.getWidth()) + (int) moviesGrid.getHgap()) / (imageWidth + (int) moviesGrid.getHgap());
+
+            int rows;
+            try {
+                rows = movies.length / cols;
+            }
+            catch (ArithmeticException ex)
+            {
+                //this is unreachable
+                cols =  (((int) scrollPane.getWidth() + 300) + (int) moviesGrid.getHgap()) / (imageWidth + (int) moviesGrid.getHgap());
+                rows = movies.length / cols;
+
+            }
+            if (movies.length % cols != 0)
+                rows++;
+
+            if (imageHeight * rows + (moviesGrid.getVgap()*(rows - 1)) < scrollPane.getHeight())
                 moviesGrid.setMinHeight(scrollPane.getHeight());
             else
-                moviesGrid.setMinHeight(242 * rows);
+                moviesGrid.setMinHeight(imageHeight * rows + (moviesGrid.getVgap()*(rows - 1)));
+
+            //System.out.println("scroll width:" + scrollWidth );
+            System.out.println("cols: " + cols);
+            System.out.println("rows: " + rows);
+
+            //System.out.println("flow height:" + moviesGrid.getHeight() );
             moviesGrid.setMaxWidth(scrollPane.getWidth());
             moviesGrid.setPrefWidth(scrollPane.getWidth());
 
-            moviesGrid.setAlignment(Pos.CENTER);
-            moviesGrid.setHgap(75);
-            moviesGrid.setVgap(25);
-
             moviesGrid.getChildren().clear();
             int k = 0;
-            for (int i = 0; i < rows; i++) {
-                for (int j = 0; j < cols; j++) {
-                    try {
-                        moviesGrid.getChildren().add(labelsMovies[k]);
-                    } catch (Exception err) {
-                        k++;
-                    }
-                    if (k == movies.length - 1)
-                        break;
-                    k++;
-                }
+            for (int i = 0; i < movies.length; i++) {
+
+                moviesGrid.getChildren().add(labelsMovies[i]);
+
             }
+            moviesGrid.autosize();
+
         }
     }
 
@@ -380,7 +481,7 @@ public class BrowserController extends Controller {
             Parent root = loader.load();
             addWindow = loader.getController();
             addWindow.stage = new Stage();
-            addWindow.stage.setScene(new Scene(root, 377, 635));
+            addWindow.stage.setScene(new Scene(root, 610, 540));
             addWindow.stage.setUserData(loader);
             addWindow.open(this);
 

+ 3 - 2
src/main/java/com/moviesdb/Main.java

@@ -33,12 +33,13 @@ public class Main extends Application {
 
         primaryStage.widthProperty().addListener(new ChangeListener<Number>() {
             @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneWidth, Number newSceneWidth) {
-                browserController.gridResize();
+                browserController.gridResize((double) newSceneWidth - 46, 0);
             }
         });
         primaryStage.heightProperty().addListener(new ChangeListener<Number>() {
             @Override public void changed(ObservableValue<? extends Number> observableValue, Number oldSceneHeight, Number newSceneHeight) {
-                browserController.gridResize();
+                browserController.gridResize( primaryStage.getWidth() - 46, 0);
+
             }
         });
 

BIN
src/main/java/com/moviesdb/mysql-connector-java-8.0.25.jar


+ 78 - 4
src/main/resources/BrowserWindow.fxml

@@ -34,12 +34,14 @@
 
 <?import java.lang.String?>
 <?import javafx.geometry.Insets?>
+<?import javafx.scene.Cursor?>
 <?import javafx.scene.control.Label?>
 <?import javafx.scene.control.Menu?>
 <?import javafx.scene.control.MenuBar?>
 <?import javafx.scene.control.MenuItem?>
 <?import javafx.scene.control.ScrollPane?>
 <?import javafx.scene.control.SplitPane?>
+<?import javafx.scene.control.TextArea?>
 <?import javafx.scene.control.TextField?>
 <?import javafx.scene.image.ImageView?>
 <?import javafx.scene.layout.AnchorPane?>
@@ -48,6 +50,7 @@
 <?import javafx.scene.layout.Pane?>
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.paint.Color?>
+<?import javafx.scene.shape.Polyline?>
 <?import javafx.scene.text.Font?>
 <?import javafx.scene.text.TextFlow?>
 
@@ -97,7 +100,73 @@
                         <Font size="14.0" />
                      </font>
                   </Label>
-                  <TextField layoutX="76.0" layoutY="48.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <TextField layoutX="82.0" layoutY="48.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="84.0" text="Genre" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextField layoutX="82.0" layoutY="82.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="118.0" text="Year" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextField layoutX="82.0" layoutY="116.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="152.0" text="Duration" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextField layoutX="82.0" layoutY="150.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="186.0" text="Studio" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextField layoutX="82.0" layoutY="184.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="220.0" text="Director" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextField layoutX="82.0" layoutY="218.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="254.0" text="Actor" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextField layoutX="82.0" layoutY="252.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="288.0" text="Role" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextField layoutX="82.0" layoutY="286.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="322.0" text="Rating" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextField layoutX="82.0" layoutY="320.0" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
+                  <Label layoutX="24.0" layoutY="353.0" text="Desc" textFill="#9f9f9f">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </Label>
+                  <TextArea fx:id="descriptionTextBox" layoutX="80.0" layoutY="353.0" minHeight="70.0" prefHeight="162.0" prefWidth="209.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #212121;" stylesheets="@FilterBlockStyle.css" wrapText="true">
+                     <font>
+                        <Font size="14.0" />
+                     </font>
+                  </TextArea>
+                  <Label fx:id="filterButton" alignment="CENTER" layoutX="252.0" layoutY="519.0" onMouseClicked="#openFilter" style="&#10;" text="Filter" textAlignment="CENTER" wrapText="false" AnchorPane.bottomAnchor="5.0" AnchorPane.rightAnchor="15.0">
+                     <font>
+                        <Font size="16.0" fx:id="x1111" />
+                     </font>
+                     <textFill>
+                        <Color red="0.624" green="0.624" blue="0.624" fx:id="x2111" />
+                     </textFill>
+                  </Label>
           </children>
         </AnchorPane>
             <AnchorPane id="Content" fx:id="browserPane" minHeight="-1.0" minWidth="-1.0" prefHeight="551.0" prefWidth="566.0" style="-fx-background-color: #212121;">
@@ -110,7 +179,7 @@
                         <Color red="0.624" green="0.624" blue="0.624" fx:id="x21" />
                      </textFill>
                   </Label>
-                  <ScrollPane fx:id="scrollPane" fitToWidth="true" fitToHeight="true" hbarPolicy="NEVER" layoutX="14.0" layoutY="48.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="400.0" prefHeight="470.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">
+                  <ScrollPane fx:id="scrollPane" fitToHeight="true" fitToWidth="true" hbarPolicy="NEVER" layoutX="14.0" layoutY="48.0" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minWidth="400.0" prefHeight="470.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" />
@@ -118,7 +187,7 @@
                      <content>
                         <AnchorPane prefHeight="200.0" prefWidth="200.0">
                            <children>
-                              <FlowPane fx:id="moviesGrid" prefHeight="469.0" prefWidth="854.0" style="-fx-background-color: #212121;" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" />
+                              <FlowPane fx:id="moviesGrid" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #212121;" AnchorPane.bottomAnchor="0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0" />
                            </children>
                         </AnchorPane>
                      </content>
@@ -131,7 +200,7 @@
                         <Color red="0.624" green="0.624" blue="0.624" fx:id="x211" />
                      </textFill>
                   </Label>
-                  <TextField layoutX="514.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="514.0" AnchorPane.rightAnchor="64.0" AnchorPane.topAnchor="14.0" />
+                  <TextField layoutX="514.0" layoutY="14.0" prefHeight="27.0" prefWidth="302.0" style="-fx-background-color: #212121; -fx-border-color: #121212; -fx-text-fill: #9f9f9f;" AnchorPane.rightAnchor="64.0" AnchorPane.topAnchor="14.0" />
                   <Label layoutX="822.0" layoutY="19.0" text="Button" textFill="#9f9f9f" AnchorPane.rightAnchor="22.0" AnchorPane.topAnchor="19.0" />
                </children>
             </AnchorPane>
@@ -173,6 +242,11 @@
         </Label>
         <Pane prefHeight="-1.0" prefWidth="-1.0" style="-fx-background-color: #121212;" HBox.hgrow="ALWAYS" />
         <Label fx:id="logInButton" font="$x3" maxWidth="-1.0" onMouseClicked="#openLoginForm" style="-fx-background-color: #121212;" text="Log in" textFill="$x4" HBox.hgrow="NEVER" />
+            <Polyline fx:id="resizerPoly" fill="#9f9f9f" points="233.0, -3.0, 251.0, -20.0, 251.0, -3.0, 233.0, -3.0" strokeType="INSIDE">
+               <cursor>
+                  <Cursor fx:constant="SE_RESIZE" />
+               </cursor>
+            </Polyline>
       </children>
       <padding>
         <Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />

+ 12 - 0
src/main/resources/FilterBlockStyle.css

@@ -0,0 +1,12 @@
+.text-area,   
+.text-area .scroll-pane .viewport, 
+.text-area .scroll-pane .content {
+    -fx-background-color: transparent;
+    -fx-border-color :#121212;
+}
+ 
+.scroll-pane,  
+.scroll-pane .viewport, 
+.scroll-pane .content {
+    -fx-background-color: transparent;
+}