diff --git a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java index 90635c4..4a265a5 100644 --- a/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java +++ b/fmframework/src/sarsoo/fmframework/fx/controller/ControllerMain.java @@ -3,6 +3,8 @@ package sarsoo.fmframework.fx.controller; import java.io.IOException; import java.text.NumberFormat; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.Locale; import java.util.concurrent.CountDownLatch; @@ -30,6 +32,7 @@ import javafx.scene.control.*; import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; import javafx.scene.chart.*; +import javafx.scene.chart.PieChart.Data; import javafx.collections.ObservableList; import javafx.collections.FXCollections; import javafx.scene.input.KeyCode; @@ -75,6 +78,8 @@ public class ControllerMain { String scrobbles = numberFormat.format(Getter.getScrobbles(Reference.getUserName())); tags = Getter.getUserTags(Reference.getUserName()); + TrackTab tab = new TrackTab(Getter.getLastTrack()); + final CountDownLatch latch = new CountDownLatch(1); Platform.runLater(new Runnable() { @Override @@ -84,6 +89,8 @@ public class ControllerMain { labelStatsScrobblesToday.setText(scrobblesToday); labelStatsUsername.setText(Reference.getUserName()); labelStatsScrobblesTotal.setText(scrobbles); + + addTab(tab); refreshPieCharts(); @@ -173,7 +180,7 @@ public class ControllerMain { @Override protected Void call() throws Exception { - Album album = Getter.getAlbum(); + Album album = sarsoo.fmframework.jframe.Getter.getAlbum(); if (album != null) { AlbumTab tab = new AlbumTab(album); @@ -210,7 +217,7 @@ public class ControllerMain { @Override protected Void call() throws Exception { - Artist artist = Getter.getArtist(); + Artist artist = sarsoo.fmframework.jframe.Getter.getArtist(); if (artist != null) { ArtistTab tab = new ArtistTab(artist); @@ -249,7 +256,7 @@ public class ControllerMain { @Override protected Void call() throws Exception { - Track track = Getter.getTrack(); + Track track = sarsoo.fmframework.jframe.Getter.getTrack(); if (track != null) { TrackTab tab = new TrackTab(track); @@ -278,9 +285,9 @@ public class ControllerMain { @FXML protected void handleScrobble(ActionEvent event) throws IOException { - Album album = Getter.getAlbum(); + Album album = sarsoo.fmframework.jframe.Getter.getAlbum(); if (album != null) { - Track track = Getter.getTrack(album); + Track track = sarsoo.fmframework.jframe.Getter.getTrack(album); } } @@ -361,7 +368,7 @@ public class ControllerMain { labelStatsUsername.setText(Reference.getUserName()); labelStatsScrobblesTotal.setText(scrobbles); - refreshPieCharts(); +// refreshPieCharts(); menuTag.getItems().clear(); int counter; @@ -464,11 +471,24 @@ public class ControllerMain { return new Task() { @Override protected Void call() throws Exception { + + int total = Getter.getScrobbles(Reference.getUserName()); FMObjList rap = Getter.getUserTag(Reference.getUserName(), "rap"); FMObjList classicRap = Getter.getUserTag(Reference.getUserName(), "classic rap"); FMObjList grime = Getter.getUserTag(Reference.getUserName(), "grime"); - + + FMObjList classicRock = Getter.getUserTag(Reference.getUserName(), "classic rock"); + FMObjList popPunk = Getter.getUserTag(Reference.getUserName(), "pop punk"); + FMObjList electronic = Getter.getUserTag(Reference.getUserName(), "electronic"); + FMObjList metal = Getter.getUserTag(Reference.getUserName(), "metal"); + FMObjList indie = Getter.getUserTag(Reference.getUserName(), "indie"); + FMObjList rock = Getter.getUserTag(Reference.getUserName(), "rock"); + FMObjList jazz = Getter.getUserTag(Reference.getUserName(), "jazz"); + FMObjList blues = Getter.getUserTag(Reference.getUserName(), "blues"); + FMObjList core = Getter.getUserTag(Reference.getUserName(), "core"); + FMObjList rnb = Getter.getUserTag(Reference.getUserName(), "rnb"); + int rapTotal = rap.getTotalUserScrobbles() - classicRap.getTotalUserScrobbles() - grime.getTotalUserScrobbles(); @@ -476,14 +496,70 @@ public class ControllerMain { new PieChart.Data("rap", rapTotal), new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()), new PieChart.Data("grime", grime.getTotalUserScrobbles())); + + Collections.sort(rapData, new Comparator() { - int other = Getter.getScrobbles(Reference.getUserName()) - rap.getTotalUserScrobbles(); + @Override + public int compare(Data arg0, Data arg1) { + return (int) (arg1.getPieValue() - arg0.getPieValue()); + } + }); + + + int other = total - rap.getTotalUserScrobbles(); ObservableList rapTotalData = FXCollections.observableArrayList( + new PieChart.Data("rap", rapTotal), + new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()), + new PieChart.Data("grime", grime.getTotalUserScrobbles())); + + Collections.sort(rapTotalData, new Comparator() { + + @Override + public int compare(Data arg0, Data arg1) { + return (int) (arg1.getPieValue() - arg0.getPieValue()); + } + }); + + rapTotalData.add(new PieChart.Data("other", other)); + + int totalOther = total - rap.getTotalUserScrobbles() + - classicRock.getTotalUserScrobbles() + - popPunk.getTotalUserScrobbles() + - electronic.getTotalUserScrobbles() + - metal.getTotalUserScrobbles() + - indie.getTotalUserScrobbles() + - rock.getTotalUserScrobbles() + - jazz.getTotalUserScrobbles() + - blues.getTotalUserScrobbles() + - core.getTotalUserScrobbles() + - rnb.getTotalUserScrobbles(); + + ObservableList genreData = 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)); + + new PieChart.Data("classic rock", classicRock.getTotalUserScrobbles()), + new PieChart.Data("pop punk", popPunk.getTotalUserScrobbles()), + new PieChart.Data("electronic", electronic.getTotalUserScrobbles()), + new PieChart.Data("metal", metal.getTotalUserScrobbles()), + new PieChart.Data("indie", indie.getTotalUserScrobbles()), + new PieChart.Data("rock", rock.getTotalUserScrobbles()), + new PieChart.Data("jazz", jazz.getTotalUserScrobbles()), + new PieChart.Data("blues", blues.getTotalUserScrobbles()), + new PieChart.Data("core", core.getTotalUserScrobbles()), + new PieChart.Data("rnb", rnb.getTotalUserScrobbles())); + + Collections.sort(genreData, new Comparator() { + + @Override + public int compare(Data arg0, Data arg1) { + return (int) (arg1.getPieValue() - arg0.getPieValue()); + } + }); + + genreData.add(new PieChart.Data("other", totalOther)); final CountDownLatch latch = new CountDownLatch(1); Platform.runLater(new Runnable() { @@ -493,6 +569,8 @@ public class ControllerMain { pieChartRap.setData(rapData); pieChartRapTotal.setData(rapTotalData); + + pieChartGenres.setData(genreData); accordionCharts.setExpandedPane(titledPaneRap); } finally { diff --git a/fmframework/src/sarsoo/fmframework/fx/ui/main.fxml b/fmframework/src/sarsoo/fmframework/fx/ui/main.fxml index 21e3f9a..bcae3e4 100644 --- a/fmframework/src/sarsoo/fmframework/fx/ui/main.fxml +++ b/fmframework/src/sarsoo/fmframework/fx/ui/main.fxml @@ -60,7 +60,7 @@ - + diff --git a/fmframework/src/sarsoo/fmframework/jframe/FMObjListView.java b/fmframework/src/sarsoo/fmframework/jframe/FMObjListView.java index f180b39..830a601 100644 --- a/fmframework/src/sarsoo/fmframework/jframe/FMObjListView.java +++ b/fmframework/src/sarsoo/fmframework/jframe/FMObjListView.java @@ -166,7 +166,7 @@ public class FMObjListView extends JFrame { addAlbum.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { - Album album = Getter.getAlbum(); + Album album = sarsoo.fmframework.jframe.Getter.getAlbum(); if (album != null) { } diff --git a/fmframework/src/sarsoo/fmframework/jframe/Getter.java b/fmframework/src/sarsoo/fmframework/jframe/Getter.java new file mode 100644 index 0000000..a4d20fb --- /dev/null +++ b/fmframework/src/sarsoo/fmframework/jframe/Getter.java @@ -0,0 +1,52 @@ +package sarsoo.fmframework.jframe; + +import javax.swing.JOptionPane; + +import sarsoo.fmframework.music.Album; +import sarsoo.fmframework.music.Artist; +import sarsoo.fmframework.music.Track; +import sarsoo.fmframework.util.Reference; + +public class Getter { + + public static Album getAlbum() { + String albumName = JOptionPane.showInputDialog(null, "Enter Album Name"); + if (albumName != null) { + String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name"); + if (artistName != null) { + return Album.getAlbum(albumName, artistName, Reference.getUserName()); + } + } + return null; + } + + public static Artist getArtist() { + String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name"); + if (artistName != null) { + return Artist.getArtist(artistName, Reference.getUserName()); + } + return null; + } + + public static Track getTrack() { + String trackName = JOptionPane.showInputDialog(null, "Enter Track Name"); + if (trackName != null) { + String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name"); + if (artistName != null) { + return Track.getTrack(artistName, trackName, Reference.getUserName()); + } + } + return null; + } + + public static Track getTrack(Album album) { + String trackName = JOptionPane.showInputDialog(null, "Enter Track Name"); + if (trackName != null) { + Track track = Track.getTrack(album.getArtist().getName(), trackName, Reference.getUserName()); + track.setAlbum(album); + return track; + } + return null; + } + +} diff --git a/fmframework/src/sarsoo/fmframework/jframe/MainMenu.java b/fmframework/src/sarsoo/fmframework/jframe/MainMenu.java index 976a10d..4e4ac99 100644 --- a/fmframework/src/sarsoo/fmframework/jframe/MainMenu.java +++ b/fmframework/src/sarsoo/fmframework/jframe/MainMenu.java @@ -33,7 +33,7 @@ public class MainMenu extends JFrame { getAlbum.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - Album album = Getter.getAlbum(); + Album album = sarsoo.fmframework.jframe.Getter.getAlbum(); if (album != null) { album.view(); } else { @@ -43,7 +43,7 @@ public class MainMenu extends JFrame { }); getArtist.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - Artist artist = Getter.getArtist(); + Artist artist = sarsoo.fmframework.jframe.Getter.getArtist(); if (artist != null) { artist.view(); } else { diff --git a/fmframework/src/sarsoo/fmframework/util/Getter.java b/fmframework/src/sarsoo/fmframework/util/Getter.java index 7bb83ac..af2e473 100644 --- a/fmframework/src/sarsoo/fmframework/util/Getter.java +++ b/fmframework/src/sarsoo/fmframework/util/Getter.java @@ -2,14 +2,10 @@ package sarsoo.fmframework.util; import java.util.ArrayList; -import javax.swing.JOptionPane; - import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; -import sarsoo.fmframework.music.Album; -import sarsoo.fmframework.music.Artist; import sarsoo.fmframework.music.Tag; import sarsoo.fmframework.music.Track; import sarsoo.fmframework.net.Network; @@ -18,46 +14,6 @@ import sarsoo.fmframework.net.URLBuilder; import sarsoo.fmframework.parser.Parser; public class Getter { - public static Album getAlbum() { - String albumName = JOptionPane.showInputDialog(null, "Enter Album Name"); - if (albumName != null) { - String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name"); - if (artistName != null) { - return Album.getAlbum(albumName, artistName, Reference.getUserName()); - } - } - return null; - } - - public static Artist getArtist() { - String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name"); - if (artistName != null) { - return Artist.getArtist(artistName, Reference.getUserName()); - } - return null; - } - - public static Track getTrack() { - String trackName = JOptionPane.showInputDialog(null, "Enter Track Name"); - if (trackName != null) { - String artistName = JOptionPane.showInputDialog(null, "Enter Artist Name"); - if (artistName != null) { - return Track.getTrack(artistName, trackName, Reference.getUserName()); - } - } - return null; - } - - public static Track getTrack(Album album) { - String trackName = JOptionPane.showInputDialog(null, "Enter Track Name"); - if (trackName != null) { - Track track = Track.getTrack(album.getArtist().getName(), trackName, Reference.getUserName()); - track.setAlbum(album); - return track; - } - return null; - } - public static Track getLastTrack() { String url = URLBuilder.getLastTrackUrl(Reference.getUserName());