added tag tab

This commit is contained in:
aj 2018-04-18 21:16:56 -07:00
parent 84562c700e
commit 7a0337ea19
8 changed files with 324 additions and 140 deletions

View File

@ -1,73 +1,43 @@
package sarsoo.fmframework.fx;
import java.io.IOException;
import java.text.NumberFormat;
import java.util.Collections;
import java.util.Locale;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import sarsoo.fmframework.fx.controller.FMObjListPaneController;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
public class FMObjListTab extends BorderPane{
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
public FMObjListTab(FMObjList list) {
getStylesheets().add("sarsoo/fmframework/fx/styles/FMObjListTab.css");
public class FMObjListTab extends Tab {
Collections.sort(list);
Collections.reverse(list);
public FMObjListTab(FMObjList list) throws IOException {
VBox stats = new VBox();
GridPane statsPane = new GridPane();
Label total = new Label(Integer.toString(list.getTotalUserScrobbles()));
total.getStyleClass().add("totalScrobbles");
statsPane.add(total, 0, 0);
setText(list.getGroupName());
double percent = Maths.getPercentListening(list, Reference.getUserName());
Label percentLabel = new Label(String.format("%.2f%%", percent));
percentLabel.getStyleClass().add("percent");
statsPane.add(percentLabel, 1, 0);
FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/FMObjListPane.fxml"));
stats.getChildren().add(statsPane);
setBottom(stats);
AnchorPane pane = (AnchorPane) loader.load();
ScrollPane scroll = new ScrollPane();
scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
AnchorPane.setTopAnchor(pane, 0.0);
AnchorPane.setLeftAnchor(pane, 0.0);
AnchorPane.setRightAnchor(pane, 0.0);
AnchorPane.setBottomAnchor(pane, 0.0);
GridPane pane = new GridPane();
scroll.setContent(pane);
setContent(pane);
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
FMObj FMObj;
int counter;
for(counter = 0; counter < list.size(); counter++) {
FMObj = list.get(counter);
FMObjListPaneController control = (FMObjListPaneController) loader.getController();
Label name = new Label(FMObj.getName());
name.getStyleClass().add("nameLabel");
control.populate(list);
Label scrobbles = new Label(numberFormat.format(FMObj.getUserPlayCount()));
Label totalScrobbles = new Label(numberFormat.format(FMObj.getPlayCount()));
totalScrobbles.getStyleClass().add("number");
pane.add(name, 0, counter);
pane.add(scrobbles, 1, counter);
pane.add(totalScrobbles, 2, counter);
}
ColumnConstraints column1 = new ColumnConstraints();
column1.setPercentWidth(50);
column1.setHgrow(Priority.ALWAYS);
ColumnConstraints column2 = new ColumnConstraints();
column2.setPercentWidth(25);
column2.setHgrow(Priority.ALWAYS);
pane.getColumnConstraints().add(column1);
pane.getColumnConstraints().add(column2);
pane.getColumnConstraints().add(column2);
setCenter(scroll);
}

View File

@ -7,20 +7,25 @@ import java.util.ArrayList;
import javax.swing.JOptionPane;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.text.Text;
import sarsoo.fmframework.fx.FMObjListTab;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Tag;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Getter;
import sarsoo.fmframework.util.Reference;
import javafx.scene.control.*;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.GridPane;
import javafx.scene.chart.*;
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.Parent;
import javafx.scene.layout.*;
@ -50,73 +55,179 @@ public class ControllerMain {
labelStatsUsername.setText(Reference.getUserName());
// updateGenrePieChart();
// updateGenrePieChart();
labelStatsScrobblesTotal
.setText(NumberFormat.getInstance().format(Getter.getScrobbles(Reference.getUserName())));
labelStatsScrobblesTotal.setText(NumberFormat.getInstance().format(Getter.getScrobbles(Reference.getUserName())));
tags = Getter.getUserTags(Reference.getUserName());
int counter;
for (counter = 0; counter < tags.size(); counter++) {
String name = tags.get(counter).getName();
// System.out.println(name);
MenuItem item = new MenuItem(name);
item.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
FMObjListTab tab = new FMObjListTab(Getter.getUserTag(Reference.getUserName(), name));
tabPane.getTabs().add(tab);
System.out.println("tab added");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
menuTag.getItems().add(item);
}
}
public void updateGenrePieChart() {
String[] names = {
"rock",
"rap",
"classic rock",
"pop punk",
"electronic",
"metal",
"grime",
"classic rap",
"indie",
"jazz",
"blues",
"core"
};
String[] names = { "rock", "rap", "classic rock", "pop punk", "electronic", "metal", "grime", "classic rap",
"indie", "jazz", "blues", "core" };
ObservableList<PieChart.Data> pieChartData =
FXCollections.observableArrayList(
// new PieChart.Data("rap", 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));
ObservableList<PieChart.Data> pieChartData = FXCollections.observableArrayList(
// new PieChart.Data("rap", 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);
}
@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("Album View");
//
// tab.setContent(pane);
//
// AlbumTabController albumControl = (AlbumTabController)loader.getController();
//
//
// albumControl.populateTab(Getter.getAlbum());
//
//
// tabPane.getTabs().add(tab);
Tab tab = new Tab("rock");
tab.setContent(new FMObjListTab(Getter.getUserTag(Reference.getUserName(), "rock")));
tabPane.getTabs().add(tab);
// 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("Album View");
//
// tab.setContent(pane);
//
// AlbumTabController albumControl = (AlbumTabController)loader.getController();
//
//
// albumControl.populateTab(Getter.getAlbum());
//
//
// tabPane.getTabs().add(tab);
// Tab tab = new Tab("rock");
//
// tab.setContent(new FMObjListTab(Getter.getUserTag(Reference.getUserName(),
// "rock")));
// tabPane.getTabs().add(tab);
//
}
@FXML
private Menu menuTag;
private ArrayList<Tag> tags;
@FXML
protected void handleTagClick(ActionEvent event) throws IOException {
// System.out.println("clicked");
if (tags == null) {
// System.out.println("list null");
tags = Getter.getUserTags(Reference.getUserName());
int counter;
for (counter = 0; counter < tags.size(); counter++) {
String name = tags.get(counter).getName();
// System.out.println(name);
MenuItem item = new MenuItem(name);
item.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
FMObjListTab tab = new FMObjListTab(Getter.getUserTag(Reference.getUserName(), name));
tabPane.getTabs().add(tab);
System.out.println("tab added");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
menuTag.getItems().add(item);
}
}
}
@FXML
protected void handleKeyShortcut(KeyEvent event) throws IOException {
if (event.getCode() == KeyCode.F5) {
refresh();
System.out.println("refreshed");
}
}
public void refresh() {
labelStatsScrobblesToday.setText(Integer.toString(Getter.getScrobblesToday(Reference.getUserName())));
labelStatsUsername.setText(Reference.getUserName());
labelStatsScrobblesTotal
.setText(NumberFormat.getInstance().format(Getter.getScrobbles(Reference.getUserName())));
tags = Getter.getUserTags(Reference.getUserName());
int counter;
for (counter = 0; counter < tags.size(); counter++) {
String name = tags.get(counter).getName();
// System.out.println(name);
MenuItem item = new MenuItem(name);
item.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
FMObjListTab tab = new FMObjListTab(Getter.getUserTag(Reference.getUserName(), name));
tabPane.getTabs().add(tab);
System.out.println("tab added");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
menuTag.getItems().clear();
menuTag.getItems().add(item);
}
}
}

View File

@ -0,0 +1,54 @@
package sarsoo.fmframework.fx.controller;
import java.text.NumberFormat;
import java.util.Collections;
import java.util.Locale;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import sarsoo.fmframework.music.FMObj;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Maths;
import sarsoo.fmframework.util.Reference;
import javafx.scene.layout.*;
public class FMObjListPaneController {
@FXML
private Label labelTotalScrobbles;
@FXML
private Label labelPercent;
@FXML
private GridPane gridPaneFMObjs;
public void populate(FMObjList list) {
double percent = Maths.getPercentListening(list, Reference.getUserName());
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
labelTotalScrobbles.setText("Σ" + list.getTotalUserScrobbles());
labelPercent.setText(String.format("%.2f%%", percent));
Collections.sort(list);
Collections.reverse(list);
int counter;
for(counter = 0; counter < list.size(); counter++) {
FMObj obj = list.get(counter);
Label name = new Label(obj.getName());
Label userScrobbles = new Label(numberFormat.format(obj.getUserPlayCount()));
Label totalScrobbles = new Label(numberFormat.format(obj.getPlayCount()));
gridPaneFMObjs.add(name, 0, counter);
gridPaneFMObjs.add(userScrobbles, 1, counter);
gridPaneFMObjs.add(totalScrobbles, 2, counter);
}
}
}

View File

@ -0,0 +1,9 @@
.statsLabel{
}
.pane{
}

View File

@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<AnchorPane styleClass="pane" stylesheets="@../styles/fmObjListTab.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.FMObjListPaneController">
<children>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" styleClass="pane" stylesheets="@../styles/fmObjListPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<center>
<ScrollPane fitToHeight="true" fitToWidth="true" prefViewportHeight="369.0" prefViewportWidth="600.0">
<content>
<GridPane fx:id="gridPaneFMObjs" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="301.0" minWidth="10.0" prefWidth="301.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="290.0" minWidth="10.0" prefWidth="157.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="194.0" minWidth="10.0" prefWidth="142.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="-Infinity" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</content>
</ScrollPane>
</center>
<top>
<VBox prefHeight="31.0" BorderPane.alignment="CENTER">
<children>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label fx:id="labelTotalScrobbles" styleClass="statsLabel" text="Label" GridPane.halignment="CENTER" />
<Label fx:id="labelPercent" styleClass="statsLabel" text="Label" GridPane.columnIndex="1" GridPane.halignment="CENTER" />
</children>
</GridPane>
</children>
</VBox>
</top>
</BorderPane>
</children>
</AnchorPane>

View File

@ -6,7 +6,7 @@
<?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">
<BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onKeyPressed="#handleKeyShortcut" 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>
@ -17,16 +17,7 @@
<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>
<Menu fx:id="menuTag" mnemonicParsing="false" text="Tags" />
</menus>
</MenuBar>
</top>
@ -45,7 +36,7 @@
</VBox>
</bottom>
<center>
<TabPane fx:id="tabPane" prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE" BorderPane.alignment="CENTER">
<TabPane fx:id="tabPane" prefHeight="200.0" prefWidth="200.0" side="LEFT" BorderPane.alignment="CENTER">
<tabs>
<Tab fx:id="tabHome" closable="false" text="home">
<content>

View File

@ -88,6 +88,7 @@ public class Getter {
doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
FMObjList list = Parser.parseUserTagList(doc);
list.setGroupName(tag);
System.out.println(pages);
if (pages > 1) {
@ -104,6 +105,7 @@ public class Getter {
}
return list;
}
return null;
}