From 76dc769e1f1489eedb6412959706a0731858ecb0 Mon Sep 17 00:00:00 2001 From: emmanue1 Date: Tue, 9 Apr 2019 23:41:38 +0200 Subject: [PATCH] Fix bug on key listener of "Search In Constant" dialog --- .../gui/view/SearchInConstantPoolsView.java | 4 +- .../gui/view/component/AbstractTextPage.java | 64 +++++++++---------- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/org/jd/gui/view/SearchInConstantPoolsView.java b/app/src/main/java/org/jd/gui/view/SearchInConstantPoolsView.java index 9f12d662..4f1694b2 100644 --- a/app/src/main/java/org/jd/gui/view/SearchInConstantPoolsView.java +++ b/app/src/main/java/org/jd/gui/view/SearchInConstantPoolsView.java @@ -103,7 +103,7 @@ public SearchInConstantPoolsView( } } @Override public void keyPressed(KeyEvent e) { - if (e.getKeyChar() == KeyEvent.VK_DOWN) { + if (e.getKeyCode() == KeyEvent.VK_DOWN) { DefaultMutableTreeNode root = (DefaultMutableTreeNode)searchInConstantPoolsTree.getModel().getRoot(); if (root.getChildCount() > 0) { searchInConstantPoolsTree.requestFocus(); @@ -194,7 +194,7 @@ public SearchInConstantPoolsView( searchInConstantPoolsTree.setCellRenderer(new TreeNodeRenderer()); searchInConstantPoolsTree.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { - if (e.getKeyChar() == KeyEvent.VK_UP) { + if (e.getKeyCode() == KeyEvent.VK_UP) { if (searchInConstantPoolsTree.getLeadSelectionRow() == 0) { searchInConstantPoolsEnterTextField.requestFocus(); e.consume(); diff --git a/services/src/main/java/org/jd/gui/view/component/AbstractTextPage.java b/services/src/main/java/org/jd/gui/view/component/AbstractTextPage.java index 4f5ca99f..2e07b6dd 100644 --- a/services/src/main/java/org/jd/gui/view/component/AbstractTextPage.java +++ b/services/src/main/java/org/jd/gui/view/component/AbstractTextPage.java @@ -91,41 +91,39 @@ public void mouseClicked(MouseEvent e) { scrollPane.removeMouseWheelListener(listener); } - scrollPane.addMouseWheelListener(new MouseWheelListener() { - public void mouseWheelMoved(MouseWheelEvent event) { - if ((event.getModifiers() & (Event.META_MASK|Event.CTRL_MASK)) != 0) { - int x = event.getX() + scrollPane.getX() - textArea.getX(); - int y = event.getY() + scrollPane.getY() - textArea.getY(); - int offset = textArea.viewToModel(new Point(x, y)); - - // Update font size - if (event.getWheelRotation() > 0) { - INCREASE_FONT_SIZE_ACTION.actionPerformedImpl(null, textArea); - } else { - DECREASE_FONT_SIZE_ACTION.actionPerformedImpl(null, textArea); - } - - // Save preferences - if (preferences != null) { - preferences.put(FONT_SIZE_KEY, String.valueOf(textArea.getFont().getSize())); - } + scrollPane.addMouseWheelListener(e -> { + if ((e.getModifiers() & (Event.META_MASK|Event.CTRL_MASK)) != 0) { + int x = e.getX() + scrollPane.getX() - textArea.getX(); + int y = e.getY() + scrollPane.getY() - textArea.getY(); + int offset = textArea.viewToModel(new Point(x, y)); + + // Update font size + if (e.getWheelRotation() > 0) { + INCREASE_FONT_SIZE_ACTION.actionPerformedImpl(null, textArea); + } else { + DECREASE_FONT_SIZE_ACTION.actionPerformedImpl(null, textArea); + } - try { - Rectangle newRectangle = textArea.modelToView(offset); - int newY = newRectangle.y + (newRectangle.height >> 1); + // Save preferences + if (preferences != null) { + preferences.put(FONT_SIZE_KEY, String.valueOf(textArea.getFont().getSize())); + } - // Scroll - Point viewPosition = scrollPane.getViewport().getViewPosition(); - viewPosition.y = Math.max(viewPosition.y +newY - y, 0); - scrollPane.getViewport().setViewPosition(viewPosition); - } catch (BadLocationException e) { - assert ExceptionUtil.printStackTrace(e); - } - } else { - // Call default listeners - for (MouseWheelListener listener : mouseWheelListeners) { - listener.mouseWheelMoved(event); - } + try { + Rectangle newRectangle = textArea.modelToView(offset); + int newY = newRectangle.y + (newRectangle.height >> 1); + + // Scroll + Point viewPosition = scrollPane.getViewport().getViewPosition(); + viewPosition.y = Math.max(viewPosition.y +newY - y, 0); + scrollPane.getViewport().setViewPosition(viewPosition); + } catch (BadLocationException ee) { + assert ExceptionUtil.printStackTrace(ee); + } + } else { + // Call default listeners + for (MouseWheelListener listener : mouseWheelListeners) { + listener.mouseWheelMoved(e); } } });