Skip to content

Commit 8e0699e

Browse files
committed
Bug fixes (Hotkeys, multiple same-name files, background color)
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
1 parent 15a1e13 commit 8e0699e

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>groupId</groupId>
88
<artifactId>jda</artifactId>
9-
<version>0.0.2-SNAPSHOT</version>
9+
<version>0.0.3-SNAPSHOT</version>
1010

1111
<repositories>
1212
<repository>

src/main/java/the/bytecode/club/jda/JDA.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
public class JDA
2525
{
2626
/*per version*/
27-
public static final String version = "0.0.2";
27+
public static final String version = "0.0.3";
2828
public static final boolean previewCopy = false;
2929
/* Constants */
3030
public static final String fs = System.getProperty("file.separator");
@@ -189,13 +189,16 @@ public static byte[] getClassBytes(String containerName, String name)
189189
* @param name the file name
190190
* @return the file contents as a byte[]
191191
*/
192-
public static byte[] getFileContents(String name)
192+
public static byte[] getFileContents(String containerName, String name)
193193
{
194194
for (FileContainer container : files)
195195
{
196-
HashMap<String, byte[]> files = container.files;
197-
if (files.containsKey(name))
198-
return files.get(name);
196+
if (container.name.equals(containerName))
197+
{
198+
HashMap<String, byte[]> files = container.files;
199+
if (files.containsKey(name))
200+
return files.get(name);
201+
}
199202
}
200203

201204
return null;
@@ -596,21 +599,15 @@ private static void hideFile(File f)
596599
sm.setBlocking();
597600
}
598601

599-
private static long last = System.currentTimeMillis();
600-
601602
/**
602603
* Checks the hotkeys
603604
*
604605
* @param e
605606
*/
606607
public static void checkHotKey(KeyEvent e)
607608
{
608-
if (System.currentTimeMillis() - last <= (4000))
609-
return;
610-
611609
if ((e.getKeyCode() == KeyEvent.VK_O) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
612610
{
613-
last = System.currentTimeMillis();
614611
JFileChooser fc = new JFileChooser();
615612
try
616613
{
@@ -663,18 +660,14 @@ public String getDescription()
663660
}
664661
else if ((e.getKeyCode() == KeyEvent.VK_N) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
665662
{
666-
last = System.currentTimeMillis();
667663
JDA.resetWorkSpace(true);
668664
}
669665
else if ((e.getKeyCode() == KeyEvent.VK_R) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
670666
{
671-
last = System.currentTimeMillis();
672667
viewer.reloadResources();
673668
}
674669
else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
675670
{
676-
last = System.currentTimeMillis();
677-
678671
if (JDA.getLoadedClasses().isEmpty())
679672
{
680673
JDA.showMessage("First open a class, jar, or zip file.");
@@ -752,7 +745,6 @@ public void run()
752745
}
753746
else if ((e.getKeyCode() == KeyEvent.VK_W) && ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0))
754747
{
755-
last = System.currentTimeMillis();
756748
if (viewer.workPane.getCurrentViewer() != null)
757749
viewer.workPane.tabs.remove(viewer.workPane.getCurrentViewer());
758750
}

src/main/java/the/bytecode/club/jda/gui/FileNavigationPane.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ public void openPath(TreePath path)
554554
}
555555
else
556556
{
557-
openFileToWorkSpace(nameBuffer.toString(), containerName, JDA.getFileContents(nameBuffer.toString()));
557+
openFileToWorkSpace(nameBuffer.toString(), containerName, JDA.getFileContents(containerName, nameBuffer.toString()));
558558
}
559559
}
560560

src/main/java/the/bytecode/club/jda/gui/MainViewerGUI.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,40 @@ public void resetWorkspace()
120120
resetWindows();
121121
}
122122

123-
public class Test implements KeyEventDispatcher
123+
public class JDAKeybindManager implements java.awt.KeyEventDispatcher
124124
{
125+
private final HashMap<Integer, Boolean> keyStates = new HashMap<>();
126+
private long lastEventTime = System.currentTimeMillis();
127+
125128
@Override
126129
public boolean dispatchKeyEvent(KeyEvent e)
127130
{
128-
JDA.checkHotKey(e);
129-
return false;
131+
if (!e.isControlDown())
132+
return false;
133+
134+
long deltaTime = System.currentTimeMillis() - lastEventTime;
135+
lastEventTime = System.currentTimeMillis();
136+
if (deltaTime <= 5) // hack to fix repeated key events, thanks Java
137+
return false;
138+
139+
int key = e.getKeyCode();
140+
synchronized (keyStates)
141+
{
142+
if (e.getID() == KeyEvent.KEY_PRESSED)
143+
{
144+
if (!keyStates.containsKey(key) || !keyStates.get(key))
145+
{
146+
keyStates.put(key, true);
147+
JDA.checkHotKey(e);
148+
}
149+
return true;
150+
}
151+
else if (e.getID() == KeyEvent.KEY_RELEASED)
152+
{
153+
keyStates.put(key, false);
154+
}
155+
return false;
156+
}
130157
}
131158
}
132159

@@ -180,7 +207,7 @@ public MainViewerGUI()
180207
editButtons.put(panelGroup1, new HashMap<>());
181208
editButtons.put(panelGroup2, new HashMap<>());
182209
editButtons.put(panelGroup3, new HashMap<>());
183-
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new Test());
210+
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new JDAKeybindManager());
184211
this.addWindowStateListener(new WindowAdapter()
185212
{
186213
@Override
@@ -396,8 +423,7 @@ private void initializeWindows()
396423
desktop.add(navigator);
397424
desktop.add(workPane);
398425
desktop.setDesktopManager(new WorkspaceDesktopManager());
399-
if (desktop.getBackground().equals(Color.BLACK))
400-
desktop.setBackground(COLOR_DESKTOP_BACKGROUND);
426+
desktop.setBackground(COLOR_DESKTOP_BACKGROUND);
401427

402428
rfComps.add(navigator);
403429
rfComps.add(workPane);

0 commit comments

Comments
 (0)