1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.corrector;
|
---|
3 |
|
---|
4 | import java.awt.Dimension;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import javax.swing.JTable;
|
---|
8 | import javax.swing.JLabel;
|
---|
9 | import javax.swing.table.TableCellRenderer;
|
---|
10 | import java.awt.Component;
|
---|
11 | import java.awt.Font;
|
---|
12 |
|
---|
13 | public class TagCorrectionTable extends JTable {
|
---|
14 |
|
---|
15 | public class BoldRenderer extends JLabel implements TableCellRenderer {
|
---|
16 |
|
---|
17 | public Component getTableCellRendererComponent(JTable table,
|
---|
18 | Object value, boolean isSelected, boolean hasFocus, int row,
|
---|
19 | int column) {
|
---|
20 |
|
---|
21 | Font f = getFont();
|
---|
22 | setFont(new Font(f.getName(), f.getStyle() | Font.BOLD, f.getSize()));
|
---|
23 |
|
---|
24 | setText((String)value);
|
---|
25 |
|
---|
26 | return this;
|
---|
27 | }
|
---|
28 | }
|
---|
29 |
|
---|
30 | private static TableCellRenderer boldRenderer = null;
|
---|
31 |
|
---|
32 | private static TagCorrectionTableModel tagCorrectionTableModel;
|
---|
33 |
|
---|
34 | public static TagCorrectionTable create(List<TagCorrection> tagCorrections) {
|
---|
35 |
|
---|
36 | tagCorrectionTableModel = new TagCorrectionTableModel(tagCorrections);
|
---|
37 | TagCorrectionTable table = new TagCorrectionTable(
|
---|
38 | tagCorrectionTableModel);
|
---|
39 | int lines = tagCorrections.size() > 10 ? 10 : tagCorrections.size();
|
---|
40 | table.setPreferredScrollableViewportSize(new Dimension(400, lines * table.getRowHeight()));
|
---|
41 | table.getColumnModel().getColumn(4).setPreferredWidth(40);
|
---|
42 | table.setRowSelectionAllowed(false);
|
---|
43 |
|
---|
44 | return table;
|
---|
45 | }
|
---|
46 |
|
---|
47 | public TableCellRenderer getCellRenderer(int row, int column) {
|
---|
48 | TagCorrection tagCorrection = tagCorrectionTableModel.tagCorrections
|
---|
49 | .get(row);
|
---|
50 | if ((column == 2 && tagCorrection.isKeyChanged())
|
---|
51 | || (column == 3 && tagCorrection.isValueChanged())) {
|
---|
52 | if (boldRenderer == null)
|
---|
53 | boldRenderer = new BoldRenderer();
|
---|
54 | return boldRenderer;
|
---|
55 | }
|
---|
56 | return super.getCellRenderer(row, column);
|
---|
57 | }
|
---|
58 |
|
---|
59 | private TagCorrectionTable(TagCorrectionTableModel tagCorrectionTableModel) {
|
---|
60 | super(tagCorrectionTableModel);
|
---|
61 | }
|
---|
62 |
|
---|
63 | public TagCorrectionTableModel getTagCorrectionTableModel() {
|
---|
64 | return tagCorrectionTableModel;
|
---|
65 | }
|
---|
66 |
|
---|
67 | }
|
---|