use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.
the class LibraryPlaylists method renameSelectedItem.
private void renameSelectedItem() {
if (!textName.isVisible() || textName.getText().trim().length() == 0) {
return;
}
Playlist selectedPlaylist = getSelectedPlaylist();
selectedPlaylist.setName(textName.getText().trim());
selectedPlaylist.save();
list.repaint();
textName.setVisible(false);
UXStats.instance().log(UXAction.LIBRARY_PLAYLIST_RENAMED);
LibraryPlaylistsTableMediator.instance().updateTableItems(selectedPlaylist);
}
use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.
the class LibraryPlaylistsTransferHandler method importData.
@Override
public boolean importData(TransferSupport support) {
if (!canImport(support)) {
return false;
}
DropLocation location = support.getDropLocation();
int index = list.locationToIndex(location.getDropPoint());
if (index != -1) {
// depending on the mouse position detect which playlist item the drop was done
Playlist playlist = getTargetPlaylist(location, index);
if (playlist == null) {
if (createNewPlaylist(support)) {
return false;
}
} else {
try {
Transferable transferable = support.getTransferable();
final DataFlavor[] dataFlavors = transferable.getTransferDataFlavors();
if (DNDUtils.contains(dataFlavors, LibraryPlaylistsTableTransferable.ITEM_ARRAY)) {
PlaylistItem[] playlistItems = LibraryUtils.convertToPlaylistItems((LibraryPlaylistsTableTransferable.PlaylistItemContainer) transferable.getTransferData(LibraryPlaylistsTableTransferable.ITEM_ARRAY));
LibraryUtils.asyncAddToPlaylist(playlist, playlistItems);
} else {
File[] files = DNDUtils.getFiles(support.getTransferable());
if (files.length == 1 && files[0].getAbsolutePath().endsWith(".m3u")) {
LibraryUtils.asyncAddToPlaylist(playlist, files[0]);
} else {
// importing a regular file
LibraryUtils.asyncAddToPlaylist(playlist, files);
}
}
} catch (Throwable e) {
return false;
}
}
} else {
return false;
}
return false;
}
use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.
the class MediaPlayerComponent method updateMediaSourceButton.
private void updateMediaSourceButton(final MediaSource currentMedia) {
SwingWorker<Void, Void> swingWorker = new SwingWorker<Void, Void>() {
private boolean isLocalFile;
private boolean isPlaylistItem;
private boolean isYT;
private boolean isSC;
private boolean isAR;
private String playlistName;
@Override
protected Void doInBackground() throws Exception {
if (currentMedia == null) {
return null;
}
if (currentMedia.getFile() != null) {
// won't be shown in 5.6.x, code here for 6.x
isLocalFile = true;
} else if (currentMedia.getPlaylistItem() != null) {
// won't be shown in 5.6.x, code here for 6.x
isPlaylistItem = true;
setupPlaylistName(currentMedia);
}
if (currentMedia instanceof StreamMediaSource) {
StreamMediaSource streamMedia = (StreamMediaSource) currentMedia;
if (streamMedia.getDetailsUrl() != null) {
isYT = streamMedia.getDetailsUrl().contains("youtube");
isSC = streamMedia.getDetailsUrl().contains("soundcloud");
isAR = streamMedia.getDetailsUrl().contains("archive");
}
}
return null;
}
@Override
protected void done() {
String tooltipText = "";
String iconUpName = "";
String iconDownName = "";
if (isLocalFile) {
// won't be shown in 5.6.x, code here for 6.x
tooltipText = I18n.tr("Playing local file");
iconUpName = iconDownName = "speaker_light";
} else if (isPlaylistItem) {
// won't be shown in 5.6.x, code here for 6.x
tooltipText = I18n.tr("Playing track from") + " " + playlistName;
iconUpName = iconDownName = "playlist";
} else if (isYT) {
tooltipText = I18n.tr("Open YouTube source page");
iconUpName = "youtube_off";
iconDownName = "youtube_on";
} else if (isSC) {
tooltipText = I18n.tr("Open SoundCloud source page");
iconUpName = "soundcloud_off";
iconDownName = "soundcloud_on";
} else if (isAR) {
tooltipText = I18n.tr("Open Archive.org source page");
iconUpName = "archive_off";
iconDownName = "archive_on";
}
// TODO: Add "isLocalFile || isPlaylistItem ||" on FrostWire 6.x when we have room for 3 buttons.
boolean mediaSourceButtonVisible = (currentMedia != null) && (isYT || isSC || isAR);
// System.out.println("mediaSourceButton should be visible? " + mediaSourceButtonVisible);
if (mediaSourceButtonVisible) {
mediaSourceButton.init(tooltipText, iconUpName, iconDownName);
}
mediaSourceButton.setVisible(mediaSourceButtonVisible);
}
private void setupPlaylistName(final MediaSource currentMedia) {
Playlist playlist = currentMedia.getPlaylistItem().getPlaylist();
if (playlist != null && playlist.getName() != null) {
playlistName = playlist.getName();
} else {
playlistName = I18n.tr("playlist");
}
}
};
swingWorker.execute();
}
use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.
the class LibraryUtils method createNewPlaylist.
static void createNewPlaylist(final List<? extends AbstractLibraryTableDataLine<?>> lines) {
DialogFinishedListener dialogListener = new DialogFinishedListener() {
@Override
public void onDialogCancelled() {
}
@Override
public void onDialogOk(String playlistName) {
if (playlistName != null && playlistName.length() > 0) {
final Playlist playlist = LibraryMediator.getLibrary().newPlaylist(playlistName, playlistName);
playlist.save();
LibraryMediator.instance().getLibraryPlaylists().addPlaylist(playlist);
LibraryMediator.instance().getLibraryPlaylists().markBeginImport(playlist);
Thread t = new Thread(new Runnable() {
public void run() {
addToPlaylist(playlist, lines);
playlist.save();
asyncAddToPlaylistFinalizer(playlist);
}
}, "createNewPlaylist");
t.setDaemon(true);
t.start();
UXStats.instance().log(UXAction.LIBRARY_PLAYLIST_CREATED);
}
}
};
FrostwireInputDialog.showInputDialog(GUIMediator.getAppFrame(), I18n.tr("Playlist name"), I18n.tr("Playlist name"), GUIMediator.getThemeImage("playlist"), suggestPlaylistName(lines), dialogListener);
}
use of com.frostwire.alexandria.Playlist in project frostwire by frostwire.
the class LibraryUtils method createNewPlaylist.
static void createNewPlaylist(final PlaylistItem[] playlistItems, boolean starred) {
if (starred) {
createStarredPlaylist(playlistItems);
} else {
DialogFinishedListener listener = new DialogFinishedListener() {
@Override
public void onDialogCancelled() {
}
@Override
public void onDialogOk(String playlistName) {
if (playlistName != null && playlistName.length() > 0) {
final Playlist playlist = LibraryMediator.getLibrary().newPlaylist(playlistName, playlistName);
Thread t = new Thread(new Runnable() {
public void run() {
try {
playlist.save();
addToPlaylist(playlist, playlistItems);
playlist.save();
GUIMediator.safeInvokeLater(new Runnable() {
public void run() {
LibraryMediator.instance().getLibraryPlaylists().addPlaylist(playlist);
}
});
UXStats.instance().log(UXAction.LIBRARY_PLAYLIST_CREATED);
} finally {
asyncAddToPlaylistFinalizer(playlist);
}
}
}, "createNewPlaylist");
t.setDaemon(true);
t.start();
}
}
};
FrostwireInputDialog.showInputDialog(GUIMediator.getAppFrame(), I18n.tr("Playlist name"), I18n.tr("Playlist name"), GUIMediator.getThemeImage("playlist"), suggestPlaylistName(playlistItems), listener);
}
}
Aggregations