📄 mytorrentsview.java
字号:
/*
* Created on 30 juin 2003
*
* Copyright (C) 2004, 2005, 2006 Aelitis SAS, 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 2 of the License.
*
* 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 ( see the LICENSE file ).
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* AELITIS, SAS au capital de 46,603.30 euros,
* 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
*/
package org.gudy.azureus2.ui.swt.views;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.category.Category;
import org.gudy.azureus2.core3.category.CategoryListener;
import org.gudy.azureus2.core3.category.CategoryManager;
import org.gudy.azureus2.core3.category.CategoryManagerListener;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
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.GlobalManagerDownloadRemovalVetoException;
import org.gudy.azureus2.core3.global.GlobalManagerListener;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.peer.PEPeerSource;
import org.gudy.azureus2.core3.torrent.TOTorrent;
import org.gudy.azureus2.core3.torrent.TOTorrentFactory;
import org.gudy.azureus2.core3.tracker.client.TRTrackerAnnouncer;
import org.gudy.azureus2.core3.tracker.util.TRTrackerUtils;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.ui.tables.TableManager;
import org.gudy.azureus2.ui.swt.*;
import org.gudy.azureus2.ui.swt.URLTransfer;
import org.gudy.azureus2.ui.swt.exporttorrent.wizard.ExportTorrentWizard;
import org.gudy.azureus2.ui.swt.help.HealthHelpWindow;
import org.gudy.azureus2.ui.swt.mainwindow.MainWindow;
import org.gudy.azureus2.ui.swt.mainwindow.TorrentOpener;
import org.gudy.azureus2.ui.swt.maketorrent.MultiTrackerEditor;
import org.gudy.azureus2.ui.swt.maketorrent.TrackerEditorListener;
import org.gudy.azureus2.ui.swt.shells.InputShell;
import org.gudy.azureus2.ui.swt.views.table.TableCellCore;
import org.gudy.azureus2.ui.swt.views.table.TableColumnCore;
import org.gudy.azureus2.ui.swt.views.table.TableRowCore;
import org.gudy.azureus2.ui.swt.views.table.impl.TableCellImpl;
import org.gudy.azureus2.ui.swt.views.utils.ManagerUtils;
import com.aelitis.azureus.core.AzureusCore;
/** Displays a list of torrents in a table view.
*
* @author Olivier
* @author TuxPaper
* 2004/Apr/18: Use TableRowImpl instead of PeerRow
* 2004/Apr/20: Remove need for tableItemToObject
* 2004/Apr/21: extends TableView instead of IAbstractView
* 2005/Oct/01: Column moving in SWT >= 3.1
*/
public class MyTorrentsView
extends TableView
implements GlobalManagerListener,
ParameterListener,
DownloadManagerListener,
CategoryManagerListener,
CategoryListener,
KeyListener
{
private static final LogIDs LOGID = LogIDs.GUI;
private static final int ASYOUTYPE_MODE_FIND = 0;
private static final int ASYOUTYPE_MODE_FILTER = 1;
private static final int ASYOUTYPE_MODE = ASYOUTYPE_MODE_FILTER;
private AzureusCore azureus_core;
private GlobalManager globalManager;
private boolean isSeedingView;
private Composite cTablePanel;
private Font fontButton = null;
private Composite cCategories;
private ControlAdapter catResizeAdapter;
private Menu menuCategory;
private MenuItem menuItemChangeDir = null;
private DragSource dragSource = null;
private DropTarget dropTarget = null;
private Label tableLabel = null;
int userMode;
boolean isTrackerOn;
private Map downloadBars;
private AEMonitor downloadBars_mon = new AEMonitor( "MyTorrentsView:DL" );
private Category currentCategory;
private boolean skipDMAdding = true;
// table item index, where the drag has started
private int drag_drop_line_start = -1;
private boolean confirmDataDelete = COConfigurationManager.getBooleanParameter("Confirm Data Delete", true);
private String sLastSearch = "";
private long lLastSearchTime;
private boolean bRegexSearch = false;
/**
* Initialize
*
* @param _azureus_core
* @param isSeedingView
* @param basicItems
*/
public
MyTorrentsView(
AzureusCore _azureus_core,
boolean isSeedingView,
TableColumnCore[] basicItems)
{
super((isSeedingView) ? TableManager.TABLE_MYTORRENTS_COMPLETE
: TableManager.TABLE_MYTORRENTS_INCOMPLETE,
"MyTorrentsView", basicItems, "#",
SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER | SWT.VIRTUAL);
setRowDefaultIconSize(new Point(16, 16));
azureus_core = _azureus_core;
this.globalManager = azureus_core.getGlobalManager();
this.isSeedingView = isSeedingView;
downloadBars = MainWindow.getWindow().getDownloadBars();
currentCategory = CategoryManager.getCategory(Category.TYPE_ALL);
}
/* (non-Javadoc)
* @see org.gudy.azureus2.ui.swt.IView#initialize(org.eclipse.swt.widgets.Composite)
*/
public void initialize(Composite composite0) {
if(cTablePanel != null) {
return;
}
super.initialize(composite0);
createTabs();
createDragDrop();
COConfigurationManager.addParameterListener("Confirm Data Delete", this);
activateCategory(currentCategory);
CategoryManager.addCategoryManagerListener(this);
// globalManager.addListener sends downloadManagerAdded()'s when you addListener
// we don't need them..
skipDMAdding = true;
globalManager.addListener(this);
skipDMAdding = false;
}
public void tableStructureChanged() {
super.tableStructureChanged();
createDragDrop();
activateCategory(currentCategory);
}
public Composite createMainPanel(Composite composite) {
GridData gridData;
Composite panel = new Composite(composite, SWT.NULL);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 0;
layout.marginHeight = 0;
layout.marginWidth = 0;
panel.setLayout(layout);
panel.setLayoutData(new GridData(GridData.FILL_BOTH));
cTablePanel = new Composite(panel, SWT.NULL);
gridData = new GridData(GridData.FILL_BOTH);
gridData.horizontalSpan = 2;
cTablePanel.setLayoutData(gridData);
layout = new GridLayout(1, false);
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
layout.horizontalSpacing = 0;
cTablePanel.setLayout(layout);
return panel;
}
private void createTabs() {
GridData gridData;
Category[] categories = CategoryManager.getCategories();
Arrays.sort(categories);
boolean showCat = sLastSearch.length() > 0;
if (!showCat)
for(int i = 0; i < categories.length; i++) {
if(categories[i].getType() == Category.TYPE_USER) {
showCat = true;
break;
}
}
if(cCategories != null && !showCat) {
Control[] controls = cCategories.getChildren();
for (int i = 0; i < controls.length; i++) {
controls[i].dispose();
}
}
if (categories.length > 0 && showCat) {
if (cCategories == null) {
Composite parent = getComposite();
cCategories = new Composite(parent, SWT.NONE);
gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
cCategories.setLayoutData(gridData);
RowLayout rowLayout = new RowLayout();
final int uniformPadding = 0;
rowLayout.marginTop = uniformPadding;
rowLayout.marginBottom = uniformPadding;
rowLayout.marginLeft = uniformPadding;
rowLayout.marginRight = uniformPadding;
rowLayout.spacing = uniformPadding;
rowLayout.wrap = true;
cCategories.setLayout(rowLayout);
tableLabel = new Label(parent, SWT.WRAP);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalIndent = 5;
tableLabel.setLayoutData(gridData);
updateTableLabel();
tableLabel.moveAbove(null);
cCategories.moveBelow(tableLabel);
} else {
Control[] controls = cCategories.getChildren();
for (int i = 0; i < controls.length; i++) {
controls[i].dispose();
}
}
int iFontPixelsHeight = 11;
int iFontPointHeight = (iFontPixelsHeight * 72) / cCategories.getDisplay().getDPI().y;
for (int i = 0; i < categories.length; i++) {
final Button catButton = new Button(cCategories, SWT.TOGGLE);
if (i == 0 && fontButton == null) {
Font f = catButton.getFont();
FontData fd = f.getFontData()[0];
fd.setHeight(iFontPointHeight);
fontButton = new Font(cCategories.getDisplay(), fd);
}
catButton.setText("|");
catButton.setFont(fontButton);
catButton.pack(true);
if (catButton.computeSize(100,SWT.DEFAULT).y > 0) {
RowData rd = new RowData();
rd.height = catButton.computeSize(100,SWT.DEFAULT).y - 2 + catButton.getBorderWidth() * 2;
catButton.setLayoutData(rd);
}
String name = categories[i].getName();
if (categories[i].getType() == Category.TYPE_USER)
catButton.setText(name);
else
Messages.setLanguageText(catButton, name);
catButton.setData("Category", categories[i]);
if (categories[i] == currentCategory) {
catButton.setSelection(true);
}
catButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
Button curButton = (Button)e.widget;
boolean isEnabled = curButton.getSelection();
Control[] controls = cCategories.getChildren();
if (!isEnabled)
curButton = (Button)controls[0];
for (int i = 0; i < controls.length; i++) {
Button b = (Button)controls[i];
if (b != curButton && b.getSelection())
b.setSelection(false);
else if (b == curButton && !b.getSelection())
b.setSelection(true);
}
activateCategory( (Category)curButton.getData("Category") );
}
});
catButton.addListener(SWT.MouseHover, new Listener() {
public void handleEvent(Event event) {
Button curButton = (Button)event.widget;
Category curCategory = (Category)curButton.getData("Category");
List dms = curCategory.getDownloadManagers();
long ttlActive = 0;
long ttlSize = 0;
long ttlRSpeed = 0;
long ttlSSpeed = 0;
int count = 0;
for (Iterator iter = dms.iterator(); iter.hasNext();) {
DownloadManager dm = (DownloadManager) iter.next();
if (!isOurDownloadManager(dm))
continue;
count++;
if (dm.getState() == DownloadManager.STATE_DOWNLOADING
|| dm.getState() == DownloadManager.STATE_SEEDING)
ttlActive++;
ttlSize += dm.getSize();
ttlRSpeed += dm.getStats().getDataReceiveRate();
ttlSSpeed += dm.getStats().getDataSendRate();
}
if (count == 0) {
curButton.setToolTipText(null);
return;
}
curButton.setToolTipText("Total: " + count + "\n"
+ "Downloading/Seeding: " + ttlActive + "\n"
+ "\n"
+ "Speed: "
+ DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlRSpeed / count) + "/"
+ DisplayFormatters.formatByteCountToKiBEtcPerSec(ttlSSpeed / count) + "\n"
+ "Size: " + DisplayFormatters.formatByteCountToKiBEtc(ttlSize));
}
});
final DropTarget tabDropTarget = new DropTarget(catButton, DND.DROP_DEFAULT | DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK);
Transfer[] types = new Transfer[] { TextTransfer.getInstance()};
tabDropTarget.setTransfer(types);
tabDropTarget.addDropListener(new DropTargetAdapter() {
public void dragOver(DropTargetEvent e) {
if(drag_drop_line_start >= 0)
e.detail = DND.DROP_MOVE;
else
e.detail = DND.DROP_NONE;
}
public void drop(DropTargetEvent e) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -