migrating track to dynamic panes

This commit is contained in:
aj 2019-05-04 12:56:34 +01:00
parent 3e8cd92fe7
commit c6cf7123bb
4 changed files with 218 additions and 137 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.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<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@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();
}
}

View File

@ -49,9 +49,6 @@ public class TrackPaneController {
@FXML @FXML
private Button buttonViewAlbum; private Button buttonViewAlbum;
@FXML
private BorderPane trackBorderPane;
@FXML @FXML
private AnchorPane infoAnchorPane; private AnchorPane infoAnchorPane;
@ -62,9 +59,7 @@ public class TrackPaneController {
Track track; Track track;
public void populate(Track track) { public void refresh(Track track) {
this.track = track;
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
@ -98,61 +93,61 @@ public class TrackPaneController {
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate()); textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
}else { }else {
trackBorderPane.setCenter(infoAnchorPane); // trackBorderPane.setCenter(infoAnchorPane);
} }
if (track.getAlbum() == null) { if (track.getAlbum() == null) {
buttonViewAlbum.setVisible(false); // buttonViewAlbum.setVisible(false);
} }
} }
@FXML // @FXML
protected void handleRefresh(ActionEvent event) { // protected void handleRefresh(ActionEvent event) {
refresh(); // 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 // public void refresh() {
protected void viewOnline(ActionEvent event) { // track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track);
Network.openURL(track.getUrl()); //
} // NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
//
@FXML // labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount())
protected void viewArtist(ActionEvent event) throws IOException { // + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName())));
FmFramework.getController().addTab(new ArtistTab(track.getArtist())); //
} // labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
// labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
@FXML //
protected void viewAlbum(ActionEvent event) throws IOException { // double ratio = track.getTimeListenRatio();
FmFramework.getController().addTab(new AlbumTab(track.getAlbum())); //
} // if (ratio > 1) {
// labelRatio.setText(String.format("listen every %.2f days", ratio));
public void refresh() { // } else if (ratio == 1) {
track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track); // labelRatio.setText("listen every day");
// } else {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); // labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
// }
labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount()) //
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName()))); // Wiki wiki = track.getWiki();
//
labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners"); // if (wiki != null) {
labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles"); //
// textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
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());
}
}
} }

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.ArtistBorderPaneController;
import sarsoo.fmframework.fx.controller.borderpane.TrackBorderPaneController;
import sarsoo.fmframework.fx.controller.info.TrackPaneController; import sarsoo.fmframework.fx.controller.info.TrackPaneController;
import sarsoo.fmframework.music.Track; import sarsoo.fmframework.music.Track;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
@ -14,8 +16,12 @@ public class TrackTab extends Tab {
setText(track.getName()); 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 pane = (AnchorPane) loader.load();
AnchorPane.setTopAnchor(pane, 0.0); AnchorPane.setTopAnchor(pane, 0.0);
@ -25,12 +31,8 @@ public class TrackTab extends Tab {
setContent(pane); setContent(pane);
TrackPaneController control = (TrackPaneController) loader.getController(); controller.populate(track);
control.populate(track);
} }
} }

View File

@ -9,83 +9,69 @@
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.info.TrackPaneController"> <AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.info.TrackPaneController">
<children> <children>
<BorderPane fx:id="trackBorderPane" 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 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 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="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"> <Label fx:id="labelTrackName" alignment="CENTER" styleClass="titleLabel" text="Track Name" wrapText="true" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.valignment="CENTER">
<columnConstraints> <font>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> <Font name="System Bold" size="18.0" />
</columnConstraints> </font>
<rowConstraints> </Label>
<RowConstraints maxHeight="115.0" minHeight="10.0" prefHeight="94.0" vgrow="SOMETIMES" /> <Label fx:id="labelArtistName" alignment="CENTER" styleClass="subLabel" text="Artist Name" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER">
<RowConstraints maxHeight="181.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" /> <font>
<RowConstraints maxHeight="181.0" minHeight="10.0" prefHeight="57.0" vgrow="SOMETIMES" /> <Font size="13.0" />
<RowConstraints maxHeight="49.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" /> </font>
<RowConstraints maxHeight="43.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" /> </Label>
<RowConstraints maxHeight="39.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" /> <Label fx:id="labelUserScrobbles" alignment="CENTER" styleClass="normalLabel" text="User Scrobbles" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER">
<RowConstraints maxHeight="37.0" minHeight="10.0" prefHeight="35.0" vgrow="SOMETIMES" /> <font>
</rowConstraints> <Font size="13.0" />
<children> </font>
<Label fx:id="labelTrackName" alignment="CENTER" styleClass="titleLabel" text="Track Name" wrapText="true" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.valignment="CENTER"> </Label>
<font> <Label fx:id="labelRatio" alignment="CENTER" styleClass="normalLabel" text="Ratio" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<Font name="System Bold" size="18.0" /> <font>
</font> <Font size="13.0" />
</Label> </font>
<Label fx:id="labelArtistName" alignment="CENTER" styleClass="subLabel" text="Artist Name" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER"> </Label>
<font> <Label fx:id="labelTotalListeners" alignment="CENTER" styleClass="normalLabel" text="Total Listeners" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<Font size="13.0" /> <font>
</font> <Font size="13.0" />
</Label> </font>
<Label fx:id="labelUserScrobbles" alignment="CENTER" styleClass="normalLabel" text="User Scrobbles" GridPane.halignment="CENTER" GridPane.rowIndex="3" GridPane.valignment="CENTER"> </Label>
<font> <Label fx:id="labelTotalScrobbles" alignment="CENTER" styleClass="normalLabel" text="Total Scrobbles" GridPane.halignment="CENTER" GridPane.rowIndex="6">
<Font size="13.0" /> <font>
</font> <Font size="13.0" />
</Label> </font>
<Label fx:id="labelRatio" alignment="CENTER" styleClass="normalLabel" text="Ratio" GridPane.halignment="CENTER" GridPane.rowIndex="4"> </Label>
<font> <Label fx:id="labelAlbumName" alignment="CENTER" styleClass="subLabel" text="Album Name" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<Font size="13.0" /> <font>
</font> <Font size="13.0" />
</Label> </font>
<Label fx:id="labelTotalListeners" alignment="CENTER" styleClass="normalLabel" text="Total Listeners" GridPane.halignment="CENTER" GridPane.rowIndex="5"> </Label>
<font>
<Font size="13.0" />
</font>
</Label>
<Label fx:id="labelTotalScrobbles" alignment="CENTER" styleClass="normalLabel" text="Total Scrobbles" GridPane.halignment="CENTER" GridPane.rowIndex="6">
<font>
<Font size="13.0" />
</font>
</Label>
<Label fx:id="labelAlbumName" alignment="CENTER" styleClass="subLabel" text="Album Name" GridPane.halignment="CENTER" GridPane.rowIndex="1">
<font>
<Font size="13.0" />
</font>
</Label>
</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="buttonViewAlbum" mnemonicParsing="false" onAction="#viewAlbum" text="view album" />
<Button fx:id="buttonViewArtist" mnemonicParsing="false" onAction="#viewArtist" text="view artist" />
<Button fx:id="buttonViewOnline" mnemonicParsing="false" onAction="#viewOnline" text="view online" />
</items>
</ToolBar>
</bottom>
</BorderPane>
</children> </children>
</AnchorPane> </AnchorPane>