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,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"> <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> <items>
<SplitPane fx:id="splitPane" dividerPositions="0.5" prefHeight="327.0" prefWidth="600.0" BorderPane.alignment="CENTER"> <AnchorPane fx:id="infoAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<items> <children>
<AnchorPane fx:id="infoAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> <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> <children>
<GridPane prefHeight="325.0" prefWidth="296.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <AnchorPane>
<columnConstraints> <children>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <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">
</columnConstraints> <font>
<rowConstraints> <Font name="System Bold" size="18.0" />
<RowConstraints maxHeight="115.0" minHeight="10.0" prefHeight="94.0" vgrow="SOMETIMES" /> </font>
<RowConstraints maxHeight="181.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" /> </Label>
<RowConstraints maxHeight="49.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" /> </children>
<RowConstraints maxHeight="43.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" /> </AnchorPane>
<RowConstraints maxHeight="39.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" /> <AnchorPane GridPane.rowIndex="1">
<RowConstraints maxHeight="37.0" minHeight="10.0" prefHeight="35.0" vgrow="SOMETIMES" /> <children>
</rowConstraints> <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">
<children> <font>
<AnchorPane> <Font size="13.0" />
<children> </font>
<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"> </Label>
<font> </children>
<Font name="System Bold" size="18.0" /> </AnchorPane>
</font> <AnchorPane GridPane.rowIndex="2">
</Label> <children>
</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">
</AnchorPane> <font>
<AnchorPane GridPane.rowIndex="1"> <Font size="13.0" />
<children> </font>
<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"> </Label>
<font> </children>
<Font size="13.0" /> </AnchorPane>
</font> <AnchorPane GridPane.rowIndex="3">
</Label> <children>
</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">
</AnchorPane> <font>
<AnchorPane GridPane.rowIndex="2"> <Font size="13.0" />
<children> </font>
<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"> </Label>
<font> </children>
<Font size="13.0" /> </AnchorPane>
</font> <AnchorPane GridPane.rowIndex="4">
</Label> <children>
</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">
</AnchorPane> <font>
<AnchorPane GridPane.rowIndex="3"> <Font size="13.0" />
<children> </font>
<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"> </Label>
<font> </children>
<Font size="13.0" /> </AnchorPane>
</font> <AnchorPane GridPane.rowIndex="5">
</Label> <children>
</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">
</AnchorPane> <font>
<AnchorPane GridPane.rowIndex="4"> <Font size="13.0" />
<children> </font>
<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"> </Label>
<font> </children>
<Font size="13.0" /> </AnchorPane>
</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>
</children> </children>
</AnchorPane> </GridPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0"> </children>
<children> </AnchorPane>
<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" /> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
</children> <children>
</AnchorPane> <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" />
</items> </children>
</SplitPane> </AnchorPane>
</center> </items>
<bottom> </SplitPane>
<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>