added top album tab, moved error catching from invocation to implicit
This commit is contained in:
parent
59bb4fdb6f
commit
6904663e59
@ -112,6 +112,16 @@ public class FmNetwork {
|
||||
.addArg(e.getMessage()));
|
||||
}
|
||||
|
||||
try {
|
||||
JSONArray imageArray = albumJson.getJSONArray("image");
|
||||
JSONObject imageObj = (JSONObject) imageArray.get(imageArray.length() - 1);
|
||||
|
||||
builder.setImageUrl(imageObj.getString("#text"));
|
||||
} catch (JSONException e) {
|
||||
log.logInfo(new InfoEntry("getAlbum").addArg("no image for").addArg(nameIn)
|
||||
.addArg(e.getMessage()));
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject wikiJson = albumJson.getJSONObject("wiki");
|
||||
|
||||
|
@ -280,9 +280,28 @@ public class FmUserNetwork extends FmNetwork {
|
||||
return LocalDateTime.ofInstant(Instant.ofEpochSecond(uts), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
public FMObjList getTopTracks(String period, int number) throws ApiCallException {
|
||||
private String getPeriod(TimePeriod period) {
|
||||
switch(period){
|
||||
case OVERALL:
|
||||
return "overall";
|
||||
case SEVENDAY:
|
||||
return "7day";
|
||||
case ONEMONTH:
|
||||
return "1month";
|
||||
case THREEMONTH:
|
||||
return "3month";
|
||||
case SIXMONTH:
|
||||
return "6month";
|
||||
case TWELVEMONTH:
|
||||
return "12month";
|
||||
default:
|
||||
throw new IllegalArgumentException("invalid period provided");
|
||||
}
|
||||
}
|
||||
|
||||
Logger.getLog().log(new LogEntry("getTopTracks").addArg(period).addArg(Integer.toString(number)));
|
||||
public FMObjList getTopTracks(TimePeriod period, int number) throws ApiCallException {
|
||||
|
||||
Logger.getLog().log(new LogEntry("getTopTracks").addArg(getPeriod(period)).addArg(Integer.toString(number)));
|
||||
|
||||
int limit = 50;
|
||||
|
||||
@ -302,7 +321,7 @@ public class FmUserNetwork extends FmNetwork {
|
||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||
|
||||
parameters.put("user", userName);
|
||||
parameters.put("period", period);
|
||||
parameters.put("period", getPeriod(period));
|
||||
parameters.put("limit", Integer.toString(limit));
|
||||
parameters.put("page", Integer.toString(counter + 1));
|
||||
|
||||
@ -326,9 +345,9 @@ public class FmUserNetwork extends FmNetwork {
|
||||
return tracks;
|
||||
}
|
||||
|
||||
public FMObjList getTopAlbums(String period, int number) throws ApiCallException {
|
||||
public FMObjList getTopAlbums(TimePeriod period, int number) throws ApiCallException {
|
||||
|
||||
Logger.getLog().log(new LogEntry("getTopAlbums").addArg(period).addArg(Integer.toString(number)));
|
||||
Logger.getLog().log(new LogEntry("getTopAlbums").addArg(getPeriod(period)).addArg(Integer.toString(number)));
|
||||
|
||||
int limit = 50;
|
||||
|
||||
@ -348,7 +367,7 @@ public class FmUserNetwork extends FmNetwork {
|
||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||
|
||||
parameters.put("user", userName);
|
||||
parameters.put("period", period);
|
||||
parameters.put("period", getPeriod(period));
|
||||
parameters.put("limit", Integer.toString(limit));
|
||||
parameters.put("page", Integer.toString(counter + 1));
|
||||
|
||||
@ -361,9 +380,15 @@ public class FmUserNetwork extends FmNetwork {
|
||||
|
||||
if (albums.size() < number) {
|
||||
Artist artist = new ArtistBuilder(json.getJSONObject("artist").getString("name")).build();
|
||||
Album album = new AlbumBuilder(json.getString("name"), artist)
|
||||
.setUserPlayCount(json.getInt("playcount")).build();
|
||||
AlbumBuilder albumBuilder = new AlbumBuilder(json.getString("name"), artist)
|
||||
.setUserPlayCount(json.getInt("playcount"));
|
||||
|
||||
JSONArray imageArray = json.getJSONArray("image");
|
||||
JSONObject imageObj = (JSONObject) imageArray.get(imageArray.length() - 1);
|
||||
|
||||
albumBuilder.setImageUrl(imageObj.getString("#text"));
|
||||
|
||||
Album album = albumBuilder.build();
|
||||
albums.add(album);
|
||||
|
||||
}
|
||||
@ -373,9 +398,9 @@ public class FmUserNetwork extends FmNetwork {
|
||||
return albums;
|
||||
}
|
||||
|
||||
public FMObjList getTopArtists(String period, int number) throws ApiCallException {
|
||||
public FMObjList getTopArtists(TimePeriod period, int number) throws ApiCallException {
|
||||
|
||||
Logger.getLog().log(new LogEntry("getTopArtists").addArg(period).addArg(Integer.toString(number)));
|
||||
Logger.getLog().log(new LogEntry("getTopArtists").addArg(getPeriod(period)).addArg(Integer.toString(number)));
|
||||
|
||||
int limit = 50;
|
||||
|
||||
@ -395,7 +420,7 @@ public class FmUserNetwork extends FmNetwork {
|
||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||
|
||||
parameters.put("user", userName);
|
||||
parameters.put("period", period);
|
||||
parameters.put("period", getPeriod(period));
|
||||
parameters.put("limit", Integer.toString(limit));
|
||||
parameters.put("page", Integer.toString(counter + 1));
|
||||
|
||||
|
12
src/main/java/sarsoo/fmframework/fm/TimePeriod.java
Normal file
12
src/main/java/sarsoo/fmframework/fm/TimePeriod.java
Normal file
@ -0,0 +1,12 @@
|
||||
package sarsoo.fmframework.fm;
|
||||
|
||||
public enum TimePeriod {
|
||||
|
||||
OVERALL,
|
||||
SEVENDAY,
|
||||
ONEMONTH,
|
||||
THREEMONTH,
|
||||
SIXMONTH,
|
||||
TWELVEMONTH
|
||||
|
||||
}
|
18
src/main/java/sarsoo/fmframework/fx/TiledImage.java
Normal file
18
src/main/java/sarsoo/fmframework/fx/TiledImage.java
Normal file
@ -0,0 +1,18 @@
|
||||
package sarsoo.fmframework.fx;
|
||||
|
||||
import javafx.scene.image.Image;
|
||||
|
||||
public class TiledImage extends Image {
|
||||
|
||||
private int index;
|
||||
|
||||
public TiledImage(String url, int index) {
|
||||
super(url);
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
@ -74,12 +74,7 @@ public class FMObjListPaneController {
|
||||
@Override
|
||||
public void handle(Event event) {
|
||||
|
||||
try {
|
||||
FmFramework.getController().addTab(new ArtistTab((Artist) obj));
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -165,12 +160,7 @@ public class FMObjListPaneController {
|
||||
@Override
|
||||
public void handle(Event event) {
|
||||
|
||||
try {
|
||||
FmFramework.getController().addTab(new ArtistTab((Artist) obj));
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -106,8 +106,6 @@ public class FMObjListPaneEditController {
|
||||
@Override
|
||||
public void handle(Event event) {
|
||||
|
||||
try {
|
||||
|
||||
if (obj.getClass() == Artist.class) {
|
||||
FmFramework.getController().addTab(new ArtistTab((Artist) obj));
|
||||
} else if (obj.getClass() == Album.class) {
|
||||
@ -115,10 +113,6 @@ public class FMObjListPaneEditController {
|
||||
} else if (obj.getClass() == Track.class) {
|
||||
FmFramework.getController().addTab(new TrackTab((Track) obj));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import sarsoo.fmframework.fx.tab.FMObjListEditTab;
|
||||
import sarsoo.fmframework.fx.tab.GenrePieChartTab;
|
||||
import sarsoo.fmframework.fx.tab.ScrobbleChartTab;
|
||||
import sarsoo.fmframework.fx.tab.ScrobbleTab;
|
||||
import sarsoo.fmframework.fx.tab.TopAlbumTab;
|
||||
import sarsoo.fmframework.fx.tab.TrackTab;
|
||||
import sarsoo.fmframework.fx.tab.WebViewTab;
|
||||
import sarsoo.fmframework.log.Log;
|
||||
@ -123,19 +124,15 @@ public class RootController {
|
||||
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);
|
||||
addTab(tab, false);
|
||||
}
|
||||
|
||||
});
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
getLastTrack.start();
|
||||
@ -181,9 +178,14 @@ public class RootController {
|
||||
}
|
||||
|
||||
public void addTab(Tab tab) {
|
||||
addTab(tab, true);
|
||||
}
|
||||
|
||||
public void addTab(Tab tab, Boolean select) {
|
||||
tabPane.getTabs().add(tab);
|
||||
SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel();
|
||||
|
||||
if(select)
|
||||
selectionModel.select(tab);
|
||||
}
|
||||
|
||||
@ -243,13 +245,14 @@ public class RootController {
|
||||
}
|
||||
});
|
||||
|
||||
addTab(tab);
|
||||
addTab(tab, true);
|
||||
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ApiCallException e) {}
|
||||
} catch (ApiCallException e) {
|
||||
}
|
||||
}
|
||||
|
||||
protected void completeAuth(FmAuthNetwork net, String token) {
|
||||
@ -262,7 +265,8 @@ public class RootController {
|
||||
FmFramework.getSessionConfig().addVariable(new ConfigVariable("session_key", sk));
|
||||
}
|
||||
|
||||
} catch (ApiCallException e) {}
|
||||
} catch (ApiCallException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void changeUsername() {
|
||||
@ -395,12 +399,8 @@ public class RootController {
|
||||
@FXML
|
||||
protected void handleCreateList(ActionEvent event) {
|
||||
|
||||
try {
|
||||
Tab tab = new FMObjListEditTab();
|
||||
addTab(tab);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
addTab(tab, true);
|
||||
|
||||
}
|
||||
|
||||
@ -421,21 +421,22 @@ public class RootController {
|
||||
|
||||
@FXML
|
||||
protected void handleScrobble(ActionEvent event) throws IOException {
|
||||
addTab(new ScrobbleTab());
|
||||
addTab(new ScrobbleTab(), true);
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleOpenConsole(ActionEvent event) {
|
||||
addTab(new ConsoleTab());
|
||||
addTab(new ConsoleTab(), true);
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleTopAlbum(ActionEvent event) {
|
||||
addTab(new TopAlbumTab(), true);
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleScrobbleChart(ActionEvent event) {
|
||||
try {
|
||||
addTab(new ScrobbleChartTab());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
addTab(new ScrobbleChartTab(), true);
|
||||
|
||||
}
|
||||
|
||||
@ -453,17 +454,13 @@ public class RootController {
|
||||
FMObjList list = persist.readListFromFile(file);
|
||||
list.setGroupName(file.getName());
|
||||
list.refresh();
|
||||
try {
|
||||
addTab(new FMObjListEditTab(list));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
addTab(new FMObjListEditTab(list), true);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleOpenEdit(ActionEvent event) {
|
||||
addTab(new ConsoleTab());
|
||||
addTab(new ConsoleTab(), true);
|
||||
}
|
||||
|
||||
public void closeCurrentTab() {
|
||||
@ -484,7 +481,7 @@ public class RootController {
|
||||
|
||||
@FXML
|
||||
protected void handleGenrePieTab(ActionEvent event) {
|
||||
addTab(new GenrePieChartTab());
|
||||
addTab(new GenrePieChartTab(), true);
|
||||
}
|
||||
|
||||
private ArrayList<Tag> tags;
|
||||
|
@ -39,6 +39,8 @@ public class ScrobbleChartPaneController {
|
||||
// dropDownTimeRange.setItems(FXCollections.observableArrayList("week", "month",
|
||||
// "3 month", "6 month", "year"));
|
||||
dropDownTimeRange.getItems().addAll("week", "30 day", "90 day", "180 day", "year");
|
||||
|
||||
dropDownTimeRange.getSelectionModel().select(0);
|
||||
}
|
||||
|
||||
@FXML
|
||||
|
@ -0,0 +1,213 @@
|
||||
package sarsoo.fmframework.fx.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.concurrent.WorkerStateEvent;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.ChoiceBox;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.ToolBar;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.BorderPane;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.TilePane;
|
||||
import sarsoo.fmframework.config.Config;
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.fm.TimePeriod;
|
||||
import sarsoo.fmframework.fx.FmFramework;
|
||||
import sarsoo.fmframework.fx.TiledImage;
|
||||
import sarsoo.fmframework.fx.service.GetFXImageService;
|
||||
import sarsoo.fmframework.fx.service.GetTopAlbumsService;
|
||||
import sarsoo.fmframework.music.Album;
|
||||
import sarsoo.fmframework.music.FMObj;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
|
||||
public class TopAlbumController {
|
||||
|
||||
@FXML
|
||||
protected BorderPane borderPane;
|
||||
|
||||
@FXML
|
||||
protected ToolBar toolBar;
|
||||
|
||||
@FXML
|
||||
protected ChoiceBox<String> dropDownTimeRange;
|
||||
|
||||
@FXML
|
||||
protected ChoiceBox<Integer> dropDownLimit;
|
||||
|
||||
@FXML
|
||||
protected Button buttonLoad;
|
||||
|
||||
@FXML
|
||||
protected Button buttonGenerate;
|
||||
|
||||
@FXML
|
||||
protected GridPane gridPane;
|
||||
|
||||
@FXML
|
||||
protected TilePane tilePane;
|
||||
|
||||
FMObjList albums;
|
||||
ArrayList<TiledImage> images = new ArrayList<>();
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
dropDownTimeRange.getItems().addAll("week", "30 day", "90 day", "180 day", "year", "overall");
|
||||
|
||||
for (int i = 1; i < 16; i++) {
|
||||
dropDownLimit.getItems().add(i);
|
||||
}
|
||||
|
||||
for (int i = 20; i < 110; i+=10) {
|
||||
dropDownLimit.getItems().add(i);
|
||||
}
|
||||
|
||||
dropDownTimeRange.getSelectionModel().select(0);
|
||||
dropDownLimit.getSelectionModel().select(0);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleLoad(ActionEvent event) {
|
||||
Config config = FmFramework.getSessionConfig();
|
||||
FmUserNetwork net = new FmUserNetwork(config.getValue("api_key"), config.getValue("username"));
|
||||
|
||||
String value = (String) dropDownTimeRange.getValue();
|
||||
|
||||
TimePeriod timePeriod = null;
|
||||
|
||||
switch (value) {
|
||||
case "week":
|
||||
timePeriod = TimePeriod.SEVENDAY;
|
||||
break;
|
||||
case "30 day":
|
||||
timePeriod = TimePeriod.ONEMONTH;
|
||||
break;
|
||||
case "90 day":
|
||||
timePeriod = TimePeriod.THREEMONTH;
|
||||
break;
|
||||
case "180 day":
|
||||
timePeriod = TimePeriod.SIXMONTH;
|
||||
break;
|
||||
case "year":
|
||||
timePeriod = TimePeriod.TWELVEMONTH;
|
||||
break;
|
||||
case "overall":
|
||||
timePeriod = TimePeriod.OVERALL;
|
||||
break;
|
||||
}
|
||||
|
||||
GetTopAlbumsService service = new GetTopAlbumsService(timePeriod, dropDownLimit.getValue(), net);
|
||||
|
||||
service.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
|
||||
|
||||
@Override
|
||||
public void handle(WorkerStateEvent t) {
|
||||
Platform.runLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
gridPane.getChildren().clear();
|
||||
|
||||
if (albums != null)
|
||||
albums.clear();
|
||||
|
||||
albums = (FMObjList) t.getSource().getValue();
|
||||
|
||||
if (albums.size() > 0) {
|
||||
buttonGenerate.setDisable(false);
|
||||
} else {
|
||||
buttonGenerate.setDisable(true);
|
||||
}
|
||||
|
||||
int counter = 0;
|
||||
for (FMObj fmObj : albums) {
|
||||
Album album = (Album) fmObj;
|
||||
|
||||
Label albumName = new Label(album.getName().toLowerCase());
|
||||
Label artistName = new Label(album.getArtist().getName().toLowerCase());
|
||||
Label userPlays = new Label(Integer.toString(album.getUserPlayCount()));
|
||||
|
||||
gridPane.add(new Label(Integer.toString(counter + 1)), 0, counter);
|
||||
gridPane.add(albumName, 1, counter);
|
||||
gridPane.add(artistName, 2, counter);
|
||||
gridPane.add(userPlays, 3, counter);
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
service.start();
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void handleGenerate(ActionEvent event) {
|
||||
|
||||
if (albums != null) {
|
||||
if (albums.size() > 0) {
|
||||
tilePane.getChildren().clear();
|
||||
images.clear();
|
||||
|
||||
int counter = 0;
|
||||
for (FMObj obj : albums) {
|
||||
|
||||
Album album = (Album) obj;
|
||||
|
||||
GetFXImageService service = new GetFXImageService(album.getImageURL().toString(), counter);
|
||||
|
||||
service.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
|
||||
|
||||
@Override
|
||||
public void handle(WorkerStateEvent t) {
|
||||
|
||||
TiledImage image = (TiledImage) t.getSource().getValue();
|
||||
|
||||
images.add(image);
|
||||
|
||||
refreshImages();
|
||||
}
|
||||
});
|
||||
|
||||
service.start();
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void refreshImages() {
|
||||
ObservableList<Node> list = tilePane.getChildren();
|
||||
|
||||
list.clear();
|
||||
|
||||
Collections.sort(images, new Comparator<TiledImage>() {
|
||||
|
||||
@Override
|
||||
public int compare(TiledImage arg0, TiledImage arg1) {
|
||||
return arg0.getIndex() - arg1.getIndex();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
for(TiledImage image: images) {
|
||||
list.add(new ImageView(image));
|
||||
}
|
||||
}
|
||||
}
|
@ -62,11 +62,7 @@ public class AlbumBorderPaneController extends FMObjBorderPaneController {
|
||||
viewArtist.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent e) {
|
||||
try {
|
||||
FmFramework.getController().addTab(new ArtistTab(album.getArtist()));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -53,11 +53,7 @@ public class TrackBorderPaneController extends FMObjBorderPaneController {
|
||||
viewAlbum.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent e) {
|
||||
try {
|
||||
FmFramework.getController().addTab(new AlbumTab(track.getAlbum()));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}else {
|
||||
@ -68,11 +64,7 @@ public class TrackBorderPaneController extends FMObjBorderPaneController {
|
||||
viewArtist.setOnAction(new EventHandler<ActionEvent>() {
|
||||
@Override
|
||||
public void handle(ActionEvent e) {
|
||||
try {
|
||||
FmFramework.getController().addTab(new ArtistTab(track.getArtist()));
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}//
|
||||
}
|
||||
});
|
||||
}else {
|
||||
|
@ -0,0 +1,42 @@
|
||||
package sarsoo.fmframework.fx.service;
|
||||
|
||||
import javafx.concurrent.Service;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.scene.image.Image;
|
||||
import sarsoo.fmframework.fx.TiledImage;
|
||||
import sarsoo.fmframework.log.Logger;
|
||||
import sarsoo.fmframework.log.entry.ErrorEntry;
|
||||
|
||||
public class GetFXImageService extends Service<TiledImage> {
|
||||
|
||||
private String url;
|
||||
private int index;
|
||||
|
||||
public GetFXImageService(String url, int index) {
|
||||
super();
|
||||
this.url = url;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Task<TiledImage> createTask() {
|
||||
return new Task<TiledImage>() {
|
||||
|
||||
@Override
|
||||
protected TiledImage call() throws Exception {
|
||||
|
||||
return new TiledImage(url, index);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void failed() {
|
||||
super.failed();
|
||||
|
||||
Logger.getLog().logError(new ErrorEntry("failed to get image " + url));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package sarsoo.fmframework.fx.service;
|
||||
|
||||
import javafx.concurrent.Service;
|
||||
import javafx.concurrent.Task;
|
||||
import sarsoo.fmframework.fm.FmUserNetwork;
|
||||
import sarsoo.fmframework.fm.TimePeriod;
|
||||
import sarsoo.fmframework.log.Logger;
|
||||
import sarsoo.fmframework.log.entry.ErrorEntry;
|
||||
import sarsoo.fmframework.util.FMObjList;
|
||||
|
||||
public class GetTopAlbumsService extends Service<FMObjList> {
|
||||
|
||||
private int limit;
|
||||
private TimePeriod period;
|
||||
private FmUserNetwork net;
|
||||
|
||||
public GetTopAlbumsService(TimePeriod period, int limit, FmUserNetwork net) {
|
||||
super();
|
||||
this.limit = limit;
|
||||
this.period = period;
|
||||
this.net = net;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Task<FMObjList> createTask() {
|
||||
return new Task<FMObjList>() {
|
||||
|
||||
@Override
|
||||
protected FMObjList call() throws Exception {
|
||||
|
||||
return net.getTopAlbums(period, limit);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void failed() {
|
||||
super.failed();
|
||||
|
||||
Logger.getLog().logError(new ErrorEntry("failed to get top albums"));
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -14,7 +14,7 @@ import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class AlbumTab extends Tab {
|
||||
|
||||
public AlbumTab(Album album) throws IOException {
|
||||
public AlbumTab(Album album) {
|
||||
|
||||
setText(album.getName().toLowerCase());
|
||||
|
||||
@ -24,7 +24,10 @@ public class AlbumTab extends Tab {
|
||||
|
||||
loader.setController(controller);
|
||||
|
||||
AnchorPane pane = (AnchorPane) loader.load();
|
||||
AnchorPane pane;
|
||||
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
@ -35,6 +38,9 @@ public class AlbumTab extends Tab {
|
||||
|
||||
controller.populate(album);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class ArtistTab extends Tab{
|
||||
|
||||
public ArtistTab(Artist artist) throws IOException {
|
||||
public ArtistTab(Artist artist) {
|
||||
|
||||
setText(artist.getName().toLowerCase());
|
||||
|
||||
@ -20,7 +20,10 @@ public class ArtistTab extends Tab{
|
||||
|
||||
loader.setController(controller);
|
||||
|
||||
AnchorPane pane = (AnchorPane) loader.load();
|
||||
AnchorPane pane;
|
||||
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
@ -30,6 +33,9 @@ public class ArtistTab extends Tab{
|
||||
setContent(pane);
|
||||
|
||||
controller.populate(artist);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,13 +9,16 @@ import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class FMObjListEditTab extends Tab {
|
||||
|
||||
public FMObjListEditTab() throws IOException {
|
||||
public FMObjListEditTab() {
|
||||
|
||||
setText("List");
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjListEditPane.fxml"));
|
||||
|
||||
AnchorPane pane = (AnchorPane) loader.load();
|
||||
AnchorPane pane;
|
||||
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
@ -30,9 +33,13 @@ public class FMObjListEditTab extends Tab {
|
||||
|
||||
FMObjListPaneEditController control = (FMObjListPaneEditController) loader.getController();
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public FMObjListEditTab(FMObjList list) throws IOException {
|
||||
public FMObjListEditTab(FMObjList list) {
|
||||
|
||||
if (list.getGroupName() != null) {
|
||||
setText(list.getGroupName());
|
||||
@ -42,7 +49,10 @@ public class FMObjListEditTab extends Tab {
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjListEditPane.fxml"));
|
||||
|
||||
AnchorPane pane = (AnchorPane) loader.load();
|
||||
AnchorPane pane;
|
||||
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
@ -56,6 +66,10 @@ public class FMObjListEditTab extends Tab {
|
||||
FMObjListPaneEditController control = (FMObjListPaneEditController) loader.getController();
|
||||
control.setList(list);
|
||||
control.refresh();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,13 +9,15 @@ import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class FMObjListTab extends Tab {
|
||||
|
||||
public FMObjListTab(FMObjList list) throws IOException {
|
||||
public FMObjListTab(FMObjList list) {
|
||||
|
||||
setText(list.getGroupName());
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjListPane.fxml"));
|
||||
|
||||
AnchorPane pane = (AnchorPane) loader.load();
|
||||
AnchorPane pane;
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
@ -30,30 +32,8 @@ public class FMObjListTab extends Tab {
|
||||
|
||||
control.populate(list);
|
||||
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// public FMObjListTab() throws IOException {
|
||||
//
|
||||
// setText("List");
|
||||
//
|
||||
// FXMLLoader loader = new FXMLLoader(getClass().getResource("ui/FMObjListPaneEdit.fxml"));
|
||||
//
|
||||
// AnchorPane pane = (AnchorPane) loader.load();
|
||||
//
|
||||
// AnchorPane.setTopAnchor(pane, 0.0);
|
||||
// AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
// AnchorPane.setRightAnchor(pane, 0.0);
|
||||
// AnchorPane.setBottomAnchor(pane, 0.0);
|
||||
//
|
||||
//// BorderPane
|
||||
//
|
||||
// setContent(pane);
|
||||
//
|
||||
// FMObjListPaneEditController control = (FMObjListPaneEditController) loader.getController();
|
||||
//
|
||||
//
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -15,11 +15,13 @@ public abstract class FMObjTab extends Tab {
|
||||
protected AnchorPane infoAnchorPane;
|
||||
protected FMObjBorderPaneController controller;
|
||||
|
||||
protected FMObjTab() throws IOException {
|
||||
protected FMObjTab() {
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/FMObjBorderPane.fxml"));
|
||||
|
||||
AnchorPane anchor = (AnchorPane) loader.load();
|
||||
AnchorPane anchor;
|
||||
try {
|
||||
anchor = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(anchor, 0.0);
|
||||
AnchorPane.setLeftAnchor(anchor, 0.0);
|
||||
@ -30,6 +32,9 @@ public abstract class FMObjTab extends Tab {
|
||||
|
||||
setContent(anchor);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public AnchorPane getInfoAnchorPane() {
|
||||
|
@ -9,13 +9,16 @@ import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class ScrobbleChartTab extends Tab {
|
||||
|
||||
public ScrobbleChartTab() throws IOException {
|
||||
public ScrobbleChartTab() {
|
||||
|
||||
setText("scrobbles");
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/ScrobbleChartPane.fxml"));
|
||||
|
||||
AnchorPane pane = (AnchorPane) loader.load();
|
||||
AnchorPane pane;
|
||||
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
@ -27,8 +30,9 @@ public class ScrobbleChartTab extends Tab {
|
||||
ScrobbleChartPaneController control = (ScrobbleChartPaneController) loader.getController();
|
||||
|
||||
//control.populate();
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,13 +9,15 @@ import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class ScrobbleTab extends Tab {
|
||||
|
||||
public ScrobbleTab() throws IOException {
|
||||
public ScrobbleTab() {
|
||||
|
||||
setText("scrobble");
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/ScrobblePane.fxml"));
|
||||
|
||||
AnchorPane pane = (AnchorPane) loader.load();
|
||||
AnchorPane pane;
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
@ -27,7 +29,9 @@ public class ScrobbleTab extends Tab {
|
||||
ScrobblePaneController control = (ScrobblePaneController) loader.getController();
|
||||
|
||||
//control.populate();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
37
src/main/java/sarsoo/fmframework/fx/tab/TopAlbumTab.java
Normal file
37
src/main/java/sarsoo/fmframework/fx/tab/TopAlbumTab.java
Normal file
@ -0,0 +1,37 @@
|
||||
package sarsoo.fmframework.fx.tab;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import sarsoo.fmframework.fx.controller.TopAlbumController;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class TopAlbumTab extends Tab {
|
||||
|
||||
public TopAlbumTab() {
|
||||
|
||||
setText("top albums");
|
||||
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("../ui/TopAlbumPane.fxml"));
|
||||
|
||||
AnchorPane pane;
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
AnchorPane.setRightAnchor(pane, 0.0);
|
||||
AnchorPane.setBottomAnchor(pane, 0.0);
|
||||
|
||||
setContent(pane);
|
||||
|
||||
TopAlbumController control = (TopAlbumController) loader.getController();
|
||||
|
||||
//control.populate();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,7 +12,7 @@ import javafx.fxml.FXMLLoader;
|
||||
|
||||
public class TrackTab extends Tab {
|
||||
|
||||
public TrackTab(Track track) throws IOException {
|
||||
public TrackTab(Track track) {
|
||||
|
||||
setText(track.getName().toLowerCase());
|
||||
|
||||
@ -22,7 +22,9 @@ public class TrackTab extends Tab {
|
||||
|
||||
loader.setController(controller);
|
||||
|
||||
AnchorPane pane = (AnchorPane) loader.load();
|
||||
AnchorPane pane;
|
||||
try {
|
||||
pane = (AnchorPane) loader.load();
|
||||
|
||||
AnchorPane.setTopAnchor(pane, 0.0);
|
||||
AnchorPane.setLeftAnchor(pane, 0.0);
|
||||
@ -33,6 +35,10 @@ public class TrackTab extends Tab {
|
||||
|
||||
controller.populate(track);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,14 @@
|
||||
package sarsoo.fmframework.music;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import sarsoo.fmframework.cache.Cacheable;
|
||||
|
||||
public class Album extends FMObj implements Serializable, Cacheable{
|
||||
@ -12,6 +18,9 @@ public class Album extends FMObj implements Serializable, Cacheable{
|
||||
protected ArrayList<Tag> tagList;
|
||||
protected ArrayList<Track> trackList;
|
||||
|
||||
protected URL imageUrl;
|
||||
protected BufferedImage image;
|
||||
|
||||
private Album(AlbumBuilder builder) {
|
||||
this.name = builder.name;
|
||||
this.artist = builder.artist;
|
||||
@ -29,9 +38,26 @@ public class Album extends FMObj implements Serializable, Cacheable{
|
||||
this.tagList = builder.tagList;
|
||||
this.trackList = builder.trackList;
|
||||
|
||||
this.imageUrl = builder.imageUrl;
|
||||
|
||||
}
|
||||
|
||||
public URL getImageURL() {
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
public void loadImage() {
|
||||
try {
|
||||
image = ImageIO.read(imageUrl);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public BufferedImage getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public Artist getArtist() {
|
||||
return artist;
|
||||
}
|
||||
@ -87,6 +113,8 @@ public class Album extends FMObj implements Serializable, Cacheable{
|
||||
protected ArrayList<Tag> tagList;
|
||||
protected ArrayList<Track> trackList;
|
||||
|
||||
protected URL imageUrl;
|
||||
|
||||
|
||||
public AlbumBuilder(String name, Artist artist) {
|
||||
|
||||
@ -134,6 +162,15 @@ public class Album extends FMObj implements Serializable, Cacheable{
|
||||
return this;
|
||||
}
|
||||
|
||||
public AlbumBuilder setImageUrl(String url) {
|
||||
try {
|
||||
this.imageUrl = new URL(url);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public Album build() {
|
||||
return new Album(this);
|
||||
}
|
||||
|
@ -89,6 +89,27 @@
|
||||
-fx-background-color: #4D4D4D;
|
||||
}
|
||||
|
||||
.text-area {
|
||||
-fx-background-color: #202124;
|
||||
-fx-text-fill: white;
|
||||
}
|
||||
|
||||
.text-area .content {
|
||||
-fx-background-color: transparent ;
|
||||
}
|
||||
|
||||
.text-area > .viewport {
|
||||
-fx-background-color: transparent;
|
||||
}
|
||||
|
||||
.scroll-pane {
|
||||
-fx-background-color: transparent;
|
||||
}
|
||||
|
||||
.scroll-pane > .viewport {
|
||||
-fx-background-color: transparent;
|
||||
}
|
||||
|
||||
.text-area {
|
||||
-fx-background-color: #202124;
|
||||
}
|
||||
@ -137,6 +158,7 @@
|
||||
.tab{
|
||||
-fx-background-insets: 0 1 0 1,0,0;
|
||||
}
|
||||
|
||||
.tab-pane .tab
|
||||
{
|
||||
-fx-background-color: #202124;
|
||||
|
@ -70,6 +70,11 @@
|
||||
<KeyCodeCombination alt="DOWN" code="R" control="UP" meta="UP" shift="UP" shortcut="UP" />
|
||||
</accelerator></MenuItem>
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu fx:id="menuTop" mnemonicParsing="false" text="top">
|
||||
<items>
|
||||
<MenuItem fx:id="menuItemAlbumCollage" mnemonicParsing="false" onAction="#handleTopAlbum" text="album" />
|
||||
</items>
|
||||
</Menu>
|
||||
<Menu fx:id="menuChart" mnemonicParsing="false" text="chart">
|
||||
<items>
|
||||
|
@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ChoiceBox?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.SplitPane?>
|
||||
<?import javafx.scene.control.ToolBar?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.BorderPane?>
|
||||
<?import javafx.scene.layout.ColumnConstraints?>
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.TilePane?>
|
||||
|
||||
<AnchorPane prefHeight="484.0" prefWidth="885.0" stylesheets="@../styles/mainPane.css" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sarsoo.fmframework.fx.controller.TopAlbumController">
|
||||
<children>
|
||||
<BorderPane fx:id="borderPane" prefHeight="327.0" prefWidth="600.0" styleClass="backGround" stylesheets="@../styles/ObjPane.css" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
|
||||
<bottom>
|
||||
<ToolBar fx:id="toolBar" prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<ChoiceBox fx:id="dropDownLimit" prefHeight="26.0" prefWidth="79.0" />
|
||||
<ChoiceBox fx:id="dropDownTimeRange" prefHeight="25.0" prefWidth="208.0" />
|
||||
<Button fx:id="buttonLoad" mnemonicParsing="false" onAction="#handleLoad" text="load" />
|
||||
<Button fx:id="buttonGenerate" disable="true" mnemonicParsing="false" onAction="#handleGenerate" text="generate" />
|
||||
</items>
|
||||
</ToolBar>
|
||||
</bottom>
|
||||
<center>
|
||||
<SplitPane dividerPositions="0.5" prefHeight="160.0" prefWidth="200.0" BorderPane.alignment="CENTER">
|
||||
<items>
|
||||
<ScrollPane fitToHeight="true" fitToWidth="true">
|
||||
<content>
|
||||
<GridPane fx:id="gridPane" alignment="CENTER" styleClass="backGround">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints halignment="CENTER" hgrow="NEVER" maxWidth="30.0" minWidth="30.0" />
|
||||
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="300.0" />
|
||||
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="128.0" />
|
||||
<ColumnConstraints halignment="CENTER" hgrow="NEVER" maxWidth="40.0" minWidth="50.0" />
|
||||
</columnConstraints>
|
||||
</GridPane>
|
||||
</content>
|
||||
</ScrollPane>
|
||||
<ScrollPane fitToWidth="true" hbarPolicy="NEVER">
|
||||
<content>
|
||||
<TilePane fx:id="tilePane" alignment="CENTER" prefColumns="3" prefHeight="0.0" prefWidth="0.0" />
|
||||
</content>
|
||||
</ScrollPane>
|
||||
</items>
|
||||
</SplitPane>
|
||||
</center>
|
||||
</BorderPane>
|
||||
</children>
|
||||
</AnchorPane>
|
@ -55,7 +55,7 @@ public class FmUserNetworkTest {
|
||||
|
||||
FMObjList list;
|
||||
try {
|
||||
list = net.getTopAlbums("7day", limit);
|
||||
list = net.getTopAlbums(TimePeriod.SEVENDAY, limit);
|
||||
|
||||
assertEquals(limit, list.size());
|
||||
|
||||
@ -73,7 +73,7 @@ public class FmUserNetworkTest {
|
||||
|
||||
FMObjList list;
|
||||
try {
|
||||
list = net.getTopArtists("7day", limit);
|
||||
list = net.getTopArtists(TimePeriod.SEVENDAY, limit);
|
||||
|
||||
// list.stream().forEach(System.out::println);
|
||||
assertEquals(limit, list.size());
|
||||
@ -92,7 +92,7 @@ public class FmUserNetworkTest {
|
||||
|
||||
FMObjList list;
|
||||
try {
|
||||
list = net.getTopTracks("7day", limit);
|
||||
list = net.getTopTracks(TimePeriod.SEVENDAY, limit);
|
||||
|
||||
// list.stream().forEach(System.out::println);
|
||||
assertEquals(limit, list.size());
|
||||
|
Loading…
Reference in New Issue
Block a user