source: josm/trunk/src/org/openstreetmap/josm/gui/history/HistoryViewerPanel.java@ 7005

Last change on this file since 7005 was 6666, checked in by Don-vip, 10 years ago

see #9508 - refactor validator preferences + handling of JScrollPane policies ("vertical as needed" / "horizontal as needed" are default policies)

File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import java.awt.GridBagConstraints;
5import java.awt.GridBagLayout;
6import java.awt.Insets;
7
8import javax.swing.JPanel;
9import javax.swing.JScrollPane;
10import javax.swing.JTable;
11
12import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
13
14/**
15 * Base class of {@link TagInfoViewer} and {@link RelationMemberListViewer}.
16 * @since 6207
17 */
18public abstract class HistoryViewerPanel extends JPanel {
19
20 protected HistoryBrowserModel model;
21 protected VersionInfoPanel referenceInfoPanel;
22 protected VersionInfoPanel currentInfoPanel;
23 protected AdjustmentSynchronizer adjustmentSynchronizer;
24 protected 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 unregisterAsObserver(model);
44 }
45 this.model = model;
46 if (this.model != null) {
47 registerAsObserver(model);
48 }
49 }
50
51 protected final void unregisterAsObserver(HistoryBrowserModel model) {
52 if (currentInfoPanel != null) {
53 model.deleteObserver(currentInfoPanel);
54 }
55 if (referenceInfoPanel != null) {
56 model.deleteObserver(referenceInfoPanel);
57 }
58 }
59
60 protected final void registerAsObserver(HistoryBrowserModel model) {
61 if (currentInfoPanel != null) {
62 model.addObserver(currentInfoPanel);
63 }
64 if (referenceInfoPanel != null) {
65 model.addObserver(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}
Note: See TracBrowser for help on using the repository browser.