source: josm/trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java @ 14675

Last change on this file since 14675 was 14675, checked in by simon04, 6 weeks ago

HistoryViewer: fix code duplication

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import java.awt.Rectangle;
5
6import javax.swing.JTable;
7import javax.swing.ListSelectionModel;
8import javax.swing.event.TableModelEvent;
9import javax.swing.event.TableModelListener;
10
11/**
12 * RelationMemberListViewer is a UI component which displays the  list of relation members of two
13 * version of a {@link org.openstreetmap.josm.data.osm.Relation} in a {@link org.openstreetmap.josm.data.osm.history.History}.
14 *
15 * <ul>
16 *   <li>on the left, it displays the list of relation members for the version at {@link PointInTimeType#REFERENCE_POINT_IN_TIME}</li>
17 *   <li>on the right, it displays the list of relation members for the version at {@link PointInTimeType#CURRENT_POINT_IN_TIME}</li>
18 * </ul>
19 * @since 1709
20 */
21public class RelationMemberListViewer extends HistoryViewerPanel {
22
23    protected static class MemberModelChanged implements TableModelListener {
24        private final JTable table;
25
26        protected MemberModelChanged(JTable table) {
27            this.table = table;
28        }
29
30        @Override
31        public void tableChanged(TableModelEvent e) {
32            Rectangle rect = table.getCellRect(((DiffTableModel) e.getSource()).getFirstChange(), 0, true);
33            table.scrollRectToVisible(rect);
34        }
35    }
36
37    @Override
38    protected JTable buildReferenceTable() {
39        return buildTable(PointInTimeType.REFERENCE_POINT_IN_TIME, "table.referencememberlisttable");
40    }
41
42    @Override
43    protected JTable buildCurrentTable() {
44        return buildTable(PointInTimeType.CURRENT_POINT_IN_TIME, "table.currentmemberlisttable");
45    }
46
47    private JTable buildTable(PointInTimeType pointInTimeType, String name) {
48        JTable table = new JTable(
49                model.getRelationMemberTableModel(pointInTimeType),
50                new RelationMemberTableColumnModel());
51        table.setName(name);
52        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
53        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
54        table.getModel().addTableModelListener(new MemberModelChanged(table));
55        return table;
56    }
57
58    /**
59     * Constructs a new {@code RelationMemberListViewer}.
60     * @param model The history browsing model
61     */
62    public RelationMemberListViewer(HistoryBrowserModel model) {
63        super(model);
64    }
65}
Note: See TracBrowser for help on using the repository browser.