Browse Source

Fixed calculation of the position of the detailed legend in the Statistics window

toomanysugar 4 năm trước cách đây
mục cha
commit
7dc241a70b

+ 27 - 5
src/main/java/com/moviesdb/GenreStatisticsController.java

@@ -7,6 +7,7 @@ import javafx.scene.Scene;
 import javafx.scene.chart.PieChart;
 import javafx.scene.control.Label;
 import javafx.scene.layout.AnchorPane;
+import javafx.scene.layout.HBox;
 import javafx.scene.paint.Color;
 import javafx.scene.text.Font;
 import javafx.scene.text.Text;
@@ -40,7 +41,7 @@ public class GenreStatisticsController extends Controller {
         genrePie.setTitle("Genre Statistics");
 
 
-        String textValue = new String();
+        String textValue = "";
 
         for (PieChart.Data sector :
                 list) {
@@ -56,13 +57,22 @@ public class GenreStatisticsController extends Controller {
         }
 
         Text text = new Text(textValue);
-        statsTextBox.getChildren().add(text);
-
+        text.setFont(new Font(16));
 
         text.setFill(Color.rgb(159,159,159));
-        text.setFont(new Font(16));
 
 
+        new Scene (new Group(text));
+
+        double height = text.getLayoutBounds().getHeight();
+        double width = text.getLayoutBounds().getWidth();
+
+        statsTextBox.getChildren().add((Text)text);
+
+        statsTextBox.setMinWidth(width);
+        statsTextBox.setMinHeight(height);
+        ((HBox) statsTextBox.getParent()).setMinHeight(height);
+        ((HBox) statsTextBox.getParent()).setMaxHeight(height);
     }
 
     public void openStudio(Object caller) {
@@ -81,7 +91,7 @@ public class GenreStatisticsController extends Controller {
         genrePie.setData(list);
         genrePie.setTitle("Studio Statistics");
 
-        String textValue = new String();
+        String textValue = "";
 
         for (PieChart.Data sector :
                 list) {
@@ -93,12 +103,24 @@ public class GenreStatisticsController extends Controller {
             }
             else
                 countPrefix = "Film";
+
             textValue = textValue.concat(sector.getName() + ":   " + (int)sector.getPieValue() + " " + countPrefix);
         }
 
         Text text = new Text(textValue);
         text.setFill(Color.rgb(159,159,159));
         text.setFont(new Font(16));
+
+        new Scene (new Group(text));
+
+        double height = text.getLayoutBounds().getHeight();
+        double width = text.getLayoutBounds().getWidth();
+
         statsTextBox.getChildren().add((Text)text);
+
+        statsTextBox.setMinWidth(width);
+        statsTextBox.setMinHeight(height);
+        ((HBox) statsTextBox.getParent()).setMinHeight(height);
+        ((HBox) statsTextBox.getParent()).setMaxHeight(height);
     }
 }

+ 4 - 9
src/main/resources/GenreStatisticsWindow.fxml

@@ -10,7 +10,6 @@
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.text.Font?>
 <?import javafx.scene.text.TextFlow?>
-<?import javafx.scene.control.ScrollPane?>
 
 <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="0.0" prefHeight="553.0" prefWidth="616.0" stylesheets="@AddMovieWindowStyle.css" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.moviesdb.GenreStatisticsController">
    <right>
@@ -71,7 +70,7 @@
       </AnchorPane>
    </top>
    <center>
-      <AnchorPane prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #212121;" BorderPane.alignment="CENTER">
+      <AnchorPane minHeight="-Infinity" prefHeight="200.0" prefWidth="200.0" style="-fx-background-color: #212121;" BorderPane.alignment="CENTER">
          <children>
             <VBox style="-fx-background-color: transparent;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
                <AnchorPane minHeight="20.0" prefHeight="20.0" prefWidth="200.0" style="-fx-background-color: transparent;" />
@@ -84,13 +83,9 @@
                   <children>
                      <HBox prefHeight="100.0" prefWidth="200.0" AnchorPane.bottomAnchor="17.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
                         <children>
-                           <Pane prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
-                           <ScrollPane fitToHeight="true" fitToWidth="true" layoutX="14.0" layoutY="290.0" prefHeight="222.0" prefWidth="277.0" style="-fx-background-color: transparent;" AnchorPane.bottomAnchor="39.0" AnchorPane.topAnchor="290.0">
-                              <content>
-                                 <TextFlow fx:id="statsTextBox" prefHeight="222.0" prefWidth="277.0" style="-fx-background-color: #212121;" />
-                              </content>
-                           </ScrollPane>
-                           <Pane prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
+                           <Pane prefHeight="200.0" prefWidth="40.0" HBox.hgrow="ALWAYS" />
+                           <TextFlow fx:id="statsTextBox" style="-fx-background-color: #212121;" HBox.hgrow="SOMETIMES" />
+                           <Pane prefHeight="200.0" prefWidth="40.0" HBox.hgrow="ALWAYS" />
                         </children>
                      </HBox>
                   </children></AnchorPane>