almost fully threaded

This commit is contained in:
aj 2018-04-19 16:25:45 -07:00
parent d3413d15eb
commit 711928b5b8

View File

@ -71,7 +71,6 @@ public class ControllerMain {
@Override
protected Void call() throws Exception {
String scrobblesToday = numberFormat.format(Getter.getScrobblesToday(Reference.getUserName()));
String scrobbles = numberFormat.format(Getter.getScrobbles(Reference.getUserName()));
tags = Getter.getUserTags(Reference.getUserName());
@ -100,16 +99,39 @@ public class ControllerMain {
item.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
FMObjListTab tab = new FMObjListTab(Getter.getUserTag(Reference.getUserName(), name));
// 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 {
FMObjListTab tab = new FMObjListTab(Getter
.getUserTag(Reference.getUserName(), name));
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
tabPane.getTabs().add(tab);
// System.out.println("tab added");
} catch (IOException e1) {
e1.printStackTrace();
} finally {
latch.countDown();
}
}
});
latch.await();
// Keep with the background work
return null;
}
};
}
};
service.start();
}
});
menuTag.getItems().add(item);
}
@ -144,20 +166,114 @@ public class ControllerMain {
@FXML
protected void handleLookupAlbum(ActionEvent event) throws IOException {
Service<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
Album album = Getter.getAlbum();
if (album != null) {
AlbumTab tab = new AlbumTab(album);
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
tabPane.getTabs().add(tab);
} finally {
latch.countDown();
}
}
});
latch.await();
}
// Keep with the background work
return null;
}
};
}
};
service.start();
tabPane.getTabs().add(new AlbumTab(Getter.getAlbum()));
}
@FXML
protected void handleLookupArtist(ActionEvent event) throws IOException {
Service<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
tabPane.getTabs().add(new ArtistTab(Getter.getArtist()));
Artist artist = Getter.getArtist();
if (artist != null) {
ArtistTab tab = new ArtistTab(artist);
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
tabPane.getTabs().add(tab);
} finally {
latch.countDown();
}
}
});
latch.await();
}
// Keep with the background work
return null;
}
};
}
};
service.start();
// tabPane.getTabs().add(new ArtistTab(Getter.getArtist()));
}
@FXML
protected void handleLookupTrack(ActionEvent event) throws IOException {
tabPane.getTabs().add(new TrackTab(Getter.getTrack()));
Service<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
Track track = Getter.getTrack();
if (track != null) {
TrackTab tab = new TrackTab(track);
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
tabPane.getTabs().add(tab);
} finally {
latch.countDown();
}
}
});
latch.await();
}
// Keep with the background work
return null;
}
};
}
};
service.start();
}
@FXML
@ -174,15 +290,80 @@ public class ControllerMain {
private ArrayList<Tag> tags;
// @FXML
// protected void handleTagClick(ActionEvent event) throws IOException {
// // System.out.println("clicked");
//
// if (tags == null) {
// // System.out.println("list null");
//
// tags = Getter.getUserTags(Reference.getUserName());
//
// int counter;
// for (counter = 0; counter < tags.size(); counter++) {
//
// String name = tags.get(counter).getName().toLowerCase();
//
// // System.out.println(name);
//
// MenuItem item = new MenuItem(name);
//
// item.setOnAction(new EventHandler<ActionEvent>() {
// @Override
// public void handle(ActionEvent e) {
// try {
// FMObjListTab tab = new
// FMObjListTab(Getter.getUserTag(Reference.getUserName(), name));
//
// tabPane.getTabs().add(tab);
// System.out.println("tab added");
// } catch (IOException e1) {
// e1.printStackTrace();
// }
// }
// });
//
// menuTag.getItems().add(item);
// }
// }
// }
@FXML
protected void handleTagClick(ActionEvent event) throws IOException {
// System.out.println("clicked");
protected void handleKeyShortcut(KeyEvent event) throws IOException {
if (tags == null) {
// System.out.println("list null");
if (event.getCode() == KeyCode.F5) {
refresh();
// System.out.println("refreshed");
}
}
public void refresh() {
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
Service<Void> service = new Service<Void>() {
@Override
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
String scrobblesToday = numberFormat.format(Getter.getScrobblesToday(Reference.getUserName()));
String scrobbles = numberFormat.format(Getter.getScrobbles(Reference.getUserName()));
tags = Getter.getUserTags(Reference.getUserName());
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
labelStatsScrobblesToday.setText(scrobblesToday);
labelStatsUsername.setText(Reference.getUserName());
labelStatsScrobblesTotal.setText(scrobbles);
refreshPieCharts();
menuTag.getItems().clear();
int counter;
for (counter = 0; counter < tags.size(); counter++) {
@ -195,66 +376,56 @@ public class ControllerMain {
item.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
try {
FMObjListTab tab = new FMObjListTab(Getter.getUserTag(Reference.getUserName(), name));
tabPane.getTabs().add(tab);
System.out.println("tab added");
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
menuTag.getItems().add(item);
}
}
}
@FXML
protected void handleKeyShortcut(KeyEvent event) throws IOException {
if (event.getCode() == KeyCode.F5) {
refresh();
// System.out.println("refreshed");
}
}
public void refresh() {
labelStatsScrobblesToday.setText(Integer.toString(Getter.getScrobblesToday(Reference.getUserName())));
labelStatsUsername.setText(Reference.getUserName());
labelStatsScrobblesTotal
.setText(NumberFormat.getInstance().format(Getter.getScrobbles(Reference.getUserName())));
tags = Getter.getUserTags(Reference.getUserName());
menuTag.getItems().clear();
int counter;
for (counter = 0; counter < tags.size(); counter++) {
String name = tags.get(counter).getName();
// System.out.println(name);
MenuItem item = new MenuItem(name);
item.setOnAction(new EventHandler<ActionEvent>() {
// TAG ITEM HANDLER SERVICE
Service<Void> service = new Service<Void>() {
@Override
public void handle(ActionEvent e) {
try {
FMObjListTab tab = new FMObjListTab(Getter.getUserTag(Reference.getUserName(), name));
protected Task<Void> createTask() {
return new Task<Void>() {
@Override
protected Void call() throws Exception {
FMObjListTab tab = new FMObjListTab(Getter
.getUserTag(Reference.getUserName(), name));
final CountDownLatch latch = new CountDownLatch(1);
Platform.runLater(new Runnable() {
@Override
public void run() {
try {
tabPane.getTabs().add(tab);
System.out.println("tab added");
} catch (IOException e1) {
e1.printStackTrace();
} finally {
latch.countDown();
}
}
});
latch.await();
// Keep with the background work
return null;
}
};
}
};
service.start();
}
});
menuTag.getItems().add(item);
}
} finally {
latch.countDown();
}
}
});
latch.await();
// Keep with the background work
return null;
}
};
}
};
service.start();
}
public void addTab(Tab tab) {