xml album tab view generating properly

This commit is contained in:
aj 2018-04-17 20:43:33 -07:00
parent fab130968c
commit 507f732861
7 changed files with 294 additions and 20 deletions

View File

@ -1,18 +0,0 @@
package sarsoo.fmframework.fx;
import javafx.fxml.FXML;
import javafx.scene.control.*;
public class Stats {
/*@FXML
private static Label scrobblesToday;
*//**
* @param scrobbles
*//*
public static void updateScrobblesToday(int scrobbles) {
// scrobblesToday.setText(Integer.toString(scrobbles));
}*/
}

View File

@ -0,0 +1,76 @@
package sarsoo.fmframework.fx.controller;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Locale;
import javax.swing.JOptionPane;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.text.Text;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Getter;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
import javafx.scene.control.*;
import javafx.scene.layout.GridPane;
import javafx.scene.chart.*;
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
public class AlbumTabController {
@FXML
private Label labelAlbumName;
@FXML
private Label labelArtistName;
@FXML
private Label labelUserScrobbles;
@FXML
private Label labelRatio;
@FXML
private Label labelTotalListeners;
@FXML
private Label labelTotalScrobbles;
@FXML
public void initialize() {
labelAlbumName.setText("Hello World");
}
public void populateTab(Album album) {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
labelAlbumName.setText(album.getName());
labelArtistName.setText(album.getArtist().getName());
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));
}
}
}

View File

@ -1,5 +1,6 @@
package sarsoo.fmframework.fx.controller; package sarsoo.fmframework.fx.controller;
import java.io.IOException;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -7,7 +8,9 @@ import javax.swing.JOptionPane;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.util.FMObjList; import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Getter; import sarsoo.fmframework.util.Getter;
import sarsoo.fmframework.util.Reference; import sarsoo.fmframework.util.Reference;
@ -17,6 +20,10 @@ import javafx.scene.chart.*;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.scene.Parent;
import javafx.scene.layout.*;
public class ControllerMain { public class ControllerMain {
@FXML @FXML
@ -31,6 +38,9 @@ public class ControllerMain {
@FXML @FXML
private PieChart pieChartGenres; private PieChart pieChartGenres;
@FXML
private TabPane tabPane;
@FXML @FXML
public void initialize() { public void initialize() {
Reference.setUserName("sarsoo"); Reference.setUserName("sarsoo");
@ -66,10 +76,40 @@ public class ControllerMain {
ObservableList<PieChart.Data> pieChartData = ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList( FXCollections.observableArrayList(
// new PieChart.Data("rap", Getter.getUserTag(Reference.getUserName(), "rap").getTotalUserScrobbles()), // new PieChart.Data("rap", Getter.getUserTag(Reference.getUserName(), "rap").getTotalUserScrobbles()),
new PieChart.Data("rock", Getter.getUserTag(Reference.getUserName(), "rap").getTotalUserScrobbles())); // new PieChart.Data("rock", Getter.getUserTag(Reference.getUserName(), "rap").getTotalUserScrobbles()),
new PieChart.Data("rock", 5),
new PieChart.Data("rock", 5),
new PieChart.Data("rock", 5));
pieChartGenres = new PieChart(pieChartData); pieChartGenres = new PieChart(pieChartData);
} }
@FXML
protected void handleLookupAlbum(ActionEvent event) throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/albumview.fxml"));
Pane pane = (Pane)loader.load();
// AlbumTabController controller = new AlbumTabController(Album.getAlbum("recovery", "eminem", Reference.getUserName()));
// loader.setController(controller);
// pane.setController(controller);
// Parent pane = loader.load();
Tab tab = new Tab("Recovery");
tab.setContent(pane);
AlbumTabController albumControl = (AlbumTabController)loader.getController();
albumControl.populateTab(Getter.getAlbum());
tabPane.getTabs().add(tab);
}
} }

View File

@ -0,0 +1,76 @@
<?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.*?>
<BorderPane prefHeight="327.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.AlbumTabController">
<center>
<SplitPane dividerPositions="0.5" prefHeight="327.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<items>
<AnchorPane 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>
<Label fx:id="labelAlbumName" alignment="CENTER" text="Album Name" wrapText="true" GridPane.halignment="CENTER" GridPane.valignment="CENTER">
<font>
<Font name="System Bold" size="18.0" />
</font>
</Label>
<Label fx:id="labelArtistName" alignment="CENTER" text="Artist Name" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER">
<font>
<Font size="13.0" />
</font>
</Label>
<Label fx:id="labelUserScrobbles" alignment="CENTER" text="User Scrobbles" GridPane.halignment="CENTER" GridPane.rowIndex="2" GridPane.valignment="CENTER">
<font>
<Font size="13.0" />
</font>
</Label>
<Label fx:id="labelRatio" alignment="CENTER" text="Ratio" GridPane.halignment="CENTER" GridPane.rowIndex="3">
<font>
<Font size="13.0" />
</font>
</Label>
<Label fx:id="labelTotalListeners" alignment="CENTER" text="Total Listeners" GridPane.halignment="CENTER" GridPane.rowIndex="4">
<font>
<Font size="13.0" />
</font>
</Label>
<Label fx:id="labelTotalScrobbles" alignment="CENTER" text="Total Scrobbles" GridPane.halignment="CENTER" GridPane.rowIndex="5">
<font>
<Font size="13.0" />
</font>
</Label>
</children>
</GridPane>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<TextArea fx:id="textAreaWiki" layoutX="37.0" layoutY="34.0" prefHeight="285.0" prefWidth="296.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</items>
</SplitPane>
</center>
<bottom>
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<Button mnemonicParsing="false" text="Button" />
</items>
</ToolBar>
</bottom>
</BorderPane>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.chart.*?> <?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?> <?import javafx.scene.control.*?>
<?import java.lang.*?> <?import java.lang.*?>
@ -12,7 +13,7 @@
<Menu fx:id="menuLookup" mnemonicParsing="false" text="Lookup"> <Menu fx:id="menuLookup" mnemonicParsing="false" text="Lookup">
<items> <items>
<MenuItem fx:id="menuItemTrack" mnemonicParsing="false" text="Track" /> <MenuItem fx:id="menuItemTrack" mnemonicParsing="false" text="Track" />
<MenuItem fx:id="menuItemAlbum" mnemonicParsing="false" text="Album" /> <MenuItem fx:id="menuItemAlbum" mnemonicParsing="false" onAction="#handleLookupAlbum" text="Album" />
<MenuItem fx:id="menuItemArtist" mnemonicParsing="false" text="Artist" /> <MenuItem fx:id="menuItemArtist" mnemonicParsing="false" text="Artist" />
</items> </items>
</Menu> </Menu>
@ -85,6 +86,7 @@
</AnchorPane> </AnchorPane>
</content> </content>
</Tab> </Tab>
</tabs></TabPane> </tabs></TabPane>
</center> </center>
</BorderPane> </BorderPane>

View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.chart.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.ControllerMain">
<top>
<MenuBar fx:id="menuBar" BorderPane.alignment="CENTER">
<menus>
<Menu fx:id="menuLookup" mnemonicParsing="false" text="Lookup">
<items>
<MenuItem fx:id="menuItemTrack" mnemonicParsing="false" text="Track" />
<MenuItem fx:id="menuItemAlbum" mnemonicParsing="false" onAction="#handleLookupAlbum" text="Album" />
<MenuItem fx:id="menuItemArtist" mnemonicParsing="false" text="Artist" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
<bottom>
<VBox fx:id="vBoxStats" prefHeight="19.0" prefWidth="600.0" BorderPane.alignment="CENTER">
<children>
<FlowPane fx:id="flowPlaneStats" alignment="TOP_RIGHT" prefHeight="20.0" prefWidth="600.0" styleClass="vBoxStats" stylesheets="@../styles/mainPane.css" VBox.vgrow="NEVER">
<children>
<Label fx:id="labelStatsUsername" styleClass="vBoxStatsLabel" stylesheets="@../styles/mainPane.css" text="user" />
<Label fx:id="labelStatsScrobblesToday" styleClass="vBoxStatsLabel" stylesheets="@../styles/mainPane.css" text="scrobblesToday" />
<Label fx:id="labelStatsSlash" styleClass="vBoxStatsLabel" stylesheets="@../styles/mainPane.css" text="/" />
<Label fx:id="labelStatsScrobblesTotal" styleClass="vBoxStatsLabel" stylesheets="@../styles/mainPane.css" text="scrobblesTotal" />
</children>
</FlowPane>
</children>
</VBox>
</bottom>
<center>
<TabPane fx:id="tabPane" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<tabs>
<Tab fx:id="tabHome" closable="false" text="home">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<SplitPane fx:id="splitPaneHome" dividerPositions="0.6237458193979933" prefHeight="327.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<Accordion fx:id="accordionCharts" prefHeight="325.0" prefWidth="222.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<panes>
<TitledPane fx:id="titledPaneGenres" animated="false" text="genres">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<PieChart fx:id="pieChartGenres" layoutX="-189.0" layoutY="-102.0" prefHeight="249.0" prefWidth="220.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane fx:id="titledPaneRap" animated="false" text="rap">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<PieChart prefHeight="274.0" prefWidth="220.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</TitledPane>
</panes>
</Accordion>
</children>
</AnchorPane>
</items>
</SplitPane>
</children>
</AnchorPane>
</content>
</Tab>
</tabs></TabPane>
</center>
</BorderPane>

View File

@ -1,7 +1,9 @@
package sarsoo.fmframework.music; package sarsoo.fmframework.music;
import sarsoo.fmframework.jframe.FMObjView; import sarsoo.fmframework.jframe.FMObjView;
import sarsoo.fmframework.util.Getter;
import sarsoo.fmframework.util.Maths; import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
public abstract class FMObj implements Comparable<FMObj>{ public abstract class FMObj implements Comparable<FMObj>{
@ -68,6 +70,10 @@ public abstract class FMObj implements Comparable<FMObj>{
return userPlayCount; return userPlayCount;
} }
public double getPercent() {
return ((double)userPlayCount*100)/(double) Getter.getScrobbles(Reference.getUserName());
}
public Wiki getWiki() { public Wiki getWiki() {
return wiki; return wiki;
} }