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 buildReferenceTable(); 033 034 protected abstract JTable buildCurrentTable(); 035 036 private void build() { 037 GridBagConstraints gc = new GridBagConstraints(); 038 039 // --------------------------- 040 gc.gridx = 0; 041 gc.gridy = 0; 042 gc.gridwidth = 1; 043 gc.gridheight = 1; 044 gc.weightx = 0.5; 045 gc.weighty = 0.0; 046 gc.insets = new Insets(5, 5, 5, 0); 047 gc.fill = GridBagConstraints.HORIZONTAL; 048 gc.anchor = GridBagConstraints.FIRST_LINE_START; 049 referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME); 050 add(referenceInfoPanel, gc); 051 052 gc.gridx = 1; 053 gc.gridy = 0; 054 gc.gridwidth = 1; 055 gc.gridheight = 1; 056 gc.fill = GridBagConstraints.HORIZONTAL; 057 gc.weightx = 0.5; 058 gc.weighty = 0.0; 059 gc.anchor = GridBagConstraints.FIRST_LINE_START; 060 currentInfoPanel = new VersionInfoPanel(model, PointInTimeType.CURRENT_POINT_IN_TIME); 061 add(currentInfoPanel, gc); 062 063 adjustmentSynchronizer = new AdjustmentSynchronizer(); 064 selectionSynchronizer = new SelectionSynchronizer(); 065 066 // --------------------------- 067 gc.gridx = 0; 068 gc.gridy = 1; 069 gc.gridwidth = 1; 070 gc.gridheight = 1; 071 gc.weightx = 0.5; 072 gc.weighty = 1.0; 073 gc.fill = GridBagConstraints.BOTH; 074 gc.anchor = GridBagConstraints.NORTHWEST; 075 add(embedInScrollPane(buildReferenceTable()), gc); 076 077 gc.gridx = 1; 078 gc.gridy = 1; 079 gc.gridwidth = 1; 080 gc.gridheight = 1; 081 gc.weightx = 0.5; 082 gc.weighty = 1.0; 083 gc.fill = GridBagConstraints.BOTH; 084 gc.anchor = GridBagConstraints.NORTHWEST; 085 add(embedInScrollPane(buildCurrentTable()), gc); 086 } 087}