simplebrowserwindow.java

来自「java 文件下载器。可自定义」· Java 代码 · 共 169 行

JAVA
169
字号
// 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:   SimpleBrowserWindow.java

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

import org.eclipse.swt.browser.*;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.ui.swt.Utils;
import org.gudy.azureus2.ui.swt.components.shell.ShellFactory;

public class SimpleBrowserWindow
{

	private Shell shell;
	private Browser browser;

	public SimpleBrowserWindow(Shell parent, String url, double wPct, double hPct, boolean allowResize, 
			boolean isModal)
	{
		if (parent == null)
		{
			init(parent, url, 0, 0, allowResize, isModal);
		} else
		{
			Rectangle clientArea = parent.getClientArea();
			init(parent, url, (int)((double)clientArea.width * wPct), (int)((double)clientArea.height * hPct), allowResize, isModal);
		}
	}

	public SimpleBrowserWindow(Shell parent, String url, int w, int h, boolean allowResize, boolean isModal)
	{
		init(parent, url, w, h, allowResize, isModal);
	}

	private void init(Shell parent, String url, int w, int h, boolean allowResize, boolean isModal)
	{
		if (parent == null)
			parent = Utils.findAnyShell();
		int style = 2144;
		if (allowResize)
			style |= 0x10;
		if (isModal)
			style |= 0x10000;
		shell = ShellFactory.createShell(parent, style);
		shell.setLayout(new FillLayout());
		Utils.setShellIcon(shell);
		try
		{
			browser = new Browser(shell, Utils.getInitialBrowserStyle(0));
			shell.addListener(21, new Listener() {

				final SimpleBrowserWindow this$0;

				public void handleEvent(Event arg0)
				{
					try
					{
						if (browser != null)
						{
							browser.setUrl("about:blank");
							browser.setVisible(false);
						}
					}
					catch (Throwable e) { }
				}

			
			{
				this$0 = SimpleBrowserWindow.this;
				super();
			}
			});
		}
		catch (Throwable t)
		{
			shell.dispose();
			return;
		}
		browser.addProgressListener(new ProgressListener() {

			final SimpleBrowserWindow this$0;

			public void completed(ProgressEvent event)
			{
				shell.open();
			}

			public void changed(ProgressEvent progressevent)
			{
			}

			
			{
				this$0 = SimpleBrowserWindow.this;
				super();
			}
		});
		browser.addCloseWindowListener(new CloseWindowListener() {

			final SimpleBrowserWindow this$0;

			public void close(WindowEvent event)
			{
				shell.dispose();
			}

			
			{
				this$0 = SimpleBrowserWindow.this;
				super();
			}
		});
		browser.addTitleListener(new TitleListener() {

			final SimpleBrowserWindow this$0;

			public void changed(TitleEvent event)
			{
				shell.setText(event.title);
			}

			
			{
				this$0 = SimpleBrowserWindow.this;
				super();
			}
		});
		if (w > 0 && h > 0)
			shell.setSize(w, h);
		Utils.centerWindowRelativeTo(shell, parent);
		browser.setUrl(url);
		browser.setData("StartURL", url);
	}

	public void waitUntilClosed()
	{
		Display display = shell.getDisplay();
		do
		{
			if (shell.isDisposed())
				break;
			if (!display.readAndDispatch())
				display.sleep();
		} while (true);
	}

	public static void main(String args[])
	{
		Display display = new Display();
		Shell shell = new Shell(display, 2144);
		shell.setSize(800, 600);
		new SimpleBrowserWindow(shell, "http://google.com", 0.80000000000000004D, 0.5D, true, false);
		shell.open();
		do
		{
			if (shell.isDisposed())
				break;
			if (!display.readAndDispatch())
				display.sleep();
		} while (true);
	}


}

⌨️ 快捷键说明

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