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
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());
// }
// }
}

View File

@ -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);
}
}
//

View File

@ -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,7 +18,11 @@ 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();
@ -27,11 +33,7 @@ public class AlbumTab extends Tab {
setContent(pane);
AlbumPaneController control = (AlbumPaneController) loader.getController();
control.populate(album);
controller.populate(album);
}

View File

@ -9,101 +9,87 @@
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.info.AlbumPaneController">
<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">
<center>
<SplitPane fx:id="splitPane" dividerPositions="0.5" prefHeight="327.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<items>
<AnchorPane fx:id="infoAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.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">
<items>
<AnchorPane fx:id="infoAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<GridPane prefHeight="325.0" prefWidth="296.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="115.0" minHeight="10.0" prefHeight="94.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="181.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="49.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="43.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="39.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="37.0" minHeight="10.0" prefHeight="35.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<GridPane prefHeight="325.0" prefWidth="296.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="115.0" minHeight="10.0" prefHeight="94.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="181.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="49.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="43.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="39.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="37.0" minHeight="10.0" prefHeight="35.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<AnchorPane>
<children>
<Label fx:id="labelAlbumName" alignment="CENTER" styleClass="titleLabel" text="Album Name" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="1">
<children>
<Label fx:id="labelArtistName" alignment="CENTER" styleClass="subLabel" text="Artist Name" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="2">
<children>
<Label fx:id="labelUserScrobbles" alignment="CENTER" styleClass="normalLabel" text="User Scrobbles" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="3">
<children>
<Label fx:id="labelRatio" alignment="CENTER" styleClass="normalLabel" text="Ratio" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="3">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="4">
<children>
<Label fx:id="labelTotalListeners" alignment="CENTER" styleClass="normalLabel" text="Total Listeners" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="5">
<children>
<Label fx:id="labelTotalScrobbles" alignment="CENTER" styleClass="normalLabel" text="Total Scrobbles" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
</children>
</GridPane>
<AnchorPane>
<children>
<Label fx:id="labelAlbumName" alignment="CENTER" styleClass="titleLabel" text="Album Name" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="1">
<children>
<Label fx:id="labelArtistName" alignment="CENTER" styleClass="subLabel" text="Artist Name" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="2">
<children>
<Label fx:id="labelUserScrobbles" alignment="CENTER" styleClass="normalLabel" text="User Scrobbles" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="3">
<children>
<Label fx:id="labelRatio" alignment="CENTER" styleClass="normalLabel" text="Ratio" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="3">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="4">
<children>
<Label fx:id="labelTotalListeners" alignment="CENTER" styleClass="normalLabel" text="Total Listeners" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane GridPane.rowIndex="5">
<children>
<Label fx:id="labelTotalScrobbles" alignment="CENTER" styleClass="normalLabel" text="Total Scrobbles" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</AnchorPane>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TextArea fx:id="textAreaWiki" editable="false" layoutX="37.0" layoutY="34.0" prefHeight="285.0" prefWidth="296.0" styleClass="wikiTextArea" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</items>
</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>
</GridPane>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TextArea fx:id="textAreaWiki" editable="false" layoutX="37.0" layoutY="34.0" prefHeight="285.0" prefWidth="296.0" styleClass="wikiTextArea" wrapText="true" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>