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

📄 utils.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			{
				item = tableitem;
				checked = flag;
				super();
			}
			});
		}
		if (Constants.isWindowsXP || isGTK)
		{
			Rectangle r = item.getBounds(0);
			Table table = item.getParent();
			Rectangle rTable = table.getClientArea();
			r.y += VerticalAligner.getTableAdjustVerticalBy(table);
			table.redraw(0, r.y, rTable.width, r.height, true);
		}
	}

	public static boolean linkShellMetricsToConfig(Shell shell, String sConfigPrefix)
	{
		String windowRectangle = COConfigurationManager.getStringParameter((new StringBuilder()).append(sConfigPrefix).append(".rectangle").toString(), null);
		boolean bDidResize = false;
		if (null != windowRectangle)
		{
			int i = 0;
			int values[] = new int[4];
			StringTokenizer st = new StringTokenizer(windowRectangle, ",");
			try
			{
				while (st.hasMoreTokens() && i < 4) 
					values[i++] = Integer.valueOf(st.nextToken()).intValue();
				if (i == 4)
				{
					Rectangle shellBounds = new Rectangle(values[0], values[1], values[2], values[3]);
					shell.setBounds(shellBounds);
					verifyShellRect(shell, true);
					bDidResize = true;
				}
			}
			catch (Exception e) { }
		}
		boolean isMaximized = COConfigurationManager.getBooleanParameter((new StringBuilder()).append(sConfigPrefix).append(".maximized").toString());
		if (Constants.isOSX && windowRectangle != null)
			isMaximized = false;
		shell.setMaximized(isMaximized);
		new ShellMetricsResizeListener(shell, sConfigPrefix);
		return bDidResize;
	}

	public static GridData setGridData(Composite composite, int gridStyle, Control ctrlBestSize, int maxHeight)
	{
		GridData gridData = new GridData(gridStyle);
		gridData.heightHint = ctrlBestSize.computeSize(-1, -1).y;
		if (gridData.heightHint > maxHeight && maxHeight > 0)
			gridData.heightHint = maxHeight;
		composite.setLayoutData(gridData);
		return gridData;
	}

	public static FormData getFilledFormData()
	{
		FormData formData = new FormData();
		formData.top = new FormAttachment(0, 0);
		formData.left = new FormAttachment(0, 0);
		formData.right = new FormAttachment(100, 0);
		formData.bottom = new FormAttachment(100, 0);
		return formData;
	}

	public static int pixelsToPoint(int pixels, int dpi)
	{
		int ret = (int)Math.round(((double)pixels * 72D) / (double)dpi);
		return ret;
	}

	private static int pixelsToPoint(double pixels, int dpi)
	{
		int ret = (int)Math.round((pixels * 72D) / (double)dpi);
		return ret;
	}

	private static boolean drawImage(GC gc, Image image, Rectangle dstRect, Rectangle clipping, int hOffset, int vOffset, boolean clearArea)
	{
		return drawImage(gc, image, new Point(0, 0), dstRect, clipping, hOffset, vOffset, clearArea);
	}

	private static boolean drawImage(GC gc, Image image, Rectangle dstRect, Rectangle clipping, int hOffset, int vOffset)
	{
		return drawImage(gc, image, new Point(0, 0), dstRect, clipping, hOffset, vOffset, false);
	}

	public static boolean drawImage(GC gc, Image image, Point srcStart, Rectangle dstRect, Rectangle clipping, int hOffset, int vOffset, boolean clearArea)
	{
		Rectangle srcRect;
		Point dstAdj;
		if (clipping == null)
		{
			dstAdj = new Point(0, 0);
			srcRect = new Rectangle(srcStart.x, srcStart.y, dstRect.width, dstRect.height);
		} else
		{
			if (!dstRect.intersects(clipping))
				return false;
			dstAdj = new Point(Math.max(0, clipping.x - dstRect.x), Math.max(0, clipping.y - dstRect.y));
			srcRect = new Rectangle(0, 0, 0, 0);
			srcRect.x = srcStart.x + dstAdj.x;
			srcRect.y = srcStart.y + dstAdj.y;
			srcRect.width = Math.min(dstRect.width - dstAdj.x, (clipping.x + clipping.width) - dstRect.x);
			srcRect.height = Math.min(dstRect.height - dstAdj.y, (clipping.y + clipping.height) - dstRect.y);
		}
		if (!srcRect.isEmpty())
			try
			{
				if (clearArea)
					gc.fillRectangle(dstRect.x + dstAdj.x + hOffset, dstRect.y + dstAdj.y + vOffset, srcRect.width, srcRect.height);
				gc.drawImage(image, srcRect.x, srcRect.y, srcRect.width, srcRect.height, dstRect.x + dstAdj.x + hOffset, dstRect.y + dstAdj.y + vOffset, srcRect.width, srcRect.height);
			}
			catch (Exception e)
			{
				System.out.println((new StringBuilder()).append("drawImage: ").append(e.getMessage()).append(": ").append(image).append(", ").append(srcRect).append(", ").append(dstRect.x + dstAdj.y + hOffset).append(",").append(dstRect.y + dstAdj.y + vOffset).append(",").append(srcRect.width).append(",").append(srcRect.height).append("; imageBounds = ").append(image.getBounds()).toString());
			}
		return true;
	}

	public static void addListenerAndChildren(Composite area, int event, Listener listener)
	{
		area.addListener(event, listener);
		Control children[] = area.getChildren();
		for (int i = 0; i < children.length; i++)
		{
			Control child = children[i];
			if (child instanceof Composite)
				addListenerAndChildren((Composite)child, event, listener);
			else
				child.addListener(event, listener);
		}

	}

	public static Shell findAnyShell()
	{
		UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
		if (uiFunctions != null)
		{
			Shell shell = uiFunctions.getMainShell();
			if (shell != null && !shell.isDisposed())
				return shell;
		}
		Display current = Display.getCurrent();
		if (current == null)
			return null;
		Shell shell = current.getActiveShell();
		if (shell != null && !shell.isDisposed())
			return shell;
		Shell shells[] = current.getShells();
		if (shells.length == 0)
			return null;
		if (shells[0] != null && !shells[0].isDisposed())
			return shells[0];
		else
			return null;
	}

	public static boolean verifyShellRect(Shell shell, boolean bAdjustIfInvalid)
	{
		boolean bMetricsOk;
		try
		{
			bMetricsOk = false;
			Point ptTopLeft = shell.getLocation();
			Monitor monitors[] = shell.getDisplay().getMonitors();
			for (int j = 0; j < monitors.length && !bMetricsOk; j++)
			{
				Rectangle bounds = monitors[j].getBounds();
				bMetricsOk = bounds.contains(ptTopLeft);
			}

		}
		catch (NoSuchMethodError e)
		{
			Rectangle bounds = shell.getDisplay().getBounds();
			bMetricsOk = shell.getBounds().intersects(bounds);
		}
		if (!bMetricsOk && bAdjustIfInvalid)
			centreWindow(shell);
		return bMetricsOk;
	}

	public static void relayout(Control control)
	{
		relayout(control, false);
	}

	public static void relayout(Control control, boolean expandOnly)
	{
		if (control == null || control.isDisposed() || !control.isVisible())
			return;
		Composite parent = control.getParent();
		Point targetSize = control.computeSize(-1, -1, true);
		Point size = control.getSize();
		if (size.y == targetSize.y && size.x == targetSize.x)
			return;
		int fixedWidth = -1;
		int fixedHeight = -1;
		Object layoutData = control.getLayoutData();
		if (layoutData instanceof FormData)
		{
			FormData fd = (FormData)layoutData;
			fixedHeight = fd.height;
			fixedWidth = fd.width;
			if (fd.width != -1 && fd.height != -1)
			{
				parent.layout();
				return;
			}
		}
		if (expandOnly && size.y >= targetSize.y && size.x >= targetSize.x)
		{
			parent.layout();
			return;
		}
		Point newSize;
		do
		{
			if (parent == null)
				break;
			parent.layout(true, true);
			parent = parent.getParent();
			newSize = control.getSize();
		} while (fixedHeight <= -1 && newSize.y < targetSize.y || fixedWidth <= -1 && newSize.x < targetSize.x);
		if (parent != null)
			parent.layout();
	}

	public static void beep()
	{
		execSWTThread(new AERunnable() {

			public void runSupport()
			{
				Display display = Display.getDefault();
				if (display != null)
					display.beep();
			}

		});
	}

	public static int getFontHeightFromPX(Font baseFont, GC gc, int heightInPixels)
	{
		Font font;
		Device device;
		int size;
		boolean bOurGC;
		font = null;
		device = baseFont.getDevice();
		size = pixelsToPoint(++heightInPixels, device.getDPI().y) + 1;
		if (size <= 0)
			return 0;
		bOurGC = gc == null || gc.isDisposed();
		if (bOurGC)
			gc = new GC(device);
		FontData fontData[] = baseFont.getFontData();
		do
		{
			if (font != null)
			{
				size--;
				font.dispose();
			}
			fontData[0].setHeight(size);
			font = new Font(device, fontData);
			gc.setFont(font);
		} while (gc.textExtent("(/|,jI~`gy").y > heightInPixels && size > 1);
		if (bOurGC)
			gc.dispose();
		if (font != null && !font.isDisposed())
			font.dispose();
		break MISSING_BLOCK_LABEL_186;
		Exception exception;
		exception;
		if (bOurGC)
			gc.dispose();
		if (font != null && !font.isDisposed())
			font.dispose();
		throw exception;
		return size;
	}

	public static int getFontHeightFromPX(Device device, FontData fontData[], GC gc, int heightInPixels)
	{
		Font font;
		int size;
		boolean bOurGC;
		font = null;
		size = pixelsToPoint(++heightInPixels, device.getDPI().y) + 1;
		if (size <= 0)
			return 0;
		bOurGC = gc == null || gc.isDisposed();
		if (bOurGC)
			gc = new GC(device);
		do
		{
			if (font != null)
			{
				size--;
				font.dispose();
			}
			fontData[0].setHeight(size);
			font = new Font(device, fontData);
			gc.setFont(font);
		} while (font != null && gc.textExtent("(/|,jI~`gy").y > heightInPixels && size > 1);
		if (bOurGC)
			gc.dispose();
		if (font != null && !font.isDisposed())
			font.dispose();
		break MISSING_BLOCK_LABEL_185;
		Exception exception;
		exception;
		if (bOurGC)
			gc.dispose();
		if (font != null && !font.isDisposed())
			font.dispose();
		throw exception;
		return size;
	}

	public static Font getFontWithHeight(Font baseFont, GC gc, int heightInPixels)
	{
		return getFontWithHeight(baseFont, gc, heightInPixels, -1);
	}

	public static Font getFontWithHeight(Font baseFont, GC gc, int heightInPixels, int style)
	{
		Font font;
		Device device;
		int size;
		boolean bOurGC;
		font = null;
		device = baseFont.getDevice();
		size = pixelsToPoint(++heightInPixels, device.getDPI().y) + 1;
		if (size <= 0)
			size = 2;
		bOurGC = gc == null || gc.isDisposed();
		if (bOurGC)
			gc = new GC(device);
		FontData fontData[] = baseFont.getFontData();
		do
		{
			if (font != null)
			{
				size--;
				font.dispose();
			}
			fontData[0].setHeight(size);
			if (style != -1)
				fontData[0].setStyle(style);
			font = new Font(device, fontData);
			gc.setFont(font);
		} while (font != null && gc.textExtent("(/|,jI~`gy").y > heightInPixels && size > 1);
		if (bOurGC)
			gc.dispose();
		break MISSING_BLOCK_LABEL_180;
		Exception exception;
		exception;
		if (bOurGC)
			gc.dispose();
		throw exception;
		return font;
	}

	/**
	 * @deprecated Method execSWTThreadWithBool is deprecated
	 */

	public static boolean execSWTThreadWithBool(String ID, AERunnableBoolean code)
	{
		return execSWTThreadWithBool(ID, code, 0L);
	}

	public static boolean execSWTThreadWithBool(String ID, AERunnableBoolean code, long millis)
	{
		boolean returnValueObject[];
		AESemaphore sem;
		if (code == null)
			return false;
		returnValueObject = (new boolean[] {
			false
		});
		Display display = getDisplay();
		sem = null;
		if (display == null || display.getThread() != Thread.currentThread())
			sem = new AESemaphore(ID);
		code.setupReturn(ID, returnValueObject, sem);
		if (!execSWTThread(code))
			return false;
		break MISSING_BLOCK_LABEL_88;
		Throwable e;
		e;
		if (sem != null)
			sem.release();
		Debug.out(ID, e);
		if (sem != null)
			sem.reserve(millis);
		return returnValueObject[0];
	}

	/**
	 * @deprecated Method execSWTThreadWithObject is deprecated
	 */

	public static Object execSWTThreadWithObject(String ID, AERunnableObject code)
	{
		return execSWTThreadWithObject(ID, code, 0L);
	}

	public static Object execSWTThreadWithObject(String ID, AERunnableObject code, long millis)
	{
		Object returnValueObject[];
		AESemaphore sem;
		if (code == null)
			return null;
		returnValueObject = (new Object[] {
			null
		});
		Display display = getDisplay();
		sem = null;
		if (display == null || display.getThread() != Thread.currentThread())
			sem = new AESemaphore(ID);
		code.setupReturn(ID, returnValueObject, sem);
		if (!execSWTThread(code))
			return null;
		break MISSING_BLOCK_LABEL_89;
		Throwable e;
		e;
		if (sem != null)
			sem.release();
		Debug.out(ID, e);
		if (sem != null)
			sem.reserve(millis);
		return returnValueObject[0];
	}

	public static void waitForModals()
	{
		SWTThread swt = SWTThread.getInstance();
		Display display;
		if (swt == null)
		{
			display = Display.getDefault();
			if (display == null)
			{
				System.err.println("SWT Thread not started yet!");
				return;
			}
		} else
		{
			if (swt.isTerminated())
				return;
			display = swt.getDisplay();
		}
		if (display == null || display.isDisposed())
			return;
		Shell shells[] = display.getShells();
		Shell modalShell = null;
		int i = 0;
		do
		{
			if (i >= shells.length)
				break;
			Shell shell = shells[i];
			if ((shell.getStyle() & 0x10000) > 0)
			{
				modalShell = shell;
				break;
			}
			i++;
		} while (true);
		if (modalShell != null)
			do
			{
				if (modalShell.isDisposed())

⌨️ 快捷键说明

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