source: josm/trunk/src/org/openstreetmap/josm/corrector/TagCorrectionTable.java@ 729

Last change on this file since 729 was 729, checked in by stoecker, 16 years ago

added automatic tag correction system by Robin Rattay

File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.corrector;
3
4import java.awt.Dimension;
5import java.util.List;
6
7import javax.swing.JTable;
8import javax.swing.JLabel;
9import javax.swing.table.TableCellRenderer;
10import java.awt.Component;
11import java.awt.Font;
12
13public 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}
Note: See TracBrowser for help on using the repository browser.