| 1 | package com.jsql.view.swing.tab; | |
| 2 | ||
| 3 | import com.jsql.util.LogLevelUtil; | |
| 4 | import org.apache.logging.log4j.LogManager; | |
| 5 | import org.apache.logging.log4j.Logger; | |
| 6 | ||
| 7 | import javax.swing.*; | |
| 8 | import java.awt.event.MouseWheelEvent; | |
| 9 | import java.awt.event.MouseWheelListener; | |
| 10 | ||
| 11 | /** | |
| 12 | * Mouse wheel allows to navigate to next/previous tab. | |
| 13 | */ | |
| 14 | public class TabbedPaneMouseWheelListener implements MouseWheelListener { | |
| 15 | | |
| 16 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 17 | | |
| 18 | @Override | |
| 19 | public void mouseWheelMoved(MouseWheelEvent event) { | |
| 20 | | |
| 21 | JTabbedPane tabPane = (JTabbedPane) event.getSource(); | |
| 22 | ||
| 23 |
1
1. mouseWheelMoved : removed negation → NO_COVERAGE |
int dir = -event.getWheelRotation(); |
| 24 | int selIndex = tabPane.getSelectedIndex(); | |
| 25 |
1
1. mouseWheelMoved : Replaced integer subtraction with addition → NO_COVERAGE |
int maxIndex = tabPane.getTabCount() - 1; |
| 26 | | |
| 27 |
6
1. mouseWheelMoved : negated conditional → NO_COVERAGE 2. mouseWheelMoved : negated conditional → NO_COVERAGE 3. mouseWheelMoved : negated conditional → NO_COVERAGE 4. mouseWheelMoved : negated conditional → NO_COVERAGE 5. mouseWheelMoved : changed conditional boundary → NO_COVERAGE 6. mouseWheelMoved : changed conditional boundary → NO_COVERAGE |
if ((selIndex == 0 && dir < 0) || (selIndex == maxIndex && dir > 0)) { |
| 28 |
1
1. mouseWheelMoved : Replaced integer subtraction with addition → NO_COVERAGE |
selIndex = maxIndex - selIndex; |
| 29 | } else { | |
| 30 |
1
1. mouseWheelMoved : Replaced integer addition with subtraction → NO_COVERAGE |
selIndex += dir; |
| 31 | } | |
| 32 | | |
| 33 |
4
1. mouseWheelMoved : negated conditional → NO_COVERAGE 2. mouseWheelMoved : negated conditional → NO_COVERAGE 3. mouseWheelMoved : changed conditional boundary → NO_COVERAGE 4. mouseWheelMoved : changed conditional boundary → NO_COVERAGE |
if (0 <= selIndex && selIndex < tabPane.getTabCount()) { |
| 34 | // Fix #54575: NullPointerException on setSelectedIndex() | |
| 35 | // Fix #90835: IllegalArgumentException on setSelectedIndex() | |
| 36 | try { | |
| 37 |
1
1. mouseWheelMoved : removed call to javax/swing/JTabbedPane::setSelectedIndex → NO_COVERAGE |
tabPane.setSelectedIndex(selIndex); |
| 38 | } catch (IllegalArgumentException | NullPointerException e) { | |
| 39 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 40 | } | |
| 41 | } | |
| 42 | } | |
| 43 | } | |
Mutations | ||
| 23 |
1.1 |
|
| 25 |
1.1 |
|
| 27 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
| 28 |
1.1 |
|
| 30 |
1.1 |
|
| 33 |
1.1 2.2 3.3 4.4 |
|
| 37 |
1.1 |