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