From 7a0337ea19a0c61c1ff8fda7a312a2072e698bd2 Mon Sep 17 00:00:00 2001 From: aj Date: Wed, 18 Apr 2018 21:16:56 -0700 Subject: [PATCH] added tag tab --- .../sarsoo/fmframework/fx/FMObjListTab.java | 82 ++---- .../fx/controller/ControllerMain.java | 255 +++++++++++++----- .../controller/FMObjListPaneController.java | 54 ++++ .../{FMObjListTab.css => FMObjListPane.css} | 0 .../fmframework/fx/styles/fmObjListTab.css | 9 + .../fmframework/fx/ui/FMObjListPane.fxml | 47 ++++ .../src/sarsoo/fmframework/fx/ui/main.fxml | 15 +- .../src/sarsoo/fmframework/util/Getter.java | 2 + 8 files changed, 324 insertions(+), 140 deletions(-) create mode 100644 fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java rename fmframework/src/sarsoo/fmframework/fx/styles/{FMObjListTab.css => FMObjListPane.css} (100%) create mode 100644 fmframework/src/sarsoo/fmframework/fx/styles/fmObjListTab.css create mode 100644 fmframework/src/sarsoo/fmframework/fx/ui/FMObjListPane.fxml diff --git a/fmframework/src/sarsoo/fmframework/fx/FMObjListTab.java b/fmframework/src/sarsoo/fmframework/fx/FMObjListTab.java index 2ed57d6..82bc040 100644 --- a/fmframework/src/sarsoo/fmframework/fx/FMObjListTab.java +++ b/fmframework/src/sarsoo/fmframework/fx/FMObjListTab.java @@ -1,74 +1,44 @@ 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{ - - public FMObjListTab(FMObjList list) { - getStylesheets().add("sarsoo/fmframework/fx/styles/FMObjListTab.css"); - - Collections.sort(list); - Collections.reverse(list); - - 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); - - double percent = Maths.getPercentListening(list, Reference.getUserName()); - Label percentLabel = new Label(String.format("%.2f%%", percent)); - percentLabel.getStyleClass().add("percent"); - statsPane.add(percentLabel, 1, 0); - - stats.getChildren().add(statsPane); - setBottom(stats); - - ScrollPane scroll = new ScrollPane(); - scroll.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; - GridPane pane = new GridPane(); - scroll.setContent(pane); +public class FMObjListTab extends Tab { + + public FMObjListTab(FMObjList list) throws IOException { + + setText(list.getGroupName()); + + FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/FMObjListPane.fxml")); + + AnchorPane pane = (AnchorPane) loader.load(); + + AnchorPane.setTopAnchor(pane, 0.0); + AnchorPane.setLeftAnchor(pane, 0.0); + AnchorPane.setRightAnchor(pane, 0.0); + AnchorPane.setBottomAnchor(pane, 0.0); + + setContent(pane); + + FMObjListPaneController control = (FMObjListPaneController) loader.getController(); + + control.populate(list); - NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); - FMObj FMObj; - int counter; - for(counter = 0; counter < list.size(); counter++) { - FMObj = list.get(counter); - - Label name = new Label(FMObj.getName()); - name.getStyleClass().add("nameLabel"); - - 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); + } - + } diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java index ecf2a72..9d05623 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java @@ -7,116 +7,227 @@ 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.*; public class ControllerMain { - + @FXML private Label labelStatsScrobblesToday; - + @FXML private Label labelStatsUsername; - + @FXML private Label labelStatsScrobblesTotal; - + @FXML private PieChart pieChartGenres; - + @FXML private TabPane tabPane; - + @FXML public void initialize() { Reference.setUserName("sarsoo"); - + labelStatsScrobblesToday.setText(Integer.toString(Getter.getScrobblesToday(Reference.getUserName()))); - + labelStatsUsername.setText(Reference.getUserName()); - - -// updateGenrePieChart(); - - labelStatsScrobblesTotal.setText(NumberFormat.getInstance().format(Getter.getScrobbles(Reference.getUserName()))); - + + // updateGenrePieChart(); + + 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() { + @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" - }; - - ObservableList 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); - - + String[] names = { "rock", "rap", "classic rock", "pop punk", "electronic", "metal", "grime", "classic rap", + "indie", "jazz", "blues", "core" }; + + ObservableList 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 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() { + @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() { + @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); + } + } + } diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java new file mode 100644 index 0000000..49db885 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java @@ -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); + + + } + + } + +} diff --git a/fmframework/src/sarsoo/fmframework/fx/styles/FMObjListTab.css b/fmframework/src/sarsoo/fmframework/fx/styles/FMObjListPane.css similarity index 100% rename from fmframework/src/sarsoo/fmframework/fx/styles/FMObjListTab.css rename to fmframework/src/sarsoo/fmframework/fx/styles/FMObjListPane.css diff --git a/fmframework/src/sarsoo/fmframework/fx/styles/fmObjListTab.css b/fmframework/src/sarsoo/fmframework/fx/styles/fmObjListTab.css new file mode 100644 index 0000000..aff8253 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/styles/fmObjListTab.css @@ -0,0 +1,9 @@ +.statsLabel{ + + +} + +.pane{ + + +} \ No newline at end of file diff --git a/fmframework/src/sarsoo/fmframework/fx/ui/FMObjListPane.fxml b/fmframework/src/sarsoo/fmframework/fx/ui/FMObjListPane.fxml new file mode 100644 index 0000000..b78d041 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/ui/FMObjListPane.fxml @@ -0,0 +1,47 @@ + + + + + + + + + +
+ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + +
+
+
diff --git a/fmframework/src/sarsoo/fmframework/fx/ui/main.fxml b/fmframework/src/sarsoo/fmframework/fx/ui/main.fxml index 1a3f6d1..71c5abb 100644 --- a/fmframework/src/sarsoo/fmframework/fx/ui/main.fxml +++ b/fmframework/src/sarsoo/fmframework/fx/ui/main.fxml @@ -6,7 +6,7 @@ - + @@ -17,16 +17,7 @@ - - - - - - - - - - + @@ -45,7 +36,7 @@
- + diff --git a/fmframework/src/sarsoo/fmframework/util/Getter.java b/fmframework/src/sarsoo/fmframework/util/Getter.java index 4374aaf..1b234a7 100644 --- a/fmframework/src/sarsoo/fmframework/util/Getter.java +++ b/fmframework/src/sarsoo/fmframework/util/Getter.java @@ -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; }