diff --git a/src/main/java/sarsoo/fmframework/fx/controller/borderpane/TrackBorderPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/borderpane/TrackBorderPaneController.java new file mode 100644 index 0000000..08ff80f --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/controller/borderpane/TrackBorderPaneController.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.ArtistPaneController; +import sarsoo.fmframework.fx.controller.info.TrackPaneController; +import sarsoo.fmframework.music.Artist; +import sarsoo.fmframework.music.Track; +import sarsoo.fmframework.net.Key; +import sarsoo.fmframework.net.Network; +import sarsoo.fmframework.util.Reference; + +public class TrackBorderPaneController extends FMObjBorderPaneController{ + + TrackPaneController infoPaneController; + Track track; + + @FXML + public void initialize() { + + borderPane.setTop(null); + + } + + public void populate(Track track) { + + this.track = track; + + try { + loadInfoPane(); + loadScrobblePane(); + } catch (IOException e) { + e.printStackTrace(); + } + setInfoView(); + } + + @Override + public void loadInfoPane() throws IOException { + + FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/TrackPane.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 = (TrackPaneController) loader.getController(); + + infoPaneController.refresh(track); + + } + + @Override + protected void handleViewOnline(ActionEvent event) { + Network.openURL(track.getUrl()); + } + + @Override + protected void handleRefresh(ActionEvent event) { + + Service service = new Service() { + @Override + protected Task createTask() { + return new Task() { + @Override + protected Void call() throws Exception { + + track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track); + + Platform.runLater(new Runnable() { + @Override + public void run() { + + infoPaneController.refresh(track); + + } + }); + return null; + } + }; + } + }; + service.start(); + } + +} diff --git a/src/main/java/sarsoo/fmframework/fx/controller/info/TrackPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/info/TrackPaneController.java index f3a83d7..38b4d4c 100644 --- a/src/main/java/sarsoo/fmframework/fx/controller/info/TrackPaneController.java +++ b/src/main/java/sarsoo/fmframework/fx/controller/info/TrackPaneController.java @@ -49,9 +49,6 @@ public class TrackPaneController { @FXML private Button buttonViewAlbum; - @FXML - private BorderPane trackBorderPane; - @FXML private AnchorPane infoAnchorPane; @@ -62,9 +59,7 @@ public class TrackPaneController { Track track; - public void populate(Track track) { - - this.track = track; + public void refresh(Track track) { NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); @@ -98,61 +93,61 @@ public class TrackPaneController { textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate()); }else { - trackBorderPane.setCenter(infoAnchorPane); +// trackBorderPane.setCenter(infoAnchorPane); } if (track.getAlbum() == null) { - buttonViewAlbum.setVisible(false); +// buttonViewAlbum.setVisible(false); } } - @FXML - protected void handleRefresh(ActionEvent event) { - refresh(); - } +// @FXML +// protected void handleRefresh(ActionEvent event) { +// refresh(); +// } +// +// @FXML +// protected void viewOnline(ActionEvent event) { +// Network.openURL(track.getUrl()); +// } +// +// @FXML +// protected void viewArtist(ActionEvent event) throws IOException { +// FmFramework.getController().addTab(new ArtistTab(track.getArtist())); +// } +// +// @FXML +// protected void viewAlbum(ActionEvent event) throws IOException { +// FmFramework.getController().addTab(new AlbumTab(track.getAlbum())); +// } - @FXML - protected void viewOnline(ActionEvent event) { - Network.openURL(track.getUrl()); - } - - @FXML - protected void viewArtist(ActionEvent event) throws IOException { - FmFramework.getController().addTab(new ArtistTab(track.getArtist())); - } - - @FXML - protected void viewAlbum(ActionEvent event) throws IOException { - FmFramework.getController().addTab(new AlbumTab(track.getAlbum())); - } - - public void refresh() { - track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track); - - NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); - - labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount()) - + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName()))); - - labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners"); - labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles"); - - double ratio = track.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 = track.getWiki(); - - if (wiki != null) { - - textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate()); - } - } +// public void refresh() { +// track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track); +// +// NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); +// +// labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount()) +// + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName()))); +// +// labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners"); +// labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles"); +// +// double ratio = track.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 = track.getWiki(); +// +// if (wiki != null) { +// +// textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate()); +// } +// } } diff --git a/src/main/java/sarsoo/fmframework/fx/tab/TrackTab.java b/src/main/java/sarsoo/fmframework/fx/tab/TrackTab.java index dcedaa6..5a0bafc 100644 --- a/src/main/java/sarsoo/fmframework/fx/tab/TrackTab.java +++ b/src/main/java/sarsoo/fmframework/fx/tab/TrackTab.java @@ -4,6 +4,8 @@ import java.io.IOException; import javafx.scene.control.*; import javafx.scene.layout.*; +import sarsoo.fmframework.fx.controller.borderpane.ArtistBorderPaneController; +import sarsoo.fmframework.fx.controller.borderpane.TrackBorderPaneController; import sarsoo.fmframework.fx.controller.info.TrackPaneController; import sarsoo.fmframework.music.Track; import javafx.fxml.FXMLLoader; @@ -14,8 +16,12 @@ public class TrackTab extends Tab { setText(track.getName()); - FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/TrackPane.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjBorderPane.fxml")); + TrackBorderPaneController controller = new TrackBorderPaneController(); + + loader.setController(controller); + AnchorPane pane = (AnchorPane) loader.load(); AnchorPane.setTopAnchor(pane, 0.0); @@ -25,12 +31,8 @@ public class TrackTab extends Tab { setContent(pane); - TrackPaneController control = (TrackPaneController) loader.getController(); - - control.populate(track); + controller.populate(track); - - } } diff --git a/src/main/resources/sarsoo/fmframework/fx/ui/TrackPane.fxml b/src/main/resources/sarsoo/fmframework/fx/ui/TrackPane.fxml index e923a6c..1e80a41 100644 --- a/src/main/resources/sarsoo/fmframework/fx/ui/TrackPane.fxml +++ b/src/main/resources/sarsoo/fmframework/fx/ui/TrackPane.fxml @@ -9,83 +9,69 @@ - -
- - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - -