diff --git a/piechart.json b/piechart.json new file mode 100644 index 0000000..47eee72 --- /dev/null +++ b/piechart.json @@ -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" + } + ] + } +} diff --git a/src/main/java/sarsoo/fmframework/fx/GenrePieChartTitledPane.java b/src/main/java/sarsoo/fmframework/fx/GenrePieChartTitledPane.java new file mode 100644 index 0000000..3d768c8 --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/GenrePieChartTitledPane.java @@ -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 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); + + + } + +} diff --git a/src/main/java/sarsoo/fmframework/fx/PieChartTitledPane.java b/src/main/java/sarsoo/fmframework/fx/PieChartTitledPane.java new file mode 100644 index 0000000..5896878 --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/PieChartTitledPane.java @@ -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 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); + + + } + +} diff --git a/src/main/java/sarsoo/fmframework/fx/chart/GenrePieChart.java b/src/main/java/sarsoo/fmframework/fx/chart/GenrePieChart.java new file mode 100644 index 0000000..a4c0011 --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/chart/GenrePieChart.java @@ -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 pieChartData; + + public GenrePieChart(String name, ArrayList tagNames) { + + setStartAngle(90); + setTitle(name); + + pieChartData = FXCollections.observableArrayList(); + + TagPool tagPool = TagPool.getPool(); + + ArrayList tagObjs = new ArrayList(); + + 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() { + + @Override + public int compare(Data arg0, Data arg1) { + return (int) (arg1.getPieValue() - arg0.getPieValue()); + } + }); + + setData(pieChartData); + + } + + +} diff --git a/src/main/java/sarsoo/fmframework/fx/chart/GenreTotalPieChart.java b/src/main/java/sarsoo/fmframework/fx/chart/GenreTotalPieChart.java new file mode 100644 index 0000000..6d231ee --- /dev/null +++ b/src/main/java/sarsoo/fmframework/fx/chart/GenreTotalPieChart.java @@ -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 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)); + + } + +} diff --git a/src/main/java/sarsoo/fmframework/fx/controller/ControllerMain.java b/src/main/java/sarsoo/fmframework/fx/controller/ControllerMain.java index 0bb220b..c76fd7f 100644 --- a/src/main/java/sarsoo/fmframework/fx/controller/ControllerMain.java +++ b/src/main/java/sarsoo/fmframework/fx/controller/ControllerMain.java @@ -1,11 +1,12 @@ package sarsoo.fmframework.fx.controller; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; 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; @@ -24,6 +25,8 @@ import sarsoo.fmframework.fx.FMObjListEditTab; import sarsoo.fmframework.fx.TextAreaConsole; import sarsoo.fmframework.fx.FMObjListTab; import sarsoo.fmframework.fx.FmFramework; +import sarsoo.fmframework.fx.GenrePieChartTitledPane; +import sarsoo.fmframework.fx.PieChartTitledPane; import sarsoo.fmframework.fx.TrackTab; import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.Artist; @@ -33,11 +36,8 @@ import sarsoo.fmframework.net.Key; import sarsoo.fmframework.util.ConsoleHandler; import sarsoo.fmframework.util.FMObjList; import sarsoo.fmframework.util.Reference; +import sarsoo.fmframework.util.tagpool.TagPool; 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.KeyEvent; import javafx.scene.layout.*; @@ -45,6 +45,8 @@ import javafx.scene.layout.*; import javafx.concurrent.*; import javafx.application.Platform; +import org.json.*; + public class ControllerMain { @FXML @@ -65,7 +67,7 @@ public class ControllerMain { @Override protected Void call() throws Exception { NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US); - + FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName()); String scrobblesToday = numberFormat.format(net.getScrobblesToday()); @@ -105,7 +107,7 @@ public class ControllerMain { public void refreshTagMenu() { FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName()); - + tags = net.getTags(); Collections.sort(tags); @@ -130,10 +132,9 @@ public class ControllerMain { return new Task() { @Override protected Void call() throws Exception { - - FMObjListTab tab = new FMObjListTab( - net.getTag(name)); - + + FMObjListTab tab = new FMObjListTab(TagPool.getPool().getTag(name)); + final CountDownLatch latch = new CountDownLatch(1); Platform.runLater(new Runnable() { @Override @@ -161,266 +162,93 @@ public class ControllerMain { } 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 service = new Service() { @Override protected Task createTask() { return new Task() { @Override 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 paneList = new ArrayList(); + + ArrayList allTags = new ArrayList(); - 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 hierarchyTagNameList = new ArrayList(); - int total = net.getUserScrobbleCount(); + String hierarchyName = hierarchyJsonObj.getString("name"); - FMObjList rap = net.getTag("rap"); - FMObjList classicRap = net.getTag("classic rap"); - FMObjList grime = net.getTag("grime"); - - FMObjList classicRock = net.getTag("classic rock"); - 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 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() { - - @Override - public int compare(Data arg0, Data arg1) { - return (int) (arg1.getPieValue() - arg0.getPieValue()); + int i; + for (i = 0; i < hierarchyTagsJsonArray.length(); i++) { + hierarchyTagNameList.add(hierarchyTagsJsonArray.getString(i)); + allTags.add(hierarchyTagsJsonArray.getString(i)); + System.out.println(hierarchyTagsJsonArray.getString(i)); } - }); - int other = total - rapTotal; - - ObservableList rapTotalData = 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())); - - Collections.sort(rapTotalData, new Comparator() { - - @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 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() { - - @Override - public int compare(Data arg0, Data arg1) { - return (int) (arg1.getPieValue() - arg0.getPieValue()); - } - }); - - int rockOther = total - rockTotal; - - ObservableList 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() { - - @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 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() { - - @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)); + System.out.println("hierarchy: " + hierarchyName); + System.out.println(hierarchyTagNameList); + + paneList.add(new GenrePieChartTitledPane(hierarchyName, hierarchyTagNameList)); + } + + JSONArray totalPieTags = pieJson.getJSONArray("tags"); + int i; + for (i = 0; i < totalPieTags.length(); i++) { + allTags.add((totalPieTags).getString(i)); + } + System.out.println(allTags); + paneList.add(new PieChartTitledPane("total", allTags)); final CountDownLatch latch = new CountDownLatch(1); Platform.runLater(new Runnable() { @Override public void run() { try { - pieChartRap.setData(rapData); - - pieChartRapTotal.setData(rapTotalData); - - pieChartRock.setData(rockData); - - pieChartRockTotal.setData(rockTotalData); - - pieChartGenres.setData(genreData); - - accordionCharts.setExpandedPane(titledPaneGenres); + accordionCharts.getPanes().clear(); + int i; + for (i = 0; i < paneList.size(); i++) { + accordionCharts.getPanes().add(paneList.get(i)); + } } finally { latch.countDown(); } } }); latch.await(); - // Keep with the background work return null; } }; @@ -443,7 +271,7 @@ public class ControllerMain { refresh(); } } - + @FXML protected void handleChangeUsername(ActionEvent event) throws IOException { // System.out.println("USERNAME"); @@ -452,7 +280,7 @@ public class ControllerMain { // Reference.setUserName(username); // } // refresh(); - + Service service = new Service() { @Override protected Task createTask() { @@ -462,10 +290,9 @@ public class ControllerMain { System.out.println("USERNAME"); String username = JOptionPane.showInputDialog("enter username:"); - if(username != null) { + if (username != null) { Reference.setUserName(username); - final CountDownLatch latch = new CountDownLatch(1); Platform.runLater(new Runnable() { @Override @@ -656,11 +483,11 @@ public class ControllerMain { @FXML protected void handleScrobble(ActionEvent event) throws IOException { - Album album = sarsoo.fmframework.jframe.Getter.getAlbum(); - if (album != null) { - Track track = sarsoo.fmframework.jframe.Getter.getTrack(album); - - } +// Album album = sarsoo.fmframework.jframe.Getter.getAlbum(); +// if (album != null) { +// Track track = sarsoo.fmframework.jframe.Getter.getTrack(album); +// +// } } @FXML @@ -705,27 +532,27 @@ public class ControllerMain { @FXML private Label labelStatsScrobblesTotal; - - @FXML - private PieChart pieChartGenres; +// +// @FXML +// private PieChart pieChartGenres; @FXML private TabPane tabPane; @FXML private Menu menuTag; - - @FXML - private PieChart pieChartRap; - - @FXML - private PieChart pieChartRapTotal; - - @FXML - private PieChart pieChartRock; - - @FXML - private PieChart pieChartRockTotal; +// +// @FXML +// private PieChart pieChartRap; +// +// @FXML +// private PieChart pieChartRapTotal; +// +// @FXML +// private PieChart pieChartRock; +// +// @FXML +// private PieChart pieChartRockTotal; @FXML private Accordion accordionCharts; diff --git a/src/main/java/sarsoo/fmframework/util/tagpool/TagPool.java b/src/main/java/sarsoo/fmframework/util/tagpool/TagPool.java new file mode 100644 index 0000000..7a163db --- /dev/null +++ b/src/main/java/sarsoo/fmframework/util/tagpool/TagPool.java @@ -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(); + } + +// 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 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(); + } + +} diff --git a/src/main/resources/sarsoo/fmframework/fx/ui/main.fxml b/src/main/resources/sarsoo/fmframework/fx/ui/main.fxml index a7ec35c..3bad9ab 100644 --- a/src/main/resources/sarsoo/fmframework/fx/ui/main.fxml +++ b/src/main/resources/sarsoo/fmframework/fx/ui/main.fxml @@ -60,57 +60,7 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +