From e4957364d23e3df00df546766c32dd4b491ba7e4 Mon Sep 17 00:00:00 2001 From: aj Date: Sat, 4 May 2019 12:26:32 +0100 Subject: [PATCH] started adding pane and pane switch handling --- .../ScrobblesViewPaneController.java | 37 +++++ .../ArtistBorderPaneController.java | 96 +++++++++++ .../borderpane/FMObjBorderPaneController.java | 85 ++++++++++ .../{ => info}/AlbumPaneController.java | 2 +- .../{ => info}/ArtistPaneController.java | 91 ++++------ .../{ => info}/TrackPaneController.java | 2 +- .../sarsoo/fmframework/fx/tab/AlbumTab.java | 2 +- .../sarsoo/fmframework/fx/tab/ArtistTab.java | 26 +-- .../sarsoo/fmframework/fx/tab/FMObjTab.java | 41 +++++ .../sarsoo/fmframework/fx/tab/TrackTab.java | 2 +- .../sarsoo/fmframework/fx/ui/AlbumPane.fxml | 2 +- .../sarsoo/fmframework/fx/ui/ArtistPane.fxml | 156 ++++++++---------- .../fmframework/fx/ui/FMObjBorderPane.fxml | 32 ++++ .../fmframework/fx/ui/FMObjScrobblePane.fxml | 42 +++++ .../sarsoo/fmframework/fx/ui/TrackPane.fxml | 2 +- 15 files changed, 455 insertions(+), 163 deletions(-) create mode 100644 src/main/java/sarsoo/fmframework/fx/controller/ScrobblesViewPaneController.java create mode 100644 src/main/java/sarsoo/fmframework/fx/controller/borderpane/ArtistBorderPaneController.java create mode 100644 src/main/java/sarsoo/fmframework/fx/controller/borderpane/FMObjBorderPaneController.java rename src/main/java/sarsoo/fmframework/fx/controller/{ => info}/AlbumPaneController.java (94%) rename src/main/java/sarsoo/fmframework/fx/controller/{ => info}/ArtistPaneController.java (53%) rename src/main/java/sarsoo/fmframework/fx/controller/{ => info}/TrackPaneController.java (95%) create mode 100644 src/main/java/sarsoo/fmframework/fx/tab/FMObjTab.java create mode 100644 src/main/resources/sarsoo/fmframework/fx/ui/FMObjBorderPane.fxml create mode 100644 src/main/resources/sarsoo/fmframework/fx/ui/FMObjScrobblePane.fxml diff --git a/src/main/java/sarsoo/fmframework/fx/controller/ScrobblesViewPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/ScrobblesViewPaneController.java new file mode 100644 index 0000000..4e2fb88 --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/controller/ScrobblesViewPaneController.java @@ -0,0 +1,37 @@ +package sarsoo.fmframework.fx.controller; + +import java.util.ArrayList; + +import javafx.fxml.FXML; +import javafx.scene.chart.AreaChart; +import javafx.scene.control.SplitPane; +import javafx.scene.layout.GridPane; +import sarsoo.fmframework.music.FMObj; +import sarsoo.fmframework.music.Scrobble; + +public class ScrobblesViewPaneController { + + @FXML + private SplitPane splitPane; + + @FXML + private GridPane gridPane; + + @FXML + private AreaChart areaChart; + + @FXML + public void initialize() { + + + + } + + public void populate(FMObj obj) { + + ArrayList scrobbles = obj.getScrobbles(); + + + } + +} diff --git a/src/main/java/sarsoo/fmframework/fx/controller/borderpane/ArtistBorderPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/borderpane/ArtistBorderPaneController.java new file mode 100644 index 0000000..21dec39 --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/controller/borderpane/ArtistBorderPaneController.java @@ -0,0 +1,96 @@ +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.music.Artist; +import sarsoo.fmframework.net.Key; +import sarsoo.fmframework.net.Network; +import sarsoo.fmframework.util.Reference; + +public class ArtistBorderPaneController extends FMObjBorderPaneController{ + + ArtistPaneController infoPaneController; + Artist artist; + + @FXML + public void initialize() { + + borderPane.setTop(null); + + } + + public void populate(Artist artist) { + + this.artist = artist; + + try { + loadInfoPane(); + loadScrobblePane(); + } catch (IOException e) { + e.printStackTrace(); + } + setInfoView(); + } + + @Override + public void loadInfoPane() throws IOException { + + FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/ArtistPane.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 = (ArtistPaneController) loader.getController(); + + infoPaneController.refresh(artist); + + } + + @Override + protected void handleViewOnline(ActionEvent event) { + Network.openURL(artist.getUrl()); + } + + @Override + protected void handleRefresh(ActionEvent event) { + + Service service = new Service() { + @Override + protected Task createTask() { + return new Task() { + @Override + protected Void call() throws Exception { + + artist = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(artist); + + Platform.runLater(new Runnable() { + @Override + public void run() { + + infoPaneController.refresh(artist); + + } + }); + return null; + } + }; + } + }; + service.start(); + } + +} diff --git a/src/main/java/sarsoo/fmframework/fx/controller/borderpane/FMObjBorderPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/borderpane/FMObjBorderPaneController.java new file mode 100644 index 0000000..ac42568 --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/controller/borderpane/FMObjBorderPaneController.java @@ -0,0 +1,85 @@ +package sarsoo.fmframework.fx.controller.borderpane; + +import java.io.IOException; + +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.Button; +import javafx.scene.control.ProgressBar; +import javafx.scene.control.ToolBar; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.BorderPane; +import sarsoo.fmframework.fx.controller.ScrobblesViewPaneController; +import sarsoo.fmframework.fx.tab.FMObjTab; +import sarsoo.fmframework.net.Network; + +public abstract class FMObjBorderPaneController { + + @FXML + protected ToolBar toolBar; + + @FXML + protected ProgressBar progressBar; + + @FXML + protected AnchorPane progressBarAnchorPane; + + @FXML + protected Button buttonViewScrobbles; + + @FXML + protected Button buttonViewInfo; + + @FXML + protected BorderPane borderPane; + + protected AnchorPane scrobbleAnchorPane; + protected ScrobblesViewPaneController scrobblePaneController; + + protected AnchorPane infoAnchorPane; + + @FXML + protected abstract void handleRefresh(ActionEvent event); + + @FXML + protected void handleViewScrobbles(ActionEvent event) { + setScrobblesView(); + } + + @FXML + protected void handleViewInfo(ActionEvent event) { + setInfoView(); + } + + @FXML + protected abstract void handleViewOnline(ActionEvent event); + + public void setScrobblesView() { + buttonViewInfo.setDisable(false); + buttonViewScrobbles.setDisable(true); + borderPane.setCenter(scrobbleAnchorPane); + } + + public void setInfoView() { + buttonViewInfo.setDisable(true); + buttonViewScrobbles.setDisable(false); + borderPane.setCenter(infoAnchorPane); + } + + public abstract void loadInfoPane()throws IOException; + + public void loadScrobblePane() throws IOException { + FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/FMObjScrobblePane.fxml")); + + this.scrobbleAnchorPane = (AnchorPane) loader.load(); + + AnchorPane.setTopAnchor(scrobbleAnchorPane, 0.0); + AnchorPane.setLeftAnchor(scrobbleAnchorPane, 0.0); + AnchorPane.setRightAnchor(scrobbleAnchorPane, 0.0); + AnchorPane.setBottomAnchor(scrobbleAnchorPane, 0.0); + + this.scrobblePaneController = (ScrobblesViewPaneController) loader.getController(); + } + +} diff --git a/src/main/java/sarsoo/fmframework/fx/controller/AlbumPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/info/AlbumPaneController.java similarity index 94% rename from src/main/java/sarsoo/fmframework/fx/controller/AlbumPaneController.java rename to src/main/java/sarsoo/fmframework/fx/controller/info/AlbumPaneController.java index c3dc2e8..9958046 100644 --- a/src/main/java/sarsoo/fmframework/fx/controller/AlbumPaneController.java +++ b/src/main/java/sarsoo/fmframework/fx/controller/info/AlbumPaneController.java @@ -1,4 +1,4 @@ -package sarsoo.fmframework.fx.controller; +package sarsoo.fmframework.fx.controller.info; import java.io.IOException; import java.text.NumberFormat; diff --git a/src/main/java/sarsoo/fmframework/fx/controller/ArtistPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/info/ArtistPaneController.java similarity index 53% rename from src/main/java/sarsoo/fmframework/fx/controller/ArtistPaneController.java rename to src/main/java/sarsoo/fmframework/fx/controller/info/ArtistPaneController.java index 4216d5e..3b80c43 100644 --- a/src/main/java/sarsoo/fmframework/fx/controller/ArtistPaneController.java +++ b/src/main/java/sarsoo/fmframework/fx/controller/info/ArtistPaneController.java @@ -1,4 +1,4 @@ -package sarsoo.fmframework.fx.controller; +package sarsoo.fmframework.fx.controller.info; import java.text.NumberFormat; import java.util.Locale; @@ -16,7 +16,7 @@ import javafx.scene.control.*; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.BorderPane; -public class ArtistPaneController { +public class ArtistPaneController{ @FXML private Label labelArtistName; @@ -45,15 +45,11 @@ public class ArtistPaneController { @FXML public void initialize() { - } - Artist artist; - public void populate(Artist artist) { - - this.artist = artist; + public void refresh(Artist artist) { NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); @@ -84,57 +80,34 @@ public class ArtistPaneController { artistBorderPane.setCenter(infoAnchorPane); } } - - @FXML - protected void handleRefresh(ActionEvent event) { - refresh(); - } - - @FXML - protected void viewOnline(ActionEvent event) { - Network.openURL(artist.getUrl()); - } - - - @FXML - protected void viewRYM(ActionEvent event) { - Network.openURL(artist.getRymURL()); - } - - @FXML - protected void handleViewTracks(ActionEvent event) { - - - } - - public void refresh() { - artist = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(artist); - - NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); - - labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount()) - + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName()))); - - labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners"); - labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles"); - - double ratio = artist.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 = artist.getWiki(); - - if(wiki != null) { - - textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); - } - } +// +// public void refresh(Artist artist) { +// +// NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); +// +// labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount()) +// + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName()))); +// +// labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners"); +// labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles"); +// +// double ratio = artist.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 = artist.getWiki(); +// +// if(wiki != null) { +// +// textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); +// } +// } } diff --git a/src/main/java/sarsoo/fmframework/fx/controller/TrackPaneController.java b/src/main/java/sarsoo/fmframework/fx/controller/info/TrackPaneController.java similarity index 95% rename from src/main/java/sarsoo/fmframework/fx/controller/TrackPaneController.java rename to src/main/java/sarsoo/fmframework/fx/controller/info/TrackPaneController.java index 174d4b9..f3a83d7 100644 --- a/src/main/java/sarsoo/fmframework/fx/controller/TrackPaneController.java +++ b/src/main/java/sarsoo/fmframework/fx/controller/info/TrackPaneController.java @@ -1,4 +1,4 @@ -package sarsoo.fmframework.fx.controller; +package sarsoo.fmframework.fx.controller.info; import java.io.IOException; import java.text.NumberFormat; diff --git a/src/main/java/sarsoo/fmframework/fx/tab/AlbumTab.java b/src/main/java/sarsoo/fmframework/fx/tab/AlbumTab.java index 8b8ab40..ab42e6b 100644 --- a/src/main/java/sarsoo/fmframework/fx/tab/AlbumTab.java +++ b/src/main/java/sarsoo/fmframework/fx/tab/AlbumTab.java @@ -4,7 +4,7 @@ import java.io.IOException; import javafx.scene.control.*; import javafx.scene.layout.*; -import sarsoo.fmframework.fx.controller.AlbumPaneController; +import sarsoo.fmframework.fx.controller.info.AlbumPaneController; import sarsoo.fmframework.music.Album; diff --git a/src/main/java/sarsoo/fmframework/fx/tab/ArtistTab.java b/src/main/java/sarsoo/fmframework/fx/tab/ArtistTab.java index c29f0b8..18116e6 100644 --- a/src/main/java/sarsoo/fmframework/fx/tab/ArtistTab.java +++ b/src/main/java/sarsoo/fmframework/fx/tab/ArtistTab.java @@ -4,33 +4,33 @@ import java.io.IOException; import javafx.scene.control.*; import javafx.scene.layout.*; -import sarsoo.fmframework.fx.controller.ArtistPaneController; +import sarsoo.fmframework.fx.controller.borderpane.ArtistBorderPaneController; import sarsoo.fmframework.music.Artist; import javafx.fxml.FXMLLoader; -public class ArtistTab extends Tab { - +public class ArtistTab extends Tab{ + public ArtistTab(Artist artist) throws IOException { - + setText(artist.getName()); - - FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/ArtistPane.fxml")); - + + FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjBorderPane.fxml")); + + ArtistBorderPaneController controller = new ArtistBorderPaneController(); + + loader.setController(controller); + AnchorPane pane = (AnchorPane) loader.load(); AnchorPane.setTopAnchor(pane, 0.0); AnchorPane.setLeftAnchor(pane, 0.0); AnchorPane.setRightAnchor(pane, 0.0); AnchorPane.setBottomAnchor(pane, 0.0); - + setContent(pane); - - ArtistPaneController control = (ArtistPaneController) loader.getController(); - - control.populate(artist); + controller.populate(artist); - } } diff --git a/src/main/java/sarsoo/fmframework/fx/tab/FMObjTab.java b/src/main/java/sarsoo/fmframework/fx/tab/FMObjTab.java new file mode 100644 index 0000000..affcf4f --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/tab/FMObjTab.java @@ -0,0 +1,41 @@ +package sarsoo.fmframework.fx.tab; + +import java.io.IOException; + +import javafx.fxml.FXMLLoader; +import javafx.scene.Node; +import javafx.scene.control.Tab; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.BorderPane; +import sarsoo.fmframework.fx.controller.ScrobblesViewPaneController; +import sarsoo.fmframework.fx.controller.borderpane.FMObjBorderPaneController; + +public abstract class FMObjTab extends Tab { + + protected AnchorPane infoAnchorPane; + protected FMObjBorderPaneController controller; + + protected FMObjTab() throws IOException { + + FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjBorderPane.fxml")); + + AnchorPane anchor = (AnchorPane) loader.load(); + + AnchorPane.setTopAnchor(anchor, 0.0); + AnchorPane.setLeftAnchor(anchor, 0.0); + AnchorPane.setRightAnchor(anchor, 0.0); + AnchorPane.setBottomAnchor(anchor, 0.0); + + this.controller = (FMObjBorderPaneController) loader.getController(); + + setContent(anchor); + + } + + public AnchorPane getInfoAnchorPane() { + return infoAnchorPane; + } + + public abstract AnchorPane loadInfoAnchorPane() throws IOException; + +} diff --git a/src/main/java/sarsoo/fmframework/fx/tab/TrackTab.java b/src/main/java/sarsoo/fmframework/fx/tab/TrackTab.java index 08aa257..dcedaa6 100644 --- a/src/main/java/sarsoo/fmframework/fx/tab/TrackTab.java +++ b/src/main/java/sarsoo/fmframework/fx/tab/TrackTab.java @@ -4,7 +4,7 @@ import java.io.IOException; import javafx.scene.control.*; import javafx.scene.layout.*; -import sarsoo.fmframework.fx.controller.TrackPaneController; +import sarsoo.fmframework.fx.controller.info.TrackPaneController; import sarsoo.fmframework.music.Track; import javafx.fxml.FXMLLoader; diff --git a/src/main/resources/sarsoo/fmframework/fx/ui/AlbumPane.fxml b/src/main/resources/sarsoo/fmframework/fx/ui/AlbumPane.fxml index f8ac1ca..767cdca 100644 --- a/src/main/resources/sarsoo/fmframework/fx/ui/AlbumPane.fxml +++ b/src/main/resources/sarsoo/fmframework/fx/ui/AlbumPane.fxml @@ -7,7 +7,7 @@ - +
diff --git a/src/main/resources/sarsoo/fmframework/fx/ui/ArtistPane.fxml b/src/main/resources/sarsoo/fmframework/fx/ui/ArtistPane.fxml index b076e9b..1cdd9f0 100644 --- a/src/main/resources/sarsoo/fmframework/fx/ui/ArtistPane.fxml +++ b/src/main/resources/sarsoo/fmframework/fx/ui/ArtistPane.fxml @@ -7,93 +7,79 @@ - + - -
- - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - -