add view album/artist buttons

This commit is contained in:
aj 2019-05-07 11:00:43 +01:00
parent fdac060b98
commit 56436c8cca
4 changed files with 163 additions and 40 deletions

View File

@ -1,40 +1,46 @@
package sarsoo.fmframework.fx.controller.borderpane; package sarsoo.fmframework.fx.controller.borderpane;
import java.awt.Desktop;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.concurrent.Service; import javafx.concurrent.Service;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import sarsoo.fmframework.fm.FmUserNetwork; import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.chart.GenrePieChartTitledPane; import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.controller.info.AlbumPaneController; import sarsoo.fmframework.fx.controller.info.AlbumPaneController;
import sarsoo.fmframework.fx.controller.info.ArtistPaneController; import sarsoo.fmframework.fx.tab.ArtistTab;
import sarsoo.fmframework.log.Logger;
import sarsoo.fmframework.log.entry.ErrorEntry;
import sarsoo.fmframework.music.Album; import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.net.Key; import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network; import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Reference; import sarsoo.fmframework.util.Reference;
public class AlbumBorderPaneController extends FMObjBorderPaneController{ public class AlbumBorderPaneController extends FMObjBorderPaneController {
AlbumPaneController infoPaneController; AlbumPaneController infoPaneController;
Album album; Album album;
@FXML @FXML
public void initialize() { public void initialize() {
borderPane.setTop(null); borderPane.setTop(null);
} }
public void populate(Album album) { public void populate(Album album) {
this.album = album; this.album = album;
try { try {
loadInfoPane(); loadInfoPane();
loadScrobblePane(); loadScrobblePane();
@ -42,11 +48,44 @@ public class AlbumBorderPaneController extends FMObjBorderPaneController{
e.printStackTrace(); e.printStackTrace();
} }
setInfoView(); setInfoView();
Button openRym = new Button("view rym");
Button viewArtist = new Button("view artist");
openRym.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent e) {
Network.openURL(album.getRymURL());
}
});
if (album.getArtist() != null) {
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 {
viewArtist.setDisable(true);
}
toolBar.getItems().add(openRym);
toolBar.getItems().add(viewArtist);
// if(album.getUrl() == null) {
buttonViewOnline.setDisable(true);
// }
} }
@Override @Override
public void loadInfoPane() throws IOException { public void loadInfoPane() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/AlbumPane.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/AlbumPane.fxml"));
this.infoAnchorPane = (AnchorPane) loader.load(); this.infoAnchorPane = (AnchorPane) loader.load();
@ -57,17 +96,27 @@ public class AlbumBorderPaneController extends FMObjBorderPaneController{
AnchorPane.setBottomAnchor(infoAnchorPane, 0.0); AnchorPane.setBottomAnchor(infoAnchorPane, 0.0);
infoPaneController = (AlbumPaneController) loader.getController(); infoPaneController = (AlbumPaneController) loader.getController();
infoPaneController.refresh(album); infoPaneController.refresh(album);
} }
@Override @Override
@FXML
protected void handleViewOnline(ActionEvent event) { protected void handleViewOnline(ActionEvent event) {
Network.openURL(album.getUrl()); System.out.println(album.getUrl());
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI(album.getUrl()));
} catch (Exception e) {
Logger.getLog().logError(new ErrorEntry("Can't Open"));
}
}
// Network.openURL(album.getUrl());
} }
@Override @Override
@FXML
protected void handleRefresh(ActionEvent event) { protected void handleRefresh(ActionEvent event) {
Service<Void> service = new Service<Void>() { Service<Void> service = new Service<Void>() {
@ -76,15 +125,15 @@ public class AlbumBorderPaneController extends FMObjBorderPaneController{
return new Task<Void>() { return new Task<Void>() {
@Override @Override
protected Void call() throws Exception { protected Void call() throws Exception {
album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album); album = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(album);
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
public void run() { public void run() {
infoPaneController.refresh(album); infoPaneController.refresh(album);
} }
}); });
return null; return null;
@ -94,5 +143,5 @@ public class AlbumBorderPaneController extends FMObjBorderPaneController{
}; };
service.start(); service.start();
} }
} }

View File

@ -1,6 +1,9 @@
package sarsoo.fmframework.fx.controller.borderpane; package sarsoo.fmframework.fx.controller.borderpane;
import java.awt.Desktop;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.concurrent.Service; import javafx.concurrent.Service;
@ -10,7 +13,6 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import sarsoo.fmframework.fm.FmUserNetwork; import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.chart.GenrePieChartTitledPane;
import sarsoo.fmframework.fx.controller.info.ArtistPaneController; import sarsoo.fmframework.fx.controller.info.ArtistPaneController;
import sarsoo.fmframework.music.Artist; import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.net.Key; import sarsoo.fmframework.net.Key;
@ -40,6 +42,10 @@ public class ArtistBorderPaneController extends FMObjBorderPaneController{
e.printStackTrace(); e.printStackTrace();
} }
setInfoView(); setInfoView();
// if(artist.getUrl() == null) {
buttonViewOnline.setDisable(true);
// }
} }
@Override @Override
@ -61,11 +67,21 @@ public class ArtistBorderPaneController extends FMObjBorderPaneController{
} }
@Override @Override
@FXML
protected void handleViewOnline(ActionEvent event) { protected void handleViewOnline(ActionEvent event) {
Network.openURL(artist.getUrl()); System.out.println(artist.getUrl());
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI(artist.getUrl()));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
// Network.openURL(artist.getUrl());
} }
@Override @Override
@FXML
protected void handleRefresh(ActionEvent event) { protected void handleRefresh(ActionEvent event) {
Service<Void> service = new Service<Void>() { Service<Void> service = new Service<Void>() {

View File

@ -31,6 +31,9 @@ public abstract class FMObjBorderPaneController {
@FXML @FXML
protected Button buttonViewInfo; protected Button buttonViewInfo;
@FXML
protected Button buttonViewOnline;
@FXML @FXML
protected BorderPane borderPane; protected BorderPane borderPane;

View File

@ -1,40 +1,45 @@
package sarsoo.fmframework.fx.controller.borderpane; package sarsoo.fmframework.fx.controller.borderpane;
import java.awt.Desktop;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.concurrent.Service; import javafx.concurrent.Service;
import javafx.concurrent.Task; import javafx.concurrent.Task;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import sarsoo.fmframework.fm.FmUserNetwork; import sarsoo.fmframework.fm.FmUserNetwork;
import sarsoo.fmframework.fx.chart.GenrePieChartTitledPane; import sarsoo.fmframework.fx.FmFramework;
import sarsoo.fmframework.fx.controller.info.ArtistPaneController;
import sarsoo.fmframework.fx.controller.info.TrackPaneController; import sarsoo.fmframework.fx.controller.info.TrackPaneController;
import sarsoo.fmframework.music.Artist; import sarsoo.fmframework.fx.tab.AlbumTab;
import sarsoo.fmframework.fx.tab.ArtistTab;
import sarsoo.fmframework.music.Track; import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.net.Key; import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.net.Network; import sarsoo.fmframework.net.Network;
import sarsoo.fmframework.util.Reference; import sarsoo.fmframework.util.Reference;
public class TrackBorderPaneController extends FMObjBorderPaneController{ public class TrackBorderPaneController extends FMObjBorderPaneController {
TrackPaneController infoPaneController; TrackPaneController infoPaneController;
Track track; Track track;
@FXML @FXML
public void initialize() { public void initialize() {
borderPane.setTop(null); borderPane.setTop(null);
} }
public void populate(Track track) { public void populate(Track track) {
this.track = track; this.track = track;
try { try {
loadInfoPane(); loadInfoPane();
loadScrobblePane(); loadScrobblePane();
@ -42,11 +47,51 @@ public class TrackBorderPaneController extends FMObjBorderPaneController{
e.printStackTrace(); e.printStackTrace();
} }
setInfoView(); setInfoView();
Button viewAlbum = new Button("view album");
Button viewArtist = new Button("view artist");
if (track.getAlbum() != null) {
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 {
viewAlbum.setDisable(true);
}
if (track.getArtist() != null) {
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 {
viewArtist.setDisable(true);
}
toolBar.getItems().add(viewAlbum);
toolBar.getItems().add(viewArtist);
// if(track.getUrl() == null) {
buttonViewOnline.setDisable(true);
// }
} }
@Override @Override
public void loadInfoPane() throws IOException { public void loadInfoPane() throws IOException {
FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/TrackPane.fxml")); FXMLLoader loader = new FXMLLoader(getClass().getResource("../../ui/TrackPane.fxml"));
this.infoAnchorPane = (AnchorPane) loader.load(); this.infoAnchorPane = (AnchorPane) loader.load();
@ -57,17 +102,27 @@ public class TrackBorderPaneController extends FMObjBorderPaneController{
AnchorPane.setBottomAnchor(infoAnchorPane, 0.0); AnchorPane.setBottomAnchor(infoAnchorPane, 0.0);
infoPaneController = (TrackPaneController) loader.getController(); infoPaneController = (TrackPaneController) loader.getController();
infoPaneController.refresh(track); infoPaneController.refresh(track);
} }
@Override @Override
@FXML
protected void handleViewOnline(ActionEvent event) { protected void handleViewOnline(ActionEvent event) {
Network.openURL(track.getUrl()); System.out.println(track.getUrl());
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI(track.getUrl()));
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
}
// Network.openURL(track.getUrl());
} }
@Override @Override
@FXML
protected void handleRefresh(ActionEvent event) { protected void handleRefresh(ActionEvent event) {
Service<Void> service = new Service<Void>() { Service<Void> service = new Service<Void>() {
@ -76,15 +131,15 @@ public class TrackBorderPaneController extends FMObjBorderPaneController{
return new Task<Void>() { return new Task<Void>() {
@Override @Override
protected Void call() throws Exception { protected Void call() throws Exception {
track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track); track = new FmUserNetwork(Key.getKey(), Reference.getUserName()).refresh(track);
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
public void run() { public void run() {
infoPaneController.refresh(track); infoPaneController.refresh(track);
} }
}); });
return null; return null;
@ -94,5 +149,5 @@ public class TrackBorderPaneController extends FMObjBorderPaneController{
}; };
service.start(); service.start();
} }
} }