1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.history;
|
---|
3 |
|
---|
4 | import java.awt.GridBagConstraints;
|
---|
5 | import java.awt.GridBagLayout;
|
---|
6 | import java.awt.Insets;
|
---|
7 |
|
---|
8 | import javax.swing.JPanel;
|
---|
9 | import javax.swing.JScrollPane;
|
---|
10 | import javax.swing.JTable;
|
---|
11 | import javax.swing.ListSelectionModel;
|
---|
12 | /**
|
---|
13 | * RelationMemberListViewer is a UI component which displays the list of relation members of two
|
---|
14 | * version of a {@see Relation} in a {@see History}.
|
---|
15 | *
|
---|
16 | * <ul>
|
---|
17 | * <li>on the left, it displays the list of relation members for the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME}</li>
|
---|
18 | * <li>on the right, it displays the list of relation members for the version at {@see PointInTimeType#CURRENT_POINT_IN_TIME}</li>
|
---|
19 | * </ul>
|
---|
20 | *
|
---|
21 | */
|
---|
22 |
|
---|
23 | public class RelationMemberListViewer extends JPanel{
|
---|
24 |
|
---|
25 | private HistoryBrowserModel model;
|
---|
26 | private VersionInfoPanel referenceInfoPanel;
|
---|
27 | private VersionInfoPanel currentInfoPanel;
|
---|
28 | private AdjustmentSynchronizer adjustmentSynchronizer;
|
---|
29 | private SelectionSynchronizer selectionSynchronizer;
|
---|
30 |
|
---|
31 | protected JScrollPane embeddInScrollPane(JTable table) {
|
---|
32 | JScrollPane pane = new JScrollPane(table);
|
---|
33 | pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
34 | pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
---|
35 | adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar());
|
---|
36 | return pane;
|
---|
37 | }
|
---|
38 |
|
---|
39 | protected JTable buildReferenceMemberListTable() {
|
---|
40 | JTable table = new JTable(
|
---|
41 | model.getRelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME),
|
---|
42 | new RelationMemberTableColumnModel()
|
---|
43 | );
|
---|
44 | table.setName("table.referencememberlisttable");
|
---|
45 | table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
46 | selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
|
---|
47 | return table;
|
---|
48 | }
|
---|
49 |
|
---|
50 | protected JTable buildCurrentMemberListTable() {
|
---|
51 | JTable table = new JTable(
|
---|
52 | model.getRelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME),
|
---|
53 | new RelationMemberTableColumnModel()
|
---|
54 | );
|
---|
55 | table.setName("table.currentmemberlisttable");
|
---|
56 | table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
57 | selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
|
---|
58 | return table;
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected void build() {
|
---|
62 | setLayout(new GridBagLayout());
|
---|
63 | GridBagConstraints gc = new GridBagConstraints();
|
---|
64 |
|
---|
65 | // ---------------------------
|
---|
66 | gc.gridx = 0;
|
---|
67 | gc.gridy = 0;
|
---|
68 | gc.gridwidth = 1;
|
---|
69 | gc.gridheight = 1;
|
---|
70 | gc.weightx = 0.5;
|
---|
71 | gc.weighty = 0.0;
|
---|
72 | gc.insets = new Insets(5,5,5,0);
|
---|
73 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
74 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
75 | referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
|
---|
76 | add(referenceInfoPanel,gc);
|
---|
77 |
|
---|
78 | gc.gridx = 1;
|
---|
79 | gc.gridy = 0;
|
---|
80 | gc.gridwidth = 1;
|
---|
81 | gc.gridheight = 1;
|
---|
82 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
83 | gc.weightx = 0.5;
|
---|
84 | gc.weighty = 0.0;
|
---|
85 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
86 | currentInfoPanel = new VersionInfoPanel(model, PointInTimeType.CURRENT_POINT_IN_TIME);
|
---|
87 | add(currentInfoPanel,gc);
|
---|
88 |
|
---|
89 | adjustmentSynchronizer = new AdjustmentSynchronizer();
|
---|
90 | selectionSynchronizer = new SelectionSynchronizer();
|
---|
91 |
|
---|
92 | // ---------------------------
|
---|
93 | gc.gridx = 0;
|
---|
94 | gc.gridy = 1;
|
---|
95 | gc.gridwidth = 1;
|
---|
96 | gc.gridheight = 1;
|
---|
97 | gc.weightx = 0.5;
|
---|
98 | gc.weighty = 1.0;
|
---|
99 | gc.fill = GridBagConstraints.BOTH;
|
---|
100 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
101 | add(embeddInScrollPane(buildReferenceMemberListTable()),gc);
|
---|
102 |
|
---|
103 | gc.gridx = 1;
|
---|
104 | gc.gridy = 1;
|
---|
105 | gc.gridwidth = 1;
|
---|
106 | gc.gridheight = 1;
|
---|
107 | gc.weightx = 0.5;
|
---|
108 | gc.weighty = 1.0;
|
---|
109 | gc.fill = GridBagConstraints.BOTH;
|
---|
110 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
111 | add(embeddInScrollPane(buildCurrentMemberListTable()),gc);
|
---|
112 | }
|
---|
113 |
|
---|
114 | public RelationMemberListViewer(HistoryBrowserModel model) {
|
---|
115 | setModel(model);
|
---|
116 | build();
|
---|
117 | }
|
---|
118 |
|
---|
119 | protected void unregisterAsObserver(HistoryBrowserModel model) {
|
---|
120 | if (currentInfoPanel != null) {
|
---|
121 | model.deleteObserver(currentInfoPanel);
|
---|
122 | }
|
---|
123 | if (referenceInfoPanel != null) {
|
---|
124 | model.deleteObserver(referenceInfoPanel);
|
---|
125 | }
|
---|
126 | }
|
---|
127 | protected void registerAsObserver(HistoryBrowserModel model) {
|
---|
128 | if (currentInfoPanel != null) {
|
---|
129 | model.addObserver(currentInfoPanel);
|
---|
130 | }
|
---|
131 | if (referenceInfoPanel != null) {
|
---|
132 | model.addObserver(referenceInfoPanel);
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | public void setModel(HistoryBrowserModel model) {
|
---|
137 | if (this.model != null) {
|
---|
138 | unregisterAsObserver(model);
|
---|
139 | }
|
---|
140 | this.model = model;
|
---|
141 | if (this.model != null) {
|
---|
142 | registerAsObserver(model);
|
---|
143 | }
|
---|
144 | }
|
---|
145 | }
|
---|