TabTransferHandler.java

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

Mutations

35

1.1
Location : createTransferable
Killed by : none
negated conditional → NO_COVERAGE

39

1.1
Location : createTransferable
Killed by : none
replaced return value with null for com/jsql/view/swing/tab/dnd/TabTransferHandler::createTransferable → NO_COVERAGE

42

1.1
Location : getTransferDataFlavors
Killed by : none
replaced return value with null for com/jsql/view/swing/tab/dnd/TabTransferHandler$1::getTransferDataFlavors → NO_COVERAGE

46

1.1
Location : isDataFlavorSupported
Killed by : none
replaced boolean return with false for com/jsql/view/swing/tab/dnd/TabTransferHandler$1::isDataFlavorSupported → NO_COVERAGE

2.2
Location : isDataFlavorSupported
Killed by : none
replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler$1::isDataFlavorSupported → NO_COVERAGE

50

1.1
Location : getTransferData
Killed by : none
negated conditional → NO_COVERAGE

51

1.1
Location : getTransferData
Killed by : none
replaced return value with null for com/jsql/view/swing/tab/dnd/TabTransferHandler$1::getTransferData → NO_COVERAGE

61

1.1
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

62

1.1
Location : canImport
Killed by : none
replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler::canImport → NO_COVERAGE

65

1.1
Location : canImport
Killed by : none
removed call to javax/swing/TransferHandler$TransferSupport::setDropAction → NO_COVERAGE

71

1.1
Location : canImport
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::autoScrollTest → NO_COVERAGE

76

1.1
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : canImport
Killed by : none
changed conditional boundary → NO_COVERAGE

3.3
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

78

1.1
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

79

1.1
Location : canImport
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

81

1.1
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : lambda$canImport$0
Killed by : none
replaced Boolean return with True for com/jsql/view/swing/tab/dnd/TabTransferHandler::lambda$canImport$0 → NO_COVERAGE

3.3
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

4.4
Location : lambda$canImport$0
Killed by : none
negated conditional → NO_COVERAGE

86

1.1
Location : canImport
Killed by : none
negated conditional → NO_COVERAGE

88

1.1
Location : canImport
Killed by : none
removed call to java/awt/Component::setCursor → NO_COVERAGE

89

1.1
Location : canImport
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::setCursor → NO_COVERAGE

91

1.1
Location : canImport
Killed by : none
removed call to javax/swing/TransferHandler$TransferSupport::setShowDropLocation → NO_COVERAGE

92

1.1
Location : canImport
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane$DnDDropLocation::setDroppable → NO_COVERAGE

93

1.1
Location : canImport
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::setDropLocation → NO_COVERAGE

94

1.1
Location : canImport
Killed by : none
replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler::canImport → NO_COVERAGE

2.2
Location : canImport
Killed by : none
replaced boolean return with false for com/jsql/view/swing/tab/dnd/TabTransferHandler::canImport → NO_COVERAGE

101

1.1
Location : makeDragTabImage
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::paint → NO_COVERAGE

102

1.1
Location : makeDragTabImage
Killed by : none
removed call to java/awt/Graphics::dispose → NO_COVERAGE

104

1.1
Location : makeDragTabImage
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : makeDragTabImage
Killed by : none
changed conditional boundary → NO_COVERAGE

105

1.1
Location : makeDragTabImage
Killed by : none
removed negation → NO_COVERAGE

2.2
Location : makeDragTabImage
Killed by : none
removed call to java/awt/Rectangle::translate → NO_COVERAGE

107

1.1
Location : makeDragTabImage
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : makeDragTabImage
Killed by : none
negated conditional → NO_COVERAGE

108

1.1
Location : makeDragTabImage
Killed by : none
removed call to java/awt/Rectangle::translate → NO_COVERAGE

2.2
Location : makeDragTabImage
Killed by : none
removed negation → NO_COVERAGE

110

1.1
Location : makeDragTabImage
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : makeDragTabImage
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : makeDragTabImage
Killed by : none
changed conditional boundary → NO_COVERAGE

111

1.1
Location : makeDragTabImage
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

113

1.1
Location : makeDragTabImage
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : makeDragTabImage
Killed by : none
changed conditional boundary → NO_COVERAGE

3.3
Location : makeDragTabImage
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

114

1.1
Location : makeDragTabImage
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

117

1.1
Location : makeDragTabImage
Killed by : none
replaced return value with null for com/jsql/view/swing/tab/dnd/TabTransferHandler::makeDragTabImage → NO_COVERAGE

122

1.1
Location : getSourceActions
Killed by : none
negated conditional → NO_COVERAGE

124

1.1
Location : getSourceActions
Killed by : none
removed call to javax/swing/JRootPane::setGlassPane → NO_COVERAGE

126

1.1
Location : getSourceActions
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : getSourceActions
Killed by : none
negated conditional → NO_COVERAGE

130

1.1
Location : getSourceActions
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/TabTransferHandler::setDragImage → NO_COVERAGE

131

1.1
Location : getSourceActions
Killed by : none
removed call to java/awt/Component::setVisible → NO_COVERAGE

133

1.1
Location : getSourceActions
Killed by : none
replaced int return with 0 for com/jsql/view/swing/tab/dnd/TabTransferHandler::getSourceActions → NO_COVERAGE

140

1.1
Location : importData
Killed by : none
negated conditional → NO_COVERAGE

141

1.1
Location : importData
Killed by : none
replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler::importData → NO_COVERAGE

152

1.1
Location : importData
Killed by : none
negated conditional → NO_COVERAGE

153

1.1
Location : importData
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::convertTab → NO_COVERAGE

155

1.1
Location : importData
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::exportTab → NO_COVERAGE

157

1.1
Location : importData
Killed by : none
replaced boolean return with false for com/jsql/view/swing/tab/dnd/TabTransferHandler::importData → NO_COVERAGE

162

1.1
Location : importData
Killed by : none
replaced boolean return with true for com/jsql/view/swing/tab/dnd/TabTransferHandler::importData → NO_COVERAGE

168

1.1
Location : exportDone
Killed by : none
removed call to java/awt/Component::setVisible → NO_COVERAGE

169

1.1
Location : exportDone
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::setDropLocation → NO_COVERAGE

170

1.1
Location : exportDone
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::repaint → NO_COVERAGE

171

1.1
Location : exportDone
Killed by : none
removed call to com/jsql/view/swing/tab/dnd/DnDTabbedPane::setCursor → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.19.1