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

📄 utils.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
// 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:   Utils.java

package org.gudy.azureus2.ui.swt;

import com.aelitis.azureus.core.impl.AzureusCoreImpl;
import com.aelitis.azureus.ui.swt.UIFunctionsManagerSWT;
import com.aelitis.azureus.ui.swt.UIFunctionsSWT;
import com.aelitis.azureus.ui.swt.imageloader.ImageLoader;
import java.io.PrintStream;
import java.util.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTException;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.dnd.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;
import org.gudy.azureus2.ui.swt.mainwindow.SWTThread;
import org.gudy.azureus2.ui.swt.mainwindow.TorrentOpener;
import org.gudy.azureus2.ui.swt.shells.MessageBoxShell;
import org.gudy.azureus2.ui.swt.views.table.TableViewSWT;
import org.gudy.azureus2.ui.swt.views.utils.VerticalAligner;

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

public class Utils
{
	public static class LabelWrapControlListener extends ControlAdapter
	{

		public void controlResized(ControlEvent e)
		{
			if (SWT.getVersion() >= 3105)
				return;
			Composite parent = (Composite)e.widget;
			Control children[] = parent.getChildren();
			if (children.length > 0)
			{
				GridLayout parentLayout = (GridLayout)parent.getLayout();
				if (parentLayout != null)
				{
					int marginWidth = parentLayout.marginWidth;
					Composite grandParent = parent.getParent();
					Point size;
					if (grandParent instanceof ScrolledComposite)
					{
						Composite greatGP = grandParent.getParent();
						if (greatGP != null)
						{
							size = greatGP.getSize();
							if (greatGP.getLayout() instanceof GridLayout)
								marginWidth += ((GridLayout)greatGP.getLayout()).marginWidth;
						} else
						{
							size = grandParent.getSize();
						}
						if (grandParent.getLayout() instanceof GridLayout)
							marginWidth += ((GridLayout)grandParent.getLayout()).marginWidth;
						ScrollBar sb = grandParent.getVerticalBar();
						if (sb != null)
							size.x -= sb.getSize().x + 1;
					} else
					{
						size = parent.getSize();
					}
					boolean oneChanged = false;
					for (int i = 0; i < children.length; i++)
					{
						if (!(children[i] instanceof Label) || (children[i].getStyle() & 0x40) != 64)
							continue;
						GridData gd = (GridData)children[i].getLayoutData();
						if (gd == null || gd.horizontalAlignment != 4)
							continue;
						if (gd.horizontalSpan == parentLayout.numColumns)
						{
							gd.widthHint = size.x - 2 * marginWidth;
							oneChanged = true;
						} else
						{
							Point pt = children[i].getLocation();
							gd.widthHint = size.x - pt.x - 2 * marginWidth;
							oneChanged = true;
						}
					}

					if (oneChanged)
					{
						parent.layout(true);
						if (grandParent instanceof ScrolledComposite)
							((ScrolledComposite)grandParent).setMinSize(parent.computeSize(-1, -1, true));
					}
				}
			}
		}

		public LabelWrapControlListener()
		{
		}
	}

	private static class ShellMetricsResizeListener
		implements Listener
	{

		private int state;
		private String sConfigPrefix;
		private Rectangle bounds;

		private int calcState(Shell shell)
		{
			return shell.getMinimized() ? 128 : !shell.getMaximized() || Constants.isOSX ? '\0' : '\u0400';
		}

		private void saveMetrics()
		{
			COConfigurationManager.setParameter((new StringBuilder()).append(sConfigPrefix).append(".maximized").toString(), state == 1024);
			if (bounds == null)
			{
				return;
			} else
			{
				COConfigurationManager.setParameter((new StringBuilder()).append(sConfigPrefix).append(".rectangle").toString(), (new StringBuilder()).append(bounds.x).append(",").append(bounds.y).append(",").append(bounds.width).append(",").append(bounds.height).toString());
				COConfigurationManager.save();
				return;
			}
		}

		public void handleEvent(Event event)
		{
			Shell shell = (Shell)event.widget;
			state = calcState(shell);
			if (event.type != 12 && state == 0)
				bounds = shell.getBounds();
			if (event.type == 12)
				saveMetrics();
		}

		ShellMetricsResizeListener(Shell shell, String sConfigPrefix)
		{
			state = -1;
			bounds = null;
			this.sConfigPrefix = sConfigPrefix;
			state = calcState(shell);
			if (state == 0)
				bounds = shell.getBounds();
			shell.addListener(11, this);
			shell.addListener(10, this);
			shell.addListener(12, this);
		}
	}

	private static class TruncatedTextResult
	{

		String text;
		int maxWidth;

		public TruncatedTextResult()
		{
		}
	}

	private static class URLDropTarget extends DropTargetAdapter
	{

		private final Text url;
		private final boolean bAllowShareAdd;

		public void dropAccept(DropTargetEvent event)
		{
			event.currentDataType = URLTransfer.pickBestType(event.dataTypes, event.currentDataType);
		}

		public void dragOver(DropTargetEvent event)
		{
			if (event.detail != 16 && (event.operations & event.detail) > 0)
				return;
			if ((event.operations & 4) > 0)
				event.detail = 4;
			else
			if ((event.operations & 0x10) > 0)
				event.detail = 16;
			else
			if ((event.operations & 1) > 0)
				event.detail = 1;
		}

		public void drop(DropTargetEvent event)
		{
			if (url == null || url.isDisposed())
				TorrentOpener.openDroppedTorrents(AzureusCoreImpl.getSingleton(), event, bAllowShareAdd);
			else
			if (event.data instanceof URLTransfer.URLType)
			{
				if (((URLTransfer.URLType)event.data).linkURL != null)
					url.setText(((URLTransfer.URLType)event.data).linkURL);
			} else
			if (event.data instanceof String)
			{
				String sURL = UrlUtils.parseTextForURL((String)event.data, true);
				if (sURL != null)
					url.setText(sURL);
			}
		}

		public URLDropTarget(Text url, boolean bAllowShareAdd)
		{
			this.url = url;
			this.bAllowShareAdd = bAllowShareAdd;
		}
	}

	public static interface addDataSourceCallback
	{

		public abstract void process();

		public abstract void debug(String s);
	}


	public static final String GOOD_STRING = "(/|,jI~`gy";
	public static final boolean isGTK;
	public static final boolean LAST_TABLECOLUMN_EXPANDS;
	public static final boolean TABLE_GRIDLINE_IS_ALTERNATING_COLOR;
	private static final boolean DIRECT_SETCHECKED;
	public static final boolean SWT32_TABLEPAINT = SWT.getVersion() >= 3200;
	private static final boolean DEBUG_SWTEXEC;
	private static ArrayList queue;
	private static AEDiagnosticsLogger diag_logger;
	private static Image shellIcons[] = null;
	private static final String shellIconNames[] = {
		"azureus", "azureus32", "azureus64", "azureus128"
	};
	public static final Rectangle EMPTY_RECT = new Rectangle(0, 0, 0, 0);
	private static boolean gotBrowserStyle = false;
	private static int browserStyle = 0;
	public static final long IMMEDIATE_ADDREMOVE_DELAY = 150L;
	private static final long IMMEDIATE_ADDREMOVE_MAXDELAY = 2000L;
	private static Timer timerProcessDataSources = new Timer("Process Data Sources");
	private static TimerEvent timerEventProcessDS;
	private static List processDataSourcesOutstanding = new ArrayList();
	private static Map truncatedTextCache = new HashMap();

	public Utils()
	{
	}

	public static boolean isAZ2UI()
	{
		String ui_type = COConfigurationManager.getStringParameter("ui");
		return ui_type.equals("az2");
	}

	public static void disposeComposite(Composite composite, boolean disposeSelf)
	{
		if (composite == null || composite.isDisposed())
			return;
		Control controls[] = composite.getChildren();
		for (int i = 0; i < controls.length; i++)
		{
			Control control = controls[i];
			if (control == null || control.isDisposed())
				continue;
			if (control instanceof Composite)
				disposeComposite((Composite)control, true);
			try
			{
				control.dispose();
			}
			catch (SWTException e)
			{
				Debug.printStackTrace(e);
			}
		}

		if (!composite.isDisposed() && disposeSelf)
			try
			{
				composite.dispose();
			}
			catch (SWTException e)
			{
				Debug.printStackTrace(e);
			}
	}

	public static void disposeComposite(Composite composite)
	{
		disposeComposite(composite, true);
	}

	public static void disposeSWTObjects(List disposeList)
	{
		disposeSWTObjects(disposeList.toArray());
		disposeList.clear();
	}

	public static void disposeSWTObjects(Object disposeList[])
	{
		if (disposeList == null)
			return;
		boolean bResourceObjectExists = SWT.getVersion() >= 3129;
		for (int i = 0; i < disposeList.length; i++)
		{
			Object o = disposeList[i];
			if ((o instanceof Widget) && !((Widget)o).isDisposed())
			{
				((Widget)o).dispose();
				continue;
			}
			if (bResourceObjectExists && (o instanceof Resource) && !((Resource)o).isDisposed())
			{
				((Resource)o).dispose();
				continue;
			}
			try
			{
				if ((o instanceof Cursor) && !((Cursor)o).isDisposed())
				{
					((Cursor)o).dispose();
					continue;
				}
				if ((o instanceof Font) && !((Font)o).isDisposed())
				{
					((Font)o).dispose();
					continue;
				}
				if ((o instanceof GC) && !((GC)o).isDisposed())
				{
					((GC)o).dispose();
					continue;
				}
				if ((o instanceof Image) && !((Image)o).isDisposed())
				{
					((Image)o).dispose();
					continue;
				}
				if ((o instanceof Region) && !((Region)o).isDisposed())
				{
					((Region)o).dispose();
					continue;
				}
				if ((o instanceof TextLayout) && !((TextLayout)o).isDisposed())
					((TextLayout)o).dispose();
			}
			catch (NoClassDefFoundError e) { }
		}

	}

	public static void setTextLinkFromClipboard(Shell shell, Text url, boolean accept_magnets)
	{
		String link = getLinkFromClipboard(shell.getDisplay(), accept_magnets);
		if (link != null)
			url.setText(link);
	}

	public static String getLinkFromClipboard(Display display, boolean accept_magnets)
	{
		Clipboard cb = new Clipboard(display);
		TextTransfer transfer = TextTransfer.getInstance();
		String data = (String)cb.getContents(transfer);
		String text = UrlUtils.parseTextForURL(data, accept_magnets);
		if (text == null)
			return "http://";
		else
			return text;
	}

	public static void centreWindow(Shell shell)
	{
		Rectangle displayArea;
		try
		{
			displayArea = shell.getMonitor().getClientArea();
		}
		catch (NoSuchMethodError e)
		{
			displayArea = shell.getDisplay().getClientArea();
		}
		Rectangle shellRect = shell.getBounds();
		if (shellRect.height > displayArea.height)
			shellRect.height = displayArea.height;
		if (shellRect.width > displayArea.width - 50)
			shellRect.width = displayArea.width;
		shellRect.x = displayArea.x + (displayArea.width - shellRect.width) / 2;
		shellRect.y = displayArea.y + (displayArea.height - shellRect.height) / 2;
		shell.setBounds(shellRect);
	}

	public static void centerWindowRelativeTo(Shell window, Control control)
	{
		Rectangle bounds = control.getBounds();
		Point shellSize = window.getSize();
		window.setLocation((bounds.x + bounds.width / 2) - shellSize.x / 2, (bounds.y + bounds.height / 2) - shellSize.y / 2);
	}

	public static void createTorrentDropTarget(Composite composite, boolean bAllowShareAdd)
	{
		try
		{
			createDropTarget(composite, bAllowShareAdd, null);
		}
		catch (Exception e)
		{
			Debug.out(e);
		}
	}

	public static void createURLDropTarget(Composite composite, Text url)
	{
		try
		{
			createDropTarget(composite, false, url);
		}
		catch (Exception e)
		{
			Debug.out(e);
		}
	}

	private static void createDropTarget(Composite composite, boolean bAllowShareAdd, Text url, DropTargetListener dropTargetListener)
	{
		Transfer transferList[];
		if (SWT.getVersion() >= 3107)
			transferList = (new Transfer[] {
				HTMLTransfer.getInstance(), URLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance()
			});
		else
			transferList = (new Transfer[] {
				URLTransfer.getInstance(), FileTransfer.getInstance(), TextTransfer.getInstance()
			});
		DropTarget dropTarget = new DropTarget(composite, 31);
		dropTarget.setTransfer(transferList);
		dropTarget.addDropListener(dropTargetListener);
		if (Constants.isWindows)
			return;
		Control children[] = composite.getChildren();
		for (int i = 0; i < children.length; i++)
		{
			Control control = children[i];
			if (control.isDisposed())
				continue;
			if (control instanceof Composite)
			{
				createDropTarget((Composite)control, bAllowShareAdd, url, dropTargetListener);
			} else
			{
				DropTarget dropTarget2 = new DropTarget(control, 31);
				dropTarget2.setTransfer(transferList);
				dropTarget2.addDropListener(dropTargetListener);
			}
		}

	}

	private static void createDropTarget(Composite composite, boolean bAllowShareAdd, Text url)
	{
		URLDropTarget target = new URLDropTarget(url, bAllowShareAdd);
		createDropTarget(composite, bAllowShareAdd, url, ((DropTargetListener) (target)));
	}

	public static void alternateRowBackground(TableItem item)
	{
		if (TABLE_GRIDLINE_IS_ALTERNATING_COLOR)
		{
			if (!item.getParent().getLinesVisible())
				item.getParent().setLinesVisible(true);
			return;
		}

⌨️ 快捷键说明

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