auto find pie chart json and view pie chart option in menu
This commit is contained in:
parent
4cfb46d022
commit
186969b115
@ -25,6 +25,8 @@
|
|||||||
"rap",
|
"rap",
|
||||||
"classic rap",
|
"classic rap",
|
||||||
"grime",
|
"grime",
|
||||||
|
"trap",
|
||||||
|
"uk hip-hop"
|
||||||
],
|
],
|
||||||
"name":"rap"
|
"name":"rap"
|
||||||
},
|
},
|
||||||
|
@ -89,6 +89,7 @@ public class ControllerMain {
|
|||||||
|
|
||||||
// refreshPieCharts();
|
// refreshPieCharts();
|
||||||
refreshTagMenu();
|
refreshTagMenu();
|
||||||
|
refreshPieChartMenu();
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
@ -161,12 +162,111 @@ public class ControllerMain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshPieCharts() {
|
public void refreshPieChartMenu() {
|
||||||
FileChooser fileChooser = new FileChooser();
|
|
||||||
fileChooser.setTitle("open pie chart json");
|
|
||||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON", "*.json"));
|
|
||||||
File file = fileChooser.showOpenDialog(FmFramework.getStage());
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (new File("./piechart.json").isFile()) {
|
||||||
|
File file = new File("./piechart.json");
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
String jsonString = sb.toString();
|
||||||
|
|
||||||
|
JSONObject rootParsedJsonObj = new JSONObject(jsonString);
|
||||||
|
|
||||||
|
JSONArray hierarchiesJsonArray = rootParsedJsonObj.getJSONObject("genrehierarchy")
|
||||||
|
.getJSONArray("genres");
|
||||||
|
|
||||||
|
int counter;
|
||||||
|
for (counter = 0; counter < hierarchiesJsonArray.length(); counter++) {
|
||||||
|
JSONObject hierarchyJsonObj = (JSONObject) hierarchiesJsonArray.get(counter);
|
||||||
|
// JSONArray hierarchyTagsJsonArray = hierarchyJsonObj.getJSONArray("tags");
|
||||||
|
// ArrayList<String> hierarchyTagNameList = new ArrayList<String>();
|
||||||
|
|
||||||
|
String hierarchyName = hierarchyJsonObj.getString("name");
|
||||||
|
JSONArray hierarchyTagsJsonArray = hierarchyJsonObj.getJSONArray("tags");
|
||||||
|
ArrayList<String> hierarchyTagNameList = new ArrayList<String>();
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("hierarchy: " + hierarchyName);
|
||||||
|
System.out.println(hierarchyTagNameList);
|
||||||
|
|
||||||
|
// paneList.add(new GenrePieChartTitledPane(hierarchyName, hierarchyTagNameList));
|
||||||
|
|
||||||
|
MenuItem item = new MenuItem(hierarchyName);
|
||||||
|
|
||||||
|
item.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent e) {
|
||||||
|
|
||||||
|
// TAG ITEM HANDLER SERVICE
|
||||||
|
Service<Void> service = new Service<Void>() {
|
||||||
|
@Override
|
||||||
|
protected Task<Void> createTask() {
|
||||||
|
return new Task<Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void call() throws Exception {
|
||||||
|
|
||||||
|
GenrePieChartTitledPane pane = new GenrePieChartTitledPane(hierarchyName,
|
||||||
|
hierarchyTagNameList);
|
||||||
|
|
||||||
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
accordionCharts.getPanes().add(pane);
|
||||||
|
} finally {
|
||||||
|
latch.countDown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
latch.await();
|
||||||
|
// Keep with the background work
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
service.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
menuPieChart.getItems().add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshPieCharts(File file) {
|
||||||
|
// File file = null;
|
||||||
|
// String path = null;
|
||||||
|
// if (new File("./piechart.json").isFile()) {
|
||||||
|
// file = new File("./piechart.json");
|
||||||
|
// } else {
|
||||||
|
// FileChooser fileChooser = new FileChooser();
|
||||||
|
// fileChooser.setTitle("open pie chart json");
|
||||||
|
// fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON", "*.json"));
|
||||||
|
// 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() {
|
||||||
@ -465,7 +565,18 @@ public class ControllerMain {
|
|||||||
@FXML
|
@FXML
|
||||||
protected void handleRefreshPieChart(ActionEvent event) throws IOException {
|
protected void handleRefreshPieChart(ActionEvent event) throws IOException {
|
||||||
|
|
||||||
refreshPieCharts();
|
File file = null;
|
||||||
|
String path = null;
|
||||||
|
if (new File("./piechart.json").isFile()) {
|
||||||
|
file = new File("./piechart.json");
|
||||||
|
} else {
|
||||||
|
FileChooser fileChooser = new FileChooser();
|
||||||
|
fileChooser.setTitle("open pie chart json");
|
||||||
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JSON", "*.json"));
|
||||||
|
file = fileChooser.showOpenDialog(FmFramework.getStage());
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshPieCharts(file);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,6 +652,9 @@ public class ControllerMain {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Menu menuTag;
|
private Menu menuTag;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Menu menuPieChart;
|
||||||
//
|
//
|
||||||
// @FXML
|
// @FXML
|
||||||
// private PieChart pieChartRap;
|
// private PieChart pieChartRap;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
<items>
|
<items>
|
||||||
<MenuItem fx:id="menuItemCreateList" mnemonicParsing="false" onAction="#handleCreateList" text="new list" />
|
<MenuItem fx:id="menuItemCreateList" mnemonicParsing="false" onAction="#handleCreateList" text="new list" />
|
||||||
<MenuItem fx:id="menuItemListEdit" mnemonicParsing="false" onAction="#handleListEdit" text="open list" />
|
<MenuItem fx:id="menuItemListEdit" mnemonicParsing="false" onAction="#handleListEdit" text="open list" />
|
||||||
|
<Menu fx:id="menuPieChart" mnemonicParsing="false" text="open pie chart" />
|
||||||
</items>
|
</items>
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu fx:id="menuLookup" mnemonicParsing="false" text="lookup">
|
<Menu fx:id="menuLookup" mnemonicParsing="false" text="lookup">
|
||||||
|
Loading…
Reference in New Issue
Block a user