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

📄 keybindings.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:   KeyBindings.java

package org.gudy.azureus2.ui.swt;

import java.io.PrintStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MenuItem;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.util.Constants;

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

public final class KeyBindings
{
	private static class KeyBindingInfo
	{

		private final String name;
		private final int accelerator;



		private KeyBindingInfo(String name, int accelerator)
		{
			this.name = name;
			this.accelerator = accelerator;
		}

	}


	private static final Pattern FUNC_EXP = Pattern.compile("([fF]{1})([1-9]{1}[0-5]{0,1})");
	private static final Pattern SANCTIONED_EXP = Pattern.compile("([ a-zA-Z\\d/\\\\=\\-,\\.`]{1})");
	private static final String SPECIAL_KEYS[] = {
		"Meta", "Ctrl", "Cmd", "Alt", "Opt", "Shift", "Ins", "Backspace", "Del", "Esc", 
		"PgUp", "PgDn", "Left", "Up", "Right", "Down", "Home", "End", "Tab"
	};
	private static final int SPECIAL_VALUES[];
	private static final String DELIM = "+";
	private static final String DELIM_EXP = "\\+";

	public KeyBindings()
	{
	}

	private static String getPlatformKeySuffix()
	{
		if (Constants.isLinux)
			return ".linux";
		if (Constants.isSolaris)
			return ".solaris";
		if (Constants.isUnix)
			return ".unix";
		if (Constants.isFreeBSD)
			return ".freebsd";
		if (Constants.isOSX)
			return ".mac";
		if (Constants.isWindows)
			return ".windows";
		else
			return "";
	}

	private static KeyBindingInfo parseKeyBinding(String keyBindingValue)
	{
		if (keyBindingValue.length() < 1)
			return new KeyBindingInfo(null, 0);
		int swtAccelerator = 0;
		String tmpValues[] = keyBindingValue.split("\\+");
		boolean specVisited[] = new boolean[SPECIAL_KEYS.length];
		boolean funcVisited = false;
		StringBuffer displayValue = new StringBuffer(keyBindingValue.length() + 2);
		displayValue.append('\t');
		for (int i = 0; i < tmpValues.length; i++)
		{
			String value = tmpValues[i];
			boolean matched = false;
			int j = 0;
			do
			{
				if (j >= SPECIAL_KEYS.length)
					break;
				if (!specVisited[j] && SPECIAL_KEYS[j].equalsIgnoreCase(value))
				{
					swtAccelerator |= SPECIAL_VALUES[j];
					if (SPECIAL_KEYS[j].equalsIgnoreCase("Meta"))
						displayValue.append(Constants.isOSX ? "Cmd" : "Ctrl").append("+");
					else
						displayValue.append(SPECIAL_KEYS[j]).append("+");
					specVisited[j] = true;
					matched = true;
					break;
				}
				j++;
			} while (true);
			if (matched)
				continue;
			if (!funcVisited)
			{
				Matcher funcMatcher = FUNC_EXP.matcher(value);
				if (funcMatcher.find() && funcMatcher.start() == 0 && funcMatcher.end() == value.length())
				{
					int funcVal = Integer.parseInt(funcMatcher.group(2));
					swtAccelerator |= 0x1000000 + (9 + funcVal);
					displayValue.append(funcMatcher.group(0)).append("+");
					funcVisited = true;
					matched = true;
				}
			}
			if (matched)
				continue;
			Matcher valMatcher = SANCTIONED_EXP.matcher(value);
			if (!valMatcher.find() || valMatcher.start() != 0)
				continue;
			char c = valMatcher.group().charAt(0);
			int subStrIndex = displayValue.indexOf((new StringBuilder()).append(c).append("+").toString());
			if (subStrIndex != 1 && (subStrIndex <= 1 || !displayValue.substring(subStrIndex - 1, subStrIndex).equals("+")))
			{
				swtAccelerator |= c;
				displayValue.append(c).append("+");
			}
		}

		if (funcVisited || specVisited[0] || specVisited[1] || specVisited[2] || specVisited[3] || specVisited[4])
			return new KeyBindingInfo(displayValue.substring(0, displayValue.length() - 1), swtAccelerator);
		else
			return new KeyBindingInfo(null, 0);
	}

	public static void removeAccelerator(MenuItem menu, String localizationKey)
	{
		setAccelerator(menu, new KeyBindingInfo("", 0));
		Messages.setLanguageText(menu, localizationKey);
	}

	public static void setAccelerator(MenuItem menu, String localizationKey)
	{
		localizationKey = (new StringBuilder()).append(localizationKey).append(".keybinding").toString();
		String platformSpecificKey = (new StringBuilder()).append(localizationKey).append(getPlatformKeySuffix()).toString();
		if (MessageText.keyExists(platformSpecificKey))
			setAccelerator(menu, parseKeyBinding(MessageText.getString(platformSpecificKey)));
		else
		if (MessageText.keyExists(localizationKey))
			setAccelerator(menu, parseKeyBinding(MessageText.getString(localizationKey)));
		else
		if (!MessageText.isCurrentLocale(MessageText.LOCALE_DEFAULT))
			if (MessageText.keyExistsForDefaultLocale(platformSpecificKey))
				setAccelerator(menu, parseKeyBinding(MessageText.getDefaultLocaleString(platformSpecificKey)));
			else
			if (MessageText.keyExistsForDefaultLocale(localizationKey))
				setAccelerator(menu, parseKeyBinding(MessageText.getDefaultLocaleString(localizationKey)));
	}

	private static void setAccelerator(MenuItem menu, KeyBindingInfo kbInfo)
	{
		if (kbInfo.accelerator != 0)
		{
			menu.setAccelerator(kbInfo.accelerator);
			if (!Constants.isOSX && !menu.getText().endsWith(kbInfo.name))
				menu.setText((new StringBuilder()).append(menu.getText()).append(kbInfo.name).toString());
		}
	}

	public static void main(String args[])
	{
		System.out.println(parseKeyBinding("Ctrl+1").name);
		System.out.println(parseKeyBinding("Ctrl+F12").name);
		System.out.println(parseKeyBinding("Ctrl+F4").name);
		System.out.println("Meta+Shift+O");
		System.out.println(parseKeyBinding("Ctrl+Shift+O").accelerator);
		System.out.println(parseKeyBinding("Shift+Ctrl+O").accelerator);
		System.out.println(SWT.MOD1 | 0x20000 | 0x4f);
		System.out.println("Meta+Shift+o");
		System.out.println(SWT.MOD1 | 0x20000 | 0x6f);
	}

	static 
	{
		SPECIAL_VALUES = (new int[] {
			SWT.MOD1, 0x40000, SWT.MOD1, 0x10000, 0x10000, 0x20000, 0x1000009, 8, 127, 27, 
			0x1000005, 0x1000006, 16384, 128, 0x20000, 1024, 0x1000007, 0x1000008, 9
		});
	}
}

⌨️ 快捷键说明

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