Skip to content

Commit

Permalink
Bug fixes (Hotkeys, multiple same-name files, background color)
Browse files Browse the repository at this point in the history
Fix hotkey system
Fix issue where opening a non-class file of the same name in two different containers to show the contents of only one file
Set the background color always because in some cases the default color was blue (?)
Bump version number

Fixes #1
Fixes #2
  • Loading branch information
rcx committed Jul 2, 2016
1 parent 15a1e13 commit 8e0699e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>groupId</groupId>
<artifactId>jda</artifactId>
<version>0.0.2-SNAPSHOT</version>
<version>0.0.3-SNAPSHOT</version>

<repositories>
<repository>
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/the/bytecode/club/jda/JDA.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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<String, byte[]> files = container.files;
if (files.containsKey(name))
return files.get(name);
if (container.name.equals(containerName))
{
HashMap<String, byte[]> files = container.files;
if (files.containsKey(name))
return files.get(name);
}
}

return null;
Expand Down Expand Up @@ -596,21 +599,15 @@ private static void hideFile(File f)
sm.setBlocking();
}

private static long last = System.currentTimeMillis();

/**
* Checks the hotkeys
*
* @param e
*/
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
{
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
}

Expand Down
38 changes: 32 additions & 6 deletions src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,40 @@ public void resetWorkspace()
resetWindows();
}

public class Test implements KeyEventDispatcher
public class JDAKeybindManager implements java.awt.KeyEventDispatcher
{
private final HashMap<Integer, Boolean> 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;
}
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8e0699e

Please sign in to comment.