pie charts working again, added console tab functionality

This commit is contained in:
aj 2018-04-25 20:08:04 -07:00
parent 2c31ab908a
commit 9c4546561d
8 changed files with 161 additions and 60 deletions

View File

@ -0,0 +1,29 @@
package sarsoo.fmframework.fx;
import javafx.scene.control.Tab;
import javafx.scene.layout.AnchorPane;
public class ConsoleTab extends Tab{
public ConsoleTab(){
setText("console");
// AnchorPane pane = new AnchorPane();
// AnchorPane.setTopAnchor(pane, 0.0);
// AnchorPane.setLeftAnchor(pane, 0.0);
// AnchorPane.setRightAnchor(pane, 0.0);
// AnchorPane.setBottomAnchor(pane, 0.0);
//
// setContent(pane);
setContent(TextAreaConsole.getInstance().getTextArea());
}
}

View File

@ -0,0 +1,40 @@
package sarsoo.fmframework.fx;
import javafx.application.Platform;
import javafx.scene.control.TextArea;
import sarsoo.fmframework.util.Console;
public class TextAreaConsole implements Console{
private static TextAreaConsole instance;
private TextArea output;
private TextAreaConsole() {
output = new TextArea();
}
public static TextAreaConsole getInstance(){
if(instance == null){
synchronized (TextAreaConsole.class) {
if(instance == null){
instance = new TextAreaConsole();
}
}
}
return instance;
}
public void write(final String string){
Platform.runLater(new Runnable() {
public void run() {
output.appendText(string + "\n");
}
});
}
public TextArea getTextArea() {
return output;
}
}

View File

@ -18,6 +18,8 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.text.Text;
import sarsoo.fmframework.fx.AlbumTab;
import sarsoo.fmframework.fx.ArtistTab;
import sarsoo.fmframework.fx.ConsoleTab;
import sarsoo.fmframework.fx.TextAreaConsole;
import sarsoo.fmframework.fx.FMObjListTab;
import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.TrackTab;
@ -50,6 +52,9 @@ public class ControllerMain {
@FXML
public void initialize() {
Reference.setUserName("sarsoo");
Reference.setVerbose(TextAreaConsole.getInstance());
refresh();
}
@ -186,9 +191,9 @@ public class ControllerMain {
- grime.getTotalUserScrobbles();
ObservableList<PieChart.Data> rapData = FXCollections.observableArrayList(
new PieChart.Data("rap", rapTotal),
new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
new PieChart.Data("grime", grime.getTotalUserScrobbles()));
new PieChart.Data(String.format("rap %d%%", (int)rapTotal*100/rap.getTotalUserScrobbles()), rapTotal),
new PieChart.Data(String.format("classic rap %d%%", (int)classicRap.getTotalUserScrobbles()*100/rap.getTotalUserScrobbles()), classicRap.getTotalUserScrobbles()),
new PieChart.Data(String.format("grime %d%%", (int)grime.getTotalUserScrobbles()*100/rap.getTotalUserScrobbles()), grime.getTotalUserScrobbles()));
Collections.sort(rapData, new Comparator<PieChart.Data>() {
@ -201,9 +206,9 @@ public class ControllerMain {
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()));
new PieChart.Data(String.format("rap %d%%", (int)rapTotal*100/total), rapTotal),
new PieChart.Data(String.format("classic rap %d%%", (int)classicRap.getTotalUserScrobbles()*100/total), classicRap.getTotalUserScrobbles()),
new PieChart.Data(String.format("grime %d%%", (int)grime.getTotalUserScrobbles()*100/total), grime.getTotalUserScrobbles()));
Collections.sort(rapTotalData, new Comparator<PieChart.Data>() {
@ -213,31 +218,33 @@ public class ControllerMain {
}
});
rapTotalData.add(new PieChart.Data("other", other));
rapTotalData.add(new PieChart.Data(String.format("other %d%%", (int)other*100/total), 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();
- rnb.getTotalUserScrobbles() - soulFunk.getTotalUserScrobbles();
ObservableList<PieChart.Data> genreData = FXCollections.observableArrayList(
new PieChart.Data(String.format("rap %.2f%%", rapTotal*100/total), rapTotal),
new PieChart.Data("classic rap", classicRap.getTotalUserScrobbles()),
new PieChart.Data("grime", grime.getTotalUserScrobbles()),
new PieChart.Data(String.format("rap %d%%", (int)rapTotal*100/total), rapTotal),
new PieChart.Data(String.format("classic rap %d%%", (int)classicRap.getTotalUserScrobbles()*100/total), classicRap.getTotalUserScrobbles()),
new PieChart.Data(String.format("grime %d%%", (int)grime.getTotalUserScrobbles()*100/total), grime.getTotalUserScrobbles()),
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("soulfunk", soulFunk.getTotalUserScrobbles()),
new PieChart.Data("rnb", rnb.getTotalUserScrobbles()));
new PieChart.Data(String.format("classic rock %d%%", (int)classicRock.getTotalUserScrobbles()*100/total), classicRock.getTotalUserScrobbles())
,
new PieChart.Data(String.format("pop punk %d%%", (int)popPunk.getTotalUserScrobbles()*100/total), popPunk.getTotalUserScrobbles()),
new PieChart.Data(String.format("electronic %d%%", (int)electronic.getTotalUserScrobbles()*100/total), electronic.getTotalUserScrobbles()),
new PieChart.Data(String.format("metal %d%%", (int)metal.getTotalUserScrobbles()*100/total), metal.getTotalUserScrobbles()),
new PieChart.Data(String.format("indie %d%%", (int)indie.getTotalUserScrobbles()*100/total), indie.getTotalUserScrobbles()),
new PieChart.Data(String.format("rock %d%%", (int)rock.getTotalUserScrobbles()*100/total), rock.getTotalUserScrobbles()),
new PieChart.Data(String.format("jazz %d%%", (int)jazz.getTotalUserScrobbles()*100/total), jazz.getTotalUserScrobbles()),
new PieChart.Data(String.format("blues %d%%", (int)blues.getTotalUserScrobbles()*100/total), blues.getTotalUserScrobbles()),
new PieChart.Data(String.format("core %d%%", (int)core.getTotalUserScrobbles()*100/total), core.getTotalUserScrobbles()),
new PieChart.Data(String.format("soul/funk %d%%", (int)soulFunk.getTotalUserScrobbles()*100/total), soulFunk.getTotalUserScrobbles()),
new PieChart.Data(String.format("rnb %d%%", (int)rnb.getTotalUserScrobbles()*100/total), rnb.getTotalUserScrobbles())
);
Collections.sort(genreData, new Comparator<PieChart.Data>() {
@ -248,7 +255,7 @@ public class ControllerMain {
});
genreData.add(new PieChart.Data("other", totalOther));
genreData.add(new PieChart.Data(String.format("other %d%%", (int)totalOther*100/total), totalOther));
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() {
@ -475,6 +482,11 @@ public class ControllerMain {
}
}
@FXML
protected void handleOpenConsole(ActionEvent event){
addTab(new ConsoleTab());
}
private ArrayList<Tag> tags;
@FXML

View File

@ -23,6 +23,7 @@
<MenuItem fx:id="menuItemScrobble" mnemonicParsing="false" onAction="#handleScrobble" text="scrobble" />
<MenuItem fx:id="menuItemCurrentTrack" mnemonicParsing="false" onAction="#handleCurrentTrack" text="current track" />
<MenuItem fx:id="menuItemCreateList" mnemonicParsing="false" onAction="#handleCreateList" text="create list" />
<MenuItem fx:id="menuItemOpenConsole" mnemonicParsing="false" onAction="#handleOpenConsole" text="open console" />
</items>
</Menu>
</menus>

View File

@ -17,6 +17,7 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import sarsoo.fmframework.fx.TextAreaConsole;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.Tag;
@ -30,7 +31,7 @@ public class Parser {
public static Album parseAlbum(Document doc) {
if(Reference.isVerbose())
System.out.println("-parseAlbum");
Reference.getConsole().write("-parseAlbum");
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
String name = doc.getElementsByTagName("name").item(0).getTextContent();
@ -83,7 +84,7 @@ public class Parser {
Album album = new Album(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki);
if(Reference.isVerbose())
System.out.println(album);
Reference.getConsole().write(album.toString());
return album;
}
@ -92,7 +93,7 @@ public class Parser {
public static Artist parseArtist(Document doc) {
if(Reference.isVerbose())
System.out.println("-parseArtist");
TextAreaConsole.getInstance().write("-parseArtist");
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
String name = doc.getElementsByTagName("name").item(0).getTextContent();
@ -170,7 +171,7 @@ public class Parser {
Artist artist = new Artist(name, url, mbid, listeners, playCount, userPlayCount, wiki);
if(Reference.isVerbose())
System.out.println(artist);
Reference.getConsole().write(artist.toString());
return artist;
}
@ -179,7 +180,8 @@ public class Parser {
public static Track parseTrack(Document doc) {
if(Reference.isVerbose())
System.out.println("-parseTrack");
// System.out.println("-parseTrack");
TextAreaConsole.getInstance().write("-parseTrack");
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
String name = " ";
@ -256,7 +258,7 @@ public class Parser {
Track track = new Track(name, url, mbid, artistObj, listeners, playCount, userPlayCount, wiki);
if(Reference.isVerbose())
System.out.println(track);
Reference.getConsole().write(track.toString());
return track;
} else {
@ -267,7 +269,8 @@ public class Parser {
public static Track parseLastTrack(Document doc) {
if(Reference.isVerbose())
System.out.println("-parseLastTrack");
// System.out.println("-parseLastTrack");
TextAreaConsole.getInstance().write("-parseLastTrack");
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
String name = doc.getElementsByTagName("name").item(0).getTextContent();
@ -294,7 +297,7 @@ public class Parser {
public static ArrayList<Tag> parseUserTags(Document doc) {
if(Reference.isVerbose())
System.out.println("-parseUserTags");
Reference.getConsole().write("-parseUserTags");
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
NodeList objList = doc.getElementsByTagName("tag");
@ -319,7 +322,7 @@ public class Parser {
Tag tag = new Tag(name, url);
if(Reference.isVerbose())
System.out.println(tag);
Reference.getConsole().write(tag.toString());
// System.out.println(name + " " + url);
list.add(tag);
@ -332,7 +335,8 @@ public class Parser {
public static FMObjList parseUserTagList(Document doc) {
if(Reference.isVerbose())
System.out.println("-parseUserTagList");
Reference.getConsole().write("-parseUserTagList");
// Console.getInstance().write("-parseUserTagList");
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
NodeList objList = doc.getElementsByTagName("artist");
@ -356,7 +360,7 @@ public class Parser {
Artist artist = Artist.getArtist(name, Reference.getUserName());
if(Reference.isVerbose())
System.out.println(artist);
Reference.getConsole().write(artist.toString());
// System.out.println(artist);
list.add(artist);
@ -369,7 +373,7 @@ public class Parser {
public static FMObjList parseArtistTracks(Document doc) {
if(Reference.isVerbose())
System.out.println("-parseArtistTracks");
Reference.getConsole().write("-parseArtistTracks");
if (doc.getDocumentElement().getAttribute("status").equals("ok")) {
NodeList objList = doc.getElementsByTagName("track");
@ -400,7 +404,7 @@ public class Parser {
Track track = Track.getTrack(name, artist, Reference.getUserName());
if(Reference.isVerbose())
System.out.println(track);
Reference.getConsole().write(track.toString());
list.add(track);
}

View File

@ -0,0 +1,6 @@
package sarsoo.fmframework.util;
public interface Console {
public void write(String string);
}

View File

@ -16,7 +16,7 @@ import sarsoo.fmframework.parser.Parser;
public class Getter {
public static Track getLastTrack() {
if(Reference.isVerbose())
System.out.println("--getLastTrack");
Reference.getConsole().write("--getLastTrack");
String url = URLBuilder.getLastTrackUrl(Reference.getUserName());
// TestCall.test(url);
@ -27,8 +27,8 @@ public class Getter {
// System.out.println(doc.getDocumentElement().getAttribute("status"));
Parser.stripSpace(doc.getDocumentElement());
Track track = Parser.parseLastTrack(doc);
if(Reference.isVerbose())
System.out.println(track);
// if(Reference.isVerbose())
// System.out.println(track);
// return null;
return track;
}
@ -38,7 +38,7 @@ public class Getter {
public static int getScrobbles(String username) {
if(Reference.isVerbose())
System.out.println("--getScrobbles");
Reference.getConsole().write("--getScrobbles");
String url = URLBuilder.getUserInfoUrl(username);
Document doc = Network.getResponse(url);
@ -46,7 +46,7 @@ public class Getter {
String scrobbles = doc.getElementsByTagName("playcount").item(0).getTextContent();
if (scrobbles != null)
if(Reference.isVerbose())
System.out.println(scrobbles);
Reference.getConsole().write("total scrobbles: " + scrobbles);
return Integer.parseInt(scrobbles);
}
return 0;
@ -54,7 +54,7 @@ public class Getter {
public static int getScrobblesToday(String username) {
if(Reference.isVerbose())
System.out.println("--getScrobblesToday");
Reference.getConsole().write("--getScrobblesToday");
String url = URLBuilder.getTodayScrobbles(username);
Document doc = Network.getResponse(url);
@ -64,7 +64,7 @@ public class Getter {
// System.out.println(var.getNamedItem("total").getNodeValue());
// if (scrobbles != null)
if(Reference.isVerbose())
System.out.println(var.getNamedItem("total").getNodeValue());
Reference.getConsole().write("scrobbles today: " + var.getNamedItem("total").getNodeValue());
return Integer.parseInt(var.getNamedItem("total").getNodeValue());
}
return 0;
@ -72,7 +72,7 @@ public class Getter {
public static FMObjList getUserTag(String username, String tag) {
if(Reference.isVerbose())
System.out.println("--getUserTag");
Reference.getConsole().write("--getUserTag");
String url = URLBuilder.getUserPersonalTags(username, tag);
Document doc = Network.getResponse(url);
@ -81,13 +81,13 @@ public class Getter {
int pages = Integer.valueOf(
doc.getFirstChild().getFirstChild().getAttributes().getNamedItem("totalPages").getNodeValue());
if(Reference.isVerbose())
System.out.println("pages: " + pages);
Reference.getConsole().write("tag pages: " + pages);
FMObjList list = Parser.parseUserTagList(doc);
list.setGroupName(tag);
if(Reference.isVerbose())
System.out.println("name: " + tag);
Reference.getConsole().write("tag: " + tag);
if (pages > 1) {
int counter;
@ -127,7 +127,7 @@ public class Getter {
// }
if(Reference.isVerbose())
System.out.println("--getArtistTracks");
Reference.getConsole().write("--getArtistTracks");
FMObjList totalList = new FMObjList();
FMObjList list = new FMObjList();
@ -151,7 +151,7 @@ public class Getter {
public static ArrayList<Tag> getUserTags(String username) {
if(Reference.isVerbose())
System.out.println("--getUserTags");
Reference.getConsole().write("--getUserTags");
String url = URLBuilder.getUserTopTags(username);
Document doc = Network.getResponse(url);

View File

@ -7,8 +7,10 @@ import sarsoo.fmframework.music.Artist;
public class Reference {
private static String userName;
private static boolean isVerbose = true;
private static boolean isHeadless = true;
private static boolean isVerbose = false;
private static boolean isHeadless = false;
private static Console console;
public static String getUserName() {
return userName;
@ -26,6 +28,22 @@ public class Reference {
isHeadless = headlessIn;
}
public static Console getConsole() {
return console;
}
public static boolean isVerbose() {
return isVerbose;
}
public static void setVerbose(Console consoleIn) {
if(consoleIn == null)
isVerbose = false;
else
isVerbose = true;
console = consoleIn;
}
private static ArrayList<FMObjList> groups = new ArrayList<FMObjList>();
// public static void initGroupsList() {
@ -136,13 +154,4 @@ public class Reference {
return emoTrio;
}
public static boolean isVerbose() {
return isVerbose;
}
public static void setVerbose(boolean isVerbose) {
Reference.isVerbose = isVerbose;
}
}