separating services and working on threading
This commit is contained in:
parent
994b8e2e6b
commit
b56bfec0b7
@ -21,6 +21,11 @@ import sarsoo.fmframework.fm.FmUserNetwork;
|
|||||||
import sarsoo.fmframework.fx.TextAreaConsole;
|
import sarsoo.fmframework.fx.TextAreaConsole;
|
||||||
import sarsoo.fmframework.fx.chart.GenrePieChartTitledPane;
|
import sarsoo.fmframework.fx.chart.GenrePieChartTitledPane;
|
||||||
import sarsoo.fmframework.fx.chart.PieChartTitledPane;
|
import sarsoo.fmframework.fx.chart.PieChartTitledPane;
|
||||||
|
import sarsoo.fmframework.fx.service.GetLastTrackService;
|
||||||
|
import sarsoo.fmframework.fx.service.GetScrobbleCountService;
|
||||||
|
import sarsoo.fmframework.fx.service.GetTagMenuItemsService;
|
||||||
|
import sarsoo.fmframework.fx.service.GetTagsService;
|
||||||
|
import sarsoo.fmframework.fx.service.ScrobbleCount;
|
||||||
import sarsoo.fmframework.fx.tab.AlbumTab;
|
import sarsoo.fmframework.fx.tab.AlbumTab;
|
||||||
import sarsoo.fmframework.fx.tab.ArtistTab;
|
import sarsoo.fmframework.fx.tab.ArtistTab;
|
||||||
import sarsoo.fmframework.fx.tab.ConsoleTab;
|
import sarsoo.fmframework.fx.tab.ConsoleTab;
|
||||||
@ -55,116 +60,100 @@ public class RootController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
// Reference.setUserName("sarsoo");
|
|
||||||
|
|
||||||
Logger.setLog(new Log(TextAreaConsole.getInstance(), false));
|
Logger.setLog(new Log(TextAreaConsole.getInstance(), false));
|
||||||
// ConsoleHandler.setVerbose(TextAreaConsole.getInstance());
|
|
||||||
|
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
|
labelStatsUsername.setText(Reference.getUserName());
|
||||||
|
refreshScrobbleCounts();
|
||||||
|
addLastTrackTab();
|
||||||
|
refreshTagMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void refreshScrobbleCounts() {
|
||||||
|
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.UK);
|
||||||
|
|
||||||
|
GetScrobbleCountService getScrobbles = new GetScrobbleCountService();
|
||||||
|
getScrobbles.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
|
||||||
|
|
||||||
Service<Void> service = new Service<Void>() {
|
|
||||||
@Override
|
@Override
|
||||||
protected Task<Void> createTask() {
|
public void handle(WorkerStateEvent t) {
|
||||||
return new Task<Void>() {
|
Platform.runLater(new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
public void run() {
|
||||||
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.US);
|
labelStatsScrobblesToday.setText(
|
||||||
|
numberFormat.format(((ScrobbleCount) t.getSource().getValue()).getDailyCount()));
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
labelStatsScrobblesTotal.setText(
|
||||||
|
numberFormat.format(((ScrobbleCount) t.getSource().getValue()).getTotalCount()));
|
||||||
String scrobblesToday = numberFormat.format(net.getScrobblesToday());
|
|
||||||
String scrobbles = numberFormat.format(net.getUserScrobbleCount());
|
|
||||||
|
|
||||||
TrackTab tab = new TrackTab(net.getLastTrack());
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
addTab(tab);
|
|
||||||
|
|
||||||
// refreshPieCharts();
|
|
||||||
refreshTagMenu();
|
|
||||||
refreshPieChartMenu();
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
latch.await();
|
|
||||||
// Keep with the background work
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
service.start();
|
getScrobbles.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLastTrackTab() {
|
||||||
|
GetLastTrackService getLastTrack = new GetLastTrackService();
|
||||||
|
getLastTrack.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(WorkerStateEvent t) {
|
||||||
|
try {
|
||||||
|
TrackTab tab = new TrackTab(((Track) t.getSource().getValue()));
|
||||||
|
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
addTab(tab);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
getLastTrack.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshTagMenu() {
|
public void refreshTagMenu() {
|
||||||
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
|
||||||
|
|
||||||
tags = net.getTags();
|
GetTagsService getTags = new GetTagsService();
|
||||||
|
getTags.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(WorkerStateEvent t) {
|
||||||
|
|
||||||
Collections.sort(tags);
|
tags = (ArrayList<Tag>) t.getSource().getValue();
|
||||||
|
|
||||||
int counter;
|
Collections.sort(tags);
|
||||||
for (counter = 0; counter < tags.size(); counter++) {
|
|
||||||
|
|
||||||
String name = tags.get(counter).getName().toLowerCase();
|
GetTagMenuItemsService getTagMenuItems = new GetTagMenuItemsService(tags);
|
||||||
|
|
||||||
// System.out.println(name);
|
getTagMenuItems.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(WorkerStateEvent t) {
|
||||||
|
|
||||||
MenuItem item = new MenuItem(name);
|
Platform.runLater(new Runnable() {
|
||||||
|
|
||||||
item.setOnAction(new EventHandler<ActionEvent>() {
|
@Override
|
||||||
@Override
|
public void run() {
|
||||||
public void handle(ActionEvent e) {
|
menuTag.getItems().setAll((ArrayList<MenuItem>) t.getSource().getValue());
|
||||||
|
}
|
||||||
|
|
||||||
// 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(TagPool.getPool().getTag(name));
|
}
|
||||||
|
});
|
||||||
|
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
getTagMenuItems.start();
|
||||||
Platform.runLater(new Runnable() {
|
|
||||||
@Override
|
}
|
||||||
public void run() {
|
});
|
||||||
try {
|
|
||||||
tabPane.getTabs().add(tab);
|
getTags.start();
|
||||||
} finally {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
latch.await();
|
|
||||||
// Keep with the background work
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
service.start();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
menuTag.getItems().add(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshPieChartMenu() {
|
public void refreshPieChartMenu() {
|
||||||
@ -189,8 +178,8 @@ public class RootController {
|
|||||||
|
|
||||||
JSONArray hierarchiesJsonArray = rootParsedJsonObj.getJSONObject("genrehierarchy")
|
JSONArray hierarchiesJsonArray = rootParsedJsonObj.getJSONObject("genrehierarchy")
|
||||||
.getJSONArray("genres");
|
.getJSONArray("genres");
|
||||||
|
|
||||||
if(hierarchiesJsonArray.length() > 0) {
|
if (hierarchiesJsonArray.length() > 0) {
|
||||||
menuPieChart.setVisible(true);
|
menuPieChart.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -229,18 +218,18 @@ public class RootController {
|
|||||||
GenrePieChartTitledPane pane = new GenrePieChartTitledPane(hierarchyName,
|
GenrePieChartTitledPane pane = new GenrePieChartTitledPane(hierarchyName,
|
||||||
hierarchyTagNameList);
|
hierarchyTagNameList);
|
||||||
|
|
||||||
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 {
|
||||||
accordionCharts.getPanes().add(pane);
|
accordionCharts.getPanes().add(pane);
|
||||||
} finally {
|
} finally {
|
||||||
latch.countDown();
|
// latch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
latch.await();
|
// latch.await();
|
||||||
// Keep with the background work
|
// Keep with the background work
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -262,9 +251,9 @@ public class RootController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void refreshPieCharts(File file) {
|
public void refreshPieCharts(File file) {
|
||||||
|
|
||||||
Logger.getLog().log(new LogEntry("refreshPieCharts"));
|
Logger.getLog().log(new LogEntry("refreshPieCharts"));
|
||||||
|
|
||||||
Service<Void> service = new Service<Void>() {
|
Service<Void> service = new Service<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Task<Void> createTask() {
|
protected Task<Void> createTask() {
|
||||||
@ -325,7 +314,7 @@ public class RootController {
|
|||||||
}
|
}
|
||||||
paneList.add(new PieChartTitledPane("total", allTags));
|
paneList.add(new PieChartTitledPane("total", allTags));
|
||||||
|
|
||||||
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() {
|
||||||
@ -336,11 +325,11 @@ public class RootController {
|
|||||||
accordionCharts.getPanes().add(paneList.get(i));
|
accordionCharts.getPanes().add(paneList.get(i));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
latch.countDown();
|
// latch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
latch.await();
|
// latch.await();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -366,13 +355,6 @@ public class RootController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleChangeUsername(ActionEvent event) throws IOException {
|
protected void handleChangeUsername(ActionEvent event) throws IOException {
|
||||||
// System.out.println("USERNAME");
|
|
||||||
// String username = JOptionPane.showInputDialog("enter username:");
|
|
||||||
// if(username != null) {
|
|
||||||
// Reference.setUserName(username);
|
|
||||||
// }
|
|
||||||
// refresh();
|
|
||||||
|
|
||||||
Service<Void> service = new Service<Void>() {
|
Service<Void> service = new Service<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Task<Void> createTask() {
|
protected Task<Void> createTask() {
|
||||||
@ -380,25 +362,17 @@ public class RootController {
|
|||||||
@Override
|
@Override
|
||||||
protected Void call() throws Exception {
|
protected Void call() throws Exception {
|
||||||
|
|
||||||
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);
|
|
||||||
Platform.runLater(new Runnable() {
|
Platform.runLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
refresh();
|
||||||
refresh();
|
|
||||||
} finally {
|
|
||||||
latch.countDown();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
latch.await();
|
|
||||||
}
|
}
|
||||||
// Keep with the background work
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -421,18 +395,18 @@ public class RootController {
|
|||||||
if (album != null) {
|
if (album != null) {
|
||||||
AlbumTab tab = new AlbumTab(album);
|
AlbumTab tab = new AlbumTab(album);
|
||||||
|
|
||||||
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 {
|
||||||
tabPane.getTabs().add(tab);
|
tabPane.getTabs().add(tab);
|
||||||
} finally {
|
} finally {
|
||||||
latch.countDown();
|
// latch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
latch.await();
|
// latch.await();
|
||||||
}
|
}
|
||||||
// Keep with the background work
|
// Keep with the background work
|
||||||
return null;
|
return null;
|
||||||
@ -458,20 +432,19 @@ public class RootController {
|
|||||||
if (artist != null) {
|
if (artist != null) {
|
||||||
ArtistTab tab = new ArtistTab(artist);
|
ArtistTab tab = new ArtistTab(artist);
|
||||||
|
|
||||||
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 {
|
||||||
tabPane.getTabs().add(tab);
|
tabPane.getTabs().add(tab);
|
||||||
} finally {
|
} finally {
|
||||||
latch.countDown();
|
// latch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
latch.await();
|
// latch.await();
|
||||||
}
|
}
|
||||||
// Keep with the background work
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -495,18 +468,18 @@ public class RootController {
|
|||||||
if (track != null) {
|
if (track != null) {
|
||||||
TrackTab tab = new TrackTab(track);
|
TrackTab tab = new TrackTab(track);
|
||||||
|
|
||||||
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 {
|
||||||
tabPane.getTabs().add(tab);
|
tabPane.getTabs().add(tab);
|
||||||
} finally {
|
} finally {
|
||||||
latch.countDown();
|
// latch.countDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
latch.await();
|
// latch.await();
|
||||||
}
|
}
|
||||||
// Keep with the background work
|
// Keep with the background work
|
||||||
return null;
|
return null;
|
||||||
@ -519,39 +492,7 @@ public class RootController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleCurrentTrack(ActionEvent event) throws IOException {
|
protected void handleCurrentTrack(ActionEvent event) throws IOException {
|
||||||
Service<Void> service = new Service<Void>() {
|
addLastTrackTab();
|
||||||
@Override
|
|
||||||
protected Task<Void> createTask() {
|
|
||||||
return new Task<Void>() {
|
|
||||||
@Override
|
|
||||||
protected Void call() throws Exception {
|
|
||||||
|
|
||||||
Track track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).getLastTrack();
|
|
||||||
|
|
||||||
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
|
@FXML
|
||||||
@ -597,15 +538,15 @@ public class RootController {
|
|||||||
protected void handleOpenConsole(ActionEvent event) {
|
protected void handleOpenConsole(ActionEvent event) {
|
||||||
addTab(new ConsoleTab());
|
addTab(new ConsoleTab());
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleScrobbleChart(ActionEvent event) {
|
protected void handleScrobbleChart(ActionEvent event) {
|
||||||
try {
|
try {
|
||||||
addTab(new ScrobbleChartTab());
|
addTab(new ScrobbleChartTab());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -658,7 +599,7 @@ public class RootController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Menu menuPieChart;
|
private Menu menuPieChart;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Menu menuChart;
|
private Menu menuChart;
|
||||||
//
|
//
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package sarsoo.fmframework.fx.service;
|
||||||
|
|
||||||
|
import javafx.concurrent.Service;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
|
import sarsoo.fmframework.music.Track;
|
||||||
|
import sarsoo.fmframework.net.Key;
|
||||||
|
import sarsoo.fmframework.util.Reference;
|
||||||
|
|
||||||
|
public class GetLastTrackService extends Service<Track>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Task<Track> createTask() {
|
||||||
|
return new Task<Track>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Track call() throws Exception {
|
||||||
|
|
||||||
|
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||||
|
|
||||||
|
return net.getLastTrack();
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package sarsoo.fmframework.fx.service;
|
||||||
|
|
||||||
|
import javafx.concurrent.Service;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
|
import sarsoo.fmframework.net.Key;
|
||||||
|
import sarsoo.fmframework.util.Reference;
|
||||||
|
|
||||||
|
public class GetScrobbleCountService extends Service<ScrobbleCount>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Task<ScrobbleCount> createTask() {
|
||||||
|
return new Task<ScrobbleCount>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ScrobbleCount call() throws Exception {
|
||||||
|
|
||||||
|
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||||
|
|
||||||
|
return new ScrobbleCount(net.getScrobblesToday(), net.getUserScrobbleCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package sarsoo.fmframework.fx.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javafx.application.Platform;
|
||||||
|
import javafx.concurrent.Service;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.control.MenuItem;
|
||||||
|
import sarsoo.fmframework.fx.FmFramework;
|
||||||
|
import sarsoo.fmframework.fx.tab.FMObjListTab;
|
||||||
|
import sarsoo.fmframework.music.Tag;
|
||||||
|
import sarsoo.fmframework.util.tagpool.TagPool;
|
||||||
|
|
||||||
|
public class GetTagMenuItemsService extends Service<ArrayList<MenuItem>> {
|
||||||
|
|
||||||
|
private ArrayList<Tag> tags;
|
||||||
|
|
||||||
|
public GetTagMenuItemsService(ArrayList<Tag> tags) {
|
||||||
|
super();
|
||||||
|
this.tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Task<ArrayList<MenuItem>> createTask() {
|
||||||
|
return new Task<ArrayList<MenuItem>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ArrayList<MenuItem> call() throws Exception {
|
||||||
|
|
||||||
|
ArrayList<MenuItem> items = new ArrayList<MenuItem>();
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
// 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(TagPool.getPool().getTag(name));
|
||||||
|
|
||||||
|
Platform.runLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
FmFramework.getController().addTab(tab);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
service.start();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
package sarsoo.fmframework.fx.service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javafx.concurrent.Service;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
|
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||||
|
import sarsoo.fmframework.music.Tag;
|
||||||
|
import sarsoo.fmframework.net.Key;
|
||||||
|
import sarsoo.fmframework.util.Reference;
|
||||||
|
|
||||||
|
public class GetTagsService extends Service<ArrayList<Tag>>{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Task<ArrayList<Tag>> createTask() {
|
||||||
|
return new Task<ArrayList<Tag>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ArrayList<Tag> call() throws Exception {
|
||||||
|
|
||||||
|
FmUserNetwork net = new FmUserNetwork(Key.getKey(), Reference.getUserName());
|
||||||
|
return net.getTags();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package sarsoo.fmframework.fx.service;
|
||||||
|
|
||||||
|
public class ScrobbleCount {
|
||||||
|
|
||||||
|
private int dailyCount;
|
||||||
|
private int totalCount;
|
||||||
|
|
||||||
|
public ScrobbleCount(int dailyCount, int totalCount) {
|
||||||
|
this.dailyCount = dailyCount;
|
||||||
|
this.totalCount = totalCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDailyCount() {
|
||||||
|
return dailyCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalCount() {
|
||||||
|
return totalCount;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user