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

Last change on this file since 14463 was 14463, checked in by Don-vip, 3 months ago

fix #17040 - fix memory leaks when calling history dialog

  • Property svn:eol-style set to native
File size: 2.6 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        JTable table = new JTable(
40                model.getRelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME),
41                new RelationMemberTableColumnModel()
42                );
43        table.setName("table.referencememberlisttable");
44        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
45        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
46        table.getModel().addTableModelListener(new MemberModelChanged(table));
47        return table;
48    }
49
50    @Override
51    protected JTable buildCurrentTable() {
52        JTable table = new JTable(
53                model.getRelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME),
54                new RelationMemberTableColumnModel()
55                );
56        table.setName("table.currentmemberlisttable");
57        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
58        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
59        table.getModel().addTableModelListener(new MemberModelChanged(table));
60        return table;
61    }
62
63    /**
64     * Constructs a new {@code RelationMemberListViewer}.
65     * @param model The history browsing model
66     */
67    public RelationMemberListViewer(HistoryBrowserModel model) {
68        super(model);
69    }
70}
Note: See TracBrowser for help on using the repository browser.