migrated albums to dynamic panes

This commit is contained in:
aj 2019-05-04 12:51:19 +01:00
parent e4957364d2
commit 3e8cd92fe7
5 changed files with 235 additions and 158 deletions

View File

@ -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<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@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();
}
}

View File

@ -42,9 +42,6 @@ public class AlbumPaneController {
@FXML @FXML
private TextArea textAreaWiki; private TextArea textAreaWiki;
@FXML
private BorderPane albumBorderPane;
@FXML @FXML
private AnchorPane infoAnchorPane; private AnchorPane infoAnchorPane;
@ -55,11 +52,8 @@ public class AlbumPaneController {
} }
Album album;
public void populate(Album album) { public void refresh(Album album) {
this.album = album;
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK); NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
@ -88,58 +82,58 @@ public class AlbumPaneController {
textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
}else { }else {
albumBorderPane.setCenter(infoAnchorPane); // albumBorderPane.setCenter(infoAnchorPane);
} }
} }
@FXML // @FXML
protected void handleRefresh(ActionEvent event) { // protected void handleRefresh(ActionEvent event) {
refresh(); // refresh();
} // }
@FXML // @FXML
protected void viewOnline(ActionEvent event) { // protected void viewOnline(ActionEvent event) {
Network.openURL(album.getUrl()); // Network.openURL(album.getUrl());
} // }
@FXML // @FXML
protected void viewArtist(ActionEvent event) throws IOException { // protected void viewArtist(ActionEvent event) throws IOException {
FmFramework.getController().addTab(new ArtistTab(album.getArtist())); // FmFramework.getController().addTab(new ArtistTab(album.getArtist()));
} // }
//
// @FXML
// protected void viewRYM(ActionEvent event) {
// Network.openURL(album.getRymURL());
// }
@FXML // public void refresh() {
protected void viewRYM(ActionEvent event) { // album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album);
Network.openURL(album.getRymURL()); //
} // NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
//
public void refresh() { // labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount())
album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album); // + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName())));
//
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); // labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners");
// labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles");
labelUserScrobbles.setText(numberFormat.format(album.getUserPlayCount()) //
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(album, Reference.getUserName()))); // double ratio = album.getTimeListenRatio();
//
labelTotalListeners.setText(numberFormat.format(album.getListeners()) + " Listeners"); //
labelTotalScrobbles.setText(numberFormat.format(album.getPlayCount()) + " Total Scrobbles"); // if (ratio > 1) {
// labelRatio.setText(String.format("listen every %.2f days", ratio));
double ratio = album.getTimeListenRatio(); // } else if (ratio == 1) {
// labelRatio.setText("listen every day");
// } else {
if (ratio > 1) { // labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
labelRatio.setText(String.format("listen every %.2f days", ratio)); // }
} else if (ratio == 1) { //
labelRatio.setText("listen every day"); // Wiki wiki = album.getWiki();
} else { //
labelRatio.setText(String.format("%.2f times a day", 1 / ratio)); // if(wiki != null) {
} //
// textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
Wiki wiki = album.getWiki(); // }
// }
if(wiki != null) {
textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
}
}
} }

View File

@ -36,9 +36,6 @@ public class ArtistPaneController{
@FXML @FXML
private TextArea textAreaWiki; private TextArea textAreaWiki;
@FXML
private BorderPane artistBorderPane;
@FXML @FXML
private AnchorPane infoAnchorPane; private AnchorPane infoAnchorPane;
@ -77,7 +74,7 @@ public class ArtistPaneController{
textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate()); textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
}else { }else {
artistBorderPane.setCenter(infoAnchorPane); // artistBorderPane.setCenter(infoAnchorPane);
} }
} }
// //

View File

@ -4,6 +4,8 @@ import java.io.IOException;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.*; 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.fx.controller.info.AlbumPaneController;
import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.Album;
@ -16,7 +18,11 @@ public class AlbumTab extends Tab {
setText(album.getName()); 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 pane = (AnchorPane) loader.load();
@ -27,11 +33,7 @@ public class AlbumTab extends Tab {
setContent(pane); setContent(pane);
AlbumPaneController control = (AlbumPaneController) loader.getController(); controller.populate(album);
control.populate(album);
} }

View File

@ -9,9 +9,7 @@
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.info.AlbumPaneController"> <AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.info.AlbumPaneController">
<children> <children>
<BorderPane fx:id="albumBorderPane" prefHeight="327.0" prefWidth="600.0" stylesheets="@../styles/ObjPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <SplitPane fx:id="splitPane" dividerPositions="0.5" prefHeight="327.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<center>
<SplitPane fx:id="splitPane" dividerPositions="0.5" prefHeight="327.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<items> <items>
<AnchorPane fx:id="infoAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> <AnchorPane fx:id="infoAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children> <children>
@ -93,17 +91,5 @@
</AnchorPane> </AnchorPane>
</items> </items>
</SplitPane> </SplitPane>
</center>
<bottom>
<ToolBar fx:id="toolBar" prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<Button fx:id="buttonRefresh" mnemonicParsing="false" onAction="#handleRefresh" text="refresh" />
<Button fx:id="buttonViewArtist" mnemonicParsing="false" onAction="#viewArtist" text="view artist" />
<Button fx:id="buttonViewOnline" mnemonicParsing="false" onAction="#viewOnline" text="view online" />
<Button fx:id="buttonViewRYM" mnemonicParsing="false" onAction="#viewRYM" text="view rym" />
</items>
</ToolBar>
</bottom>
</BorderPane>
</children> </children>
</AnchorPane> </AnchorPane>