📄 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.*;
import java.util.List;
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.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.category.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
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.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.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.Colors;
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;
import com.aelitis.azureus.ui.UIFunctions;
import com.aelitis.azureus.ui.UIFunctionsManager;
import org.gudy.azureus2.plugins.ui.tables.TableManager;
/** 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 static final int ASYOUTYPE_UPDATEDELAY = 300;
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 Composite cHeader = null;
private Label lblHeader = null;
private Text txtFilter = null;
private Label lblX = null;
int userMode;
boolean isTrackerOn;
private Category currentCategory;
// table item index, where the drag has started
private int drag_drop_line_start = -1;
private TimerEvent searchUpdateEvent;
private String sLastSearch = "";
private long lLastSearchTime;
private boolean bRegexSearch = false;
private boolean bDNDalwaysIncomplete;
/**
* 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.VIRTUAL);
setRowDefaultIconSize(new Point(16, 16));
azureus_core = _azureus_core;
this.globalManager = azureus_core.getGlobalManager();
this.isSeedingView = isSeedingView;
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.addAndFireParameterListeners(new String[] {
"DND Always In Incomplete",
"Confirm Data Delete",
"User Mode" }, this);
if (currentCategory != null) {
currentCategory.addCategoryListener(this);
}
CategoryManager.addCategoryManagerListener(this);
globalManager.addListener(this, false);
Object[] dms = globalManager.getDownloadManagers().toArray();
for (int i = 0; i < dms.length; i++) {
DownloadManager dm = (DownloadManager) dms[i];
dm.addListener(this);
if (!isOurDownloadManager(dm)) {
dms[i] = null;
}
}
addDataSources(dms);
processDataSourceQueue();
}
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 (!showCat) {
if (cCategories != null && !cCategories.isDisposed()) {
Control[] controls = cCategories.getChildren();
for (int i = 0; i < controls.length; i++) {
controls[i].dispose();
}
}
} else {
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();
rowLayout.marginTop = 0;
rowLayout.marginBottom = 0;
rowLayout.marginLeft = 3;
rowLayout.marginRight = 0;
rowLayout.spacing = 0;
rowLayout.wrap = true;
cCategories.setLayout(rowLayout);
cHeader = new Composite(parent, SWT.NONE);
gridData = new GridData(GridData.FILL_HORIZONTAL);
gridData.horizontalIndent = 5;
cHeader.setLayoutData(gridData);
GridLayout layout = new GridLayout();
layout.numColumns = 6;
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.horizontalSpacing = 2;
layout.verticalSpacing = 0;
cHeader.setLayout(layout);
lblHeader = new Label(cHeader, SWT.WRAP);
gridData = new GridData();
lblHeader.setLayoutData(gridData);
updateTableLabel();
Label lblSep = new Label(cHeader, SWT.SEPARATOR | SWT.VERTICAL);
gridData = new GridData(GridData.FILL_VERTICAL);
gridData.heightHint = 5;
lblSep.setLayoutData(gridData);
Label lblFilter = new Label(cHeader, SWT.WRAP);
gridData = new GridData(GridData.BEGINNING);
lblFilter.setLayoutData(gridData);
Messages.setLanguageText(lblFilter, "MyTorrentsView.filter");
lblX = new Label(cHeader, SWT.WRAP);
Messages.setLanguageTooltip(lblX, "MyTorrentsView.clearFilter.tooltip");
gridData = new GridData(SWT.TOP);
lblX.setLayoutData(gridData);
lblX.setImage(ImageRepository.getImage("smallx-gray"));
lblX.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
if (e.y <= 10) {
sLastSearch = "";
updateLastSearch();
}
}
});
txtFilter = new Text(cHeader, SWT.BORDER);
Messages.setLanguageTooltip(txtFilter, "MyTorrentsView.filter.tooltip");
txtFilter.addKeyListener(this);
gridData = new GridData(GridData.FILL_HORIZONTAL);
txtFilter.setLayoutData(gridData);
txtFilter.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
sLastSearch = ((Text)e.widget).getText();
updateLastSearch();
}
});
txtFilter.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.keyCode == SWT.ARROW_DOWN) {
getTable().setFocus();
e.doit = false;
}
}
});
lblSep = new Label(cHeader, SWT.SEPARATOR | SWT.VERTICAL);
gridData = new GridData(GridData.FILL_VERTICAL);
gridData.heightHint = 5;
lblSep.setLayoutData(gridData);
cHeader.moveAbove(null);
cCategories.moveBelow(cHeader);
} 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);
catButton.addKeyListener(this);
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]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -