瀏覽代碼

Added new stat window.

Veloe 4 年之前
父節點
當前提交
92d8a83b01

+ 16 - 2
src/main/java/com/moviesdb/BrowserController.java

@@ -162,6 +162,15 @@ public class BrowserController extends Controller {
             my_connector.initConnection(workParams);
         }
 
+        try {
+            Properties property = new Properties();
+            FileInputStream fis = new FileInputStream("connection.properties");
+            property.load(fis);
+            setUserName(property.getProperty("CONFIG_DEFAULT_USER"));
+        }
+        catch (IOException ex)
+        {}
+
         System.out.println(my_connector.granted("USAGE"));
         System.out.println(my_connector.granted("INSERT"));
         System.out.println(my_connector.granted("UPDATE"));
@@ -402,6 +411,9 @@ public class BrowserController extends Controller {
             filterPane.setMinWidth(filterWidth);
             filterPane.setPrefWidth(filterWidth);
             filterPane.setMaxWidth(filterWidth);
+
+            //actorTextBox.setItems(my_connector.getAllActors());
+
             //loadPosters();
             // 300px is filter window width
             //scrollPane.setPrefWidth(browserPane.getWidth()-300);
@@ -623,8 +635,9 @@ public class BrowserController extends Controller {
             statsWindow = loader.getController();
             statsWindow.stage = new Stage();
             statsWindow.stage.setScene(new Scene(root, 500, 500));
+            //editWindow.stage.initStyle(StageStyle.UNDECORATED);
             statsWindow.stage.setUserData(loader);
-            statsWindow.open(this);
+            statsWindow.openGenre(this);
 
         } catch (IOException e) {
             e.printStackTrace();
@@ -640,8 +653,9 @@ public class BrowserController extends Controller {
             statsWindow = loader.getController();
             statsWindow.stage = new Stage();
             statsWindow.stage.setScene(new Scene(root, 500, 500));
+           // editWindow.stage.initStyle(StageStyle.UNDECORATED);
             statsWindow.stage.setUserData(loader);
-            statsWindow.open(this);
+            statsWindow.openStudio(this);
 
         } catch (IOException e) {
             e.printStackTrace();

+ 61 - 1
src/main/java/com/moviesdb/DataBaseConnector.java

@@ -509,7 +509,6 @@ public class DataBaseConnector {
 
             rs.first();
 
-
             for (int i = 0; i < Count; i++)
             {
                 String name = rs.getString("genre");
@@ -518,8 +517,37 @@ public class DataBaseConnector {
                 list.add(new PieChart.Data(name, rs.getInt("number")));
                 rs.next();
             }
+        }
+        catch (SQLException ex) {
+            //exception
+            ex.printStackTrace();
+        }
+        return  list;
+    }
 
+    public ObservableList<PieChart.Data> getStudioStats()
+    {
+        ObservableList<PieChart.Data> list = FXCollections.observableArrayList();
 
+        try
+        {
+            Statement statement = conn.prepareStatement("SELECT count(id) AS number, studio FROM moviesdb.Movies GROUP BY studio;", ResultSet.TYPE_SCROLL_SENSITIVE,
+                    ResultSet.CONCUR_UPDATABLE);
+            String req = "SELECT count(id) AS number, studio FROM moviesdb.Movies GROUP BY studio;";
+            ResultSet rs = statement.executeQuery(req);
+            rs.last();
+            int Count = rs.getRow();
+
+            rs.first();
+
+            for (int i = 0; i < Count; i++)
+            {
+                String name = rs.getString("studio");
+                if (name == null)
+                    name = "Empty";
+                list.add(new PieChart.Data(name, rs.getInt("number")));
+                rs.next();
+            }
         }
         catch (SQLException ex) {
             //exception
@@ -528,4 +556,36 @@ public class DataBaseConnector {
         return  list;
     }
 
+    public ObservableList<String> getAllActors()
+    {
+        ObservableList<String> actors = FXCollections.observableArrayList();
+
+        try
+        {
+            Statement statement = conn.prepareStatement("SELECT distinct actor FROM moviesdb.Roles;", ResultSet.TYPE_SCROLL_SENSITIVE,
+                    ResultSet.CONCUR_UPDATABLE);
+            String req = "SELECT distinct actor FROM moviesdb.Roles;";
+            ResultSet rs = statement.executeQuery(req);
+            rs.last();
+            int Count = rs.getRow();
+
+            rs.first();
+
+            for (int i = 0; i < Count; i++)
+            {
+                String name = rs.getString("actor");
+                if (name == null)
+                    name = "";
+                actors.add(name);
+                rs.next();
+            }
+            actors.add("");
+        }
+        catch (SQLException ex) {
+            //exception
+            ex.printStackTrace();
+        }
+        return  actors;
+
+    }
 }

+ 26 - 3
src/main/java/com/moviesdb/GenreStatisticsController.java

@@ -18,18 +18,18 @@ public class GenreStatisticsController extends Controller {
     @FXML
     TextFlow statsTextBox;
 
-    public void open(Object caller)
+    public void openGenre(Object caller)
     {
         //getStats
         //get num of films
 
-        stage.setTitle("Log in");
+        stage.setTitle("Stats");
         stage.show();
 
         ObservableList<PieChart.Data> list = ((BrowserController) caller).my_connector.getGenreStats();
 
         genrePie.setData(list);
-        genrePie.setTitle("TestTitle");
+        genrePie.setTitle("Genre Statistics");
 
         String textValue = new String();
 
@@ -41,7 +41,30 @@ public class GenreStatisticsController extends Controller {
         Text text = new Text(textValue);
         statsTextBox.getChildren().add(text);
 
+    }
+
+    public void openStudio(Object caller)
+    {
+        //getStats
+        //get num of films
+
+        stage.setTitle("Stats");
+        stage.show();
+
+        ObservableList<PieChart.Data> list = ((BrowserController) caller).my_connector.getStudioStats();
+
+        genrePie.setData(list);
+        genrePie.setTitle("Studio Statistics");
+
+        String textValue = new String();
 
+        for (PieChart.Data sector:
+                list) {
+            textValue += sector.getName() + ": " + sector.getPieValue() + "\n";
+        }
+
+        Text text = new Text(textValue);
+        statsTextBox.getChildren().add(text);
 
     }
 }

+ 2 - 2
src/main/resources/BrowserWindow.fxml

@@ -87,7 +87,7 @@
       </AnchorPane>
     <SplitPane dividerPositions="0.3392857142857143, 0.9955357142857143" focusTraversable="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" prefHeight="-1.0" prefWidth="-1.0" style="-fx-background-color: #121212; -fx-border-color: #121212;" stylesheets="@style.css" VBox.vgrow="ALWAYS">
       <items>
-        <AnchorPane fx:id="filterPane" maxWidth="0.0" minWidth="0.0" prefHeight="550.0" prefWidth="120.0" style="-fx-background-color: #212121;" SplitPane.resizableWithParent="false">
+        <AnchorPane fx:id="filterPane" maxWidth="0.0" minWidth="300.0" prefHeight="550.0" prefWidth="120.0" style="-fx-background-color: #212121;" SplitPane.resizableWithParent="false">
           <children>
             <Label alignment="CENTER" layoutX="14.0" layoutY="14.0" minWidth="60.0" prefWidth="-1.0" style="&#10;" text="Filter" textAlignment="CENTER" wrapText="false">
               <font>
@@ -138,7 +138,6 @@
                         <Font size="14.0" />
                      </font>
                   </Label>
-                  <TextField fx:id="actorTextBox" layoutX="82.0" layoutY="252.0" onKeyTyped="#getFilterMovies" 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" />
@@ -169,6 +168,7 @@
                         <Color red="0.624" green="0.624" blue="0.624" fx:id="x2111" />
                      </textFill>
                   </Label>
+                  <TextField fx:id="actorTextBox" layoutX="82.0" layoutY="252.0" onKeyTyped="#getFilterMovies" prefHeight="25.0" prefWidth="205.0" style="-fx-text-fill: #9f9f9f; -fx-background-color: #212121; -fx-border-color: #121212;" />
           </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;">

+ 2 - 2
src/main/resources/GenreStatisticsWindow.fxml

@@ -5,7 +5,7 @@
 <?import javafx.scene.layout.VBox?>
 <?import javafx.scene.text.TextFlow?>
 
-<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="516.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.moviesdb.GenreStatisticsController">
+<VBox maxHeight="1.7976931348623157E308" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="516.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/16" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.moviesdb.GenreStatisticsController">
    <children>
       <AnchorPane minHeight="20.0" prefHeight="20.0" prefWidth="200.0" />
       <AnchorPane prefHeight="385.0" prefWidth="600.0">
@@ -13,7 +13,7 @@
             <PieChart fx:id="genrePie" layoutX="50.0" prefHeight="250.0" prefWidth="600.0" style="-fx-max-height: 600; -fx-max-width: 600;" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
          </children>
       </AnchorPane>
-      <AnchorPane minHeight="20.0" prefHeight="111.0" prefWidth="600.0">
+      <AnchorPane maxHeight="1.7976931348623157E308" minHeight="20.0" prefHeight="111.0" prefWidth="600.0">
          <children>
             <TextFlow fx:id="statsTextBox" prefHeight="111.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
          </children></AnchorPane>