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

📄 utils.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		if (item == null || item.isDisposed())
			return;
		Color colors[] = {
			item.getDisplay().getSystemColor(25), Colors.colorAltRow
		};
		Color newColor = colors[item.getParent().indexOf(item) % colors.length];
		if (!item.getBackground().equals(newColor))
			item.setBackground(newColor);
	}

	public static void alternateTableBackground(Table table)
	{
		if (table == null || table.isDisposed())
			return;
		if (TABLE_GRIDLINE_IS_ALTERNATING_COLOR)
		{
			if (!table.getLinesVisible())
				table.setLinesVisible(true);
			return;
		}
		int iTopIndex = table.getTopIndex();
		int iBottomIndex = getTableBottomIndex(table, iTopIndex);
		Color colors[] = {
			table.getDisplay().getSystemColor(25), Colors.colorAltRow
		};
		int iFixedIndex = iTopIndex;
		for (int i = iTopIndex; i <= iBottomIndex; i++)
		{
			TableItem row = table.getItem(i);
			if (row.isDisposed())
				continue;
			Color newColor = colors[iFixedIndex % colors.length];
			iFixedIndex++;
			if (!row.getBackground().equals(newColor))
				row.setBackground(newColor);
		}

	}

	public static void setMenuItemImage(MenuItem item, String repoKey)
	{
		if (Constants.isOSX || repoKey == null)
		{
			return;
		} else
		{
			ImageLoader imageLoader = ImageLoader.getInstance();
			item.setImage(imageLoader.getImage(repoKey));
			item.addDisposeListener(new DisposeListener(repoKey) {

				final String val$repoKey;

				public void widgetDisposed(DisposeEvent e)
				{
					ImageLoader imageLoader = ImageLoader.getInstance();
					imageLoader.releaseImage(repoKey);
				}

			
			{
				repoKey = s;
				super();
			}
			});
			return;
		}
	}

	public static void setMenuItemImage(MenuItem item, Image image)
	{
		if (!Constants.isOSX)
			item.setImage(image);
	}

	public static void setShellIcon(Shell shell)
	{
		if (Constants.isOSX)
			return;
		try
		{
			if (shellIcons == null)
			{
				ArrayList listShellIcons = new ArrayList(shellIconNames.length);
				ImageLoader imageLoader = ImageLoader.getInstance();
				for (int i = 0; i < shellIconNames.length; i++)
				{
					Image image = imageLoader.getImage(shellIconNames[i]);
					if (ImageLoader.isRealImage(image))
						listShellIcons.add(image);
				}

				shellIcons = (Image[])(Image[])listShellIcons.toArray(new Image[listShellIcons.size()]);
			}
			shell.setImages(shellIcons);
		}
		catch (NoSuchMethodError e) { }
	}

	public static Display getDisplay()
	{
		SWTThread swt = SWTThread.getInstance();
		Display display;
		if (swt == null)
		{
			display = Display.getDefault();
			if (display == null)
			{
				System.err.println("SWT Thread not started yet!");
				return null;
			}
		} else
		{
			if (swt.isTerminated())
				return null;
			display = swt.getDisplay();
		}
		if (display == null || display.isDisposed())
			return null;
		else
			return display;
	}

	public static boolean execSWTThread(Runnable code, boolean async)
	{
		return execSWTThread(code, async ? -1 : -2);
	}

	public static boolean execSWTThreadLater(int msLater, Runnable code)
	{
		return execSWTThread(code, msLater);
	}

	private static boolean execSWTThread(Runnable code, int msLater)
	{
		Display display = getDisplay();
		if (display == null || code == null)
			return false;
		boolean isSWTThread = display.getThread() == Thread.currentThread();
		if (msLater < 0 && isSWTThread)
		{
			if (queue == null)
			{
				code.run();
			} else
			{
				long lStartTimeRun = SystemTime.getCurrentTime();
				code.run();
				long wait = SystemTime.getCurrentTime() - lStartTimeRun;
				if (wait > 700L)
					diag_logger.log((new StringBuilder()).append(SystemTime.getCurrentTime()).append("] took ").append(wait).append("ms to run ").append(Debug.getCompressedStackTrace()).toString());
			}
		} else
		if (msLater >= -1)
			try
			{
				if (queue == null)
				{
					if (msLater <= 0)
						display.asyncExec(code);
					else
					if (isSWTThread)
						display.timerExec(msLater, code);
					else
						SimpleTimer.addEvent("execSWTThreadLater", SystemTime.getOffsetTime(msLater), new TimerEventPerformer(display, code) {

							final Display val$display;
							final Runnable val$code;

							public void perform(TimerEvent event)
							{
								if (!display.isDisposed())
									display.asyncExec(code);
							}

			
			{
				display = display1;
				code = runnable;
				super();
			}
						});
				} else
				{
					queue.add(code);
					diag_logger.log((new StringBuilder()).append(SystemTime.getCurrentTime()).append("] + Q. size= ").append(queue.size()).append("; add ").append(code).append(" via ").append(Debug.getCompressedStackTrace()).toString());
					long lStart = SystemTime.getCurrentTime();
					Display fDisplay = display;
					AERunnable runnableWrapper = new AERunnable(lStart, msLater, code, fDisplay) {

						final long val$lStart;
						final int val$msLater;
						final Runnable val$code;
						final Display val$fDisplay;

						public void runSupport()
						{
							long wait = SystemTime.getCurrentTime() - lStart - (long)msLater;
							if (wait > 700L)
								Utils.diag_logger.log((new StringBuilder()).append(SystemTime.getCurrentTime()).append("] took ").append(wait).append("ms before SWT ran async code ").append(code).toString());
							long lStartTimeRun = SystemTime.getCurrentTime();
							try
							{
								if (fDisplay.isDisposed())
								{
									Debug.out((new StringBuilder()).append("Display disposed while trying to execSWTThread ").append(code).toString());
									try
									{
										code.run();
									}
									catch (SWTException e)
									{
										Debug.out("Error while execSWTThread w/disposed Display", e);
									}
								} else
								{
									code.run();
								}
							}
							finally
							{
								long runTIme = SystemTime.getCurrentTime() - lStartTimeRun;
								if (runTIme > 500L)
									Utils.diag_logger.log((new StringBuilder()).append(SystemTime.getCurrentTime()).append("] took ").append(runTIme).append("ms to run ").append(code).toString());
								Utils.queue.remove(code);
								Utils.diag_logger.log((new StringBuilder()).append(SystemTime.getCurrentTime()).append("] - Q. size=").append(Utils.queue.size()).append(";wait:").append(wait).append("ms;run:").append(runTIme).append("ms").toString());
							}
						}

			
			{
				lStart = l;
				msLater = i;
				code = runnable;
				fDisplay = display;
				super();
			}
					};
					if (msLater <= 0)
						display.asyncExec(runnableWrapper);
					else
					if (isSWTThread)
						display.timerExec(msLater, code);
					else
						SimpleTimer.addEvent("execSWTThreadLater", SystemTime.getOffsetTime(msLater), new TimerEventPerformer(display, code) {

							final Display val$display;
							final Runnable val$code;

							public void perform(TimerEvent event)
							{
								if (!display.isDisposed())
									display.asyncExec(code);
							}

			
			{
				display = display1;
				code = runnable;
				super();
			}
						});
				}
			}
			catch (NullPointerException e)
			{
				return false;
			}
		else
			display.syncExec(code);
		return true;
	}

	public static boolean execSWTThread(Runnable code)
	{
		return execSWTThread(code, -1);
	}

	public static boolean isThisThreadSWT()
	{
		SWTThread swt = SWTThread.getInstance();
		if (swt == null)
			System.err.println("WARNING: SWT Thread not started yet");
		Display display = swt != null ? swt.getDisplay() : Display.getCurrent();
		if (display == null)
			return false;
		try
		{
			display.getWarnings();
		}
		catch (SWTException e)
		{
			return false;
		}
		return display.getThread() == Thread.currentThread();
	}

	public static int openMessageBox(Shell parent, int style, String keyPrefix, String textParams[])
	{
		if ((style & 0xfe0) == 0)
			style |= 0x20;
		Object buttonInfo[] = swtButtonStylesToText(style);
		MessageBoxShell mb = new MessageBoxShell(parent, MessageText.getString((new StringBuilder()).append(keyPrefix).append(".title").toString()), MessageText.getString((new StringBuilder()).append(keyPrefix).append(".text").toString(), textParams), (String[])(String[])buttonInfo[0], 0);
		mb.setLeftImage(style & 0x1f);
		int ret = mb.open();
		Integer buttonVals[] = (Integer[])(Integer[])buttonInfo[1];
		if (ret < 0 || ret > buttonVals.length)
			return 256;
		else
			return buttonVals[ret].intValue();
	}

	public static int openMessageBox(Shell parent, int style, String title, String text)
	{
		if (parent == null)
			parent = findAnyShell();
		if ((style & 0xfe0) == 0)
			style |= 0x20;
		Object buttonInfo[] = swtButtonStylesToText(style);
		MessageBoxShell mb = new MessageBoxShell(parent, title, text, (String[])(String[])buttonInfo[0], 0);
		mb.setLeftImage(style & 0x1f);
		int ret = mb.open();
		Integer buttonVals[] = (Integer[])(Integer[])buttonInfo[1];
		if (ret < 0 || ret > buttonVals.length)
			return 256;
		else
			return buttonVals[ret].intValue();
	}

	public static int openMessageBox(Shell parent, int style, int default_style, String title, String text)
	{
		if (parent == null)
			parent = findAnyShell();
		if ((style & 0xfe0) == 0)
			style |= 0x20;
		Object buttonInfo[] = swtButtonStylesToText(style);
		Object defaultButtonInfo[] = swtButtonStylesToText(default_style);
		int defaultIndex = 0;
		if (defaultButtonInfo.length > 0)
		{
			String name = ((String[])(String[])defaultButtonInfo[0])[0];
			String names[] = (String[])(String[])buttonInfo[0];
			int i = 0;
			do
			{
				if (i >= names.length)
					break;
				if (names[i].equals(name))
				{
					defaultIndex = i;
					break;
				}
				i++;
			} while (true);
		}
		MessageBoxShell mb = new MessageBoxShell(parent, title, text, (String[])(String[])buttonInfo[0], defaultIndex);
		mb.setLeftImage(style & 0x1f);
		int ret = mb.open();
		Integer buttonVals[] = (Integer[])(Integer[])buttonInfo[1];
		if (ret < 0 || ret > buttonVals.length)
			return 256;
		else
			return buttonVals[ret].intValue();
	}

	private static Object[] swtButtonStylesToText(int style)
	{
		List buttons = new ArrayList(2);
		List buttonVal = new ArrayList(2);
		int buttonCount = 0;
		if ((style & 0x20) > 0)
		{
			buttons.add(MessageText.getString("Button.ok"));
			buttonVal.add(new Integer(32));
			buttonCount++;
		}
		if ((style & 0x40) > 0)
		{
			buttons.add(MessageText.getString("Button.yes"));
			buttonVal.add(new Integer(64));
			buttonCount++;
		}
		if ((style & 0x80) > 0)
		{
			buttons.add(MessageText.getString("Button.no"));
			buttonVal.add(new Integer(128));
			buttonCount++;
		}
		if ((style & 0x100) > 0)
		{
			buttons.add(MessageText.getString("Button.cancel"));
			buttonVal.add(new Integer(256));
			buttonCount++;
		}
		if ((style & 0x200) > 0)
		{
			buttons.add(MessageText.getString("Button.abort"));
			buttonVal.add(new Integer(512));
			buttonCount++;
		}
		if ((style & 0x400) > 0)
		{
			buttons.add(MessageText.getString("Button.retry"));
			buttonVal.add(new Integer(1024));
			buttonCount++;
		}
		if ((style & 0x800) > 0)
		{
			buttons.add(MessageText.getString("Button.ignore"));
			buttonVal.add(new Integer(2048));
			buttonCount++;
		}
		return (new Object[] {
			(String[])(String[])buttons.toArray(new String[buttonCount]), (Integer[])(Integer[])buttonVal.toArray(new Integer[buttonCount])
		});
	}

	public static int getTableBottomIndex(Table table, int iTopIndex)
	{
		int itemCount;
		itemCount = table.getItemCount();
		if (iTopIndex >= itemCount)
			return -1;
		if (!Constants.isOSX && !Constants.isWindows)
			break MISSING_BLOCK_LABEL_117;
		int iBottomIndex;
		TableItem item = table.getItem(iTopIndex);
		Rectangle bounds = item.getBounds();
		Rectangle clientArea = table.getClientArea();
		int itemHeight = table.getItemHeight();
		iBottomIndex = Math.min(iTopIndex + ((clientArea.height + clientArea.y) - bounds.y - 1) / itemHeight, itemCount - 1);
		return iBottomIndex;
		NoSuchMethodError e;
		e;
		return Math.min(iTopIndex + (table.getClientArea().height - table.getHeaderHeight() - 1) / table.getItemHeight() + 1, table.getItemCount() - 1);
		int areaHeight = table.getClientArea().height;
		if (areaHeight <= table.getHeaderHeight())
		{
			return -1;
		} else
		{
			TableItem bottomItem = table.getItem(new Point(2, table.getClientArea().height - 1));
			int iBottomIndex = bottomItem == null ? itemCount - 1 : table.indexOf(bottomItem);
			return iBottomIndex;
		}
	}

	public static void launch(String sFile)
	{
		if (sFile == null || sFile.trim().length() == 0)
			return;
		if (SWT.getVersion() >= 3315 || SWT.getVersion() < 3300 || UrlUtils.isURL(sFile) || sFile.startsWith("mailto:"))
		{
			boolean launched = Program.launch(sFile);
			if (!launched && Constants.isUnix && (UrlUtils.isURL(sFile) || sFile.startsWith("mailto:")) && !Program.launch((new StringBuilder()).append("xdg-open ").append(sFile).toString()))
				Program.launch((new StringBuilder()).append("htmlview ").append(sFile).toString());
		} else
		if (Constants.isOSX)
			Program.launch((new StringBuilder()).append("file://").append(sFile.replaceAll(" ", "%20")).toString());
		else
			Program.launch(sFile);
	}

	public static void setCheckedInSetData(TableItem item, boolean checked)
	{
		if (DIRECT_SETCHECKED)
		{
			item.setChecked(checked);
		} else
		{
			item.setChecked(!checked);
			item.getDisplay().asyncExec(new AERunnable(item, checked) {

				final TableItem val$item;
				final boolean val$checked;

				public void runSupport()
				{
					item.setChecked(checked);
				}

			

⌨️ 快捷键说明

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