📄 torrentlistview.java
字号:
/**
*
*/
package com.aelitis.azureus.ui.swt.views;
import java.util.*;
import java.util.List;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.disk.DiskManagerFileInfo;
import org.gudy.azureus2.core3.download.DownloadManager;
import org.gudy.azureus2.core3.download.DownloadManagerListener;
import org.gudy.azureus2.core3.download.DownloadManagerState;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.global.GlobalManagerListener;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.torrent.TOTorrent;
import org.gudy.azureus2.core3.util.AEMonitor;
import org.gudy.azureus2.core3.util.AERunnable;
import org.gudy.azureus2.ui.swt.Utils;
import org.gudy.azureus2.ui.swt.views.table.TableColumnCore;
import org.gudy.azureus2.ui.swt.views.tableitems.mytorrents.SizeItem;
import org.gudy.azureus2.ui.swt.views.tableitems.mytorrents.UpItem;
import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.torrent.PlatformTorrentUtils;
import com.aelitis.azureus.ui.swt.columns.torrent.*;
import com.aelitis.azureus.ui.swt.skin.SWTSkin;
import com.aelitis.azureus.ui.swt.skin.SWTSkinObjectText;
import com.aelitis.azureus.ui.swt.skin.SWTSkinProperties;
import com.aelitis.azureus.ui.swt.views.list.*;
import org.gudy.azureus2.plugins.ui.tables.TableManager;
/**
* @author TuxPaper
* @created Jun 12, 2006
*
* TODO: Mini mode - displays most recent (date added or data complete)
*/
public class TorrentListView extends ListView implements GlobalManagerListener
{
public final static int VIEW_DOWNLOADING = 0;
public final static int VIEW_RECENT_DOWNLOADED = 1;
public final static int VIEW_MY_MEDIA = 2;
public static final String TABLE_MYMEDIA = "MyMedia";
private final static String[] LINK_KEYS = {
"MainWindow.v3.currentDL.manage",
"MainWindow.v3.recentDL.library",
null,
};
private final static String[] TABLE_IDS = {
"Downloading",
"Recent",
"Media",
};
final static TableColumnCore[] tableIncompleteItemsMini = {
new ColumnAzProduct(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnMediaThumb(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnTitle(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new SizeItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnQuality(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnSpeed(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnProgressETA(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnDateAdded2Liner(TableManager.TABLE_MYTORRENTS_INCOMPLETE, false),
};
final static TableColumnCore[] tableIncompleteItems = {
new ColumnAzProduct(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnMediaThumb(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnTitle(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnRate(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new SizeItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnQuality(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnSpeed(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnProgressETA(TableManager.TABLE_MYTORRENTS_INCOMPLETE),
new ColumnDateAdded2Liner(TableManager.TABLE_MYTORRENTS_INCOMPLETE, false),
};
final static TableColumnCore[] tableCompleteItemsMini = {
new ColumnAzProduct(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnMediaThumb(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnTitle(TableManager.TABLE_MYTORRENTS_COMPLETE),
new SizeItem(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnRateUpDown(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnRate(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnDateAdded2Liner(TableManager.TABLE_MYTORRENTS_COMPLETE, false),
};
final static TableColumnCore[] tableCompleteItems = {
new ColumnIsSeeding(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnAzProduct(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnMediaThumb(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnTitle(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnRate(TableManager.TABLE_MYTORRENTS_COMPLETE),
new SizeItem(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnSpeed(TableManager.TABLE_MYTORRENTS_COMPLETE),
new UpItem(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnRateUpDown(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnIsPrivate(TableManager.TABLE_MYTORRENTS_COMPLETE),
new ColumnDateAdded2Liner(TableManager.TABLE_MYTORRENTS_COMPLETE, false),
};
final static TableColumnCore[] tableMyMediaItems = {
new ColumnComplete(TABLE_MYMEDIA),
new ColumnAzProduct(TABLE_MYMEDIA),
new ColumnMediaThumb(TABLE_MYMEDIA),
new ColumnTitle(TABLE_MYMEDIA),
new SizeItem(TABLE_MYMEDIA),
new ColumnQuality(TABLE_MYMEDIA),
new ColumnDateAdded2Liner(TABLE_MYMEDIA, true),
new ColumnRateUpDown(TABLE_MYMEDIA),
new ColumnRate(TABLE_MYMEDIA),
};
private final dowloadManagerListener dmListener;
private final GlobalManager globalManager;
private final int viewMode;
private TableColumnCore[] tableColumns;
private final boolean bMiniMode;
private final SWTSkin skin;
private final SWTSkinObjectText countArea;
private final ArrayList listeners = new ArrayList();
private final AEMonitor listeners_mon = new AEMonitor("3.TLV.listeners");
private final Composite dataArea;
private boolean bAllowScrolling;
public TorrentListView(AzureusCore core, final SWTSkin skin,
SWTSkinProperties skinProperties, Composite headerArea, SWTSkinObjectText countArea,
Composite dataArea, int viewMode, final boolean bMiniMode,
boolean bAllowScrolling) {
super(TABLE_IDS[viewMode] + ((bMiniMode) ? "-Mini" : ""), skinProperties,
dataArea);
this.skin = skin;
this.countArea = countArea;
this.dataArea = dataArea;
this.viewMode = viewMode;
this.bMiniMode = bMiniMode;
this.bAllowScrolling = bAllowScrolling;
dmListener = new dowloadManagerListener(this);
if (viewMode == VIEW_DOWNLOADING) {
tableColumns = (bMiniMode) ? tableIncompleteItemsMini
: tableIncompleteItems;
} else if (viewMode == VIEW_RECENT_DOWNLOADED) {
tableColumns = (bMiniMode) ? tableCompleteItemsMini : tableCompleteItems;
} else {
tableColumns = tableMyMediaItems;
}
updateColumnList(tableColumns, "date_added");
if (headerArea != null) {
setupHeader(headerArea);
}
getScrolledComposite().addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
if (bMiniMode) {
fixupRowCount();
}
expandNameColumn();
}
});
final Listener l = new Listener() {
public void handleEvent(Event event) {
if (event.button == 2) {
ListRow row = (ListRow) event.widget.getData("ListRow");
if (row != null) {
DownloadManager dm = (DownloadManager) row.getDataSource(true);
if (dm != null) {
TOTorrent torrent = dm.getTorrent();
PlatformTorrentUtils.updateMetaData(torrent, 1);
Utils.beep();
}
}
}
}
};
addCountChangeListener(new ListCountChangeAdapter() {
public void rowAdded(ListRow row) {
row.getComposite().addListener(SWT.MouseUp, l);
}
});
addSelectionListener(new ListSelectionAdapter() {
public void defaultSelected(ListRow[] rows) {
ListRow[] selectedRows = getSelectedRows();
if (selectedRows.length > 0) {
//TorrentListViewsUtils.viewDetails(skin, selectedRows[0]);
}
}
}, false);
this.globalManager = core.getGlobalManager();
globalManager.addListener(this, false);
// Needed or Java borks!
dataArea.getDisplay().asyncExec(new AERunnable() {
public void runSupport() {
DownloadManager[] managers = sortDMList(globalManager.getDownloadManagers());
for (int i = 0; i < managers.length; i++) {
DownloadManager dm = managers[i];
downloadManagerAdded(dm);
}
}
});
dataArea.layout();
_expandNameColumn();
}
// XXX Please get rid of me! I suck and I am slow
public void regetDownloads() {
ListRow[] selectedRows = getSelectedRows();
final int[] rowIndexes = new int[selectedRows.length];
int selectedIndex = -1;
if (selectedRows.length > 0) {
for (int i = 0; i < selectedRows.length; i++) {
rowIndexes[i] = selectedRows[i].getIndex();
}
}
//System.out.println("SelectedIndex" + selectedIndex);
// globalManager.removeListener(this);
this.removeAllDataSources(true);
System.out.println("reget");
// globalManager.addListener(this, false);
fixupRowCount();
if (selectedIndex >= 0) {
dataArea.getDisplay().asyncExec(new AERunnable() {
public void runSupport() {
for (int i = 0; i < rowIndexes.length; i++) {
ListRow row = getRow(rowIndexes[i]);
if (row != null) {
row.setSelected(true);
}
}
}
});
}
}
protected void expandNameColumn() {
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
_expandNameColumn();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -