From 507f732861718c87bb80a8b784fc3eaf97a7066c Mon Sep 17 00:00:00 2001 From: aj Date: Tue, 17 Apr 2018 20:43:33 -0700 Subject: [PATCH] xml album tab view generating properly --- .../src/sarsoo/fmframework/fx/Stats.java | 18 ---- .../fx/controller/AlbumTabController.java | 76 +++++++++++++++ .../fx/controller/ControllerMain.java | 42 ++++++++- .../sarsoo/fmframework/fx/ui/albumview.fxml | 76 +++++++++++++++ .../src/sarsoo/fmframework/fx/ui/main.fxml | 4 +- .../sarsoo/fmframework/fx/ui/template.fxml | 92 +++++++++++++++++++ .../src/sarsoo/fmframework/music/FMObj.java | 6 ++ 7 files changed, 294 insertions(+), 20 deletions(-) delete mode 100644 fmframework/src/sarsoo/fmframework/fx/Stats.java create mode 100644 fmframework/src/sarsoo/fmframework/fx/controller/AlbumTabController.java create mode 100644 fmframework/src/sarsoo/fmframework/fx/ui/albumview.fxml create mode 100644 fmframework/src/sarsoo/fmframework/fx/ui/template.fxml diff --git a/fmframework/src/sarsoo/fmframework/fx/Stats.java b/fmframework/src/sarsoo/fmframework/fx/Stats.java deleted file mode 100644 index 0e25a43..0000000 --- a/fmframework/src/sarsoo/fmframework/fx/Stats.java +++ /dev/null @@ -1,18 +0,0 @@ -package sarsoo.fmframework.fx; - -import javafx.fxml.FXML; -import javafx.scene.control.*; - -public class Stats { - - /*@FXML - private static Label scrobblesToday; - - *//** - * @param scrobbles - *//* - public static void updateScrobblesToday(int scrobbles) { - -// scrobblesToday.setText(Integer.toString(scrobbles)); - }*/ -} diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/AlbumTabController.java b/fmframework/src/sarsoo/fmframework/fx/controller/AlbumTabController.java new file mode 100644 index 0000000..a41a91f --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/controller/AlbumTabController.java @@ -0,0 +1,76 @@ +package sarsoo.fmframework.fx.controller; + +import java.io.IOException; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Locale; + +import javax.swing.JOptionPane; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.text.Text; +import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.util.FMObjList; +import sarsoo.fmframework.util.Getter; +import sarsoo.fmframework.util.Maths; +import sarsoo.fmframework.util.Reference; +import javafx.scene.control.*; +import javafx.scene.layout.GridPane; +import javafx.scene.chart.*; +import javafx.collections.ObservableList; +import javafx.collections.FXCollections; + +public class AlbumTabController { + + @FXML + private Label labelAlbumName; + + @FXML + private Label labelArtistName; + + @FXML + private Label labelUserScrobbles; + + @FXML + private Label labelRatio; + + @FXML + private Label labelTotalListeners; + + @FXML + private Label labelTotalScrobbles; + + @FXML + public void initialize() { + + labelAlbumName.setText("Hello World"); + + } + + public void populateTab(Album album) { + NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); + + labelAlbumName.setText(album.getName()); + labelArtistName.setText(album.getArtist().getName()); + labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount()) + + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName()))); + + labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners"); + labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + "Total Scrobbles"); + + double ratio = album.getTimeListenRatio(); + + + if (ratio > 1) { + labelRatio.setText(String.format("listen every %.2f days", ratio)); + } else if (ratio == 1) { + labelRatio.setText("listen every day"); + } else { + labelRatio.setText(String.format("%.2f times a day", 1 / ratio)); + } + + } + +} diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java index 4dd140f..3dbd2b9 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java @@ -1,5 +1,6 @@ package sarsoo.fmframework.fx.controller; +import java.io.IOException; import java.text.NumberFormat; import java.util.ArrayList; @@ -7,7 +8,9 @@ import javax.swing.JOptionPane; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.scene.text.Text; +import sarsoo.fmframework.music.Album; import sarsoo.fmframework.util.FMObjList; import sarsoo.fmframework.util.Getter; import sarsoo.fmframework.util.Reference; @@ -17,6 +20,10 @@ import javafx.scene.chart.*; import javafx.collections.ObservableList; import javafx.collections.FXCollections; +import javafx.scene.Parent; + +import javafx.scene.layout.*; + public class ControllerMain { @FXML @@ -31,6 +38,9 @@ public class ControllerMain { @FXML private PieChart pieChartGenres; + @FXML + private TabPane tabPane; + @FXML public void initialize() { Reference.setUserName("sarsoo"); @@ -66,10 +76,40 @@ public class ControllerMain { ObservableList pieChartData = FXCollections.observableArrayList( // new PieChart.Data("rap", Getter.getUserTag(Reference.getUserName(), "rap").getTotalUserScrobbles()), - new PieChart.Data("rock", Getter.getUserTag(Reference.getUserName(), "rap").getTotalUserScrobbles())); +// new PieChart.Data("rock", Getter.getUserTag(Reference.getUserName(), "rap").getTotalUserScrobbles()), + new PieChart.Data("rock", 5), + new PieChart.Data("rock", 5), + new PieChart.Data("rock", 5)); pieChartGenres = new PieChart(pieChartData); } + @FXML + protected void handleLookupAlbum(ActionEvent event) throws IOException { + + FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/albumview.fxml")); + + Pane pane = (Pane)loader.load(); + +// AlbumTabController controller = new AlbumTabController(Album.getAlbum("recovery", "eminem", Reference.getUserName())); +// loader.setController(controller); +// pane.setController(controller); + +// Parent pane = loader.load(); + + Tab tab = new Tab("Recovery"); + + tab.setContent(pane); + + AlbumTabController albumControl = (AlbumTabController)loader.getController(); + + + albumControl.populateTab(Getter.getAlbum()); + + + tabPane.getTabs().add(tab); + } + + } diff --git a/fmframework/src/sarsoo/fmframework/fx/ui/albumview.fxml b/fmframework/src/sarsoo/fmframework/fx/ui/albumview.fxml new file mode 100644 index 0000000..441d5ff --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/ui/albumview.fxml @@ -0,0 +1,76 @@ + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +