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

📄 swtthread.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:   SWTThread.java

package org.gudy.azureus2.ui.swt.mainwindow;

import com.aelitis.azureus.ui.IUIIntializer;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.platform.PlatformManager;
import org.gudy.azureus2.platform.PlatformManagerFactory;

// Referenced classes of package org.gudy.azureus2.ui.swt.mainwindow:
//			SWTThreadAlreadyInstanciatedException

public class SWTThread
{

	private static final int FREQ_PER_SEC_LIMIT = 10;
	private static SWTThread instance;
	Display display;
	private boolean sleak;
	private boolean terminated;
	private Thread runner;
	private final IUIIntializer initializer;
	private Map freq_map;
	private Monitor primaryMonitor;

	public static SWTThread getInstance()
	{
		return instance;
	}

	public static void createInstance(IUIIntializer initializer)
		throws SWTThreadAlreadyInstanciatedException
	{
		if (instance != null)
		{
			throw new SWTThreadAlreadyInstanciatedException();
		} else
		{
			boolean bGTKTableBug_default = SWT.getPlatform().equals("gtk");
			COConfigurationManager.setBooleanDefault("SWT_bGTKTableBug", bGTKTableBug_default);
			new SWTThread(initializer);
			return;
		}
	}

	private SWTThread(final IUIIntializer app)
	{
		freq_map = new HashMap();
		initializer = app;
		instance = this;
		try
		{
			display = Display.getCurrent();
			if (display == null)
			{
				display = new Display();
				sleak = false;
			} else
			{
				sleak = true;
			}
		}
		catch (Exception e)
		{
			display = new Display();
			sleak = false;
		}
		catch (UnsatisfiedLinkError ue)
		{
			String sMin = "3.4";
			try
			{
				sMin = (new StringBuilder()).append("").append((double)(SWT.getVersion() / 100) / 10D).toString();
			}
			catch (Throwable t) { }
			try
			{
				String tempDir = System.getProperty("swt.library.path");
				if (tempDir == null)
					tempDir = System.getProperty("java.io.tmpdir");
				Debug.out((new StringBuilder()).append("Loading SWT Libraries failed. Typical causes:\n\n(1) swt.jar is not for your os architecture (").append(System.getProperty("os.arch")).append(").  ").append("You can get a new swt.jar (Min Version: ").append(sMin).append(") ").append("from http://eclipse.org/swt").append("\n\n").append("(2) No write access to '").append(tempDir).append("'. SWT will extract libraries contained in the swt.jar to this dir.\n").toString(), ue);
				if (!terminated)
				{
					app.stopIt(false, false);
					terminated = true;
				}
				PlatformManagerFactory.getPlatformManager().dispose();
			}
			catch (Throwable t) { }
			return;
		}
		Display.setAppName(Constants.APP_NAME);
		primaryMonitor = display.getPrimaryMonitor();
		AEDiagnostics.addEvidenceGenerator(new AEDiagnosticsEvidenceGenerator() {

			final SWTThread this$0;

			public void generate(IndentWriter writer)
			{
				writer.println("SWT");
				writer.indent();
				writer.println((new StringBuilder()).append("SWT Version:").append(SWT.getVersion()).append("/").append(SWT.getPlatform()).toString());
				writer.println((new StringBuilder()).append("org.eclipse.swt.browser.XULRunnerPath: ").append(System.getProperty("org.eclipse.swt.browser.XULRunnerPath", "")).toString());
				writer.println((new StringBuilder()).append("MOZILLA_FIVE_HOME: ").append(SystemProperties.getEnvironmentalVariable("MOZILLA_FIVE_HOME")).toString());
				writer.exdent();
				break MISSING_BLOCK_LABEL_116;
				Exception exception;
				exception;
				writer.exdent();
				throw exception;
			}

			
			{
				this$0 = SWTThread.this;
				super();
			}
		});
		if (Constants.isOSX && SWT.getPlatform().equals("carbon"))
			try
			{
				Class ehancerClass = Class.forName("org.gudy.azureus2.ui.swt.osx.CarbonUIEnhancer");
				Constructor constructor = ehancerClass.getConstructor(new Class[0]);
				constructor.newInstance(new Object[0]);
			}
			catch (Exception e)
			{
				Debug.printStackTrace(e);
			}
		if (app != null)
		{
			runner = new Thread(new AERunnable() {

				final IUIIntializer val$app;
				final SWTThread this$0;

				public void runSupport()
				{
					app.run();
				}

			
			{
				this$0 = SWTThread.this;
				app = iuiintializer;
				super();
			}
			}, "Main Thread");
			runner.start();
		}
		if (!sleak)
		{
			do
			{
				if (display.isDisposed() || terminated)
					break;
				try
				{
					if (!display.readAndDispatch())
						display.sleep();
				}
				catch (Throwable e)
				{
					if (Constants.isOSX && (e instanceof SWTException) && e.getMessage().endsWith(" is disposed") && (terminated || Debug.getStackTrace(e).indexOf("DropTarget") > 0))
					{
						Logger.log(new LogEvent(LogIDs.GUI, "Weird non-critical display disposal in readAndDispatch"));
					} else
					{
						if (SWT.getVersion() < 3119)
							e.printStackTrace();
						if (Constants.isCVSVersion())
							Logger.log(new LogAlert(false, MessageText.getString("SWT.alert.erroringuithread"), e));
					}
				}
			} while (true);
			if (!terminated)
			{
				if (app != null)
					app.stopIt(false, false);
				terminated = true;
			}
			try
			{
				if (!display.isDisposed())
					display.dispose();
			}
			catch (Throwable t)
			{
				if (SWT.getVersion() < 3119)
					t.printStackTrace();
				else
					Debug.printStackTrace(t);
			}
			PlatformManagerFactory.getPlatformManager().dispose();
		}
	}

	public void terminate()
	{
		terminated = true;
		if (!display.isDisposed())
		{
			try
			{
				Shell shells[] = display.getShells();
				for (int i = 0; i < shells.length; i++)
					try
					{
						Shell shell = shells[i];
						shell.dispose();
					}
					catch (Throwable t)
					{
						Debug.out(t);
					}

			}
			catch (Throwable t)
			{
				Debug.out(t);
			}
			display.dispose();
		}
	}

	public Display getDisplay()
	{
		return display;
	}

	public boolean isTerminated()
	{
		return terminated;
	}

	public IUIIntializer getInitializer()
	{
		return initializer;
	}

	public void limitFrequencyAsyncExec(Object owner, Display display, AERunnable target)
	{
		if (display.isDisposed())
			return;
		int now = (int)(SystemTime.getCurrentTime() / 1000L);
		boolean do_it = true;
		synchronized (freq_map)
		{
			if (freq_map.size() > 1024)
			{
				Debug.out("Frequency map is overloaded - check your logic!!!!");
			} else
			{
				int data[] = (int[])(int[])freq_map.get(owner);
				if (data == null)
				{
					data = (new int[] {
						now, 0
					});
					freq_map.put(owner, data);
				}
				if (data[0] == now)
				{
					data[1]++;
					if (data[1] > 10)
					{
						do_it = false;
						Debug.out((new StringBuilder()).append("SWT frequency limit exceeded for ").append(owner.getClass()).toString());
					}
				} else
				{
					data[0] = now;
					data[1] = 1;
				}
			}
		}
		if (do_it)
			display.asyncExec(target);
	}

	public void removeLimitedFrequencyOwner(Object owner)
	{
		synchronized (freq_map)
		{
			freq_map.remove(owner);
		}
	}

	public Monitor getPrimaryMonitor()
	{
		return primaryMonitor;
	}
}

⌨️ 快捷键说明

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