diff --git a/pom.xml b/pom.xml index 0e27ebb..74774e4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ groupId jda - 0.0.2-SNAPSHOT + 0.0.3-SNAPSHOT diff --git a/src/main/java/the/bytecode/club/jda/JDA.java b/src/main/java/the/bytecode/club/jda/JDA.java index f44514f..146b383 100644 --- a/src/main/java/the/bytecode/club/jda/JDA.java +++ b/src/main/java/the/bytecode/club/jda/JDA.java @@ -24,7 +24,7 @@ public class JDA { /*per version*/ - public static final String version = "0.0.2"; + public static final String version = "0.0.3"; public static final boolean previewCopy = false; /* Constants */ public static final String fs = System.getProperty("file.separator"); @@ -189,13 +189,16 @@ public static byte[] getClassBytes(String containerName, String name) * @param name the file name * @return the file contents as a byte[] */ - public static byte[] getFileContents(String name) + public static byte[] getFileContents(String containerName, String name) { for (FileContainer container : files) { - HashMap files = container.files; - if (files.containsKey(name)) - return files.get(name); + if (container.name.equals(containerName)) + { + HashMap files = container.files; + if (files.containsKey(name)) + return files.get(name); + } } return null; @@ -596,8 +599,6 @@ private static void hideFile(File f) sm.setBlocking(); } - private static long last = System.currentTimeMillis(); - /** * Checks the hotkeys * @@ -605,12 +606,8 @@ private static void hideFile(File f) */ public static void checkHotKey(KeyEvent e) { - if (System.currentTimeMillis() - last <= (4000)) - return; - if ((e.getKeyCode() == KeyEvent.VK_O) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); JFileChooser fc = new JFileChooser(); try { @@ -663,18 +660,14 @@ public String getDescription() } else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); JDA.resetWorkSpace(true); } else if ((e.getKeyCode() == KeyEvent.VK_R) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); viewer.reloadResources(); } else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); - if (JDA.getLoadedClasses().isEmpty()) { JDA.showMessage("First open a class, jar, or zip file."); @@ -752,7 +745,6 @@ public void run() } else if ((e.getKeyCode() == KeyEvent.VK_W) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0)) { - last = System.currentTimeMillis(); if (viewer.workPane.getCurrentViewer() != null) viewer.workPane.tabs.remove(viewer.workPane.getCurrentViewer()); } diff --git a/src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java b/src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java index ed1eb56..34694cf 100644 --- a/src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java +++ b/src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java @@ -554,7 +554,7 @@ public void openPath(TreePath path) } else { - openFileToWorkSpace(nameBuffer.toString(), containerName, JDA.getFileContents(nameBuffer.toString())); + openFileToWorkSpace(nameBuffer.toString(), containerName, JDA.getFileContents(containerName, nameBuffer.toString())); } } diff --git a/src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java index 6f4b0a9..b9a33b3 100644 --- a/src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java @@ -120,13 +120,40 @@ public void resetWorkspace() resetWindows(); } - public class Test implements KeyEventDispatcher + public class JDAKeybindManager implements java.awt.KeyEventDispatcher { + private final HashMap keyStates = new HashMap<>(); + private long lastEventTime = System.currentTimeMillis(); + @Override public boolean dispatchKeyEvent(KeyEvent e) { - JDA.checkHotKey(e); - return false; + if (!e.isControlDown()) + return false; + + long deltaTime = System.currentTimeMillis() - lastEventTime; + lastEventTime = System.currentTimeMillis(); + if (deltaTime <= 5) // hack to fix repeated key events, thanks Java + return false; + + int key = e.getKeyCode(); + synchronized (keyStates) + { + if (e.getID() == KeyEvent.KEY_PRESSED) + { + if (!keyStates.containsKey(key) || !keyStates.get(key)) + { + keyStates.put(key, true); + JDA.checkHotKey(e); + } + return true; + } + else if (e.getID() == KeyEvent.KEY_RELEASED) + { + keyStates.put(key, false); + } + return false; + } } } @@ -180,7 +207,7 @@ public MainViewerGUI() editButtons.put(panelGroup1, new HashMap<>()); editButtons.put(panelGroup2, new HashMap<>()); editButtons.put(panelGroup3, new HashMap<>()); - KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new Test()); + KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new JDAKeybindManager()); this.addWindowStateListener(new WindowAdapter() { @Override @@ -396,8 +423,7 @@ private void initializeWindows() desktop.add(navigator); desktop.add(workPane); desktop.setDesktopManager(new WorkspaceDesktopManager()); - if (desktop.getBackground().equals(Color.BLACK)) - desktop.setBackground(COLOR_DESKTOP_BACKGROUND); + desktop.setBackground(COLOR_DESKTOP_BACKGROUND); rfComps.add(navigator); rfComps.add(workPane);