Bläddra i källkod

Fixed grid resize, add working TextFlow in detailsPane

Veloe 4 år sedan
förälder
incheckning
28fd868526

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


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


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

@@ -51,6 +51,7 @@
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.paint.Color?>
 <?import javafx.scene.text.Font?>
+<?import javafx.scene.text.TextFlow?>
 
 <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>
@@ -157,60 +158,12 @@
           <children>
             <Label alignment="CENTER" font="$x1" layoutX="14.0" layoutY="14.0" style="&#10;" text="Details" textAlignment="CENTER" textFill="$x2" wrapText="false" />
                   <AnchorPane fx:id="detailsPicPane" layoutX="14.0" layoutY="41.0" prefHeight="222.0" AnchorPane.bottomAnchor="287.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="9.0" AnchorPane.topAnchor="41.0" />
-                  <Label fx:id="detailsNameLabel" layoutX="14.0" layoutY="267.0" text="Name" textFill="#9f9f9f">
+                  <Label fx:id="detailsNameLabel" layoutX="14.0" layoutY="265.0" text="Info" textFill="#9f9f9f">
                      <font>
-                        <Font size="14.0" />
+                        <Font size="16.0" />
                      </font>
                   </Label>
-                  <Label fx:id="detailsNameContent" layoutX="30.0" layoutY="292.0" text="detailsNameContent" textFill="#9f9f9f">
-                      <font>
-                          <Font size="14.0" />
-                      </font>
-                  </Label>
-
-              <Label fx:id="detailsYearLabel" layoutX="14.0" layoutY="317.0" text="Year" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-              <Label fx:id="detailsYearContent" layoutX="30.0" layoutY="342.0" text="detailsYearContent" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-
-              <Label fx:id="detailsDurLabel" layoutX="14.0" layoutY="367.0" text="Duration" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-              <Label fx:id="detailsDurContent" layoutX="30.0" layoutY="392.0" text="detailsDurContent" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-
-              <Label fx:id="detailsGenreLabel" layoutX="14.0" layoutY="417.0" text="Genre" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-              <Label fx:id="detailsGenreContent" layoutX="30.0" layoutY="442.0" text="detailsGenreContent" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-
-              <Label fx:id="detailsDescLabel" layoutX="14.0" layoutY="467.0" text="Description" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-              <Label fx:id="detailsDescContent" layoutX="30.0" layoutY="492.0" text="detailsDescContent" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
+                  <TextFlow fx:id="detailsContent" layoutX="14.0" layoutY="287.0" prefHeight="255.0" prefWidth="277.0" />
 
 
           </children>

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

@@ -13,6 +13,8 @@ import javafx.scene.layout.Pane;
 import javafx.scene.control.Alert.AlertType;
 
 import com.moviesdb.Movie;
+import javafx.scene.text.Text;
+import javafx.scene.text.TextFlow;
 
 import java.awt.event.MouseEvent;
 import java.time.chrono.AbstractChronology;
@@ -29,15 +31,7 @@ public class Controller {
     @FXML
     AnchorPane detailsPane;
     @FXML
-    Label detailsNameContent;
-    @FXML
-    Label detailsYearContent;
-    @FXML
-    Label detailsDurContent;
-    @FXML
-    Label detailsGenreContent;
-    @FXML
-    Label detailsDescContent;
+    TextFlow detailsContent;
     @FXML
     AnchorPane detailsPicPane;
     @FXML
@@ -48,7 +42,6 @@ public class Controller {
 
     Movie my_movie;
 
-
     public void loadPosters()
     {
 
@@ -104,11 +97,19 @@ public class Controller {
 
             detailsPane.setMinWidth(300);
 
-            detailsNameContent.setText(my_movie.name());
-            detailsYearContent.setText(my_movie.year());
-            detailsDurContent.setText(my_movie.duration());
-            detailsGenreContent.setText(my_movie.genre());
-            detailsDescContent.setText(my_movie.description());
+            //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" +
+                                    "Year: \n    " + my_movie.year() + "\n" +
+                                    "Duration: \n    " + my_movie.duration() + "\n" +
+                                    "Genre: \n    " + my_movie.genre() + "\n" +
+                                    "Description: \n    " + my_movie.description());
+            info.setStyle("-fx-font-size: 14; -fx-fill: #9f9f9f;");
+            detailsContent.getChildren().clear();
+            detailsContent.getChildren().add(info);
+            //detailsContent.setText(my_movie.year());
+            //detailsContent.setText(my_movie.duration());
+            //detailsContent.setText(my_movie.genre());
+            //detailsContent.setText(my_movie.description());
 
             detailsPicPane.getChildren().clear();
             //detailsPane.setMaxWidth(300);
@@ -125,12 +126,12 @@ public class Controller {
             detailsImage.setY(0);
             //movie.
             detailsPicPane.getChildren().add(detailsImage);
-
-            scrollPane.setMaxWidth(browserPane.getWidth()-26);
-            scrollPane.setMaxHeight(browserPane.getHeight()-50);
-            moviesGrid.setMaxWidth(browserPane.getWidth()-26);
-            moviesGrid.setMaxHeight(browserPane.getHeight()-50);
-            loadPosters();
+            // 300px is details window width
+            scrollPane.setMaxWidth(browserPane.getWidth()-300);
+            scrollPane.setMaxHeight(browserPane.getHeight());
+            moviesGrid.setMaxWidth(browserPane.getWidth() -300);
+            moviesGrid.setMaxHeight(browserPane.getHeight());
+            //loadPosters();
 
         }
         else
@@ -139,6 +140,11 @@ public class Controller {
             detailsPane.setMinWidth(0);
             detailsPane.setPrefWidth(0);
             detailsPane.setMaxWidth(0);
+            // 300px is details window width
+            scrollPane.setMaxWidth(browserPane.getWidth()+300);
+            scrollPane.setMaxHeight(browserPane.getHeight());
+            moviesGrid.setMaxWidth(browserPane.getWidth()+300);
+            moviesGrid.setMaxHeight(browserPane.getHeight());
         }
     }
 
@@ -158,6 +164,11 @@ public class Controller {
             filterPane.setPrefWidth(300);
             filterPane.setMaxWidth(300);
             //loadPosters();
+            // 300px is filter window width
+            scrollPane.setMaxWidth(browserPane.getWidth()-300);
+            scrollPane.setMaxHeight(browserPane.getHeight());
+            moviesGrid.setMaxWidth(browserPane.getWidth()-300);
+            moviesGrid.setMaxHeight(browserPane.getHeight());
         }
         else
         {
@@ -165,6 +176,11 @@ public class Controller {
             filterPane.setPrefWidth(0);
             filterPane.setMaxWidth(0);
             //loadPosters();
+            // 300px is filter window width
+            scrollPane.setMaxWidth(browserPane.getWidth()+300);
+            scrollPane.setMaxHeight(browserPane.getHeight());
+            moviesGrid.setMaxWidth(browserPane.getWidth()+300);
+            moviesGrid.setMaxHeight(browserPane.getHeight());
         }
     }
 

+ 12 - 1
src/com/moviesdb/Main.java

@@ -1,19 +1,30 @@
 package com.moviesdb;
 
 import javafx.application.Application;
+import javafx.event.EventHandler;
 import javafx.fxml.FXMLLoader;
 import javafx.scene.Parent;
 import javafx.scene.Scene;
 import javafx.scene.layout.GridPane;
 import javafx.stage.Stage;
+import javafx.stage.WindowEvent;
 
 public class Main extends Application {
 
     @Override
     public void start(Stage primaryStage) throws Exception{
-        Parent root = FXMLLoader.load(getClass().getResource("test2.fxml"));
+        FXMLLoader loader = new FXMLLoader();
+        loader.setLocation(getClass().getResource("test2.fxml"));
+        Parent root = loader.load();
         primaryStage.setTitle("Hello World");
         primaryStage.setScene(new Scene(root, 1280, 720));
+        Controller controller = loader.getController();
+        primaryStage.setOnShown(new EventHandler<WindowEvent>() {
+            @Override
+            public void handle(WindowEvent event) {
+                controller.loadPosters();
+            }
+        });
         primaryStage.show();
 
     }

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

@@ -51,6 +51,7 @@
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.paint.Color?>
 <?import javafx.scene.text.Font?>
+<?import javafx.scene.text.TextFlow?>
 
 <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>
@@ -157,60 +158,12 @@
           <children>
             <Label alignment="CENTER" font="$x1" layoutX="14.0" layoutY="14.0" style="&#10;" text="Details" textAlignment="CENTER" textFill="$x2" wrapText="false" />
                   <AnchorPane fx:id="detailsPicPane" layoutX="14.0" layoutY="41.0" prefHeight="222.0" AnchorPane.bottomAnchor="287.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="9.0" AnchorPane.topAnchor="41.0" />
-                  <Label fx:id="detailsNameLabel" layoutX="14.0" layoutY="267.0" text="Name" textFill="#9f9f9f">
+                  <Label fx:id="detailsNameLabel" layoutX="14.0" layoutY="265.0" text="Info" textFill="#9f9f9f">
                      <font>
-                        <Font size="14.0" />
+                        <Font size="16.0" />
                      </font>
                   </Label>
-                  <Label fx:id="detailsNameContent" layoutX="30.0" layoutY="292.0" text="detailsNameContent" textFill="#9f9f9f">
-                      <font>
-                          <Font size="14.0" />
-                      </font>
-                  </Label>
-
-              <Label fx:id="detailsYearLabel" layoutX="14.0" layoutY="317.0" text="Year" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-              <Label fx:id="detailsYearContent" layoutX="30.0" layoutY="342.0" text="detailsYearContent" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-
-              <Label fx:id="detailsDurLabel" layoutX="14.0" layoutY="367.0" text="Duration" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-              <Label fx:id="detailsDurContent" layoutX="30.0" layoutY="392.0" text="detailsDurContent" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-
-              <Label fx:id="detailsGenreLabel" layoutX="14.0" layoutY="417.0" text="Genre" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-              <Label fx:id="detailsGenreContent" layoutX="30.0" layoutY="442.0" text="detailsGenreContent" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-
-              <Label fx:id="detailsDescLabel" layoutX="14.0" layoutY="467.0" text="Description" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
-              <Label fx:id="detailsDescContent" layoutX="30.0" layoutY="492.0" text="detailsDescContent" textFill="#9f9f9f">
-                  <font>
-                      <Font size="14.0" />
-                  </font>
-              </Label>
+                  <TextFlow fx:id="detailsContent" layoutX="14.0" layoutY="287.0" prefHeight="255.0" prefWidth="277.0" />
 
 
           </children>