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 |
|
---|
12 | import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Base class of {@link TagInfoViewer} and {@link RelationMemberListViewer}.
|
---|
16 | * @since 6207
|
---|
17 | */
|
---|
18 | public abstract class HistoryViewerPanel extends JPanel {
|
---|
19 |
|
---|
20 | protected transient HistoryBrowserModel model;
|
---|
21 | protected VersionInfoPanel referenceInfoPanel;
|
---|
22 | protected VersionInfoPanel currentInfoPanel;
|
---|
23 | protected transient AdjustmentSynchronizer adjustmentSynchronizer;
|
---|
24 | protected transient SelectionSynchronizer selectionSynchronizer;
|
---|
25 |
|
---|
26 | protected HistoryViewerPanel(HistoryBrowserModel model) {
|
---|
27 | setModel(model);
|
---|
28 | build();
|
---|
29 | }
|
---|
30 |
|
---|
31 | private JScrollPane embedInScrollPane(JTable table) {
|
---|
32 | JScrollPane pane = new JScrollPane(table);
|
---|
33 | adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar());
|
---|
34 | return pane;
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Sets the history browsing model.
|
---|
39 | * @param model The history browsing model
|
---|
40 | */
|
---|
41 | public final void setModel(HistoryBrowserModel model) {
|
---|
42 | if (this.model != null) {
|
---|
43 | unregisterAsChangeListener(model);
|
---|
44 | }
|
---|
45 | this.model = model;
|
---|
46 | if (this.model != null) {
|
---|
47 | registerAsChangeListener(model);
|
---|
48 | }
|
---|
49 | }
|
---|
50 |
|
---|
51 | protected final void unregisterAsChangeListener(HistoryBrowserModel model) {
|
---|
52 | if (currentInfoPanel != null) {
|
---|
53 | model.removeChangeListener(currentInfoPanel);
|
---|
54 | }
|
---|
55 | if (referenceInfoPanel != null) {
|
---|
56 | model.removeChangeListener(referenceInfoPanel);
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | protected final void registerAsChangeListener(HistoryBrowserModel model) {
|
---|
61 | if (currentInfoPanel != null) {
|
---|
62 | model.addChangeListener(currentInfoPanel);
|
---|
63 | }
|
---|
64 | if (referenceInfoPanel != null) {
|
---|
65 | model.addChangeListener(referenceInfoPanel);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected abstract JTable buildReferenceTable();
|
---|
70 |
|
---|
71 | protected abstract JTable buildCurrentTable();
|
---|
72 |
|
---|
73 | private void build() {
|
---|
74 | setLayout(new GridBagLayout());
|
---|
75 | GridBagConstraints gc = new GridBagConstraints();
|
---|
76 |
|
---|
77 | // ---------------------------
|
---|
78 | gc.gridx = 0;
|
---|
79 | gc.gridy = 0;
|
---|
80 | gc.gridwidth = 1;
|
---|
81 | gc.gridheight = 1;
|
---|
82 | gc.weightx = 0.5;
|
---|
83 | gc.weighty = 0.0;
|
---|
84 | gc.insets = new Insets(5, 5, 5, 0);
|
---|
85 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
86 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
87 | referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
|
---|
88 | add(referenceInfoPanel, gc);
|
---|
89 |
|
---|
90 | gc.gridx = 1;
|
---|
91 | gc.gridy = 0;
|
---|
92 | gc.gridwidth = 1;
|
---|
93 | gc.gridheight = 1;
|
---|
94 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
95 | gc.weightx = 0.5;
|
---|
96 | gc.weighty = 0.0;
|
---|
97 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
98 | currentInfoPanel = new VersionInfoPanel(model, PointInTimeType.CURRENT_POINT_IN_TIME);
|
---|
99 | add(currentInfoPanel, gc);
|
---|
100 |
|
---|
101 | adjustmentSynchronizer = new AdjustmentSynchronizer();
|
---|
102 | selectionSynchronizer = new SelectionSynchronizer();
|
---|
103 |
|
---|
104 | // ---------------------------
|
---|
105 | gc.gridx = 0;
|
---|
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(embedInScrollPane(buildReferenceTable()), gc);
|
---|
114 |
|
---|
115 | gc.gridx = 1;
|
---|
116 | gc.gridy = 1;
|
---|
117 | gc.gridwidth = 1;
|
---|
118 | gc.gridheight = 1;
|
---|
119 | gc.weightx = 0.5;
|
---|
120 | gc.weighty = 1.0;
|
---|
121 | gc.fill = GridBagConstraints.BOTH;
|
---|
122 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
123 | add(embedInScrollPane(buildCurrentTable()), gc);
|
---|
124 | }
|
---|
125 | }
|
---|