1 | package com.jsql.view.swing.splitpane; | |
2 | /* | |
3 | * Copyright (c) 2011 Karl Tauber <karl at jformdesigner dot com> | |
4 | * All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * o Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
13 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
14 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
15 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
16 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
17 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
18 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
22 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
23 | */ | |
24 | ||
25 | import com.jsql.util.LogLevelUtil; | |
26 | import com.jsql.view.swing.util.UiUtil; | |
27 | import org.apache.logging.log4j.LogManager; | |
28 | import org.apache.logging.log4j.Logger; | |
29 | ||
30 | import javax.swing.*; | |
31 | import javax.swing.border.Border; | |
32 | import javax.swing.plaf.basic.BasicSplitPaneDivider; | |
33 | import javax.swing.plaf.basic.BasicSplitPaneUI; | |
34 | import java.awt.*; | |
35 | ||
36 | /** | |
37 | * A JSplitPane that uses a 1 pixel thin visible divider, | |
38 | * but a 9 pixel wide transparent drag area. | |
39 | */ | |
40 | public class JSplitPaneWithZeroSizeDivider extends JSplitPane { | |
41 | | |
42 | /** | |
43 | * Log4j logger sent to view. | |
44 | */ | |
45 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
46 | | |
47 | /** | |
48 | * The size of the transparent drag area. | |
49 | */ | |
50 | private int dividerDragSize = 9; | |
51 | | |
52 | /** | |
53 | * The offset of the transparent drag area relative to the visible divider line. | |
54 | * Positive offset moves the drag area left/top to the divider line. | |
55 | * If zero then the drag area is right/bottom of the divider line. | |
56 | * Useful values are in the range 0 to {@link #dividerDragSize}. | |
57 | * Default is centered. | |
58 | */ | |
59 | private int dividerDragOffset = 0; | |
60 | | |
61 | public JSplitPaneWithZeroSizeDivider(int orientation) { | |
62 | super(orientation, true); | |
63 | } | |
64 | | |
65 | public void disableDragSize() { | |
66 | this.dividerDragSize = 0; | |
67 | } | |
68 | | |
69 | public void enableDragSize() { | |
70 | this.dividerDragSize = 9; | |
71 | } | |
72 | ||
73 | public int getDividerDragSize() { | |
74 |
1
1. getDividerDragSize : replaced int return with 0 for com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::getDividerDragSize → NO_COVERAGE |
return this.dividerDragSize; |
75 | } | |
76 | ||
77 | public void setDividerDragSize(int dividerDragSize) { | |
78 | | |
79 | this.dividerDragSize = dividerDragSize; | |
80 |
1
1. setDividerDragSize : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::revalidate → NO_COVERAGE |
this.revalidate(); |
81 | } | |
82 | ||
83 | public int getDividerDragOffset() { | |
84 |
1
1. getDividerDragOffset : replaced int return with 0 for com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::getDividerDragOffset → NO_COVERAGE |
return this.dividerDragOffset; |
85 | } | |
86 | ||
87 | public void setDividerDragOffset(int dividerDragOffset) { | |
88 | | |
89 | this.dividerDragOffset = dividerDragOffset; | |
90 |
1
1. setDividerDragOffset : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::revalidate → NO_COVERAGE |
this.revalidate(); |
91 | } | |
92 | ||
93 | @Override | |
94 | public void doLayout() { | |
95 | | |
96 |
1
1. doLayout : removed call to javax/swing/JSplitPane::doLayout → NO_COVERAGE |
super.doLayout(); |
97 | ||
98 | // increase divider width or height | |
99 | BasicSplitPaneDivider divider = ((BasicSplitPaneUI) this.getUI()).getDivider(); | |
100 | Rectangle bounds = divider.getBounds(); | |
101 | | |
102 |
1
1. doLayout : negated conditional → NO_COVERAGE |
if (this.orientation == HORIZONTAL_SPLIT) { |
103 | | |
104 |
1
1. doLayout : Replaced integer subtraction with addition → NO_COVERAGE |
bounds.x -= this.dividerDragOffset; |
105 | bounds.width = this.dividerDragSize; | |
106 | | |
107 | } else { | |
108 | | |
109 |
1
1. doLayout : Replaced integer subtraction with addition → NO_COVERAGE |
bounds.y -= this.dividerDragOffset; |
110 | bounds.height = this.dividerDragSize; | |
111 | } | |
112 | | |
113 |
1
1. doLayout : removed call to javax/swing/plaf/basic/BasicSplitPaneDivider::setBounds → NO_COVERAGE |
divider.setBounds(bounds); |
114 | } | |
115 | ||
116 | @Override | |
117 | public void updateUI() { | |
118 | | |
119 |
1
1. updateUI : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::setUI → NO_COVERAGE |
this.setUI(new SplitPaneWithZeroSizeDividerUI()); |
120 |
1
1. updateUI : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider::revalidate → NO_COVERAGE |
this.revalidate(); |
121 | } | |
122 | ||
123 | private class SplitPaneWithZeroSizeDividerUI extends BasicSplitPaneUI { | |
124 | @Override | |
125 | public BasicSplitPaneDivider createDefaultDivider() { | |
126 |
1
1. createDefaultDivider : replaced return value with null for com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider$SplitPaneWithZeroSizeDividerUI::createDefaultDivider → NO_COVERAGE |
return new ZeroSizeDivider(this); |
127 | } | |
128 | } | |
129 | ||
130 | private class ZeroSizeDivider extends BasicSplitPaneDivider { | |
131 | | |
132 | public ZeroSizeDivider(BasicSplitPaneUI ui) { | |
133 | super(ui); | |
134 |
1
1. <init> : removed call to javax/swing/plaf/basic/BasicSplitPaneDivider::setBorder → NO_COVERAGE |
super.setBorder(null); |
135 |
1
1. <init> : removed call to com/jsql/view/swing/splitpane/JSplitPaneWithZeroSizeDivider$ZeroSizeDivider::setBackground → NO_COVERAGE |
this.setBackground(UiUtil.COLOR_COMPONENT_BORDER); |
136 | } | |
137 | ||
138 | @Override | |
139 | public void setBorder(Border border) { | |
140 | // ignore | |
141 | } | |
142 | ||
143 | @Override | |
144 | public void paint(Graphics g) { | |
145 | | |
146 |
1
1. paint : removed call to java/awt/Graphics::setColor → NO_COVERAGE |
g.setColor(this.getBackground()); |
147 | | |
148 |
1
1. paint : negated conditional → NO_COVERAGE |
if (this.orientation == HORIZONTAL_SPLIT) { |
149 | // Fix #38925: ClassCastException on drawLine() | |
150 | try { | |
151 |
1
1. paint : removed call to java/awt/Graphics::drawLine → NO_COVERAGE |
g.drawLine( |
152 | JSplitPaneWithZeroSizeDivider.this.dividerDragOffset, | |
153 | 0, | |
154 | JSplitPaneWithZeroSizeDivider.this.dividerDragOffset, | |
155 |
1
1. paint : Replaced integer subtraction with addition → NO_COVERAGE |
this.getHeight() - 1 |
156 | ); | |
157 | } catch (ClassCastException e) { | |
158 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
159 | } | |
160 | } else { | |
161 |
1
1. paint : removed call to java/awt/Graphics::drawLine → NO_COVERAGE |
g.drawLine( |
162 | 0, | |
163 | JSplitPaneWithZeroSizeDivider.this.dividerDragOffset, | |
164 |
1
1. paint : Replaced integer subtraction with addition → NO_COVERAGE |
this.getWidth() - 1, |
165 | JSplitPaneWithZeroSizeDivider.this.dividerDragOffset | |
166 | ); | |
167 | } | |
168 | } | |
169 | ||
170 | @Override | |
171 | protected void dragDividerTo(int location) { | |
172 |
2
1. dragDividerTo : removed call to javax/swing/plaf/basic/BasicSplitPaneDivider::dragDividerTo → NO_COVERAGE 2. dragDividerTo : Replaced integer addition with subtraction → NO_COVERAGE |
super.dragDividerTo(location + JSplitPaneWithZeroSizeDivider.this.dividerDragOffset); |
173 | } | |
174 | ||
175 | @Override | |
176 | protected void finishDraggingTo(int location) { | |
177 |
2
1. finishDraggingTo : removed call to javax/swing/plaf/basic/BasicSplitPaneDivider::finishDraggingTo → NO_COVERAGE 2. finishDraggingTo : Replaced integer addition with subtraction → NO_COVERAGE |
super.finishDraggingTo(location + JSplitPaneWithZeroSizeDivider.this.dividerDragOffset); |
178 | } | |
179 | } | |
180 | } | |
Mutations | ||
74 |
1.1 |
|
80 |
1.1 |
|
84 |
1.1 |
|
90 |
1.1 |
|
96 |
1.1 |
|
102 |
1.1 |
|
104 |
1.1 |
|
109 |
1.1 |
|
113 |
1.1 |
|
119 |
1.1 |
|
120 |
1.1 |
|
126 |
1.1 |
|
134 |
1.1 |
|
135 |
1.1 |
|
146 |
1.1 |
|
148 |
1.1 |
|
151 |
1.1 |
|
155 |
1.1 |
|
161 |
1.1 |
|
164 |
1.1 |
|
172 |
1.1 2.2 |
|
177 |
1.1 2.2 |