Skip to content

Commit 3894abf

Browse files
committed
AbilityPicker Empty Selection Error
Do not call objectMouseClicked with an empty selection. Handle selection clamping in a ListSelectionListener. Fixes #13148
1 parent 6b9532f commit 3894abf

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.mage.card.arcane.ManaSymbols;
1818

1919
import javax.swing.*;
20+
import javax.swing.event.ListSelectionEvent;
21+
import javax.swing.event.ListSelectionListener;
2022
import java.awt.*;
2123
import java.awt.event.*;
2224
import java.util.List;
@@ -152,7 +154,7 @@ private void initComponents() {
152154
setBackgroundPainter(mwPanelPainter);
153155

154156
title = new ColorPane();
155-
title.setFont(new Font("Times New Roman", 1, sizeMod(15)));
157+
title.setFont(new Font("Times New Roman", Font.BOLD, sizeMod(15)));
156158
title.setEditable(false);
157159
title.setFocusCycleRoot(false);
158160
title.setOpaque(false);
@@ -186,11 +188,14 @@ private void initComponents() {
186188
rows.addMouseListener(new MouseAdapter() {
187189
@Override
188190
public void mousePressed(MouseEvent evt) {
189-
if (SwingUtilities.isLeftMouseButton(evt)) {
191+
if (SwingUtilities.isLeftMouseButton(evt) && !rows.isSelectionEmpty()) {
190192
objectMouseClicked(evt);
191193
}
192194
}
193195
});
196+
}
197+
});
198+
194199
rows.setSelectedIndex(0);
195200
rows.setFont(new Font("Times New Roman", 1, sizeMod(17)));
196201
rows.setBorder(BorderFactory.createEmptyBorder());
@@ -233,18 +238,16 @@ public void mousePressed(MouseEvent evt) {
233238

234239
@Override
235240
public void mouseWheelMoved(MouseWheelEvent e) {
236-
int notches = e.getWheelRotation();
237-
int index = rows.getSelectedIndex();
238-
239-
if (notches < 0) {
240-
if (index > 0) {
241-
rows.setSelectedIndex(index - 1);
242-
rows.repaint();
243-
}
244-
} else if (index < choices.size() - 1) {
245-
rows.setSelectedIndex(index + 1);
246-
rows.repaint();
241+
int direction = e.getWheelRotation() < 0 ? -1 : +1;
242+
int index = rows.getSelectedIndex() + direction;
243+
if (index < 0) {
244+
index = 0;
245+
} else if (index >= choices.size()) {
246+
index = choices.size() - 1;
247247
}
248+
249+
rows.setSelectedIndex(index);
250+
rows.repaint();
248251
}
249252

250253
private void objectMouseClicked(MouseEvent event) {

0 commit comments

Comments
 (0)