diff --git a/fmframework/src/sarsoo/fmframework/fx/FmFramework.java b/fmframework/src/sarsoo/fmframework/fx/FmFramework.java index a04939d..2b64a8b 100644 --- a/fmframework/src/sarsoo/fmframework/fx/FmFramework.java +++ b/fmframework/src/sarsoo/fmframework/fx/FmFramework.java @@ -26,13 +26,15 @@ public class FmFramework extends Application { // Parent root = FXMLLoader.load(getClass().getResource("ui/main.fxml")); Parent root = (Parent)loader.load(); - Scene scene = new Scene(root, 800, 400); + Scene scene = new Scene(root, 1000, 800); rootScene = scene; // scene.getStylesheets().add("styles/style.css"); control = (ControllerMain)loader.getController(); - +// (new Thread(new TagCaller())).start(); + stage.setMinHeight(800); + stage.setMinWidth(1000); stage.setTitle("fm framework"); stage.setScene(scene); stage.show(); diff --git a/fmframework/src/sarsoo/fmframework/fx/TagCaller.java b/fmframework/src/sarsoo/fmframework/fx/TagCaller.java new file mode 100644 index 0000000..d0bf0aa --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/TagCaller.java @@ -0,0 +1,14 @@ +package sarsoo.fmframework.fx; + +import javafx.concurrent.*; +import sarsoo.fmframework.util.Getter; +import sarsoo.fmframework.util.Reference; + +public class TagCaller extends Task{ + + @Override + protected Object call() throws Exception { + + return Getter.getUserTags(Reference.getUserName()); + } +} diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java index 824004e..a5a6385 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java @@ -3,6 +3,7 @@ package sarsoo.fmframework.fx.controller; import java.io.IOException; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.concurrent.CountDownLatch; import javax.swing.JOptionPane; @@ -15,9 +16,12 @@ import javafx.scene.text.Text; import sarsoo.fmframework.fx.AlbumTab; import sarsoo.fmframework.fx.ArtistTab; import sarsoo.fmframework.fx.FMObjListTab; +import sarsoo.fmframework.fx.FmFramework; import sarsoo.fmframework.fx.TrackTab; import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.Artist; import sarsoo.fmframework.music.Tag; +import sarsoo.fmframework.music.Track; import sarsoo.fmframework.util.FMObjList; import sarsoo.fmframework.util.Getter; import sarsoo.fmframework.util.Reference; @@ -33,6 +37,9 @@ import javafx.scene.Parent; import javafx.scene.layout.*; +import javafx.concurrent.*; +import javafx.application.Platform; + public class ControllerMain { @FXML @@ -81,7 +88,7 @@ public class ControllerMain { FMObjListTab tab = new FMObjListTab(Getter.getUserTag(Reference.getUserName(), name)); tabPane.getTabs().add(tab); -// System.out.println("tab added"); + // System.out.println("tab added"); } catch (IOException e1) { e1.printStackTrace(); } @@ -91,6 +98,31 @@ public class ControllerMain { menuTag.getItems().add(item); } + // FMObjList rap = Getter.getUserTag(Reference.getUserName(), "rap"); + // FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic + // rap"); + // FMObjList grime = Getter.getUserTag(Reference.getUserName(), "grime"); + // + // int rapTotal = rap.getTotalUserScrobbles() - + // classicRap.getTotalUserScrobbles() - grime.getTotalUserScrobbles(); + // + // ObservableList rapData = FXCollections.observableArrayList( + // new PieChart.Data("rap", rapTotal), + // new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()), + // new PieChart.Data("grime", grime.getTotalUserScrobbles())); + // pieChartRap.setData(rapData); + // + // int other = Getter.getScrobbles(Reference.getUserName()) - + // rap.getTotalUserScrobbles(); + // + // ObservableList rapTotalData = + // FXCollections.observableArrayList( + // new PieChart.Data("rap", rapTotal), + // new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()), + // new PieChart.Data("grime", grime.getTotalUserScrobbles()), + // new PieChart.Data("other", other)); + // pieChartRapTotal.setData(rapTotalData); + } public void updateGenrePieChart() { @@ -99,10 +131,7 @@ public class ControllerMain { "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); @@ -111,53 +140,30 @@ public class ControllerMain { @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); - // - tabPane.getTabs().add(new AlbumTab(Getter.getAlbum())); } - + @FXML protected void handleLookupArtist(ActionEvent event) throws IOException { tabPane.getTabs().add(new ArtistTab(Getter.getArtist())); } - + @FXML protected void handleLookupTrack(ActionEvent event) throws IOException { tabPane.getTabs().add(new TrackTab(Getter.getTrack())); } + @FXML + protected void handleScrobble(ActionEvent event) throws IOException { + Album album = Getter.getAlbum(); + if (album != null) { + Track track = Getter.getTrack(album); + + } + } + @FXML private Menu menuTag; @@ -205,7 +211,7 @@ public class ControllerMain { if (event.getCode() == KeyCode.F5) { refresh(); -// System.out.println("refreshed"); + // System.out.println("refreshed"); } } @@ -218,7 +224,8 @@ public class ControllerMain { .setText(NumberFormat.getInstance().format(Getter.getScrobbles(Reference.getUserName()))); tags = Getter.getUserTags(Reference.getUserName()); - + menuTag.getItems().clear(); + int counter; for (counter = 0; counter < tags.size(); counter++) { @@ -241,8 +248,6 @@ public class ControllerMain { } } }); - - menuTag.getItems().clear(); menuTag.getItems().add(item); } } @@ -250,7 +255,81 @@ public class ControllerMain { public void addTab(Tab tab) { tabPane.getTabs().add(tab); SingleSelectionModel selectionModel = tabPane.getSelectionModel(); - + selectionModel.select(tab); } + + @FXML + private PieChart pieChartRap; + + @FXML + private PieChart pieChartRapTotal; + + @FXML + private Accordion accordionCharts; + + @FXML + private TitledPane titledPaneGenres; + + @FXML + private TitledPane titledPaneRap; + + @FXML + protected void handleRefreshPieChart(ActionEvent event) throws IOException { + + refreshPieCharts(); + + } + + public void refreshPieCharts() { + Service service = new Service() { + @Override + protected Task createTask() { + return new Task() { + @Override + protected Void call() throws Exception { + + FMObjList rap = Getter.getUserTag(Reference.getUserName(), "rap"); + FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic rap"); + FMObjList grime = Getter.getUserTag(Reference.getUserName(), "grime"); + + int rapTotal = rap.getTotalUserScrobbles() - classicRap.getTotalUserScrobbles() - grime.getTotalUserScrobbles(); + + ObservableList rapData = FXCollections.observableArrayList(new PieChart.Data("rap", rapTotal), + new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()), + new PieChart.Data("grime", grime.getTotalUserScrobbles())); + + int other = Getter.getScrobbles(Reference.getUserName()) - rap.getTotalUserScrobbles(); + + ObservableList rapTotalData = FXCollections.observableArrayList( + new PieChart.Data("rap", rapTotal), + new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()), + new PieChart.Data("grime", grime.getTotalUserScrobbles()), new PieChart.Data("other", other)); + + final CountDownLatch latch = new CountDownLatch(1); + Platform.runLater(new Runnable() { + @Override + public void run() { + try{ + pieChartRap.setData(rapData); + + + pieChartRapTotal.setData(rapTotalData); + + accordionCharts.setExpandedPane(titledPaneRap); + }finally{ + latch.countDown(); + } + } + }); + latch.await(); + //Keep with the background work + return null; + } + }; + } + }; + service.start(); + } + } diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java index 23392be..55011ea 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/FMObjListPaneController.java @@ -5,6 +5,9 @@ import java.text.NumberFormat; import java.util.Collections; import java.util.Locale; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; import javafx.event.Event; import javafx.event.EventHandler; import javafx.fxml.FXML; @@ -16,9 +19,11 @@ import sarsoo.fmframework.fx.FmFramework; import sarsoo.fmframework.music.Artist; import sarsoo.fmframework.music.FMObj; import sarsoo.fmframework.util.FMObjList; +import sarsoo.fmframework.util.Getter; import sarsoo.fmframework.util.Maths; import sarsoo.fmframework.util.Reference; import javafx.scene.layout.*; +import javafx.scene.chart.*; public class FMObjListPaneController { @@ -30,8 +35,15 @@ public class FMObjListPaneController { @FXML private GridPane gridPaneFMObjs; + + @FXML + private PieChart pieChart; + + private FMObjList list; public void populate(FMObjList list) { + this.list = list; + double percent = Maths.getPercentListening(list, Reference.getUserName()); NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); @@ -47,7 +59,9 @@ public class FMObjListPaneController { FMObj obj = list.get(counter); Label name = new Label(obj.getName().toLowerCase()); - + + name.getStyleClass().add("nameLabel"); + name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { @Override @@ -72,7 +86,73 @@ public class FMObjListPaneController { gridPaneFMObjs.add(totalScrobbles, 2, counter); } + + + + ObservableList pieChartData = FXCollections.observableArrayList( + new PieChart.Data(list.getGroupName(), list.getTotalUserScrobbles()), + new PieChart.Data("other", Getter.getScrobbles(Reference.getUserName()) - list.getTotalUserScrobbles())); + pieChart.setData(pieChartData); } + + @FXML + protected void handleRefresh(ActionEvent event) { + + list = Getter.getUserTag(Reference.getUserName(), list.getGroupName()); + + + 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); + + gridPaneFMObjs.getChildren().clear(); + + int counter; + for (counter = 0; counter < list.size(); counter++) { + + FMObj obj = list.get(counter); + + Label name = new Label(obj.getName().toLowerCase()); + + name.getStyleClass().add("nameLabel"); + + name.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler() { + + @Override + public void handle(Event event) { + + try { + FmFramework.getController().addTab(new ArtistTab((Artist) obj)); + } catch (IOException e) { + + e.printStackTrace(); + } + + } + + }); + + 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); + + } + + + + ObservableList pieChartData = FXCollections.observableArrayList( + new PieChart.Data(list.getGroupName(), list.getTotalUserScrobbles()), + new PieChart.Data("other", Getter.getScrobbles(Reference.getUserName()) - list.getTotalUserScrobbles())); + pieChart.setData(pieChartData); + } } diff --git a/fmframework/src/sarsoo/fmframework/fx/styles/FMObjListPane.css b/fmframework/src/sarsoo/fmframework/fx/styles/FMObjListPane.css index c4115e7..900bf39 100644 --- a/fmframework/src/sarsoo/fmframework/fx/styles/FMObjListPane.css +++ b/fmframework/src/sarsoo/fmframework/fx/styles/FMObjListPane.css @@ -1,7 +1,9 @@ .nameLabel{ -fx-alignment: center; - + -fx-font-size: 150%; -fx-font-style: italic; + -fx-text-alignment: center; + } @@ -18,9 +20,27 @@ } -.percent{ - -fx-text-alignment: right; +.stats{ + + + -fx-font-size: 300%; -fx-font-style: italic; -} \ No newline at end of file +} + +.pane{ + + + +} + +.pieChart{ + + -fx-start-angle: 90; + + +} + +.default-color0.chart-pie { -fx-pie-color: #820000; } +.default-color1.chart-pie { -fx-pie-color: #49505b; } \ No newline at end of file diff --git a/fmframework/src/sarsoo/fmframework/fx/styles/ObjPane.css b/fmframework/src/sarsoo/fmframework/fx/styles/ObjPane.css new file mode 100644 index 0000000..c23a1c8 --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/fx/styles/ObjPane.css @@ -0,0 +1,22 @@ +.title{ + + -fx-font-size: 400%; + +} + +.sub{ + + + +} + +.wiki{ + + +} + +.stats{ + + + +} \ No newline at end of file diff --git a/fmframework/src/sarsoo/fmframework/fx/styles/fmObjListTab.css b/fmframework/src/sarsoo/fmframework/fx/styles/fmObjListTab.css deleted file mode 100644 index aff8253..0000000 --- a/fmframework/src/sarsoo/fmframework/fx/styles/fmObjListTab.css +++ /dev/null @@ -1,9 +0,0 @@ -.statsLabel{ - - -} - -.pane{ - - -} \ No newline at end of file diff --git a/fmframework/src/sarsoo/fmframework/fx/styles/mainPane.css b/fmframework/src/sarsoo/fmframework/fx/styles/mainPane.css index df72bdc..8c82183 100644 --- a/fmframework/src/sarsoo/fmframework/fx/styles/mainPane.css +++ b/fmframework/src/sarsoo/fmframework/fx/styles/mainPane.css @@ -10,4 +10,9 @@ .vBoxStatsLabel{ -fx-text-fill: white; +} + +.pieChart{ + + -fx-start-angle: 90; } \ No newline at end of file diff --git a/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml b/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml index 40dfdbb..fa2d7e2 100644 --- a/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml +++ b/fmframework/src/sarsoo/fmframework/fx/ui/AlbumPane.fxml @@ -9,7 +9,7 @@ - +
@@ -28,12 +28,12 @@ -