mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-28 14:35:33 +08:00
GT-3473 improve mouse wheel scrolling behavior
Improve scrolling to match row heights, less hard coded values.
This commit is contained in:
+15
-22
@@ -16,8 +16,6 @@
|
|||||||
package ghidra.app.plugin.core.byteviewer;
|
package ghidra.app.plugin.core.byteviewer;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.MouseWheelEvent;
|
|
||||||
import java.awt.event.MouseWheelListener;
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -807,10 +805,6 @@ public class ByteViewerPanel extends JPanel implements TableColumnModelListener,
|
|||||||
indexPanel.setCursorOn(false);
|
indexPanel.setCursorOn(false);
|
||||||
indexPanel.setFocusable(false);
|
indexPanel.setFocusable(false);
|
||||||
|
|
||||||
// this lets us scroll the byte viewer when the user is not over any panel, but still
|
|
||||||
// over the view
|
|
||||||
addMouseWheelListener(new DeadSpaceScrollListener(indexPanel));
|
|
||||||
|
|
||||||
compPanel = new CompositePanel(indexPanel);
|
compPanel = new CompositePanel(indexPanel);
|
||||||
|
|
||||||
scrollp = new IndexedScrollPane(compPanel);
|
scrollp = new IndexedScrollPane(compPanel);
|
||||||
@@ -1054,22 +1048,6 @@ public class ByteViewerPanel extends JPanel implements TableColumnModelListener,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeadSpaceScrollListener implements MouseWheelListener {
|
|
||||||
|
|
||||||
private final FieldPanel fieldPanel;
|
|
||||||
|
|
||||||
DeadSpaceScrollListener(FieldPanel fieldPanel) {
|
|
||||||
this.fieldPanel = fieldPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
|
||||||
int scrollAmount = e.getWheelRotation() * 40; // magic value pulled from FieldPanel
|
|
||||||
fieldPanel.scrollView(scrollAmount);
|
|
||||||
e.consume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CompositePanel extends JPanel implements IndexedScrollable, IndexScrollListener {
|
class CompositePanel extends JPanel implements IndexedScrollable, IndexScrollListener {
|
||||||
FieldPanel indexPanel;
|
FieldPanel indexPanel;
|
||||||
BoundedRangeModel verticalScrollBarModel;
|
BoundedRangeModel verticalScrollBarModel;
|
||||||
@@ -1082,6 +1060,21 @@ class CompositePanel extends JPanel implements IndexedScrollable, IndexScrollLis
|
|||||||
super(new HorizontalLayout(0));
|
super(new HorizontalLayout(0));
|
||||||
this.indexPanel = indexPanel;
|
this.indexPanel = indexPanel;
|
||||||
indexPanel.addIndexScrollListener(this);
|
indexPanel.addIndexScrollListener(this);
|
||||||
|
addMouseWheelListener(e -> {
|
||||||
|
// this lets us scroll the byte viewer when the user is not over any panel, but still over the view
|
||||||
|
Layout firstLayout = indexPanel.getLayoutModel().getLayout(BigInteger.ZERO);
|
||||||
|
int layoutScrollHt = firstLayout != null //
|
||||||
|
? firstLayout.getScrollableUnitIncrement(0, 1)
|
||||||
|
: 0;
|
||||||
|
|
||||||
|
double wheelRotation = e.getPreciseWheelRotation();
|
||||||
|
int scrollAmount =
|
||||||
|
(int) (wheelRotation * layoutScrollHt * FieldPanel.MOUSEWHEEL_LINES_TO_SCROLL);
|
||||||
|
|
||||||
|
indexPanel.scrollView(scrollAmount);
|
||||||
|
e.consume();
|
||||||
|
});
|
||||||
|
|
||||||
allPanels.add(indexPanel);
|
allPanels.add(indexPanel);
|
||||||
rebuildPanels();
|
rebuildPanels();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ import ghidra.util.SystemUtilities;
|
|||||||
|
|
||||||
public class FieldPanel extends JPanel
|
public class FieldPanel extends JPanel
|
||||||
implements IndexedScrollable, LayoutModelListener, ChangeListener {
|
implements IndexedScrollable, LayoutModelListener, ChangeListener {
|
||||||
|
public static final int MOUSEWHEEL_LINES_TO_SCROLL = 3;
|
||||||
|
|
||||||
private LayoutModel model;
|
private LayoutModel model;
|
||||||
|
|
||||||
private boolean repaintPosted;
|
private boolean repaintPosted;
|
||||||
@@ -1504,7 +1506,12 @@ public class FieldPanel extends JPanel
|
|||||||
@Override
|
@Override
|
||||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
public void mouseWheelMoved(MouseWheelEvent e) {
|
||||||
double wheelRotation = e.getPreciseWheelRotation();
|
double wheelRotation = e.getPreciseWheelRotation();
|
||||||
int scrollAmount = (int) (wheelRotation * 40);
|
|
||||||
|
Layout firstLayout = model.getLayout(BigInteger.ZERO);
|
||||||
|
int layoutScrollHt = firstLayout != null //
|
||||||
|
? firstLayout.getScrollableUnitIncrement(0, 1)
|
||||||
|
: 0;
|
||||||
|
int scrollAmount = (int) (wheelRotation * layoutScrollHt * MOUSEWHEEL_LINES_TO_SCROLL);
|
||||||
if (scrollAmount == 0) {
|
if (scrollAmount == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user