diff --git a/src/main/java/sarsoo/fmframework/fx/controller/borderpane/AlbumBorderPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/borderpane/AlbumBorderPaneController.java new file mode 100644 index 0000000..b869a3b --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/controller/borderpane/AlbumBorderPaneController.java @@ -0,0 +1,98 @@ +package sarsoo.fmframework.fx.controller.borderpane; + +import java.io.IOException; + +import javafx.application.Platform; +import javafx.concurrent.Service; +import javafx.concurrent.Task; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.layout.AnchorPane; +import sarsoo.fmframework.fm.FmUserNetwork; +import sarsoo.fmframework.fx.chart.GenrePieChartTitledPane; +import sarsoo.fmframework.fx.controller.info.AlbumPaneController; +import sarsoo.fmframework.fx.controller.info.ArtistPaneController; +import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.Artist; +import sarsoo.fmframework.net.Key; +import sarsoo.fmframework.net.Network; +import sarsoo.fmframework.util.Reference; + +public class AlbumBorderPaneController extends FMObjBorderPaneController{ + + AlbumPaneController infoPaneController; + Album album; + + @FXML + public void initialize() { + + borderPane.setTop(null); + + } + + public void populate(Album album) { + + this.album = album; + + try { + loadInfoPane(); + loadScrobblePane(); + } catch (IOException e) { + e.printStackTrace(); + } + setInfoView(); + } + + @Override + public void loadInfoPane() throws IOException { + + FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/AlbumPane.fxml")); + + this.infoAnchorPane = (AnchorPane) loader.load(); + + AnchorPane.setTopAnchor(infoAnchorPane, 0.0); + AnchorPane.setLeftAnchor(infoAnchorPane, 0.0); + AnchorPane.setRightAnchor(infoAnchorPane, 0.0); + AnchorPane.setBottomAnchor(infoAnchorPane, 0.0); + + infoPaneController = (AlbumPaneController) loader.getController(); + + infoPaneController.refresh(album); + + } + + @Override + protected void handleViewOnline(ActionEvent event) { + Network.openURL(album.getUrl()); + } + + @Override + protected void handleRefresh(ActionEvent event) { + + Service service = new Service() { + @Override + protected Task createTask() { + return new Task() { + @Override + protected Void call() throws Exception { + + album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album); + + Platform.runLater(new Runnable() { + @Override + public void run() { + + infoPaneController.refresh(album); + + } + }); + return null; + } + }; + } + }; + service.start(); + } + +} diff --git a/src/main/java/sarsoo/fmframework/fx/controller/info/AlbumPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/info/AlbumPaneController.java index 9958046..bd757b0 100644 --- a/src/main/java/sarsoo/fmframework/fx/controller/info/AlbumPaneController.java +++ b/src/main/java/sarsoo/fmframework/fx/controller/info/AlbumPaneController.java @@ -42,9 +42,6 @@ public class AlbumPaneController { @FXML private TextArea textAreaWiki; - @FXML - private BorderPane albumBorderPane; - @FXML private AnchorPane infoAnchorPane; @@ -55,11 +52,8 @@ public class AlbumPaneController { } - Album album; - public void populate(Album album) { - - this.album = album; + public void refresh(Album album) { NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK); @@ -88,58 +82,58 @@ public class AlbumPaneController { textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); }else { - albumBorderPane.setCenter(infoAnchorPane); +// albumBorderPane.setCenter(infoAnchorPane); } } - @FXML - protected void handleRefresh(ActionEvent event) { - refresh(); - } +// @FXML +// protected void handleRefresh(ActionEvent event) { +// refresh(); +// } - @FXML - protected void viewOnline(ActionEvent event) { - Network.openURL(album.getUrl()); - } +// @FXML +// protected void viewOnline(ActionEvent event) { +// Network.openURL(album.getUrl()); +// } - @FXML - protected void viewArtist(ActionEvent event) throws IOException { - FmFramework.getController().addTab(new ArtistTab(album.getArtist())); - } +// @FXML +// protected void viewArtist(ActionEvent event) throws IOException { +// FmFramework.getController().addTab(new ArtistTab(album.getArtist())); +// } +// +// @FXML +// protected void viewRYM(ActionEvent event) { +// Network.openURL(album.getRymURL()); +// } - @FXML - protected void viewRYM(ActionEvent event) { - Network.openURL(album.getRymURL()); - } - - public void refresh() { - album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album); - - NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); - - 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)); - } - - Wiki wiki = album.getWiki(); - - if(wiki != null) { - - textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); - } - } +// public void refresh() { +// album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album); +// +// NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); +// +// 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)); +// } +// +// Wiki wiki = album.getWiki(); +// +// if(wiki != null) { +// +// textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); +// } +// } } diff --git a/src/main/java/sarsoo/fmframework/fx/controller/info/ArtistPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/info/ArtistPaneController.java index 3b80c43..ee33325 100644 --- a/src/main/java/sarsoo/fmframework/fx/controller/info/ArtistPaneController.java +++ b/src/main/java/sarsoo/fmframework/fx/controller/info/ArtistPaneController.java @@ -36,9 +36,6 @@ public class ArtistPaneController{ @FXML private TextArea textAreaWiki; - @FXML - private BorderPane artistBorderPane; - @FXML private AnchorPane infoAnchorPane; @@ -77,7 +74,7 @@ public class ArtistPaneController{ textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); }else { - artistBorderPane.setCenter(infoAnchorPane); +// artistBorderPane.setCenter(infoAnchorPane); } } // diff --git a/src/main/java/sarsoo/fmframework/fx/tab/AlbumTab.java b/src/main/java/sarsoo/fmframework/fx/tab/AlbumTab.java index ab42e6b..bbb9575 100644 --- a/src/main/java/sarsoo/fmframework/fx/tab/AlbumTab.java +++ b/src/main/java/sarsoo/fmframework/fx/tab/AlbumTab.java @@ -4,6 +4,8 @@ import java.io.IOException; import javafx.scene.control.*; import javafx.scene.layout.*; +import sarsoo.fmframework.fx.controller.borderpane.AlbumBorderPaneController; +import sarsoo.fmframework.fx.controller.borderpane.ArtistBorderPaneController; import sarsoo.fmframework.fx.controller.info.AlbumPaneController; import sarsoo.fmframework.music.Album; @@ -16,8 +18,12 @@ public class AlbumTab extends Tab { setText(album.getName()); - FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/AlbumPane.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjBorderPane.fxml")); + AlbumBorderPaneController controller = new AlbumBorderPaneController(); + + loader.setController(controller); + AnchorPane pane = (AnchorPane) loader.load(); AnchorPane.setTopAnchor(pane, 0.0); @@ -27,11 +33,7 @@ public class AlbumTab extends Tab { setContent(pane); - AlbumPaneController control = (AlbumPaneController) loader.getController(); - - control.populate(album); - - + controller.populate(album); } diff --git a/src/main/resources/sarsoo/fmframework/fx/ui/AlbumPane.fxml b/src/main/resources/sarsoo/fmframework/fx/ui/AlbumPane.fxml index 767cdca..a027b4b 100644 --- a/src/main/resources/sarsoo/fmframework/fx/ui/AlbumPane.fxml +++ b/src/main/resources/sarsoo/fmframework/fx/ui/AlbumPane.fxml @@ -9,101 +9,87 @@ - -
- - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - -