refactored jframe getter methods to jframe package
This commit is contained in:
parent
711928b5b8
commit
1e5539d4f1
@ -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
|
||||
@ -85,6 +90,8 @@ public class ControllerMain {
|
||||
labelStatsUsername.setText(Reference.getUserName());
|
||||
labelStatsScrobblesTotal.setText(scrobbles);
|
||||
|
||||
addTab(tab);
|
||||
|
||||
refreshPieCharts();
|
||||
|
||||
int counter;
|
||||
@ -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;
|
||||
@ -465,10 +472,23 @@ public class ControllerMain {
|
||||
@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();
|
||||
|
||||
@ -477,13 +497,69 @@ public class ControllerMain {
|
||||
new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
|
||||
new PieChart.Data("grime", grime.getTotalUserScrobbles()));
|
||||
|
||||
int other = Getter.getScrobbles(Reference.getUserName()) - rap.getTotalUserScrobbles();
|
||||
Collections.sort(rapData, new Comparator<PieChart.Data>() {
|
||||
|
||||
@Override
|
||||
public int compare(Data arg0, Data arg1) {
|
||||
return (int) (arg1.getPieValue() - arg0.getPieValue());
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
int other = total - rap.getTotalUserScrobbles();
|
||||
|
||||
ObservableList<PieChart.Data> 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<PieChart.Data>() {
|
||||
|
||||
@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<PieChart.Data> 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<PieChart.Data>() {
|
||||
|
||||
@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() {
|
||||
@ -494,6 +570,8 @@ public class ControllerMain {
|
||||
|
||||
pieChartRapTotal.setData(rapTotalData);
|
||||
|
||||
pieChartGenres.setData(genreData);
|
||||
|
||||
accordionCharts.setExpandedPane(titledPaneRap);
|
||||
} finally {
|
||||
latch.countDown();
|
||||
|
@ -60,7 +60,7 @@
|
||||
<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" />
|
||||
<PieChart fx:id="pieChartGenres" layoutX="-189.0" layoutY="-102.0" prefHeight="249.0" prefWidth="220.0" styleClass="pieChart" stylesheets="@../styles/mainPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
|
@ -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) {
|
||||
|
||||
}
|
||||
|
52
fmframework/src/sarsoo/fmframework/jframe/Getter.java
Normal file
52
fmframework/src/sarsoo/fmframework/jframe/Getter.java
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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 {
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user