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

📄 opentorrentwindow.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		torrentTable.setHeaderVisible(true);
		Menu menu = new Menu(torrentTable);
		String sTitle = MessageText.getString("OpenTorrentWindow.startMode");
		int userMode = COConfigurationManager.getIntParameter("User Mode");
		MenuItem item;
		for (int i = 0; i < startModes.length; i++)
			if (i != 2 || userMode != 0)
			{
				item = new MenuItem(menu, 8);
				item.setData("Value", new Long(i));
				item.setText((new StringBuilder()).append(sTitle).append(": ").append(MessageText.getString((new StringBuilder()).append("OpenTorrentWindow.startMode.").append(startModes[i]).toString())).toString());
				item.addSelectionListener(new SelectionAdapter() {

					final OpenTorrentWindow this$0;

					public void widgetSelected(SelectionEvent e)
					{
						Long l = (Long)e.widget.getData("Value");
						if (l != null)
						{
							setSelectedStartMode(l.intValue());
							checkSeedingMode();
						}
					}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
				});
			}

		item = new MenuItem(menu, 2);
		sTitle = MessageText.getString("OpenTorrentWindow.addPosition");
		for (int i = 0; i < queueLocations.length; i++)
		{
			item = new MenuItem(menu, 8);
			item.setData("Value", new Long(i));
			item.setText((new StringBuilder()).append(sTitle).append(": ").append(MessageText.getString((new StringBuilder()).append("OpenTorrentWindow.addPosition.").append(queueLocations[i]).toString())).toString());
			item.addSelectionListener(new SelectionAdapter() {

				final OpenTorrentWindow this$0;

				public void widgetSelected(SelectionEvent e)
				{
					Long l = (Long)e.widget.getData("Value");
					if (l != null)
						setSelectedQueueLocation(l.intValue());
				}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
			});
		}

		item = new MenuItem(menu, 2);
		item = new MenuItem(menu, 8);
		Messages.setLanguageText(item, "MyTorrentsView.menu.remove");
		item.addSelectionListener(new SelectionAdapter() {

			final OpenTorrentWindow this$0;

			public void widgetSelected(SelectionEvent e)
			{
				deleteSelected(torrentTable, torrentList);
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		item = new MenuItem(menu, 8);
		Messages.setLanguageText(item, "OpenTorrentWindow.fileList.changeDestination");
		item.addSelectionListener(new SelectionAdapter() {

			final OpenTorrentWindow this$0;

			public void widgetSelected(SelectionEvent e)
			{
				int indexes[] = torrentTable.getSelectionIndices();
				String sDefPath = sDestDir;
				for (int i = 0; i < indexes.length; i++)
				{
					TorrentInfo info = (TorrentInfo)torrentList.get(indexes[i]);
					TorrentFileInfo files[] = info.getFiles();
					if (files.length == 1)
					{
						changeFileDestination(new int[] {
							0
						});
						continue;
					}
					DirectoryDialog dDialog = new DirectoryDialog(shellForChildren, 0x20000);
					dDialog.setFilterPath(sDefPath);
					dDialog.setMessage((new StringBuilder()).append(MessageText.getString("MainWindow.dialog.choose.savepath")).append(" (").append(info.getTorrentName()).append(")").toString());
					String sNewDir = dDialog.open();
					if (sNewDir == null)
						return;
					File newDir = (new File(sNewDir)).getAbsoluteFile();
					if (newDir.isDirectory())
						sDefPath = sNewDir;
					info.sDestDir = newDir.getParent();
					if (info.sDestDir == null)
						info.sDestDir = newDir.getPath();
					info.sDestSubDir = newDir.getName();
					for (int j = 0; j < files.length; j++)
					{
						TorrentFileInfo fileInfo = files[j];
						fileInfo.setDestFileName(null);
					}

				}

				checkSeedingMode();
				updateDataDirCombo();
				diskFreeInfoRefreshPending = true;
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		torrentTable.setMenu(menu);
		Composite cTorrentListRight = new Composite(cArea, 0);
		gridData = new GridData();
		cTorrentListRight.setLayoutData(gridData);
		RowLayout rLayout = new RowLayout(512);
		rLayout.marginBottom = 0;
		rLayout.marginLeft = 0;
		rLayout.marginRight = 0;
		rLayout.marginTop = 0;
		if (!Constants.isOSX)
			rLayout.spacing = 0;
		rLayout.fill = true;
		cTorrentListRight.setLayout(rLayout);
		ImageLoader imageLoader = ImageLoader.getInstance();
		Button torMoveUp = new Button(cTorrentListRight, 8);
		imageLoader.setButtonImage(torMoveUp, "up");
		torMoveUp.setToolTipText(MessageText.getString("Button.moveUp"));
		torMoveUp.addListener(13, new Listener() {

			final OpenTorrentWindow this$0;

			public void handleEvent(Event event)
			{
				int indices[] = torrentTable.getSelectionIndices();
				if (indices.length == 0)
					return;
				Arrays.sort(indices);
				if (indices[0] == 0)
					return;
				for (int i = 0; i < indices.length; i++)
				{
					int pos = indices[i];
					Object save = torrentList.get(pos - 1);
					torrentList.set(pos - 1, torrentList.get(pos));
					torrentList.set(pos, save);
					indices[i]--;
				}

				torrentTable.setSelection(indices);
				torrentTable.clearAll();
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		Button torMoveDown = new Button(cTorrentListRight, 8);
		imageLoader.setButtonImage(torMoveDown, "down");
		torMoveDown.setToolTipText(MessageText.getString("Button.moveDown"));
		torMoveDown.addListener(13, new Listener() {

			final OpenTorrentWindow this$0;

			public void handleEvent(Event event)
			{
				int indices[] = torrentTable.getSelectionIndices();
				if (indices.length == 0)
					return;
				Arrays.sort(indices);
				int max = indices.length - 1;
				if (indices[max] == torrentList.size() - 1)
					return;
				for (int i = max; i >= 0; i--)
				{
					int pos = indices[i];
					Object save = torrentList.get(pos + 1);
					torrentList.set(pos + 1, torrentList.get(pos));
					torrentList.set(pos, save);
					indices[i]++;
				}

				torrentTable.setSelection(indices);
				torrentTable.clearAll();
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
		Button torMoveRemove = new Button(cTorrentListRight, 8);
		torMoveRemove.setToolTipText(MessageText.getString("OpenTorrentWindow.torrent.remove"));
		imageLoader.setButtonImage(torMoveRemove, "delete");
		torMoveRemove.addListener(13, new Listener() {

			final OpenTorrentWindow this$0;

			public void handleEvent(Event event)
			{
				deleteSelected(torrentTable, torrentList);
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
	}

	protected void setSelectedQueueLocation(int iLocation)
	{
		int indices[] = torrentTable.getSelectionIndices();
		for (int i = 0; i < indices.length; i++)
		{
			TorrentInfo info = (TorrentInfo)torrentList.get(indices[i]);
			info.iQueueLocation = iLocation;
		}

		updateQueueLocationCombo();
		torrentTable.clear(indices);
	}

	protected void setSelectedStartMode(int iStartID)
	{
		int indices[] = torrentTable.getSelectionIndices();
		for (int i = 0; i < indices.length; i++)
		{
			TorrentInfo info = (TorrentInfo)torrentList.get(indices[i]);
			info.iStartID = iStartID;
		}

		checkSeedingMode();
		updateStartModeCombo();
		torrentTable.clear(indices);
	}

	private void checkSeedingMode()
	{
		for (int i = 0; i < torrentList.size(); i++)
		{
			boolean bTorrentValid = true;
			TorrentInfo info = (TorrentInfo)torrentList.get(i);
			if (info.iStartID == 3)
			{
				TorrentFileInfo files[] = info.getFiles();
				for (int j = 0; j < files.length; j++)
				{
					TorrentFileInfo fileInfo = files[j];
					if (!fileInfo.bDownload)
						continue;
					File file = fileInfo.getDestFileFullName();
					if (!file.exists())
					{
						fileInfo.isValid = false;
						bTorrentValid = false;
						continue;
					}
					if (!fileInfo.isValid)
						fileInfo.isValid = true;
				}

			}
			info.isValid = bTorrentValid;
		}

		Utils.execSWTThread(new AERunnable() {

			final OpenTorrentWindow this$0;

			public void runSupport()
			{
				if (torrentTable != null && !torrentTable.isDisposed())
					torrentTable.clearAll();
				if (dataFileTable != null && !dataFileTable.isDisposed())
				{
					dataFileTable.clearAll();
					editCell(-1);
				}
			}

			
			{
				this$0 = OpenTorrentWindow.this;
				super();
			}
		});
	}

	private void deleteSelected(Table table, ArrayList list)
	{
		int indexes[] = table.getSelectionIndices();
		Arrays.sort(indexes);
		for (int i = indexes.length - 1; i >= 0; i--)
		{
			if (list.get(indexes[i]) instanceof TorrentInfo)
			{
				TorrentInfo info = (TorrentInfo)list.get(indexes[i]);
				if (info.bDeleteFileOnCancel)
				{
					File file = new File(info.sFileName);
					if (file.exists())
						file.delete();
				}
			}
			list.remove(indexes[i]);
		}

		table.setItemCount(list.size());
		table.clearAll();
		table.notifyListeners(13, new Event());
	}

	private void editCell(final int row)
	{
		Text oldEditor = (Text)dataFileTableEditor.getEditor();
		if (row < 0 || row >= dataFileTable.getItemCount())
		{
			if (oldEditor != null && !oldEditor.isDisposed())
				oldEditor.dispose();
			return;
		}
		final Text newEditor = oldEditor != null && !oldEditor.isDisposed() ? oldEditor : new Text(dataFileTable, 2048);
		final TorrentFileInfo file = (TorrentFileInfo)dataFiles.get(row);
		final String uneditedName = file.getDestFileName();
		TableItem item = dataFileTable.getItem(row);
		TableColumn column = dataFileTable.getColumn(1);
		newEditor.setText(uneditedName);
		newEditor.selectAll();
		newEditor.forceFocus();
		Rectangle leftAlignedBounds = item.getBounds(1);
		leftAlignedBounds.width = dataFileTableEditor.minimumWidth = newEditor.computeSize(-1, -1).x;
		if (leftAlignedBounds.intersection(dataFileTable.getClientArea()).equals(leftAlignedBounds))
			dataFileTableEditor.horizontalAlignment = 16384;
		else
			dataFileTableEditor.horizontalAlignment = 0x20000;
		dataFileTable.deselectAll();
		dataFileTable.select(row);
		dataFileTable.showItem(item);
		dataFileTable.showColumn(column);
		class 1QuickEditListener
			implements ModifyListener, SelectionListener, KeyListener, TraverseListener
		{

			final TorrentFileInfo val$file;
			final Text val$newEditor;
			final String val$uneditedName;
			final int val$row;
			final OpenTorrentWindow this$0;

			public void modifyText(ModifyEvent e)
			{
				file.setDestFileName(newEditor.getText());
				try
				{
					file.getDestFileFullName().getCanonicalFile();
					newEditor.setBackground(null);
				}
				catch (IOException e1)
				{
					newEditor.setBackground(Colors.colorErrorBG);
				}
			}

			public void widgetDefaultSelected(SelectionEvent e)
			{
				try
				{
					file.getDestFileFullName().getCanonicalFile();
				}
				catch (IOException e1)
				{
					file.setDestFileName(uneditedName);
				}
				move(row, 1, (Text)e.widget);
			}

			public void widgetSelected(SelectionEvent selectionevent)
			{
			}

			public void keyReleased(KeyEvent keyevent)
			{
			}

			public void keyPressed(KeyEvent e)
			{
				if (e.keyCode == 0x1000002 || e.keyCode == 0x1000001)
				{
					e.doit = false;
					move(row, e.keyCode != 0x1000002 ? -1 : 1, (Text)e.widget);
				}
			}

			public void keyTraversed(TraverseEvent e)
			{
				if (e.detail == 2 || e.detail == 4)
					e.doit = false;
				if (e.detail == 2)
					editCell(-1);
			}

			private void move(int oldRow, int offset, Text current)
			{
				current.removeModifyListener(this);
				current.removeSelectionListener(this);
				current.removeKeyListener(this);
				current.removeTraverseListener(this);
				editCell(oldRow + offset);
				dataFileTable.clear(oldRow);
			}

			1QuickEditListener()
			{
				this$0 = OpenTorrentWindow.this;
				file = torrentfileinfo;
				newEditor = text;
				uneditedName = s;
				row = i;
				super();
			}
		}

		1QuickEditListener listener = new 1QuickEditListener();
		newEditor.addModifyListener(listener);
		newEditor.addSelectionListener(listener);
		newEditor.addKeyListener(listener);
		newEditor.addTraverseListener(listener);
		dataFileTableEditor.setEditor(newEditor, dataFileTable.getItem(row), 1);
	}

	private void createTableDataFiles(Composite cArea)
	{
		dataFileTable = new Table(cArea, 0x10010822);
		dataFileTableEditor = new TableEditor(dataFileTable);
		dataFileTableEditor.grabHorizontal = true;
		dataFileTableEditor.minimumWidth = 50;
		GridData gridData = new GridData(1808);
		gridData.heightHint = 80;
		gridData.widthHint = 100;
		dataFileTable.setLayoutData(gridData);

⌨️ 快捷键说明

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