| 1 | package com.jsql.view.swing.tab.dnd; | |
| 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.*; | |
| 9 | import java.awt.datatransfer.DataFlavor; | |
| 10 | import java.awt.datatransfer.Transferable; | |
| 11 | import java.awt.datatransfer.UnsupportedFlavorException; | |
| 12 | import java.awt.dnd.DragSource; | |
| 13 | import java.awt.image.BufferedImage; | |
| 14 | import java.io.IOException; | |
| 15 | import java.util.Objects; | |
| 16 | import java.util.Optional; | |
| 17 | ||
| 18 | public class TabTransferHandler extends TransferHandler { | |
| 19 | | |
| 20 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
| 21 | | |
| 22 | protected final DataFlavor localObjectFlavor; | |
| 23 | | |
| 24 | protected DnDTabbedPane source; | |
| 25 | ||
| 26 | public TabTransferHandler() { | |
| 27 | this.localObjectFlavor = new DataFlavor(DnDTabData.class, "DnDTabData"); | |
| 28 | } | |
| 29 | | |
| 30 | @Override | |
| 31 | protected Transferable createTransferable(JComponent c) { | |
| 32 |
1
1. createTransferable : negated conditional → NO_COVERAGE |
if (c instanceof DnDTabbedPane) { |
| 33 | this.source = (DnDTabbedPane) c; | |
| 34 | } | |
| 35 | ||
| 36 |
1
1. createTransferable : replaced return value with null for com/jsql/view/swing/tab/dnd/TabTransferHandler::createTransferable → NO_COVERAGE |
return new Transferable() { |
| 37 | @Override | |
| 38 | public DataFlavor[] getTransferDataFlavors() { | |
| 39 |
1
1. getTransferDataFlavors : replaced return value with null for com/jsql/view/swing/tab/dnd/TabTransferHandler$1::getTransferDataFlavors → NO_COVERAGE |
return new DataFlavor[] { TabTransferHandler.this.localObjectFlavor }; |
| 40 | } | |
| 41 | @Override | |
| 42 | public boolean isDataFlavorSupported(DataFlavor flavor) { | |
| 43 |
2
1. isDataFlavorSupported : replaced boolean return with false for com/jsql/view/swing/tab/dnd/TabTransferHandler$1::isDataFlavorSupported → NO_COVERAGE 2. isDataFlavorSupported : replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler$1::isDataFlavorSupported → NO_COVERAGE |
return Objects.equals(TabTransferHandler.this.localObjectFlavor, flavor); |
| 44 | } | |
| 45 | @Override | |
| 46 | public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { | |
| 47 |
1
1. getTransferData : negated conditional → NO_COVERAGE |
if (this.isDataFlavorSupported(flavor)) { |
| 48 |
1
1. getTransferData : replaced return value with null for com/jsql/view/swing/tab/dnd/TabTransferHandler$1::getTransferData → NO_COVERAGE |
return new DnDTabData(TabTransferHandler.this.source); |
| 49 | } else { | |
| 50 | throw new UnsupportedFlavorException(flavor); | |
| 51 | } | |
| 52 | } | |
| 53 | }; | |
| 54 | } | |
| 55 | | |
| 56 | @Override | |
| 57 | public boolean canImport(TransferHandler.TransferSupport support) { | |
| 58 |
2
1. canImport : negated conditional → NO_COVERAGE 2. canImport : negated conditional → NO_COVERAGE |
if (!support.isDrop() || !support.isDataFlavorSupported(this.localObjectFlavor)) { |
| 59 |
1
1. canImport : replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler::canImport → NO_COVERAGE |
return false; |
| 60 | } | |
| 61 | | |
| 62 |
1
1. canImport : removed call to javax/swing/TransferHandler$TransferSupport::setDropAction → NO_COVERAGE |
support.setDropAction(TransferHandler.MOVE); |
| 63 | var tdl = support.getDropLocation(); | |
| 64 | var pt = tdl.getDropPoint(); | |
| 65 | | |
| 66 | DnDTabbedPane target = (DnDTabbedPane) support.getComponent(); | |
| 67 | | |
| 68 |
1
1. canImport : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::autoScrollTest → NO_COVERAGE |
target.autoScrollTest(pt); |
| 69 | DnDTabbedPane.DnDDropLocation dl = target.dropLocationForPointDnD(pt); | |
| 70 | int idx = dl.getIndex(); | |
| 71 | ||
| 72 | var isDroppable = false; | |
| 73 |
3
1. canImport : negated conditional → NO_COVERAGE 2. canImport : changed conditional boundary → NO_COVERAGE 3. canImport : negated conditional → NO_COVERAGE |
boolean isAreaContains = target.getTabAreaBounds().contains(pt) && idx >= 0; |
| 74 | | |
| 75 |
1
1. canImport : negated conditional → NO_COVERAGE |
if (target.equals(this.source)) { |
| 76 |
4
1. canImport : Replaced integer addition with subtraction → NO_COVERAGE 2. canImport : negated conditional → NO_COVERAGE 3. canImport : negated conditional → NO_COVERAGE 4. canImport : negated conditional → NO_COVERAGE |
isDroppable = isAreaContains && idx != target.dragTabIndex && idx != target.dragTabIndex + 1; |
| 77 | } else { | |
| 78 |
4
1. canImport : negated conditional → NO_COVERAGE 2. lambda$canImport$0 : replaced Boolean return with True for com/jsql/view/swing/tab/dnd/TabTransferHandler::lambda$canImport$0 → NO_COVERAGE 3. canImport : negated conditional → NO_COVERAGE 4. lambda$canImport$0 : negated conditional → NO_COVERAGE |
isDroppable = Optional.ofNullable(this.source).map(c -> !c.isAncestorOf(target)).orElse(false) && isAreaContains; |
| 79 | } | |
| 80 | ||
| 81 | // [JDK-6700748] Cursor flickering during D&D when using CellRendererPane with validation - Java Bug System | |
| 82 | // https://bugs.openjdk.java.net/browse/JDK-6700748 | |
| 83 |
1
1. canImport : negated conditional → NO_COVERAGE |
Cursor cursor = isDroppable ? DragSource.DefaultMoveDrop : DragSource.DefaultMoveNoDrop; |
| 84 | Component glassPane = target.getRootPane().getGlassPane(); | |
| 85 |
1
1. canImport : removed call to java/awt/Component::setCursor → NO_COVERAGE |
glassPane.setCursor(cursor); |
| 86 |
1
1. canImport : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::setCursor → NO_COVERAGE |
target.setCursor(cursor); |
| 87 | ||
| 88 |
1
1. canImport : removed call to javax/swing/TransferHandler$TransferSupport::setShowDropLocation → NO_COVERAGE |
support.setShowDropLocation(isDroppable); |
| 89 |
1
1. canImport : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane$DnDDropLocation::setDroppable → NO_COVERAGE |
dl.setDroppable(isDroppable); |
| 90 |
1
1. canImport : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::setDropLocation → NO_COVERAGE |
target.setDropLocation(dl, isDroppable); |
| 91 |
2
1. canImport : replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler::canImport → NO_COVERAGE 2. canImport : replaced boolean return with false for com/jsql/view/swing/tab/dnd/TabTransferHandler::canImport → NO_COVERAGE |
return isDroppable; |
| 92 | } | |
| 93 | | |
| 94 | private BufferedImage makeDragTabImage(DnDTabbedPane tabbedPane) { | |
| 95 | Rectangle rect = tabbedPane.getBoundsAt(tabbedPane.dragTabIndex); | |
| 96 | var image = new BufferedImage(tabbedPane.getWidth(), tabbedPane.getHeight(), BufferedImage.TYPE_INT_ARGB); | |
| 97 | Graphics g2 = image.createGraphics(); | |
| 98 |
1
1. makeDragTabImage : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::paint → NO_COVERAGE |
tabbedPane.paint(g2); |
| 99 |
1
1. makeDragTabImage : removed call to java/awt/Graphics::dispose → NO_COVERAGE |
g2.dispose(); |
| 100 | | |
| 101 |
2
1. makeDragTabImage : negated conditional → NO_COVERAGE 2. makeDragTabImage : changed conditional boundary → NO_COVERAGE |
if (rect.x < 0) { |
| 102 |
2
1. makeDragTabImage : removed negation → NO_COVERAGE 2. makeDragTabImage : removed call to java/awt/Rectangle::translate → NO_COVERAGE |
rect.translate(-rect.x, 0); |
| 103 | } | |
| 104 |
2
1. makeDragTabImage : changed conditional boundary → NO_COVERAGE 2. makeDragTabImage : negated conditional → NO_COVERAGE |
if (rect.y < 0) { |
| 105 |
2
1. makeDragTabImage : removed call to java/awt/Rectangle::translate → NO_COVERAGE 2. makeDragTabImage : removed negation → NO_COVERAGE |
rect.translate(0, -rect.y); |
| 106 | } | |
| 107 |
3
1. makeDragTabImage : Replaced integer addition with subtraction → NO_COVERAGE 2. makeDragTabImage : negated conditional → NO_COVERAGE 3. makeDragTabImage : changed conditional boundary → NO_COVERAGE |
if (rect.x + rect.width > image.getWidth()) { |
| 108 |
1
1. makeDragTabImage : Replaced integer subtraction with addition → NO_COVERAGE |
rect.width = image.getWidth() - rect.x; |
| 109 | } | |
| 110 |
3
1. makeDragTabImage : negated conditional → NO_COVERAGE 2. makeDragTabImage : changed conditional boundary → NO_COVERAGE 3. makeDragTabImage : Replaced integer addition with subtraction → NO_COVERAGE |
if (rect.y + rect.height > image.getHeight()) { |
| 111 |
1
1. makeDragTabImage : Replaced integer subtraction with addition → NO_COVERAGE |
rect.height = image.getHeight() - rect.y; |
| 112 | } | |
| 113 | | |
| 114 |
1
1. makeDragTabImage : replaced return value with null for com/jsql/view/swing/tab/dnd/TabTransferHandler::makeDragTabImage → NO_COVERAGE |
return image.getSubimage(rect.x, rect.y, rect.width, rect.height); |
| 115 | } | |
| 116 | | |
| 117 | @Override | |
| 118 | public int getSourceActions(JComponent c) { | |
| 119 |
1
1. getSourceActions : negated conditional → NO_COVERAGE |
if (c instanceof DnDTabbedPane) { |
| 120 | DnDTabbedPane src = (DnDTabbedPane) c; | |
| 121 |
1
1. getSourceActions : removed call to javax/swing/JRootPane::setGlassPane → NO_COVERAGE |
c.getRootPane().setGlassPane(new GhostGlassPane(src)); |
| 122 | | |
| 123 |
2
1. getSourceActions : changed conditional boundary → NO_COVERAGE 2. getSourceActions : negated conditional → NO_COVERAGE |
if (src.dragTabIndex < 0) { |
| 124 | return TransferHandler.NONE; | |
| 125 | } | |
| 126 | | |
| 127 |
1
1. getSourceActions : removed call to com/jsql/view/swing/tab/dnd/TabTransferHandler::setDragImage → NO_COVERAGE |
this.setDragImage(this.makeDragTabImage(src)); |
| 128 |
1
1. getSourceActions : removed call to java/awt/Component::setVisible → NO_COVERAGE |
c.getRootPane().getGlassPane().setVisible(true); |
| 129 | | |
| 130 |
1
1. getSourceActions : replaced int return with 0 for com/jsql/view/swing/tab/dnd/TabTransferHandler::getSourceActions → NO_COVERAGE |
return TransferHandler.MOVE; |
| 131 | } | |
| 132 | return TransferHandler.NONE; | |
| 133 | } | |
| 134 | | |
| 135 | @Override | |
| 136 | public boolean importData(TransferHandler.TransferSupport support) { | |
| 137 |
1
1. importData : negated conditional → NO_COVERAGE |
if (!this.canImport(support)) { |
| 138 |
1
1. importData : replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler::importData → NO_COVERAGE |
return false; |
| 139 | } | |
| 140 | ||
| 141 | DnDTabbedPane target = (DnDTabbedPane) support.getComponent(); | |
| 142 | DnDTabbedPane.DnDDropLocation dl = target.getDropLocation(); | |
| 143 | | |
| 144 | try { | |
| 145 | DnDTabData data = (DnDTabData) support.getTransferable().getTransferData(this.localObjectFlavor); | |
| 146 | DnDTabbedPane src = data.tabbedPane; | |
| 147 | int index = dl.getIndex(); | |
| 148 | | |
| 149 |
1
1. importData : negated conditional → NO_COVERAGE |
if (target.equals(src)) { |
| 150 |
1
1. importData : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::convertTab → NO_COVERAGE |
src.convertTab(src.dragTabIndex, index); |
| 151 | } else { | |
| 152 |
1
1. importData : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::exportTab → NO_COVERAGE |
src.exportTab(src.dragTabIndex, target, index); |
| 153 | } | |
| 154 |
1
1. importData : replaced boolean return with false for com/jsql/view/swing/tab/dnd/TabTransferHandler::importData → NO_COVERAGE |
return true; |
| 155 | } catch (UnsupportedFlavorException | IOException e) { | |
| 156 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
| 157 | } | |
| 158 | | |
| 159 |
1
1. importData : replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler::importData → NO_COVERAGE |
return false; |
| 160 | } | |
| 161 | | |
| 162 | @Override | |
| 163 | protected void exportDone(JComponent c, Transferable data, int action) { | |
| 164 | DnDTabbedPane src = (DnDTabbedPane) c; | |
| 165 |
1
1. exportDone : removed call to java/awt/Component::setVisible → NO_COVERAGE |
src.getRootPane().getGlassPane().setVisible(false); |
| 166 |
1
1. exportDone : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::setDropLocation → NO_COVERAGE |
src.setDropLocation(null, false); |
| 167 |
1
1. exportDone : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::repaint → NO_COVERAGE |
src.repaint(); |
| 168 |
1
1. exportDone : removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::setCursor → NO_COVERAGE |
src.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
| 169 | } | |
| 170 | } | |
Mutations | ||
| 32 |
1.1 |
|
| 36 |
1.1 |
|
| 39 |
1.1 |
|
| 43 |
1.1 2.2 |
|
| 47 |
1.1 |
|
| 48 |
1.1 |
|
| 58 |
1.1 2.2 |
|
| 59 |
1.1 |
|
| 62 |
1.1 |
|
| 68 |
1.1 |
|
| 73 |
1.1 2.2 3.3 |
|
| 75 |
1.1 |
|
| 76 |
1.1 2.2 3.3 4.4 |
|
| 78 |
1.1 2.2 3.3 4.4 |
|
| 83 |
1.1 |
|
| 85 |
1.1 |
|
| 86 |
1.1 |
|
| 88 |
1.1 |
|
| 89 |
1.1 |
|
| 90 |
1.1 |
|
| 91 |
1.1 2.2 |
|
| 98 |
1.1 |
|
| 99 |
1.1 |
|
| 101 |
1.1 2.2 |
|
| 102 |
1.1 2.2 |
|
| 104 |
1.1 2.2 |
|
| 105 |
1.1 2.2 |
|
| 107 |
1.1 2.2 3.3 |
|
| 108 |
1.1 |
|
| 110 |
1.1 2.2 3.3 |
|
| 111 |
1.1 |
|
| 114 |
1.1 |
|
| 119 |
1.1 |
|
| 121 |
1.1 |
|
| 123 |
1.1 2.2 |
|
| 127 |
1.1 |
|
| 128 |
1.1 |
|
| 130 |
1.1 |
|
| 137 |
1.1 |
|
| 138 |
1.1 |
|
| 149 |
1.1 |
|
| 150 |
1.1 |
|
| 152 |
1.1 |
|
| 154 |
1.1 |
|
| 159 |
1.1 |
|
| 165 |
1.1 |
|
| 166 |
1.1 |
|
| 167 |
1.1 |
|
| 168 |
1.1 |