⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mytorrentsview.java

📁 基于JXTA开发平台的下载软件开发源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:

							try {
								((DownloadManager) dms[i]).moveDataFiles(target);

							} catch (Throwable e) {

								Logger.log(new LogAlert(LogAlert.REPEATABLE,
										"Download data move operation failed", e));
							}
						}
					}
				}
			}
		});
		itemFileMoveData.setEnabled(fileMove);
		
		final MenuItem itemFileMoveTorrent = new MenuItem(menuFiles, SWT.PUSH);
		Messages.setLanguageText(itemFileMoveTorrent,
				"MyTorrentsView.menu.movetorrent");
		itemFileMoveTorrent.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				Object[] dms = getSelectedDataSources();

				if (dms != null && dms.length > 0) {

					DirectoryDialog dd = new DirectoryDialog(getComposite().getShell());

					dd.setFilterPath(TorrentOpener.getFilterPathTorrent());

					dd.setText(MessageText
							.getString("MyTorrentsView.menu.movedata.dialog"));

					String path = dd.open();

					if (path != null) {

						File target = new File(path);

						TorrentOpener.setFilterPathTorrent(target.toString());

						for (int i = 0; i < dms.length; i++) {

							try {
								((DownloadManager) dms[i]).moveTorrentFile(target);

							} catch (Throwable e) {

								Logger.log(new LogAlert(LogAlert.REPEATABLE,
										"Download torrent move operation failed", e));
							}
						}
					}
				}
			}
		});		
		itemFileMoveTorrent.setEnabled(fileMove);
		
		final MenuItem itemFileRescan = new MenuItem(menuFiles, SWT.CHECK );
		Messages.setLanguageText(itemFileRescan,
				"MyTorrentsView.menu.rescanfile");
		itemFileRescan.addListener(SWT.Selection, new SelectedTableRowsListener() {
			public void run(TableRowCore row) {
				DownloadManager dm = (DownloadManager) row.getDataSource(true);
				
				dm.getDownloadState().setFlag( 
						DownloadManagerState.FLAG_SCAN_INCOMPLETE_PIECES,
						itemFileRescan.getSelection());
			}
		});

		itemFileRescan.setSelection( allScanSelected );
		itemFileRescan.setEnabled( fileRescan );
		
		// === advanced > export ===
		// =========================

		if (userMode > 0) {
			final MenuItem itemExport = new MenuItem(menuAdvanced, SWT.CASCADE);
			Messages.setLanguageText(itemExport, "MyTorrentsView.menu.exportmenu"); //$NON-NLS-1$
			Utils.setMenuItemImage(itemExport, "export");
			itemExport.setEnabled(hasSelection);
	
			final Menu menuExport = new Menu(getComposite().getShell(), SWT.DROP_DOWN);
			itemExport.setMenu(menuExport);
	
			// Advanced > Export > Export XML
			final MenuItem itemExportXML = new MenuItem(menuExport, SWT.PUSH);
			Messages.setLanguageText(itemExportXML, "MyTorrentsView.menu.export");
			itemExportXML.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event event) {
					DownloadManager dm = (DownloadManager) getFirstSelectedDataSource();
					if (dm != null)
						new ExportTorrentWizard(azureus_core, itemExportXML.getDisplay(), dm);
				}
			});
	
			// Advanced > Export > Export Torrent
			final MenuItem itemExportTorrent = new MenuItem(menuExport, SWT.PUSH);
			Messages.setLanguageText(itemExportTorrent,
					"MyTorrentsView.menu.exporttorrent");
			itemExportTorrent.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event event) {
					DownloadManager dm = (DownloadManager) getFirstSelectedDataSource();
					if (dm != null) {
						FileDialog fd = new FileDialog(getComposite().getShell(), SWT.SAVE );
	
						fd.setFileName(dm.getTorrentFileName());
	
						String path = fd.open();
	
						if (path != null) {
	
							try {
								File target = new File(path);
	
								// first copy the torrent - DON'T use "writeTorrent" as this amends the
								// "filename" field in the torrent
	
								TorrentUtils.copyToFile(dm.getDownloadState().getTorrent(),
										target);
	
								// now remove the non-standard entries
	
								TOTorrent dest = TOTorrentFactory
										.deserialiseFromBEncodedFile(target);
	
								dest.removeAdditionalProperties();
	
								dest.serialiseToBEncodedFile(target);
	
							} catch (Throwable e) {
								Logger.log(new LogAlert(LogAlert.UNREPEATABLE,
										"Torrent export failed", e));
							}
	
						}
					}
				}
			});
		} // export menu

		// === advanced > peer sources ===
		// ===============================

		if (userMode > 0) {
			final MenuItem itemPeerSource = new MenuItem(menuAdvanced, SWT.CASCADE);
			Messages.setLanguageText(itemPeerSource, "MyTorrentsView.menu.peersource"); //$NON-NLS-1$
	
			final Menu menuPeerSource = new Menu(getComposite().getShell(),
					SWT.DROP_DOWN);
			itemPeerSource.setMenu(menuPeerSource);
	
			for (int i = 0; i < PEPeerSource.PS_SOURCES.length; i++) {
	
				final String p = PEPeerSource.PS_SOURCES[i];
				String msg_text = "ConfigView.section.connection.peersource." + p;
				final MenuItem itemPS = new MenuItem(menuPeerSource, SWT.CHECK);
				itemPS.setData("peerSource", p);
				Messages.setLanguageText(itemPS, msg_text); //$NON-NLS-1$
				itemPS.addListener(SWT.Selection, new SelectedTableRowsListener() {
					public void run(TableRowCore row) {
						((DownloadManager) row.getDataSource(true)).getDownloadState()
								.setPeerSourceEnabled(p, itemPS.getSelection());
					}
				});
				itemPS.setSelection(true);
				
				boolean bChecked = hasSelection;
				boolean bEnabled = !hasSelection;
				if (bChecked) {
					bEnabled = true;
					
					// turn on check if just one dm is not enabled
					for (int j = 0; j < dms.length; j++) {
						DownloadManager dm = (DownloadManager) dms[j];
						
						if (!dm.getDownloadState().isPeerSourceEnabled(p)) {
							bChecked = false;
						}
						if (!dm.getDownloadState().isPeerSourcePermitted(p)) {
							bEnabled = false;
						}
					}
				}
				
				itemPS.setSelection(bChecked);
				itemPS.setEnabled(bEnabled);
			}
		}
		

		// === advanced > networks ===
		// ===========================

		if (userMode > 1) {
			final MenuItem itemNetworks = new MenuItem(menuAdvanced, SWT.CASCADE);
			Messages.setLanguageText(itemNetworks, "MyTorrentsView.menu.networks"); //$NON-NLS-1$
	
			final Menu menuNetworks = new Menu(getComposite().getShell(), SWT.DROP_DOWN);
			itemNetworks.setMenu(menuNetworks);
	
			for (int i = 0; i < AENetworkClassifier.AT_NETWORKS.length; i++) {
				final String nn = AENetworkClassifier.AT_NETWORKS[i];
				String msg_text = "ConfigView.section.connection.networks." + nn;
				final MenuItem itemNetwork = new MenuItem(menuNetworks, SWT.CHECK);
				itemNetwork.setData("network", nn);
				Messages.setLanguageText(itemNetwork, msg_text); //$NON-NLS-1$
				itemNetwork.addListener(SWT.Selection, new SelectedTableRowsListener() {
					public void run(TableRowCore row) {
						((DownloadManager) row.getDataSource(true)).getDownloadState()
								.setNetworkEnabled(nn, itemNetwork.getSelection());
					}
				});
				boolean bChecked = hasSelection;
				if (bChecked) {
					// turn on check if just one dm is not enabled
					for (int j = 0; j < dms.length; j++) {
						DownloadManager dm = (DownloadManager) dms[j];
						
						if (!dm.getDownloadState().isNetworkEnabled(nn)) {
							bChecked = false;
							break;
						}
					}
				}
				
				itemNetwork.setSelection(bChecked);
			}
		}

		final MenuItem itemPositionManual = new MenuItem(menuAdvanced, SWT.PUSH);
		Messages.setLanguageText(itemPositionManual,
				"MyTorrentsView.menu.reposition.manual");
		itemPositionManual.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				InputShell is = new InputShell(
						"MyTorrentsView.dialog.setPosition.title",
						"MyTorrentsView.dialog.setPosition.text");

				String sReturn = is.getText();
				if (sReturn == null)
					return;

				int newPosition = -1;
				try {
					newPosition = Integer.valueOf(sReturn).intValue();
				} catch (NumberFormatException er) {
					// Ignore
				}

				int size = globalManager.downloadManagerCount(isSeedingView);
				if (newPosition > size)
					newPosition = size;

				if (newPosition <= 0) {
					MessageBox mb = new MessageBox(MainWindow.getWindow().getShell(),
							SWT.ICON_ERROR | SWT.OK);
					mb.setText(MessageText
							.getString("MyTorrentsView.dialog.NumberError.title"));
					mb.setMessage(MessageText
							.getString("MyTorrentsView.dialog.NumberError.text"));

					mb.open();
					return;
				}

				moveSelectedTorrentsTo(newPosition);
			}
		});

		// back to main menu

		if (userMode > 0 && isTrackerOn) {
			// Host
			final MenuItem itemHost = new MenuItem(menu, SWT.PUSH);
			Messages.setLanguageText(itemHost, "MyTorrentsView.menu.host");
			Utils.setMenuItemImage(itemHost, "host");
			itemHost.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event event) {
					hostSelectedTorrents();
				}
			});
	
			// Publish
			final MenuItem itemPublish = new MenuItem(menu, SWT.PUSH);
			Messages.setLanguageText(itemPublish, "MyTorrentsView.menu.publish");
			Utils.setMenuItemImage(itemPublish, "publish");
			itemPublish.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event event) {
					publishSelectedTorrents();
				}
			});

			itemHost.setEnabled(hasSelection);
			itemPublish.setEnabled(hasSelection);
		}
/*  Do we really need the Move submenu?  There's shortcut keys and toolbar
 *  buttons..

		new MenuItem(menu, SWT.SEPARATOR);

		final MenuItem itemMove = new MenuItem(menu, SWT.CASCADE);
		Messages.setLanguageText(itemMove, "MyTorrentsView.menu.move");
		Utils.setMenuItemImage(itemMove, "move");
		itemMove.setEnabled(hasSelection);

		final Menu menuMove = new Menu(getComposite().getShell(), SWT.DROP_DOWN);
		itemMove.setMenu(menuMove);

		final MenuItem itemMoveTop = new MenuItem(menuMove, SWT.PUSH);
		Messages.setLanguageText(itemMoveTop, "MyTorrentsView.menu.moveTop");
		Utils.setMenuItemImage(itemMoveTop, "top");
		itemMoveTop.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				moveSelectedTorrentsTop();
			}
		});
		itemMoveTop.setEnabled(moveUp);

		final MenuItem itemMoveUp = new MenuItem(menuMove, SWT.PUSH);
		Messages.setLanguageText(itemMoveUp, "MyTorrentsView.menu.moveUp");
		Utils.setMenuItemImage(itemMoveUp, "up");
		itemMoveUp.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				moveSelectedTorrentsUp();
			}
		});

		final MenuItem itemMoveDown = new MenuItem(menuMove, SWT.PUSH);
		Messages.setLanguageText(itemMoveDown, "MyTorrentsView.menu.moveDown");
		Utils.setMenuItemImage(itemMoveDown, "down");
		itemMoveDown.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				moveSelectedTorrentsDown();
			}
		});

		final MenuItem itemMoveEnd = new MenuItem(menuMove, SWT.PUSH);
		Messages.setLanguageText(itemMoveEnd, "MyTorrentsView.menu.moveEnd");
		Utils.setMenuItemImage(itemMoveEnd, "bottom");
		itemMoveEnd.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event event) {
				moveSelectedTorrentsEnd();
			}
		});
		itemMoveEnd.setEnabled(moveDown);
*/
		/*  //TODO ensure that all limits combined don't go under the min 5kbs ?
		 //Disable at the end of the list, thus the first item of the array is instanciated last.
		 itemsSpeed[0] = new MenuItem(menuSpeed,SWT.PUSH);
		 Messages.setLanguageText(itemsSpeed[0],"MyTorrentsView.menu.setSpeed.disable");
		 itemsSpeed[0].setData("maxul", new Integer(-1));    
		 itemsSpeed[0].addListener(SWT.Selection,itemsSpeedListener);
		 */

		// Category
		menuCategory = new Menu(getComposite().getShell(), SWT.DROP_DOWN);
		final MenuItem itemCategory = new MenuItem(menu, SWT.CASCADE);
		Messages.setLanguageText(itemCategory, "MyTorrentsView.menu.setCategory"); //$NON-NLS-1$
		//itemCategory.setImage(ImageRepository.getImage("speed"));
		itemCategory.setMenu(menuCategory);
		itemCategory.setEnabled(hasSelection);

		addCategorySubMenu();

		// ---
		new MenuItem(menu, SWT.SEPARATOR);

		// Queue
		final MenuItem itemQueue = new MenuItem(menu, SWT.PUSH);
		Messages.setLanguageText(itemQueue, "MyTorrentsView.menu.queue"); //$NON-NLS-1$
		Utils.setMenuItemImage(itemQueue, "start");
		itemQueue.addListener(SWT.Selection, new Listener() {
			public void handleEvent(Event e) {
				queueSelectedTorrents();
			}
		});
		itemQueue.setEnabled(start);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -