[7937] | 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 {
|
---|
[8308] | 19 |
|
---|
| 20 | protected transient HistoryBrowserModel model;
|
---|
[7937] | 21 | protected VersionInfoPanel referenceInfoPanel;
|
---|
| 22 | protected VersionInfoPanel currentInfoPanel;
|
---|
[8308] | 23 | protected transient AdjustmentSynchronizer adjustmentSynchronizer;
|
---|
| 24 | protected transient SelectionSynchronizer selectionSynchronizer;
|
---|
[7937] | 25 |
|
---|
| 26 | protected HistoryViewerPanel(HistoryBrowserModel model) {
|
---|
| 27 | setModel(model);
|
---|
| 28 | build();
|
---|
| 29 | }
|
---|
[8308] | 30 |
|
---|
[7937] | 31 | private JScrollPane embedInScrollPane(JTable table) {
|
---|
| 32 | JScrollPane pane = new JScrollPane(table);
|
---|
| 33 | adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar());
|
---|
| 34 | return pane;
|
---|
| 35 | }
|
---|
[8308] | 36 |
|
---|
[7937] | 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) {
|
---|
[10210] | 43 | unregisterAsChangeListener(model);
|
---|
[7937] | 44 | }
|
---|
| 45 | this.model = model;
|
---|
| 46 | if (this.model != null) {
|
---|
[10210] | 47 | registerAsChangeListener(model);
|
---|
[7937] | 48 | }
|
---|
| 49 | }
|
---|
[8308] | 50 |
|
---|
[10210] | 51 | protected final void unregisterAsChangeListener(HistoryBrowserModel model) {
|
---|
[7937] | 52 | if (currentInfoPanel != null) {
|
---|
[10210] | 53 | model.removeChangeListener(currentInfoPanel);
|
---|
[7937] | 54 | }
|
---|
| 55 | if (referenceInfoPanel != null) {
|
---|
[10210] | 56 | model.removeChangeListener(referenceInfoPanel);
|
---|
[7937] | 57 | }
|
---|
| 58 | }
|
---|
[8308] | 59 |
|
---|
[10210] | 60 | protected final void registerAsChangeListener(HistoryBrowserModel model) {
|
---|
[7937] | 61 | if (currentInfoPanel != null) {
|
---|
[10210] | 62 | model.addChangeListener(currentInfoPanel);
|
---|
[7937] | 63 | }
|
---|
| 64 | if (referenceInfoPanel != null) {
|
---|
[10210] | 65 | model.addChangeListener(referenceInfoPanel);
|
---|
[7937] | 66 | }
|
---|
| 67 | }
|
---|
[8308] | 68 |
|
---|
[7937] | 69 | protected abstract JTable buildReferenceTable();
|
---|
[8308] | 70 |
|
---|
[7937] | 71 | protected abstract JTable buildCurrentTable();
|
---|
[8308] | 72 |
|
---|
[7937] | 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;
|
---|
[8510] | 84 | gc.insets = new Insets(5, 5, 5, 0);
|
---|
[7937] | 85 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
| 86 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
| 87 | referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
|
---|
[8510] | 88 | add(referenceInfoPanel, gc);
|
---|
[7937] | 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);
|
---|
[8510] | 99 | add(currentInfoPanel, gc);
|
---|
[7937] | 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;
|
---|
[8510] | 113 | add(embedInScrollPane(buildReferenceTable()), gc);
|
---|
[7937] | 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;
|
---|
[8510] | 123 | add(embedInScrollPane(buildCurrentTable()), gc);
|
---|
[7937] | 124 | }
|
---|
| 125 | }
|
---|