Skip to content

Commit

Permalink
[desktop] TransferDetailFilesActionsRenderer fixes and updates
Browse files Browse the repository at this point in the history
 - Fixes bug where transfer file detail actions would go blank when left clicked. Solution was to cancel cell editing
 - Ads right click popup menu actions: Explore, Play
  • Loading branch information
gubatron committed Dec 28, 2020
1 parent 3ca7158 commit 74291c0
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 39 deletions.
Expand Up @@ -21,6 +21,7 @@
import com.frostwire.bittorrent.PaymentOptions;
import com.frostwire.gui.bittorrent.BTDownloadActions.PlaySingleMediaFileAction;
import com.frostwire.gui.components.slides.Slide;
import com.frostwire.gui.components.transfers.TransferDetailFiles;
import com.frostwire.gui.filters.TableLineFilter;
import com.frostwire.gui.library.LibraryUtils;
import com.frostwire.gui.player.MediaPlayer;
Expand Down Expand Up @@ -614,6 +615,7 @@ protected void setDefaultRenderers() {
TABLE.setDefaultRenderer(PaymentOptions.class, new PaymentOptionsRenderer());
TABLE.setDefaultRenderer(TransferHolder.class, new TransferActionsRenderer());
TABLE.setDefaultRenderer(SeedingHolder.class, new TransferSeedingRenderer());
TABLE.setDefaultRenderer(TransferDetailFiles.TransferItemHolder.class, new TransferDetailFilesActionsRenderer());
}

@Override
Expand Down
@@ -1,19 +1,19 @@
/*
* Created by Angel Leon (@gubatron), Alden Torres (aldenml)
* Copyright (c) 2011-2015, FrostWire(R). All rights reserved.
* Created by Angel Leon (@gubatron), Alden Torres (aldenml),
* Marcelina Knitter (@marcelinkaaa), Jose Molina (@votaguz)
* Copyright (c) 2011-2020, FrostWire(R). All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* http://www.apache.org/licenses/LICENSE-2.0
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.frostwire.gui.bittorrent;
Expand Down Expand Up @@ -116,7 +116,7 @@ private void openPaymentOptionsURL(PaymentOptions paymentOptions, PaymentMethod
} else {
String paymentOptionsJSON = UrlUtils.encode(JsonUtils.toJson(paymentOptions).replaceAll("\n", ""));
String title = UrlUtils.encode(paymentOptions.getItemName());
paymentOptionsUrl = "http://www.frostwire.com/tips/?method=" + method.toString() + "&po=" + paymentOptionsJSON + "&title=" + title;
paymentOptionsUrl = "https://www.frostwire.com/tips/?method=" + method.toString() + "&po=" + paymentOptionsJSON + "&title=" + title;
}
GUIMediator.openURL(paymentOptionsUrl);
}
Expand Down
Expand Up @@ -23,11 +23,13 @@
import com.frostwire.gui.player.MediaPlayer;
import com.frostwire.gui.player.MediaSource;
import com.limegroup.gnutella.gui.GUIMediator;
import com.limegroup.gnutella.gui.I18n;
import com.limegroup.gnutella.gui.actions.LimeAction;
import com.limegroup.gnutella.gui.search.FWAbstractJPanelTableCellRenderer;
import net.miginfocom.swing.MigLayout;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
Expand All @@ -45,12 +47,13 @@ public class TransferDetailFilesActionsRenderer extends FWAbstractJPanelTableCel
share_faded = new AlphaIcon(share_solid, 0.1f);
}

private JLabel playButton;
private JLabel shareButton;
private final JLabel playButton;
private final JLabel shareButton;
private TransferDetailFiles.TransferItemHolder transferItemHolder;

public TransferDetailFilesActionsRenderer() {
setLayout(new MigLayout("insets 2px 18px 0 0", "align center"));
setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0));
setLayout(new MigLayout("gap 2px, fillx, center, insets 5px 5px 5px 5px", "[20px!][20px!]"));
playButton = new JLabel(play_transparent);
playButton.addMouseListener(new MouseAdapter() {
@Override
Expand All @@ -69,18 +72,13 @@ public void mouseReleased(MouseEvent e) {
}
}
});
add(playButton, "center");
add(shareButton, "center");
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
updateButtons();
add(playButton, "width 20px!, growx 0, aligny top, push");
add(shareButton, "width 20px!, growx 0, aligny top, push");
}

@Override
protected void updateUIData(Object dataHolder, JTable table, int row, int column) {
cancelEdit(); // Gubatron: This is what solved the flickering/empty cell bug when the first column cells were clicked on. -Dec 28th 2020
if (!(dataHolder instanceof TransferDetailFiles.TransferItemHolder)) {
if (transferItemHolder != null) {
updateButtons();
Expand All @@ -95,12 +93,7 @@ private void onPlay() {
if (!transferItemHolder.transferItem.isComplete()) {
return;
}
File file = transferItemHolder.transferItem.getFile();
if (MediaPlayer.isPlayableFile(file)) {
MediaPlayer.instance().asyncLoadMedia(new MediaSource(file), false, false);
} else {
GUIMediator.launchFile(file);
}
new PlayAction(transferItemHolder).actionPerformed(null);
}

private void onShare() {
Expand All @@ -111,9 +104,7 @@ private void onShare() {
if (TorrentUtil.askForPermissionToSeedAndSeedDownloads(null)) {
new Thread(() -> {
TorrentUtil.makeTorrentAndDownload(file, null, true);
GUIMediator.safeInvokeLater(() -> {
BTDownloadMediator.instance().updateTableFilters();
});
GUIMediator.safeInvokeLater(() -> BTDownloadMediator.instance().updateTableFilters());
}).start();
}
}
Expand All @@ -127,4 +118,43 @@ private void updateButtons() {
playButton.invalidate();
shareButton.invalidate();
}

public final static class OpenInFolderAction extends AbstractAction {
private final TransferDetailFiles.TransferItemHolder transferItemHolder;

public OpenInFolderAction(TransferDetailFiles.TransferItemHolder itemHolder) {
transferItemHolder = itemHolder;
putValue(Action.NAME, I18n.tr("Explore"));
putValue(LimeAction.SHORT_NAME, I18n.tr("Explore"));
putValue(Action.SHORT_DESCRIPTION, I18n.tr("Open Folder Containing the File"));
putValue(LimeAction.ICON_NAME, "LIBRARY_EXPLORE");
}

public void actionPerformed(ActionEvent ae) {
File selectedFile = transferItemHolder.transferItem.getFile();
if (selectedFile.isFile() && selectedFile.getParentFile() != null) {
GUIMediator.launchExplorer(selectedFile);
}
}
}

public final static class PlayAction extends AbstractAction {
private final TransferDetailFiles.TransferItemHolder transferItemHolder;

public PlayAction(TransferDetailFiles.TransferItemHolder itemHolder) {
transferItemHolder = itemHolder;
putValue(Action.NAME, I18n.tr("Play"));
putValue(LimeAction.SHORT_NAME, I18n.tr("Play"));
}

@Override
public void actionPerformed(ActionEvent e) {
File file = transferItemHolder.transferItem.getFile();
if (MediaPlayer.isPlayableFile(file)) {
MediaPlayer.instance().asyncLoadMedia(new MediaSource(file), false, false);
} else {
GUIMediator.launchFile(file);
}
}
}
}
Expand Up @@ -73,7 +73,7 @@ public void updateData(BittorrentDownload btDownload) {
* <p>
* Also, this is necessary to update the table, since tableMediator.update() doesn't work with plain TransferItems
*/
public class TransferItemHolder {
public static class TransferItemHolder {
public final TransferItem transferItem;
final int fileOffset;

Expand Down
Expand Up @@ -32,6 +32,7 @@ public final class TransferDetailFilesDataLine extends AbstractDataLine<Transfer
// -> A custom cell renderer for that column that displays a button and it's action listener
static LimeTableColumn ACTIONS_COLUMN;
private static final LimeTableColumn[] columns = new LimeTableColumn[]{
// See TransferDetailFilesActionsRenderer for action's code
ACTIONS_COLUMN = new LimeTableColumn(0, "ACTIONS", I18n.tr("Actions"), 80, true, true, true, TransferDetailFiles.TransferItemHolder.class),
new LimeTableColumn(1, "NUMBER", "#", 40, true, true, true, String.class),
new LimeTableColumn(2, "NAME", I18n.tr("Name"), 400, true, true, true, String.class),
Expand Down Expand Up @@ -87,6 +88,7 @@ public Object getValueAt(int col) {
case TYPE:
return holder.transferItem.getName().substring(holder.transferItem.getName().lastIndexOf(".") + 1);
case ACTIONS:
// See TransferDetailFilesActionsRenderer for action's code
return holder;
}
return null;
Expand Down
Expand Up @@ -18,6 +18,8 @@

package com.frostwire.gui.components.transfers;

import com.frostwire.gui.bittorrent.TransferDetailFilesActionsRenderer;
import com.frostwire.gui.theme.SkinPopupMenu;
import com.limegroup.gnutella.gui.PaddedPanel;
import com.limegroup.gnutella.gui.search.GenericCellEditor;
import com.limegroup.gnutella.gui.tables.AbstractTableMediator;
Expand Down Expand Up @@ -45,7 +47,15 @@ protected void setupConstants() {

@Override
protected JPopupMenu createPopupMenu() {
return null;
TransferDetailFilesModel dataModel = getDataModel();
TransferDetailFilesDataLine transferDetailFilesDataLine = dataModel.get(TABLE.getSelectedRow());
TransferDetailFiles.TransferItemHolder transferItemHolder = transferDetailFilesDataLine.getInitializeObject();
JPopupMenu menu = new SkinPopupMenu();
menu.add(new TransferDetailFilesActionsRenderer.OpenInFolderAction(transferItemHolder));
if (transferItemHolder.transferItem.isComplete()) {
menu.add(new TransferDetailFilesActionsRenderer.PlayAction(transferItemHolder));
}
return menu;
}

@Override
Expand All @@ -62,7 +72,7 @@ public void handleNoSelection() {

@Override
protected void setDefaultEditors() {
super.setDefaultEditors();
TransferDetailFilesDataLine.ACTIONS_COLUMN.setCellEditor(new GenericCellEditor(getTransferDetailFileActionsRenderer()));
TransferDetailFilesDataLine.ACTIONS_COLUMN.setCellRenderer(getTransferDetailFileActionsRenderer());
}
}
}
Expand Up @@ -277,7 +277,7 @@ protected void buildSettings() {
/**
* Assigns the listeners to their slots.
* This must be done _before_ the individual components
* are created, incase any of them want to use a listener.
* are created, in case any of them want to use a listener.
* Extending components that want to build extra listeners
* should call super.buildListeners and then build their own.
* DEFAULT_LISTENER, SELECTION_LISTENER, HEADER_LISTENER,
Expand Down

0 comments on commit 74291c0

Please sign in to comment.