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

Mutations

39

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

43

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

47

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

52

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

57

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

58

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

69

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

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

70

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

73

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

79

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

84

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

86

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

87

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

89

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

94

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

96

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

97

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

99

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

100

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

101

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

102

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

110

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

111

1.1
Location : makeDragTabImage
Killed by : none
removed call to java/awt/Graphics::dispose → 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

114

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

117

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

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

118

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

121

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

122

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

125

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

126

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

129

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

135

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

138

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

140

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

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

144

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

145

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

147

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

156

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

157

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 : importData
Killed by : none
negated conditional → NO_COVERAGE

169

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

171

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

174

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

180

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

188

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

189

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

190

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

191

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.16.1