mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-19 22:35:35 +00:00
Load from browser cache removed
Old "debugger" tool removed in favor of new real debugger Hotkeys unified
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
package com.jpexs.decompiler.flash.gui;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Menu Builder. Creates menu.
|
||||
@@ -25,6 +29,143 @@ import java.awt.event.ActionListener;
|
||||
*/
|
||||
public interface MenuBuilder {
|
||||
|
||||
public static class HotKey {
|
||||
|
||||
private static Map<Integer, String> keyCodesToNames = new HashMap<>();
|
||||
private static Map<String, Integer> keyNamesToCodes = new HashMap<>();
|
||||
|
||||
{
|
||||
|
||||
Field[] fields = KeyEvent.class.getFields();
|
||||
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
|
||||
String fieldName = fields[i].getName();
|
||||
|
||||
// We only care about the field names corresponding to key codes
|
||||
if (fieldName.startsWith("VK")) {
|
||||
try {
|
||||
int keyCode = fields[i].getInt(null);
|
||||
String keyName = fieldName.substring(3);
|
||||
keyCodesToNames.put(keyCode, keyName);
|
||||
keyNamesToCodes.put(keyName, keyCode);
|
||||
} catch (Exception ex) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int key;
|
||||
public boolean shiftDown;
|
||||
public boolean ctrlDown;
|
||||
public boolean altDown;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 41 * hash + this.key;
|
||||
hash = 41 * hash + (this.shiftDown ? 1 : 0);
|
||||
hash = 41 * hash + (this.ctrlDown ? 1 : 0);
|
||||
hash = 41 * hash + (this.altDown ? 1 : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final HotKey other = (HotKey) obj;
|
||||
if (this.key != other.key) {
|
||||
return false;
|
||||
}
|
||||
if (this.shiftDown != other.shiftDown) {
|
||||
return false;
|
||||
}
|
||||
if (this.ctrlDown != other.ctrlDown) {
|
||||
return false;
|
||||
}
|
||||
return (this.altDown == other.altDown);
|
||||
}
|
||||
|
||||
public boolean matches(KeyEvent ev) {
|
||||
return ev.getKeyCode() == key && ev.isControlDown() == ctrlDown && ev.isShiftDown() == shiftDown && ev.isAltDown() == altDown;
|
||||
}
|
||||
|
||||
public int getModifier() {
|
||||
return (shiftDown ? KeyEvent.SHIFT_MASK : 0) + (ctrlDown ? KeyEvent.CTRL_MASK : 0) + (altDown ? KeyEvent.ALT_MASK : 0);
|
||||
}
|
||||
|
||||
public HotKey(String h) {
|
||||
String parts[] = h.contains("+") ? h.split("\\+") : new String[]{h};
|
||||
for (String s : parts) {
|
||||
switch (s) {
|
||||
case "SHIFT":
|
||||
shiftDown = true;
|
||||
break;
|
||||
case "CTRL":
|
||||
ctrlDown = true;
|
||||
break;
|
||||
case "ALT":
|
||||
altDown = true;
|
||||
break;
|
||||
default:
|
||||
if (keyNamesToCodes.containsKey(s)) {
|
||||
key = keyNamesToCodes.get(s);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Key " + s + " not found!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public HotKey(KeyEvent ev) {
|
||||
this(ev.getKeyCode(), ev.isShiftDown(), ev.isControlDown(), ev.isAltDown());
|
||||
}
|
||||
|
||||
public HotKey(int key) {
|
||||
this(key, false, false, false);
|
||||
}
|
||||
|
||||
public HotKey(int key, boolean shiftDown, boolean ctrlDown, boolean altDown) {
|
||||
this.key = key;
|
||||
this.shiftDown = shiftDown;
|
||||
this.ctrlDown = ctrlDown;
|
||||
this.altDown = altDown;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String s = "";
|
||||
if (shiftDown) {
|
||||
s += "SHIFT";
|
||||
}
|
||||
if (ctrlDown) {
|
||||
if (!s.isEmpty()) {
|
||||
s += "+";
|
||||
}
|
||||
s += "CTRL";
|
||||
}
|
||||
if (altDown) {
|
||||
if (!s.isEmpty()) {
|
||||
s += "+";
|
||||
}
|
||||
s += "ALT";
|
||||
}
|
||||
if (!s.isEmpty()) {
|
||||
s += "+";
|
||||
}
|
||||
s += keyCodesToNames.get(key);
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final int PRIORITY_LOW = 1;
|
||||
|
||||
public static final int PRIORITY_MEDIUM = 2;
|
||||
@@ -54,7 +195,7 @@ public interface MenuBuilder {
|
||||
* @param subloader Action which loads menu inside
|
||||
* @param isLeaf Has no subitems?
|
||||
*/
|
||||
public void addMenuItem(String path, String title, String icon, ActionListener action, int priority, ActionListener subloader, boolean isLeaf);
|
||||
public void addMenuItem(String path, String title, String icon, ActionListener action, int priority, ActionListener subloader, boolean isLeaf, HotKey key);
|
||||
|
||||
/**
|
||||
* Adds toggle item (radio/checkbox)
|
||||
@@ -66,7 +207,7 @@ public interface MenuBuilder {
|
||||
* @param action Action for clicking
|
||||
* @param priority Priority
|
||||
*/
|
||||
public void addToggleMenuItem(String path, String title, String group, String icon, ActionListener action, int priority);
|
||||
public void addToggleMenuItem(String path, String title, String group, String icon, ActionListener action, int priority, HotKey key);
|
||||
|
||||
/**
|
||||
* Test menu checked (toggle)
|
||||
@@ -76,6 +217,14 @@ public interface MenuBuilder {
|
||||
*/
|
||||
public boolean isMenuChecked(String path);
|
||||
|
||||
/**
|
||||
* Hotkey for menu
|
||||
*
|
||||
* @param path Menu path
|
||||
* @return
|
||||
*/
|
||||
public HotKey getMenuHotkey(String path);
|
||||
|
||||
/**
|
||||
* Sets menu checked (toggle)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user