migrating track to dynamic panes
This commit is contained in:
parent
3e8cd92fe7
commit
c6cf7123bb
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -49,9 +49,6 @@ public class TrackPaneController {
|
||||
@FXML
|
||||
private Button buttonViewAlbum;
|
||||
|
||||
@FXML
|
||||
private BorderPane trackBorderPane;
|
||||
|
||||
@FXML
|
||||
private AnchorPane infoAnchorPane;
|
||||
|
||||
@ -62,9 +59,7 @@ public class TrackPaneController {
|
||||
|
||||
Track track;
|
||||
|
||||
public void populate(Track track) {
|
||||
|
||||
this.track = track;
|
||||
public void refresh(Track track) {
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
@ -98,61 +93,61 @@ public class TrackPaneController {
|
||||
|
||||
textAreaWiki.setText(wiki.getContent() + "\n\n" + wiki.getDate());
|
||||
}else {
|
||||
trackBorderPane.setCenter(infoAnchorPane);
|
||||
// trackBorderPane.setCenter(infoAnchorPane);
|
||||
}
|
||||
|
||||
if (track.getAlbum() == null) {
|
||||
buttonViewAlbum.setVisible(false);
|
||||
// buttonViewAlbum.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleRefresh(ActionEvent event) {
|
||||
refresh();
|
||||
}
|
||||
// @FXML
|
||||
// protected void handleRefresh(ActionEvent event) {
|
||||
// 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
|
||||
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()));
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track);
|
||||
|
||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
|
||||
labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount())
|
||||
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName())));
|
||||
|
||||
labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
|
||||
labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
// public void refresh() {
|
||||
// track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track);
|
||||
//
|
||||
// NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
||||
//
|
||||
// labelUserScrobbles.setText(numberFormat.format(track.getUserPlayCount())
|
||||
// + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(track, Reference.getUserName())));
|
||||
//
|
||||
// labelTotalListeners.setText(numberFormat.format(track.getListeners()) + " Listeners");
|
||||
// labelTotalScrobbles.setText(numberFormat.format(track.getPlayCount()) + " Total Scrobbles");
|
||||
//
|
||||
// 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());
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ import java.io.IOException;
|
||||
|
||||
import javafx.scene.control.*;
|
||||
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.music.Track;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
@ -14,7 +16,11 @@ public class TrackTab extends Tab {
|
||||
|
||||
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();
|
||||
|
||||
@ -25,11 +31,7 @@ public class TrackTab extends Tab {
|
||||
|
||||
setContent(pane);
|
||||
|
||||
TrackPaneController control = (TrackPaneController) loader.getController();
|
||||
|
||||
control.populate(track);
|
||||
|
||||
|
||||
controller.populate(track);
|
||||
|
||||
}
|
||||
|
||||
|
@ -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.TrackPaneController">
|
||||
<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">
|
||||
<center>
|
||||
<SplitPane dividerPositions="0.5" prefHeight="327.0" prefWidth="600.0" BorderPane.alignment="CENTER">
|
||||
<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>
|
||||
@ -75,17 +73,5 @@
|
||||
</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="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>
|
||||
</AnchorPane>
|
||||
|
Loading…
Reference in New Issue
Block a user