| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.fest.swing.format; |
| 17 |
|
|
| 18 |
|
import static org.fest.swing.edt.GuiActionRunner.execute; |
| 19 |
|
import static org.fest.util.Strings.*; |
| 20 |
|
|
| 21 |
|
import java.awt.*; |
| 22 |
|
import java.util.concurrent.ConcurrentHashMap; |
| 23 |
|
import java.util.concurrent.ConcurrentMap; |
| 24 |
|
import java.util.logging.Logger; |
| 25 |
|
|
| 26 |
|
import javax.swing.*; |
| 27 |
|
import javax.swing.text.JTextComponent; |
| 28 |
|
|
| 29 |
|
import org.fest.swing.annotation.RunsInCurrentThread; |
| 30 |
|
import org.fest.swing.annotation.RunsInEDT; |
| 31 |
|
import org.fest.swing.edt.GuiQuery; |
| 32 |
|
import org.fest.util.VisibleForTesting; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@author |
| 38 |
|
@author |
| 39 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (73) |
Complexity: 16 |
Complexity Density: 0.31 |
|
| 40 |
|
public class Formatting { |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
private static final String MAXIMUM = "maximum"; |
| 44 |
|
|
| 45 |
|
private static final String MINIMUM = "minimum"; |
| 46 |
|
|
| 47 |
|
private static final String NULL_COMPONENT_MESSAGE = "Null Component"; |
| 48 |
|
|
| 49 |
|
private static final String ENABLED = "enabled"; |
| 50 |
|
private static final String NAME = "name"; |
| 51 |
|
private static final String SHOWING = "showing"; |
| 52 |
|
private static final String TEXT = "text"; |
| 53 |
|
private static final String TITLE = "title"; |
| 54 |
|
private static final String VALUE = "value"; |
| 55 |
|
private static final String VISIBLE = "visible"; |
| 56 |
|
|
| 57 |
|
private static final ConcurrentMap<Class<?>, ComponentFormatter> FORMATTERS = new ConcurrentHashMap<Class<?>, ComponentFormatter>(); |
| 58 |
|
|
| 59 |
|
private static Logger logger = Logger.getLogger(Formatting.class.getName()); |
| 60 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
|
| 61 |
322
|
static {... |
| 62 |
322
|
register(instrospect(AbstractButton.class, NAME, TEXT, "selected", ENABLED, VISIBLE, SHOWING)); |
| 63 |
322
|
register(instrospect(Dialog.class, NAME, TITLE, ENABLED, "modal", VISIBLE, SHOWING)); |
| 64 |
322
|
register(instrospect(Frame.class, NAME, TITLE, ENABLED, VISIBLE, SHOWING)); |
| 65 |
322
|
register(new JComboBoxFormatter()); |
| 66 |
322
|
register(instrospect(JButton.class, NAME, TEXT, ENABLED, VISIBLE, SHOWING)); |
| 67 |
322
|
register(new JFileChooserFormatter()); |
| 68 |
322
|
register(instrospect(JLabel.class, NAME, TEXT, ENABLED, VISIBLE, SHOWING)); |
| 69 |
322
|
register(empty(JLayeredPane.class)); |
| 70 |
322
|
register(new JListFormatter()); |
| 71 |
322
|
register(empty(JMenuBar.class)); |
| 72 |
322
|
register(new JOptionPaneFormatter()); |
| 73 |
322
|
register(nameOnly(JPanel.class)); |
| 74 |
322
|
register(instrospect(JPopupMenu.class, NAME, "label", ENABLED, VISIBLE, SHOWING)); |
| 75 |
322
|
register(instrospect(JProgressBar.class, NAME, VALUE, MINIMUM, MAXIMUM, "string", "stringPainted", ENABLED, VISIBLE, SHOWING)); |
| 76 |
322
|
register(empty(JRootPane.class)); |
| 77 |
322
|
register(instrospect(JScrollBar.class, NAME, VALUE, "blockIncrement", MINIMUM, MAXIMUM, ENABLED, VISIBLE, SHOWING)); |
| 78 |
322
|
register(instrospect(JScrollPane.class, NAME, ENABLED, VISIBLE, SHOWING)); |
| 79 |
322
|
register(instrospect(JSlider.class, NAME, VALUE, MINIMUM, MAXIMUM, ENABLED, VISIBLE, SHOWING)); |
| 80 |
322
|
register(instrospect(JSpinner.class, NAME, VALUE, ENABLED, VISIBLE, SHOWING)); |
| 81 |
322
|
register(new JTabbedPaneFormatter()); |
| 82 |
322
|
register(new JTableFormatter()); |
| 83 |
322
|
register(nameOnly(JToolBar.class)); |
| 84 |
322
|
register(instrospect(JPasswordField.class, NAME, ENABLED, VISIBLE, SHOWING)); |
| 85 |
322
|
register(instrospect(JTextComponent.class, NAME, TEXT, ENABLED, VISIBLE, SHOWING)); |
| 86 |
322
|
register(new JTreeFormatter()); |
| 87 |
|
} |
| 88 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 89 |
4186
|
private static ComponentFormatter instrospect(Class<? extends Component> targetType, String...propertyNames) {... |
| 90 |
4186
|
return new IntrospectionComponentFormatter(targetType, propertyNames); |
| 91 |
|
} |
| 92 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 93 |
966
|
private static ComponentFormatter empty(Class<? extends Component> targetType) {... |
| 94 |
966
|
return new IntrospectionComponentFormatter(targetType); |
| 95 |
|
} |
| 96 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 97 |
644
|
private static ComponentFormatter nameOnly(Class<? extends Component> targetType) {... |
| 98 |
644
|
return new IntrospectionComponentFormatter(targetType, NAME); |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
|
| 102 |
|
|
| 103 |
|
@param |
| 104 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 105 |
8052
|
public static void register(ComponentFormatter formatter) {... |
| 106 |
8052
|
Class<?> key = formatter.targetType(); |
| 107 |
8052
|
ComponentFormatter previous = FORMATTERS.put(key, formatter); |
| 108 |
8052
|
if (previous != null) |
| 109 |
2
|
logger.info( |
| 110 |
|
concat("Replaced formatter ", previous, " with ", formatter, " for the type ", key.getName())); |
| 111 |
|
} |
| 112 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 113 |
9
|
@VisibleForTesting... |
| 114 |
|
static ComponentFormatter formatter(Class<?> type) { |
| 115 |
9
|
return FORMATTERS.get(type); |
| 116 |
|
} |
| 117 |
|
|
| 118 |
|
|
| 119 |
|
@link |
| 120 |
|
|
| 121 |
|
@param |
| 122 |
|
@return |
| 123 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 124 |
1
|
@RunsInEDT... |
| 125 |
|
public static String inEdtFormat(final Component c) { |
| 126 |
1
|
return execute(new GuiQuery<String>() { |
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 127 |
1
|
protected String executeInEDT() {... |
| 128 |
1
|
return format(c); |
| 129 |
|
} |
| 130 |
|
}); |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
|
| 134 |
|
@link |
| 135 |
|
|
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
@param |
| 140 |
|
@return |
| 141 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
| 142 |
43680
|
@RunsInCurrentThread... |
| 143 |
|
public static String format(Component c) { |
| 144 |
2
|
if (c == null) return NULL_COMPONENT_MESSAGE; |
| 145 |
43678
|
ComponentFormatter formatter = formatterFor(c.getClass()); |
| 146 |
41059
|
if (formatter != null) return formatter.format(c); |
| 147 |
2619
|
String name = c.getName(); |
| 148 |
2612
|
if (isEmpty(name)) return c.toString(); |
| 149 |
7
|
return concat(c.getClass().getName(), "[name=", quote(name), "]"); |
| 150 |
|
} |
| 151 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 152 |
71126
|
private static ComponentFormatter formatterFor(Class<?> type) {... |
| 153 |
71126
|
ComponentFormatter formatter = FORMATTERS.get(type); |
| 154 |
41059
|
if (formatter != null) return formatter; |
| 155 |
30067
|
Class<?> superType = type.getSuperclass(); |
| 156 |
27448
|
if (superType != null) return formatterFor(superType); |
| 157 |
2619
|
return null; |
| 158 |
|
} |
| 159 |
|
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
| 160 |
|
private Formatting() {}... |
| 161 |
|
} |