1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2020. | |
3 | * This program and the accompanying materials | |
4 | * are made available under no term at all, use it like | |
5 | * you want, but share and discuss about it | |
6 | * every time possible with every body. | |
7 | * | |
8 | * Contributors: | |
9 | * ron190 at ymail dot com - initial implementation | |
10 | ******************************************************************************/ | |
11 | package com.jsql.view.swing.list; | |
12 | ||
13 | import com.jsql.view.swing.util.UiUtil; | |
14 | ||
15 | import javax.swing.*; | |
16 | import javax.swing.border.AbstractBorder; | |
17 | import java.awt.*; | |
18 | ||
19 | /** | |
20 | * Item renderer for JList. | |
21 | */ | |
22 | public class RendererComplexCell implements ListCellRenderer<ItemList> { | |
23 | | |
24 | /** | |
25 | * List component renderer. | |
26 | */ | |
27 | private static final DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer(); | |
28 | ||
29 | @Override | |
30 | public Component getListCellRendererComponent( | |
31 | JList<? extends ItemList> list, | |
32 | ItemList value, | |
33 | int index, | |
34 | boolean isSelected, | |
35 | boolean isFocused | |
36 | ) { | |
37 | | |
38 | JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, isFocused); | |
39 | ||
40 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setFont → NO_COVERAGE |
renderer.setFont(UiUtil.FONT_NON_MONO); |
41 | ||
42 | // setBackground | |
43 |
1
1. getListCellRendererComponent : negated conditional → NO_COVERAGE |
if (isSelected) { |
44 |
1
1. getListCellRendererComponent : negated conditional → NO_COVERAGE |
if (list.isFocusOwner()) { |
45 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setBackground → NO_COVERAGE |
renderer.setBackground(UiUtil.COLOR_FOCUS_GAINED); |
46 | } else { | |
47 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setBackground → NO_COVERAGE |
renderer.setBackground(UiUtil.COLOR_FOCUS_LOST); |
48 | } | |
49 | } else { | |
50 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setBackground → NO_COVERAGE |
renderer.setBackground(Color.WHITE); |
51 | } | |
52 | | |
53 | // setForeground | |
54 |
1
1. getListCellRendererComponent : negated conditional → NO_COVERAGE |
if (value.getIsVulnerable()) { |
55 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setForeground → NO_COVERAGE |
renderer.setForeground(UiUtil.COLOR_GREEN); |
56 |
1
1. getListCellRendererComponent : negated conditional → NO_COVERAGE |
} else if (value.getIsDatabaseConfirmed()) { |
57 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setForeground → NO_COVERAGE |
renderer.setForeground(Color.BLUE); |
58 | } else { | |
59 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setForeground → NO_COVERAGE |
renderer.setForeground(Color.BLACK); // Hardcode black for Mac default is white |
60 | } | |
61 | ||
62 | // setBorder | |
63 |
1
1. getListCellRendererComponent : negated conditional → NO_COVERAGE |
if (isSelected) { |
64 |
1
1. getListCellRendererComponent : negated conditional → NO_COVERAGE |
if (list.isFocusOwner()) { |
65 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
renderer.setBorder(UiUtil.BORDER_FOCUS_GAINED); |
66 | } else { | |
67 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
renderer.setBorder(UiUtil.BORDER_FOCUS_LOST); |
68 | } | |
69 |
1
1. getListCellRendererComponent : negated conditional → NO_COVERAGE |
} else if (isFocused) { |
70 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
renderer.setBorder(BorderFactory.createCompoundBorder(new BorderList(), BorderFactory.createEmptyBorder(0, 1, 0, 0))); |
71 | } else { | |
72 |
1
1. getListCellRendererComponent : removed call to javax/swing/JLabel::setBorder → NO_COVERAGE |
renderer.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); |
73 | } | |
74 | ||
75 |
1
1. getListCellRendererComponent : replaced return value with null for com/jsql/view/swing/list/RendererComplexCell::getListCellRendererComponent → NO_COVERAGE |
return renderer; |
76 | } | |
77 | | |
78 | private static class BorderList extends AbstractBorder { | |
79 | | |
80 | @Override | |
81 | public void paintBorder(Component comp, Graphics g, int x, int y, int w, int h) { | |
82 | | |
83 | Graphics2D g2D = (Graphics2D) g; | |
84 |
1
1. paintBorder : removed call to java/awt/Graphics2D::setColor → NO_COVERAGE |
g2D.setColor(Color.GRAY); |
85 |
1
1. paintBorder : removed call to java/awt/Graphics2D::setStroke → NO_COVERAGE |
g2D.setStroke( |
86 | new BasicStroke( | |
87 | 1, | |
88 | BasicStroke.CAP_BUTT, | |
89 | BasicStroke.JOIN_BEVEL, | |
90 | 0, | |
91 | new float[]{1}, | |
92 | 0 | |
93 | ) | |
94 | ); | |
95 |
3
1. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE 2. paintBorder : Replaced integer subtraction with addition → NO_COVERAGE 3. paintBorder : removed call to java/awt/Graphics2D::drawRect → NO_COVERAGE |
g2D.drawRect(x, y, w - 1, h - 1); |
96 | } | |
97 | } | |
98 | } | |
Mutations | ||
40 |
1.1 |
|
43 |
1.1 |
|
44 |
1.1 |
|
45 |
1.1 |
|
47 |
1.1 |
|
50 |
1.1 |
|
54 |
1.1 |
|
55 |
1.1 |
|
56 |
1.1 |
|
57 |
1.1 |
|
59 |
1.1 |
|
63 |
1.1 |
|
64 |
1.1 |
|
65 |
1.1 |
|
67 |
1.1 |
|
69 |
1.1 |
|
70 |
1.1 |
|
72 |
1.1 |
|
75 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
95 |
1.1 2.2 3.3 |