GUI: fixed wrong clicks from additional mouse buttons (now only left clicks are allowed, closes #11455)

This commit is contained in:
Oleg Agafonov 2023-11-23 09:23:01 +04:00
parent 75958e3710
commit a0ed89035f
17 changed files with 82 additions and 21 deletions

View file

@ -1022,8 +1022,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
btnDebug.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
btnDebug.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
btnDebugMouseClicked(evt);
public void mouseClicked(java.awt.event.MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
btnDebugMouseClicked(e);
}
});
mageToolbar.add(btnDebug);

View file

@ -163,6 +163,9 @@
mainTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
// simulate mouse click on the card
if ((e.getClickCount() & 1) == 0 && (e.getClickCount() > 0) && !e.isConsumed()) { // double clicks and repeated double clicks
e.consume();

View file

@ -789,11 +789,12 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
@Override
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
isDragging = true;
beginSelectionDrag(e.getX(), e.getY(), e.isShiftDown());
updateSelectionDrag(e.getX(), e.getY());
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
isDragging = true;
beginSelectionDrag(e.getX(), e.getY(), e.isShiftDown());
updateSelectionDrag(e.getX(), e.getY());
}
@Override
@ -973,6 +974,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
visibilityButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
visPopup.show(e.getComponent(), 0, e.getComponent().getHeight());
}
});
@ -2297,6 +2301,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
this.countLabelListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
JLabel countLabel = (JLabel) e.getComponent();
List<CardView> cards = findCardStackByCountLabel(countLabel);
boolean selected = !cards.isEmpty() && cards.get(0).isSelected();

View file

@ -271,10 +271,11 @@ public class HoverButton extends JPanel implements MouseListener {
@Override
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
if (isEnabled() && observer != null) {
observer.execute();
}
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if (isEnabled() && observer != null) {
observer.execute();
}
}

View file

@ -249,15 +249,15 @@ public class DialogManager extends JComponent implements MouseListener, MouseMot
@Override
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e)) {
j = (JComponent) getComponentAt(e.getX(), e.getY());
if (j instanceof DialogContainer) {
rec = j.getBounds();
bDragged = true;
mx = e.getX();
my = e.getY();
}
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
j = (JComponent) getComponentAt(e.getX(), e.getY());
if (j instanceof DialogContainer) {
rec = j.getBounds();
bDragged = true;
mx = e.getX();
my = e.getY();
}
}

View file

@ -143,6 +143,9 @@ public class CardSelector extends javax.swing.JPanel implements ComponentListene
mainTable.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if ((e.getClickCount() & 1) == 0 && (e.getClickCount() > 0) && !e.isConsumed()) { // double clicks and repeated double clicks
e.consume();
if (e.isAltDown()) {

View file

@ -113,6 +113,9 @@ public class DeckEditorPanel extends javax.swing.JPanel {
.forEach(c -> {
c.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
List<String> cardNames = new ArrayList<>();
LegalityLabel label = (LegalityLabel) e.getComponent();
label.getValidator().getErrorsList().stream()

View file

@ -345,6 +345,9 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
table.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
int row = table.getSelectedRow();
if (row != -1) {
showImage(row);
@ -356,6 +359,9 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
MouseListener mouse = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
TableColumnModel columnModel = table.getColumnModel();
int viewColumn = columnModel.getColumnIndexAtX(e.getX());
int column = table.convertColumnIndexToModel(viewColumn);

View file

@ -37,6 +37,10 @@ public class MageDialog extends javax.swing.JInternalFrame {
@Override
public void mouseClicked(MouseEvent e) {
// double clicks and repeated double clicks
// minimize window to title bar
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if ((e.getClickCount() & 1) == 0 && (e.getClickCount() > 0) && !e.isConsumed()) {
e.consume();
try {

View file

@ -162,6 +162,9 @@ public class PickCheckBoxDialog extends MageDialog {
listChoices.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if (e.getClickCount() == 2) {
doChoose();
}

View file

@ -136,6 +136,9 @@ public class PickChoiceDialog extends MageDialog {
@Override
public void mouseClicked(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if (e.getClickCount() == 2) {
doChoose();
}

View file

@ -3769,6 +3769,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
jLabel.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if (selectedAvatarId != id) {
setSelectedId(id);
SessionHandler.updatePreferencesForServer(getUserData());

View file

@ -121,6 +121,14 @@ public class MageActionCallback implements ActionCallback {
if (e.isConsumed()) {
return;
}
// allows only a standard mouse buttons
if (!e.isPopupTrigger()
&& !SwingUtilities.isLeftMouseButton(e)
&& !SwingUtilities.isRightMouseButton(e)) {
return;
}
if (data.getComponent().getCardContainer() instanceof CardEventProducer) {
ClientEventType clickType = doubleClick ? ClientEventType.CARD_DOUBLE_CLICK : ClientEventType.CARD_CLICK;
CardEventProducer cardContainer = (CardEventProducer) data.getComponent().getCardContainer();

View file

@ -90,7 +90,10 @@ public class TablesButtonColumn extends AbstractCellEditor implements TableCellR
}
@Override
public void mousePressed(MouseEvent arg0) {
public void mousePressed(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if (table.isEditing() && table.getCellEditor() == this) {
isButtonColumnEditor = true;
}

View file

@ -580,6 +580,9 @@ public class TablesPanel extends javax.swing.JPanel {
table.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
int modelRow = TablesUtil.getSelectedModelRow(table);
if (e.getClickCount() == 2 && modelRow != -1) {
action.actionPerformed(new ActionEvent(table, ActionEvent.ACTION_PERFORMED, TablesUtil.getSearchIdFromTable(table, modelRow)));

View file

@ -8,7 +8,7 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import javax.swing.JLabel;
import javax.swing.*;
/**
*
@ -44,6 +44,9 @@ public class URLHandler {
currentMouseAdapter = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
if (e.getClickCount() > 0) {
if (Desktop.isDesktopSupported()) {
Desktop desktop = Desktop.getDesktop();

View file

@ -608,6 +608,11 @@ public abstract class CardPanel extends MagePermanent implements ComponentListen
return;
}
// ignore all additional mouse buttons
if (!SwingUtilities.isLeftMouseButton(e)) {
return;
}
// double clicks processing, see https://stackoverflow.com/questions/4051659/identifying-double-click-in-java
// logic: run timer to reset clicks counter
mouseClicksCount = e.getClickCount();