started adding pane and pane switch handling

This commit is contained in:
aj 2019-05-04 12:26:32 +01:00
parent b776e91436
commit e4957364d2
15 changed files with 455 additions and 163 deletions

View File

@ -0,0 +1,37 @@
package sarsoo.fmframework.fx.controller;
import java.util.ArrayList;
import javafx.fxml.FXML;
import javafx.scene.chart.AreaChart;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.GridPane;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.music.Scrobble;
public class ScrobblesViewPaneController {
@FXML
private SplitPane splitPane;
@FXML
private GridPane gridPane;
@FXML
private AreaChart areaChart;
@FXML
public void initialize() {
}
public void populate(FMObj obj) {
ArrayList<Scrobble> scrobbles = obj.getScrobbles();
}
}

View File

@ -0,0 +1,96 @@
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.music.Artist;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Reference;
public class ArtistBorderPaneController extends FMObjBorderPaneController{
ArtistPaneController infoPaneController;
Artist artist;
@FXML
public void initialize() {
borderPane.setTop(null);
}
public void populate(Artist artist) {
this.artist = artist;
try {
loadInfoPane();
loadScrobblePane();
} catch (IOException e) {
e.printStackTrace();
}
setInfoView();
}
@Override
public void loadInfoPane() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/ArtistPane.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 = (ArtistPaneController) loader.getController();
infoPaneController.refresh(artist);
}
@Override
protected void handleViewOnline(ActionEvent event) {
Network.openURL(artist.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 {
artist = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(artist);
Platform.runLater(new Runnable() {
@Override
public void run() {
infoPaneController.refresh(artist);
}
});
return null;
}
};
}
};
service.start();
}
}

View File

@ -0,0 +1,85 @@
package sarsoo.fmframework.fx.controller.borderpane;
import java.io.IOException;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import sarsoo.fmframework.fx.controller.ScrobblesViewPaneController;
import sarsoo.fmframework.fx.tab.FMObjTab;
import sarsoo.fmframework.net.Network;
public abstract class FMObjBorderPaneController {
@FXML
protected ToolBar toolBar;
@FXML
protected ProgressBar progressBar;
@FXML
protected AnchorPane progressBarAnchorPane;
@FXML
protected Button buttonViewScrobbles;
@FXML
protected Button buttonViewInfo;
@FXML
protected BorderPane borderPane;
protected AnchorPane scrobbleAnchorPane;
protected ScrobblesViewPaneController scrobblePaneController;
protected AnchorPane infoAnchorPane;
@FXML
protected abstract void handleRefresh(ActionEvent event);
@FXML
protected void handleViewScrobbles(ActionEvent event) {
setScrobblesView();
}
@FXML
protected void handleViewInfo(ActionEvent event) {
setInfoView();
}
@FXML
protected abstract void handleViewOnline(ActionEvent event);
public void setScrobblesView() {
buttonViewInfo.setDisable(false);
buttonViewScrobbles.setDisable(true);
borderPane.setCenter(scrobbleAnchorPane);
}
public void setInfoView() {
buttonViewInfo.setDisable(true);
buttonViewScrobbles.setDisable(false);
borderPane.setCenter(infoAnchorPane);
}
public abstract void loadInfoPane()throws IOException;
public void loadScrobblePane() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/FMObjScrobblePane.fxml"));
this.scrobbleAnchorPane = (AnchorPane) loader.load();
AnchorPane.setTopAnchor(scrobbleAnchorPane, 0.0);
AnchorPane.setLeftAnchor(scrobbleAnchorPane, 0.0);
AnchorPane.setRightAnchor(scrobbleAnchorPane, 0.0);
AnchorPane.setBottomAnchor(scrobbleAnchorPane, 0.0);
this.scrobblePaneController = (ScrobblesViewPaneController) loader.getController();
}
}

View File

@ -1,4 +1,4 @@
package sarsoo.fmframework.fx.controller; package sarsoo.fmframework.fx.controller.info;
import java.io.IOException; import java.io.IOException;
import java.text.NumberFormat; import java.text.NumberFormat;

View File

@ -1,4 +1,4 @@
package sarsoo.fmframework.fx.controller; package sarsoo.fmframework.fx.controller.info;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Locale; import java.util.Locale;
@ -16,7 +16,7 @@ import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane; import javafx.scene.layout.BorderPane;
public class ArtistPaneController { public class ArtistPaneController{
@FXML @FXML
private Label labelArtistName; private Label labelArtistName;
@ -46,14 +46,10 @@ public class ArtistPaneController {
public void initialize() { public void initialize() {
} }
Artist artist;
public void populate(Artist artist) { public void refresh(Artist artist) {
this.artist = artist;
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
@ -84,57 +80,34 @@ public class ArtistPaneController {
artistBorderPane.setCenter(infoAnchorPane); artistBorderPane.setCenter(infoAnchorPane);
} }
} }
//
@FXML // public void refresh(Artist artist) {
protected void handleRefresh(ActionEvent event) { //
refresh(); // NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
} //
// labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount())
@FXML // + String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName())));
protected void viewOnline(ActionEvent event) { //
Network.openURL(artist.getUrl()); // labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners");
} // labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles");
//
// double ratio = artist.getTimeListenRatio();
@FXML //
protected void viewRYM(ActionEvent event) { //
Network.openURL(artist.getRymURL()); // if (ratio > 1) {
} // labelRatio.setText(String.format("listen every %.2f days", ratio));
// } else if (ratio == 1) {
@FXML // labelRatio.setText("listen every day");
protected void handleViewTracks(ActionEvent event) { // } else {
// labelRatio.setText(String.format("%.2f times a day", 1 / ratio));
// }
} //
// Wiki wiki = artist.getWiki();
public void refresh() { //
artist = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(artist); // if(wiki != null) {
//
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); // textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
// }
labelUserScrobbles.setText(numberFormat.format(artist.getUserPlayCount()) // }
+ String.format(" Scrobbles (%.2f%%)", Maths.getPercentListening(artist, Reference.getUserName())));
labelTotalListeners.setText(numberFormat.format(artist.getListeners()) + " Listeners");
labelTotalScrobbles.setText(numberFormat.format(artist.getPlayCount()) + " Total Scrobbles");
double ratio = artist.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 = artist.getWiki();
if(wiki != null) {
textAreaWiki.setText(wiki.getContent()+ "\n\n" + wiki.getDate());
}
}
} }

View File

@ -1,4 +1,4 @@
package sarsoo.fmframework.fx.controller; package sarsoo.fmframework.fx.controller.info;
import java.io.IOException; import java.io.IOException;
import java.text.NumberFormat; import java.text.NumberFormat;

View File

@ -4,7 +4,7 @@ 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.AlbumPaneController; import sarsoo.fmframework.fx.controller.info.AlbumPaneController;
import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.Album;

View File

@ -4,17 +4,21 @@ 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.ArtistPaneController; import sarsoo.fmframework.fx.controller.borderpane.ArtistBorderPaneController;
import sarsoo.fmframework.music.Artist; import sarsoo.fmframework.music.Artist;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
public class ArtistTab extends Tab { public class ArtistTab extends Tab{
public ArtistTab(Artist artist) throws IOException { public ArtistTab(Artist artist) throws IOException {
setText(artist.getName()); setText(artist.getName());
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/ArtistPane.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjBorderPane.fxml"));
ArtistBorderPaneController controller = new ArtistBorderPaneController();
loader.setController(controller);
AnchorPane pane = (AnchorPane) loader.load(); AnchorPane pane = (AnchorPane) loader.load();
@ -25,11 +29,7 @@ public class ArtistTab extends Tab {
setContent(pane); setContent(pane);
ArtistPaneController control = (ArtistPaneController) loader.getController(); controller.populate(artist);
control.populate(artist);
} }

View File

@ -0,0 +1,41 @@
package sarsoo.fmframework.fx.tab;
import java.io.IOException;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.Tab;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import sarsoo.fmframework.fx.controller.ScrobblesViewPaneController;
import sarsoo.fmframework.fx.controller.borderpane.FMObjBorderPaneController;
public abstract class FMObjTab extends Tab {
protected AnchorPane infoAnchorPane;
protected FMObjBorderPaneController controller;
protected FMObjTab() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjBorderPane.fxml"));
AnchorPane anchor = (AnchorPane) loader.load();
AnchorPane.setTopAnchor(anchor, 0.0);
AnchorPane.setLeftAnchor(anchor, 0.0);
AnchorPane.setRightAnchor(anchor, 0.0);
AnchorPane.setBottomAnchor(anchor, 0.0);
this.controller = (FMObjBorderPaneController) loader.getController();
setContent(anchor);
}
public AnchorPane getInfoAnchorPane() {
return infoAnchorPane;
}
public abstract AnchorPane loadInfoAnchorPane() throws IOException;
}

View File

@ -4,7 +4,7 @@ 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.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;

View File

@ -7,7 +7,7 @@
<?import javafx.scene.paint.*?> <?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.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"> <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> <center>

View File

@ -7,11 +7,9 @@
<?import javafx.scene.paint.*?> <?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.ArtistPaneController"> <AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.info.ArtistPaneController">
<children> <children>
<BorderPane fx:id="artistBorderPane" prefHeight="800.0" prefWidth="1000.0" stylesheets="@../styles/ObjPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> <SplitPane dividerPositions="0.6983967935871743" prefHeight="327.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<center>
<SplitPane dividerPositions="0.6983967935871743" 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>
@ -83,17 +81,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="buttonViewTracks" mnemonicParsing="false" onAction="#handleViewTracks" text="view tracks" />
<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>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<BorderPane fx:id="borderPane" prefHeight="800.0" prefWidth="1000.0" stylesheets="@../styles/ObjPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<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="buttonViewInfo" mnemonicParsing="false" onAction="#handleViewInfo" text="view info" />
<Button fx:id="buttonViewScrobbles" mnemonicParsing="false" onAction="#handleViewScrobbles" text="view scrobbles" />
<Button fx:id="buttonViewOnline" mnemonicParsing="false" onAction="#handleViewOnline" text="view online" />
</items>
</ToolBar>
</bottom>
<top>
<AnchorPane fx:id="progressBarAnchorPane" prefHeight="0.0" prefWidth="1000.0">
<children>
<ProgressBar fx:id="progressBar" prefHeight="30.0" prefWidth="1000.0" progress="0.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" BorderPane.alignment="CENTER" />
</children>
</AnchorPane>
</top>
</BorderPane>
</children>
</AnchorPane>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.chart.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.ScrobblesViewPaneController">
<children>
<SplitPane fx:id="splitPane" dividerPositions="0.4909819639278557" prefHeight="160.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane>
<children>
<GridPane fx:id="gridPane" prefHeight="798.0" prefWidth="486.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 hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
</GridPane>
</children>
</AnchorPane>
<AnchorPane fx:id="areaChartAnchorPane" minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<AreaChart fx:id="areaChart" layoutX="-93.0" layoutY="69.0" prefHeight="798.0" prefWidth="504.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<xAxis>
<CategoryAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis side="LEFT" />
</yAxis>
</AreaChart>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>

View File

@ -7,7 +7,7 @@
<?import javafx.scene.paint.*?> <?import javafx.scene.paint.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<AnchorPane xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.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"> <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> <center>