added tag pool, dynamic pie charts with json formatting

first stage, still to do:

caching time limit on tag pool to update
This commit is contained in:
aj 2018-12-04 14:31:00 +00:00
parent 9bcd99dcf8
commit 4cfb46d022
8 changed files with 405 additions and 323 deletions

52
piechart.json Normal file
View File

@ -0,0 +1,52 @@
{
"pie":
{
"tags":[
"electronic",
"jazz",
"blues",
"rnb",
"soulfunk",
],
"hierarchies":[
"rap",
"rock",
"metal"
]
}
,
"genrehierarchy":{
"genres":[
{
"tags":[
"rap",
"classic rap",
"grime",
],
"name":"rap"
},
{
"tags":[
"rock",
"classic rock",
"indie",
"pop punk",
"punk",
"emo"
],
"name":"rock"
},
{
"tags":[
"metal",
"industrial",
"thrash"
],
"name":"metal"
}
]
}
}

View File

@ -0,0 +1,54 @@
package sarsoo.fmframework.fx;
import java.io.IOException;
import java.util.ArrayList;
import javafx.scene.chart.PieChart;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import sarsoo.fmframework.fx.chart.GenrePieChart;
import sarsoo.fmframework.fx.chart.GenreTotalPieChart;
public class GenrePieChartTitledPane extends TitledPane {
public GenrePieChartTitledPane(String genreName, ArrayList<String> tagNames) throws IOException {
setText(genreName);
AnchorPane rootAnchor = new AnchorPane();
// AnchorPane.setTopAnchor(rootAnchor, 0.0);
// AnchorPane.setLeftAnchor(rootAnchor, 0.0);
// AnchorPane.setRightAnchor(rootAnchor, 0.0);
// AnchorPane.setBottomAnchor(rootAnchor, 0.0);
GridPane gridPane = new GridPane();
ColumnConstraints constraint = new ColumnConstraints();
constraint.setHgrow(Priority.ALWAYS);
RowConstraints rowConstraint = new RowConstraints();
rowConstraint.setPercentHeight(50);
RowConstraints rowConstraint2 = new RowConstraints();
rowConstraint2.setPercentHeight(50);
gridPane.getColumnConstraints().add(constraint);
gridPane.getRowConstraints().addAll(rowConstraint, rowConstraint2);;
setContent(rootAnchor);
AnchorPane.setTopAnchor(gridPane, 0.0);
AnchorPane.setLeftAnchor(gridPane, 0.0);
AnchorPane.setRightAnchor(gridPane, 0.0);
AnchorPane.setBottomAnchor(gridPane, 0.0);
rootAnchor.getChildren().add(gridPane);
PieChart pieChartTotal = new GenreTotalPieChart(genreName, tagNames);
PieChart pieChartGenre = new GenrePieChart(genreName, tagNames);
gridPane.add(pieChartGenre, 0, 0);
gridPane.add(pieChartTotal, 0, 1);
}
}

View File

@ -0,0 +1,48 @@
package sarsoo.fmframework.fx;
import java.io.IOException;
import java.util.ArrayList;
import javafx.scene.chart.PieChart;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import sarsoo.fmframework.fx.chart.GenreTotalPieChart;
public class PieChartTitledPane extends TitledPane {
public PieChartTitledPane(String genreName, ArrayList<String> tagNames) throws IOException {
setText(genreName);
AnchorPane rootAnchor = new AnchorPane();
// AnchorPane.setTopAnchor(rootAnchor, 0.0);
// AnchorPane.setLeftAnchor(rootAnchor, 0.0);
// AnchorPane.setRightAnchor(rootAnchor, 0.0);
// AnchorPane.setBottomAnchor(rootAnchor, 0.0);
// GridPane gridPane = new GridPane();
// ColumnConstraints columnConstraint = new ColumnConstraints();
// columnConstraint.setHgrow(Priority.ALWAYS);
// RowConstraints rowConstraint = new RowConstraints();
// rowConstraint.setPercentHeight(100);
// gridPane.getColumnConstraints().add(columnConstraint);
// gridPane.getRowConstraints().add(rowConstraint);
setContent(rootAnchor);
PieChart pieChartTotal = new GenreTotalPieChart(genreName, tagNames);
AnchorPane.setTopAnchor(pieChartTotal, 0.0);
AnchorPane.setLeftAnchor(pieChartTotal, 0.0);
AnchorPane.setRightAnchor(pieChartTotal, 0.0);
AnchorPane.setBottomAnchor(pieChartTotal, 0.0);
// PieChart pieChartTotal = new GenreTotalPieChart(genreName, tagNames);
rootAnchor.getChildren().add(pieChartTotal);
// gridPane.add(pieChartTotal, 0, 1);
}
}

View File

@ -0,0 +1,57 @@
package sarsoo.fmframework.fx.chart;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.chart.PieChart;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.tagpool.TagPool;
public class GenrePieChart extends PieChart{
protected int genreTotal;
protected ObservableList<PieChart.Data> pieChartData;
public GenrePieChart(String name, ArrayList<String> tagNames) {
setStartAngle(90);
setTitle(name);
pieChartData = FXCollections.observableArrayList();
TagPool tagPool = TagPool.getPool();
ArrayList<FMObjList> tagObjs = new ArrayList<FMObjList>();
int i;
for(i = 0; i < tagNames.size(); i++){
tagObjs.add(tagPool.getTag(tagNames.get(i)));
}
for(i = 0; i < tagObjs.size(); i++) {
genreTotal += tagObjs.get(i).getTotalUserScrobbles();
}
for(i = 0; i < tagNames.size(); i++) {
FMObjList list = tagObjs.get(i);
System.out.println(list.getGroupName());
pieChartData.add(new PieChart.Data(
String.format("%s %d%%", list.getGroupName(),(int) list.getTotalUserScrobbles() * 100 / genreTotal), list.getTotalUserScrobbles()));
}
Collections.sort(pieChartData, new Comparator<PieChart.Data>() {
@Override
public int compare(Data arg0, Data arg1) {
return (int) (arg1.getPieValue() - arg0.getPieValue());
}
});
setData(pieChartData);
}
}

View File

@ -0,0 +1,26 @@
package sarsoo.fmframework.fx.chart;
import java.util.ArrayList;
import javafx.scene.chart.PieChart;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.Reference;
public class GenreTotalPieChart extends GenrePieChart{
public GenreTotalPieChart(String name, ArrayList<String> tagNames) {
super(name, tagNames);
setTitle(name + " total");
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
int totalScrobbles = net.getUserScrobbleCount();
int other = totalScrobbles - genreTotal;
pieChartData.add(new PieChart.Data(String.format("other %d%%", (int) other * 100 / totalScrobbles), other));
}
}

View File

@ -1,11 +1,12 @@
package sarsoo.fmframework.fx.controller; package sarsoo.fmframework.fx.controller;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
@ -24,6 +25,8 @@ import sarsoo.fmframework.fx.FMObjListEditTab;
import sarsoo.fmframework.fx.TextAreaConsole; import sarsoo.fmframework.fx.TextAreaConsole;
import sarsoo.fmframework.fx.FMObjListTab; import sarsoo.fmframework.fx.FMObjListTab;
import sarsoo.fmframework.fx.FmFramework; import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.GenrePieChartTitledPane;
import sarsoo.fmframework.fx.PieChartTitledPane;
import sarsoo.fmframework.fx.TrackTab; import sarsoo.fmframework.fx.TrackTab;
import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist; import sarsoo.fmframework.music.Artist;
@ -33,11 +36,8 @@ import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.ConsoleHandler; import sarsoo.fmframework.util.ConsoleHandler;
import sarsoo.fmframework.util.FMObjList; import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Reference; import sarsoo.fmframework.util.Reference;
import sarsoo.fmframework.util.tagpool.TagPool;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.chart.*;
import javafx.scene.chart.PieChart.Data;
import javafx.collections.ObservableList;
import javafx.collections.FXCollections;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyEvent;
import javafx.scene.layout.*; import javafx.scene.layout.*;
@ -45,6 +45,8 @@ import javafx.scene.layout.*;
import javafx.concurrent.*; import javafx.concurrent.*;
import javafx.application.Platform; import javafx.application.Platform;
import org.json.*;
public class ControllerMain { public class ControllerMain {
@FXML @FXML
@ -65,7 +67,7 @@ public class ControllerMain {
@Override @Override
protected Void call() throws Exception { protected Void call() throws Exception {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName()); FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
String scrobblesToday = numberFormat.format(net.getScrobblesToday()); String scrobblesToday = numberFormat.format(net.getScrobblesToday());
@ -105,7 +107,7 @@ public class ControllerMain {
public void refreshTagMenu() { public void refreshTagMenu() {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName()); FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
tags = net.getTags(); tags = net.getTags();
Collections.sort(tags); Collections.sort(tags);
@ -130,10 +132,9 @@ public class ControllerMain {
return new Task<Void>() { return new Task<Void>() {
@Override @Override
protected Void call() throws Exception { protected Void call() throws Exception {
FMObjListTab tab = new FMObjListTab( FMObjListTab tab = new FMObjListTab(TagPool.getPool().getTag(name));
net.getTag(name));
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
@ -161,266 +162,93 @@ public class ControllerMain {
} }
public void refreshPieCharts() { public void refreshPieCharts() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("open pie chart json");
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON", "*.json"));
File file = fileChooser.showOpenDialog(FmFramework.getStage());
Service<Void> service = new Service<Void>() { Service<Void> service = new Service<Void>() {
@Override @Override
protected Task<Void> createTask() { protected Task<Void> createTask() {
return new Task<Void>() { return new Task<Void>() {
@Override @Override
protected Void call() throws Exception { protected Void call() throws Exception {
String jsonString = null;
// System.out.println(file.getPath());
if (file != null) {
BufferedReader br = new BufferedReader(new FileReader(file));
StringBuilder sb = new StringBuilder();
String jsonLine = br.readLine();
while (jsonLine != null) {
sb.append(jsonLine);
jsonLine = br.readLine();
}
br.close();
jsonString = sb.toString();
System.out.println("json read");
}
JSONObject rootParsedJsonObj = new JSONObject(jsonString);
JSONArray hierarchiesJsonArray = rootParsedJsonObj.getJSONObject("genrehierarchy")
.getJSONArray("genres");
JSONObject pieJson = rootParsedJsonObj.getJSONObject("pie");
System.out.println("arrays parsed");
int counter;
ArrayList<TitledPane> paneList = new ArrayList<TitledPane>();
ArrayList<String> allTags = new ArrayList<String>();
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName()); for (counter = 0; counter < hierarchiesJsonArray.length(); counter++) {
JSONObject hierarchyJsonObj = (JSONObject) hierarchiesJsonArray.get(counter);
JSONArray hierarchyTagsJsonArray = hierarchyJsonObj.getJSONArray("tags");
ArrayList<String> hierarchyTagNameList = new ArrayList<String>();
int total = net.getUserScrobbleCount(); String hierarchyName = hierarchyJsonObj.getString("name");
FMObjList rap = net.getTag("rap"); int i;
FMObjList classicRap = net.getTag("classic rap"); for (i = 0; i < hierarchyTagsJsonArray.length(); i++) {
FMObjList grime = net.getTag("grime"); hierarchyTagNameList.add(hierarchyTagsJsonArray.getString(i));
allTags.add(hierarchyTagsJsonArray.getString(i));
FMObjList classicRock = net.getTag("classic rock"); System.out.println(hierarchyTagsJsonArray.getString(i));
FMObjList popPunk = net.getTag("pop punk");
FMObjList electronic = net.getTag("electronic");
FMObjList metal = net.getTag("metal");
FMObjList indie = net.getTag("indie");
FMObjList rock = net.getTag("rock");
FMObjList jazz = net.getTag("jazz");
FMObjList blues = net.getTag("blues");
FMObjList core = net.getTag("core");
FMObjList rnb = net.getTag("rnb");
FMObjList soulFunk = net.getTag("soulfunk");
FMObjList punk = net.getTag("punk");
int rapTotal = rap.getTotalUserScrobbles() + classicRap.getTotalUserScrobbles()
+ grime.getTotalUserScrobbles();
ObservableList<PieChart.Data> rapData = FXCollections
.observableArrayList(
new PieChart.Data(
String.format("rap %d%%",
(int) rap.getTotalUserScrobbles() * 100 / rapTotal),
rap.getTotalUserScrobbles()),
new PieChart.Data(
String.format("classic rap %d%%",
(int) classicRap.getTotalUserScrobbles() * 100 / rapTotal),
classicRap.getTotalUserScrobbles()),
new PieChart.Data(
String.format("grime %d%%",
(int) grime.getTotalUserScrobbles() * 100 / rapTotal),
grime.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 - rapTotal; System.out.println("hierarchy: " + hierarchyName);
System.out.println(hierarchyTagNameList);
ObservableList<PieChart.Data> rapTotalData = FXCollections
.observableArrayList( paneList.add(new GenrePieChartTitledPane(hierarchyName, hierarchyTagNameList));
new PieChart.Data( }
String.format("rap %d%%",
(int) rap.getTotalUserScrobbles() * 100 / total), JSONArray totalPieTags = pieJson.getJSONArray("tags");
rap.getTotalUserScrobbles()), int i;
new PieChart.Data( for (i = 0; i < totalPieTags.length(); i++) {
String.format("classic rap %d%%", allTags.add((totalPieTags).getString(i));
(int) classicRap.getTotalUserScrobbles() * 100 / total), }
classicRap.getTotalUserScrobbles()), System.out.println(allTags);
new PieChart.Data( paneList.add(new PieChartTitledPane("total", allTags));
String.format("grime %d%%",
(int) grime.getTotalUserScrobbles() * 100 / total),
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(String.format("other %d%%", (int) other * 100 / total), other));
int rockTotal = rock.getTotalUserScrobbles() + classicRock.getTotalUserScrobbles()
+ indie.getTotalUserScrobbles() + popPunk.getTotalUserScrobbles()
+ punk.getTotalUserScrobbles();
ObservableList<PieChart.Data> rockData = FXCollections
.observableArrayList(
new PieChart.Data(
String.format("rock %d%%",
(int) rock.getTotalUserScrobbles() * 100 / rockTotal),
rock.getTotalUserScrobbles()),
new PieChart.Data(
String.format("classic rock %d%%",
(int) classicRock.getTotalUserScrobbles() * 100 / rockTotal),
classicRock.getTotalUserScrobbles()),
new PieChart.Data(
String.format("indie %d%%",
(int) indie.getTotalUserScrobbles() * 100 / rockTotal),
indie.getTotalUserScrobbles()),
new PieChart.Data(
String.format("pop punk %d%%",
(int) popPunk.getTotalUserScrobbles() * 100 / rockTotal),
popPunk.getTotalUserScrobbles()),
new PieChart.Data(
String.format("punk %d%%",
(int) punk.getTotalUserScrobbles() * 100 / rockTotal),
punk.getTotalUserScrobbles()));
Collections.sort(rockData, new Comparator<PieChart.Data>() {
@Override
public int compare(Data arg0, Data arg1) {
return (int) (arg1.getPieValue() - arg0.getPieValue());
}
});
int rockOther = total - rockTotal;
ObservableList<PieChart.Data> rockTotalData = FXCollections
.observableArrayList(
new PieChart.Data(
String.format("rock %d%%",
(int) rock.getTotalUserScrobbles() * 100 / total),
rock.getTotalUserScrobbles()),
new PieChart.Data(
String.format("classic rock %d%%",
(int) classicRock.getTotalUserScrobbles() * 100 / total),
classicRock.getTotalUserScrobbles()),
new PieChart.Data(
String.format("indie %d%%",
(int) indie.getTotalUserScrobbles() * 100 / total),
indie.getTotalUserScrobbles()),
new PieChart.Data(
String.format("pop punk %d%%",
(int) popPunk.getTotalUserScrobbles() * 100 / total),
popPunk.getTotalUserScrobbles()),
new PieChart.Data(
String.format("punk %d%%",
(int) punk.getTotalUserScrobbles() * 100 / total),
punk.getTotalUserScrobbles()));
Collections.sort(rockTotalData, new Comparator<PieChart.Data>() {
@Override
public int compare(Data arg0, Data arg1) {
return (int) (arg1.getPieValue() - arg0.getPieValue());
}
});
rockTotalData.add(new PieChart.Data(String.format("other %d%%", (int) rockOther * 100 / total),
rockOther));
int totalOther = total - rap.getTotalUserScrobbles() - classicRap.getTotalUserScrobbles()
- grime.getTotalUserScrobbles() - classicRock.getTotalUserScrobbles()
- popPunk.getTotalUserScrobbles() - electronic.getTotalUserScrobbles()
- metal.getTotalUserScrobbles() - indie.getTotalUserScrobbles()
- rock.getTotalUserScrobbles() - jazz.getTotalUserScrobbles()
- blues.getTotalUserScrobbles() - core.getTotalUserScrobbles()
- rnb.getTotalUserScrobbles() - soulFunk.getTotalUserScrobbles()
- punk.getTotalUserScrobbles();
ObservableList<PieChart.Data> genreData = FXCollections
.observableArrayList(
new PieChart.Data(
String.format("rap %d%%",
(int) rap.getTotalUserScrobbles() * 100 / total),
rap.getTotalUserScrobbles()),
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(
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()),
new PieChart.Data(
String.format("punk %d%%",
(int) punk.getTotalUserScrobbles() * 100 / total),
punk.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(String.format("other %d%%", (int) totalOther * 100 / total),
totalOther));
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
public void run() { public void run() {
try { try {
pieChartRap.setData(rapData); accordionCharts.getPanes().clear();
int i;
pieChartRapTotal.setData(rapTotalData); for (i = 0; i < paneList.size(); i++) {
accordionCharts.getPanes().add(paneList.get(i));
pieChartRock.setData(rockData); }
pieChartRockTotal.setData(rockTotalData);
pieChartGenres.setData(genreData);
accordionCharts.setExpandedPane(titledPaneGenres);
} finally { } finally {
latch.countDown(); latch.countDown();
} }
} }
}); });
latch.await(); latch.await();
// Keep with the background work
return null; return null;
} }
}; };
@ -443,7 +271,7 @@ public class ControllerMain {
refresh(); refresh();
} }
} }
@FXML @FXML
protected void handleChangeUsername(ActionEvent event) throws IOException { protected void handleChangeUsername(ActionEvent event) throws IOException {
// System.out.println("USERNAME"); // System.out.println("USERNAME");
@ -452,7 +280,7 @@ public class ControllerMain {
// Reference.setUserName(username); // Reference.setUserName(username);
// } // }
// refresh(); // refresh();
Service<Void> service = new Service<Void>() { Service<Void> service = new Service<Void>() {
@Override @Override
protected Task<Void> createTask() { protected Task<Void> createTask() {
@ -462,10 +290,9 @@ public class ControllerMain {
System.out.println("USERNAME"); System.out.println("USERNAME");
String username = JOptionPane.showInputDialog("enter username:"); String username = JOptionPane.showInputDialog("enter username:");
if(username != null) { if (username != null) {
Reference.setUserName(username); Reference.setUserName(username);
final CountDownLatch latch = new CountDownLatch(1); final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
@ -656,11 +483,11 @@ public class ControllerMain {
@FXML @FXML
protected void handleScrobble(ActionEvent event) throws IOException { protected void handleScrobble(ActionEvent event) throws IOException {
Album album = sarsoo.fmframework.jframe.Getter.getAlbum(); // Album album = sarsoo.fmframework.jframe.Getter.getAlbum();
if (album != null) { // if (album != null) {
Track track = sarsoo.fmframework.jframe.Getter.getTrack(album); // Track track = sarsoo.fmframework.jframe.Getter.getTrack(album);
//
} // }
} }
@FXML @FXML
@ -705,27 +532,27 @@ public class ControllerMain {
@FXML @FXML
private Label labelStatsScrobblesTotal; private Label labelStatsScrobblesTotal;
//
@FXML // @FXML
private PieChart pieChartGenres; // private PieChart pieChartGenres;
@FXML @FXML
private TabPane tabPane; private TabPane tabPane;
@FXML @FXML
private Menu menuTag; private Menu menuTag;
//
@FXML // @FXML
private PieChart pieChartRap; // private PieChart pieChartRap;
//
@FXML // @FXML
private PieChart pieChartRapTotal; // private PieChart pieChartRapTotal;
//
@FXML // @FXML
private PieChart pieChartRock; // private PieChart pieChartRock;
//
@FXML // @FXML
private PieChart pieChartRockTotal; // private PieChart pieChartRockTotal;
@FXML @FXML
private Accordion accordionCharts; private Accordion accordionCharts;

View File

@ -0,0 +1,68 @@
package sarsoo.fmframework.util.tagpool;
import java.util.ArrayList;
import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.music.Tag;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.FMObjList;
import sarsoo.fmframework.util.Reference;
public class TagPool {
private static TagPool instance;
private TagPool(){
tagList = new ArrayList<FMObjList>();
}
// public static synchronized TagPool getInstance() {
// if (instance == null) {
// instance = new TagPool();
// }
// return instance;
// }
public static TagPool getPool(){
if(instance == null){
synchronized (TagPool.class) {
if(instance == null){
instance = new TagPool();
}
}
}
return instance;
}
private ArrayList<FMObjList> tagList;
public FMObjList getTag(String name) {
System.out.println("gettag " + name);
int i;
boolean containedInPool = false;
for(i = 0; i < tagList.size(); i++) {
if(tagList.get(i).getGroupName().equals(name)) {
containedInPool = true;
System.out.println("found in pool");
break;
}
}
if(containedInPool) {
System.out.println("returned from pool");
return tagList.get(i);
}else {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
FMObjList tag = net.getTag(name);
tagList.add(tag);
System.out.println("pulling tag");
return tag;
}
}
public void flush() {
tagList.clear();
}
}

View File

@ -60,57 +60,7 @@
<center> <center>
<Accordion fx:id="accordionCharts" prefHeight="325.0" prefWidth="222.0" BorderPane.alignment="CENTER"> <Accordion fx:id="accordionCharts" prefHeight="325.0" prefWidth="222.0" BorderPane.alignment="CENTER">
<panes> <panes>
<TitledPane fx:id="titledPaneGenres" animated="false" text="genres">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<PieChart fx:id="pieChartGenres" prefHeight="263.0" prefWidth="209.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>
</TitledPane>
<TitledPane fx:id="titledPaneRap" animated="false" text="rap">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<GridPane prefHeight="303.0" prefWidth="209.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<PieChart fx:id="pieChartRapTotal" prefHeight="274.0" prefWidth="220.0" styleClass="pieChart" stylesheets="@../styles/mainPane.css" title="total" GridPane.rowIndex="1" />
<PieChart fx:id="pieChartRap" styleClass="pieChart" stylesheets="@../styles/mainPane.css" title="rap" />
</children>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
<TitledPane animated="false" text="rock">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<GridPane prefHeight="240.0" prefWidth="569.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<PieChart fx:id="pieChartRockTotal" prefHeight="274.0" prefWidth="220.0" styleClass="pieChart" stylesheets="@../styles/mainPane.css" title="total" GridPane.rowIndex="1" />
<PieChart fx:id="pieChartRock" styleClass="pieChart" stylesheets="@../styles/mainPane.css" title="rock" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
</children>
</AnchorPane>
</content>
</TitledPane>
</panes> </panes>
</Accordion> </Accordion>
</center> </center>