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

📄 systemtrayswt.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   SystemTraySWT.java

package org.gudy.azureus2.ui.systray;

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.ui.common.updater.UIUpdatableAlways;
import com.aelitis.azureus.ui.common.updater.UIUpdater;
import com.aelitis.azureus.ui.swt.UIFunctionsManagerSWT;
import com.aelitis.azureus.ui.swt.UIFunctionsSWT;
import com.aelitis.azureus.ui.swt.imageloader.ImageLoader;
import java.util.List;
import org.eclipse.swt.events.MenuEvent;
import org.eclipse.swt.events.MenuListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.download.DownloadManager;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.global.GlobalManagerStats;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.ui.common.util.MenuItemManager;
import org.gudy.azureus2.ui.swt.*;
import org.gudy.azureus2.ui.swt.mainwindow.SWTThread;
import org.gudy.azureus2.ui.swt.mainwindow.SelectableSpeedMenu;
import org.gudy.azureus2.ui.swt.views.utils.ManagerUtils;

public class SystemTraySWT
	implements UIUpdatableAlways
{

	Display display;
	UIFunctionsSWT uiFunctions;
	Tray tray;
	TrayItem trayItem;
	Menu menu;
	Image imgAzureus;
	Image imgAzureusGray;
	Image imgAzureusWhite;

	public SystemTraySWT()
	{
		uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
		display = SWTThread.getInstance().getDisplay();
		tray = display.getSystemTray();
		trayItem = new TrayItem(tray, 0);
		ImageLoader imageLoader = ImageLoader.getInstance();
		if (Constants.isOSX)
		{
			imgAzureusGray = imageLoader.getImage("azureus_grey");
			imgAzureusWhite = imageLoader.getImage("azureus_white");
			trayItem.setImage(imgAzureusGray);
		} else
		{
			imgAzureus = imageLoader.getImage("azureus");
			trayItem.setImage(imgAzureus);
		}
		trayItem.setVisible(true);
		menu = new Menu(uiFunctions.getMainShell(), 8);
		menu.addMenuListener(new MenuListener() {

			final SystemTraySWT this$0;

			public void menuShown(MenuEvent menuevent)
			{
			}

			public void menuHidden(MenuEvent _menu)
			{
				if (Constants.isOSX)
					trayItem.setImage(imgAzureusGray);
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		MenuBuildUtils.addMaintenanceListenerForMenu(menu, new org.gudy.azureus2.ui.swt.MenuBuildUtils.MenuBuilder() {

			final SystemTraySWT this$0;

			public void buildMenu(Menu menu)
			{
				fillMenu(menu);
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		trayItem.addListener(14, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				showMainWindow();
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		trayItem.addListener(13, new Listener() {

			long lastTime;
			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				if (Constants.isWindows)
				{
					long now = SystemTime.getCurrentTime();
					if (now - lastTime < 200L)
						showMainWindow();
					else
						lastTime = now;
				} else
				if (Constants.isOSX)
				{
					trayItem.setImage(imgAzureusWhite);
					menu.setVisible(true);
				}
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
				lastTime = 0L;
			}
		});
		trayItem.addListener(35, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				menu.setVisible(true);
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		uiFunctions.getUIUpdater().addUpdater(this);
	}

	public void fillMenu(Menu menu)
	{
		MenuItem itemShow = new MenuItem(menu, 0);
		Messages.setLanguageText(itemShow, "SystemTray.menu.show");
		new MenuItem(menu, 2);
		MenuItem itemCloseAll = new MenuItem(menu, 0);
		Messages.setLanguageText(itemCloseAll, "SystemTray.menu.closealldownloadbars");
		MenuItem itemShowGlobalTransferBar = new MenuItem(menu, 32);
		Messages.setLanguageText(itemShowGlobalTransferBar, "SystemTray.menu.open_global_transfer_bar");
		new MenuItem(menu, 2);
		org.gudy.azureus2.plugins.ui.menus.MenuItem menu_items[] = MenuItemManager.getInstance().getAllAsArray("systray");
		if (menu_items.length > 0)
		{
			MenuBuildUtils.addPluginMenuItems(uiFunctions.getMainShell(), menu_items, menu, true, true, MenuBuildUtils.BASIC_MENU_ITEM_CONTROLLER);
			new MenuItem(menu, 2);
		}
		createUploadLimitMenu(menu);
		createDownloadLimitMenu(menu);
		new MenuItem(menu, 2);
		MenuItem itemStartAll = new MenuItem(menu, 0);
		Messages.setLanguageText(itemStartAll, "SystemTray.menu.startalltransfers");
		MenuItem itemStopAll = new MenuItem(menu, 0);
		Messages.setLanguageText(itemStopAll, "SystemTray.menu.stopalltransfers");
		MenuItem itemPause = new MenuItem(menu, 0);
		Messages.setLanguageText(itemPause, "SystemTray.menu.pausetransfers");
		MenuItem itemResume = new MenuItem(menu, 0);
		Messages.setLanguageText(itemResume, "SystemTray.menu.resumetransfers");
		new MenuItem(menu, 2);
		MenuItem itemExit = new MenuItem(menu, 0);
		Messages.setLanguageText(itemExit, "SystemTray.menu.exit");
		itemShow.addListener(13, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				showMainWindow();
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		itemStartAll.addListener(13, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				AzureusCoreFactory.getSingleton().getGlobalManager().startAllDownloads();
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		itemStopAll.addListener(13, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				ManagerUtils.asyncStopAll();
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		itemPause.addListener(13, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				ManagerUtils.asyncPause();
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		itemResume.addListener(13, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				AzureusCoreFactory.getSingleton().getGlobalManager().resumeDownloads();
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
		itemPause.setEnabled(gm.canPauseDownloads());
		itemResume.setEnabled(gm.canResumeDownloads());
		itemCloseAll.addListener(13, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				uiFunctions.closeDownloadBars();
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		itemShowGlobalTransferBar.setSelection(uiFunctions.isGlobalTransferBarShown());
		itemShowGlobalTransferBar.addListener(13, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				if (uiFunctions.isGlobalTransferBarShown())
					uiFunctions.closeGlobalTransferBar();
				else
					uiFunctions.showGlobalTransferBar();
			}

			
			{
				this$0 = SystemTraySWT.this;
				super();
			}
		});
		itemExit.addListener(13, new Listener() {

			final SystemTraySWT this$0;

			public void handleEvent(Event arg0)
			{
				uiFunctions.dispose(false, false);
			}

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

	private final void createUploadLimitMenu(Menu parent)
	{
		MenuItem uploadSpeedItem = new MenuItem(parent, 64);
		uploadSpeedItem.setText(MessageText.getString("GeneralView.label.maxuploadspeed"));
		final Menu uploadSpeedMenu = new Menu(uiFunctions.getMainShell(), 4);
		uploadSpeedMenu.addListener(22, new Listener() {

			final Menu val$uploadSpeedMenu;
			final SystemTraySWT this$0;

			public void handleEvent(Event event)
			{
				AzureusCore core = AzureusCoreFactory.getSingleton();
				SelectableSpeedMenu.generateMenuItems(uploadSpeedMenu, core, core.getGlobalManager(), true);
			}

			
			{
				this$0 = SystemTraySWT.this;
				uploadSpeedMenu = menu1;
				super();
			}
		});
		uploadSpeedItem.setMenu(uploadSpeedMenu);
	}

	private final void createDownloadLimitMenu(Menu parent)
	{
		MenuItem downloadSpeedItem = new MenuItem(parent, 64);
		downloadSpeedItem.setText(MessageText.getString("GeneralView.label.maxdownloadspeed"));
		final Menu downloadSpeedMenu = new Menu(uiFunctions.getMainShell(), 4);
		downloadSpeedMenu.addListener(22, new Listener() {

			final Menu val$downloadSpeedMenu;
			final SystemTraySWT this$0;

			public void handleEvent(Event event)
			{
				AzureusCore core = AzureusCoreFactory.getSingleton();
				SelectableSpeedMenu.generateMenuItems(downloadSpeedMenu, core, core.getGlobalManager(), false);
			}

			
			{
				this$0 = SystemTraySWT.this;
				downloadSpeedMenu = menu1;
				super();
			}
		});
		downloadSpeedItem.setMenu(downloadSpeedMenu);
	}

	public void dispose()
	{
		uiFunctions.getUIUpdater().removeUpdater(this);
		Utils.execSWTThread(new AERunnable() {

			final SystemTraySWT this$0;

			public void runSupport()
			{
				if (trayItem != null && !trayItem.isDisposed())
					trayItem.dispose();
				ImageLoader imageLoader = ImageLoader.getInstance();
				if (Constants.isOSX)
				{
					imageLoader.releaseImage("azureus_grey");
					imageLoader.releaseImage("azureus_white");
				} else
				{
					imageLoader.releaseImage("azureus");
				}
			}

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

	public void updateUI()
	{
		if (trayItem.isDisposed())
		{
			uiFunctions.getUIUpdater().removeUpdater(this);
			return;
		}
		List managers = AzureusCoreFactory.getSingleton().getGlobalManager().getDownloadManagers();
		StringBuffer toolTip = new StringBuffer();
		int seeding = 0;
		int downloading = 0;
		for (int i = 0; i < managers.size(); i++)
		{
			DownloadManager manager = (DownloadManager)managers.get(i);
			int state = manager.getState();
			if (state == 50)
				downloading++;
			if (state == 60)
				seeding++;
		}

		String seeding_text = MessageText.getString("SystemTray.tooltip.seeding").replaceAll("%1", (new StringBuilder()).append("").append(seeding).toString());
		String downloading_text = MessageText.getString("SystemTray.tooltip.downloading").replaceAll("%1", (new StringBuilder()).append("").append(downloading).toString());
		if (!downloading_text.startsWith(" "))
			downloading_text = (new StringBuilder()).append(" ").append(downloading_text).toString();
		GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager();
		GlobalManagerStats stats = gm.getStats();
		toolTip.append(seeding_text).append(downloading_text).append("\n");
		toolTip.append(MessageText.getString("ConfigView.download.abbreviated")).append(" ");
		toolTip.append(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(stats.getDataReceiveRate(), stats.getProtocolReceiveRate()));
		toolTip.append(", ").append(MessageText.getString("ConfigView.upload.abbreviated")).append(" ");
		toolTip.append(DisplayFormatters.formatDataProtByteCountToKiBEtcPerSec(stats.getDataSendRate(), stats.getProtocolSendRate()));
		trayItem.setToolTipText(toolTip.toString());
		trayItem.setVisible(true);
	}

	private void showMainWindow()
	{
		uiFunctions.bringToFront(false);
	}

	public void updateLanguage()
	{
		if (menu != null)
			Messages.updateLanguageForControl(menu);
		updateUI();
	}

	public String getUpdateUIName()
	{
		return "SystemTraySWT";
	}

}

⌨️ 快捷键说明

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