Switch server tabs with the scroll wheel

Wheel events on the tab strip step through the open connections,
clamped at the ends. The content area is excluded so the tree and chat
keep their own scrolling.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-13 15:28:20 +00:00
parent 41bf9506e3
commit 1249242c89

View File

@@ -7,11 +7,13 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Insets;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.util.ArrayList;
import java.util.List;
@@ -48,6 +50,24 @@ final class ServerTabPane extends JPanel {
int i = tabbed.getSelectedIndex();
if (i >= 0 && i < tabs.size()) listener.selectTab(tabs.get(i));
});
tabbed.addMouseWheelListener(this::onWheel);
}
/**
* Scrolling over the tab strip steps through the connections. The content
* area keeps its own scrolling, so only wheel events on the strip itself
* (and on the tab labels, which forward theirs) change tabs.
*/
private void onWheel(MouseWheelEvent e) {
if (!tabbedMode) return;
Component content = tabbed.getSelectedComponent();
if (content != null && content.getBounds().contains(e.getPoint())) return;
int steps = e.getWheelRotation();
if (steps == 0) return;
int target = Math.max(0, Math.min(tabs.size() - 1, tabbed.getSelectedIndex() + steps));
if (target != tabbed.getSelectedIndex()) listener.selectTab(tabs.get(target));
e.consume();
}
void addTab(ServerTab tab) {