001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.history;
003
004import java.awt.GridBagConstraints;
005import java.awt.Insets;
006
007import javax.swing.JScrollPane;
008import javax.swing.JTable;
009
010import org.openstreetmap.josm.gui.util.AdjustmentSynchronizer;
011
012/**
013 * Base class of {@link TagInfoViewer} and {@link RelationMemberListViewer}.
014 * @since 6207
015 */
016public abstract class HistoryViewerPanel extends HistoryBrowserPanel {
017
018    protected transient AdjustmentSynchronizer adjustmentSynchronizer;
019    protected transient SelectionSynchronizer selectionSynchronizer;
020
021    protected HistoryViewerPanel(HistoryBrowserModel model) {
022        setModel(model);
023        build();
024    }
025
026    private JScrollPane embedInScrollPane(JTable table) {
027        JScrollPane pane = new JScrollPane(table);
028        adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar());
029        return pane;
030    }
031
032    protected abstract JTable buildTable(PointInTimeType pointInTimeType);
033
034    private void build() {
035        GridBagConstraints gc = new GridBagConstraints();
036
037        // ---------------------------
038        gc.gridx = 0;
039        gc.gridy = 0;
040        gc.gridwidth = 1;
041        gc.gridheight = 1;
042        gc.weightx = 0.5;
043        gc.weighty = 0.0;
044        gc.insets = new Insets(5, 5, 5, 0);
045        gc.fill = GridBagConstraints.HORIZONTAL;
046        gc.anchor = GridBagConstraints.FIRST_LINE_START;
047        referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
048        add(referenceInfoPanel, gc);
049
050        gc.gridx = 1;
051        gc.gridy = 0;
052        gc.gridwidth = 1;
053        gc.gridheight = 1;
054        gc.fill = GridBagConstraints.HORIZONTAL;
055        gc.weightx = 0.5;
056        gc.weighty = 0.0;
057        gc.anchor = GridBagConstraints.FIRST_LINE_START;
058        currentInfoPanel = new VersionInfoPanel(model, PointInTimeType.CURRENT_POINT_IN_TIME);
059        add(currentInfoPanel, gc);
060
061        adjustmentSynchronizer = new AdjustmentSynchronizer();
062        selectionSynchronizer = new SelectionSynchronizer();
063
064        // ---------------------------
065        gc.gridx = 0;
066        gc.gridy = 1;
067        gc.gridwidth = 1;
068        gc.gridheight = 1;
069        gc.weightx = 0.5;
070        gc.weighty = 1.0;
071        gc.fill = GridBagConstraints.BOTH;
072        gc.anchor = GridBagConstraints.NORTHWEST;
073        add(embedInScrollPane(buildTable(PointInTimeType.REFERENCE_POINT_IN_TIME)), gc);
074
075        gc.gridx = 1;
076        gc.gridy = 1;
077        gc.gridwidth = 1;
078        gc.gridheight = 1;
079        gc.weightx = 0.5;
080        gc.weighty = 1.0;
081        gc.fill = GridBagConstraints.BOTH;
082        gc.anchor = GridBagConstraints.NORTHWEST;
083        add(embedInScrollPane(buildTable(PointInTimeType.CURRENT_POINT_IN_TIME)), gc);
084    }
085}