[2512] | 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 | import javax.swing.ListSelectionModel;
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * TagInfoViewer is a UI component which displays the list of tags of two
|
---|
| 15 | * version of a {@see OsmPrimitive} in a {@see History}.
|
---|
| 16 | *
|
---|
| 17 | * <ul>
|
---|
| 18 | * <li>on the left, it displays the list of tags for the version at {@see PointInTimeType#REFERENCE_POINT_IN_TIME}</li>
|
---|
| 19 | * <li>on the right, it displays the list of tags for the version at {@see PointInTimeType#CURRENT_POINT_IN_TIME}</li>
|
---|
| 20 | * </ul>
|
---|
| 21 | *
|
---|
| 22 | */
|
---|
| 23 | public class TagInfoViewer extends JPanel{
|
---|
| 24 |
|
---|
| 25 | private HistoryBrowserModel model;
|
---|
| 26 | private VersionInfoPanel referenceInfoPanel;
|
---|
| 27 | private VersionInfoPanel currentInfoPanel;
|
---|
| 28 | private AdjustmentSynchronizer adjustmentSynchronizer;
|
---|
| 29 | private SelectionSynchronizer selectionSynchronizer;
|
---|
| 30 |
|
---|
| 31 | protected JScrollPane embeddInScrollPane(JTable table) {
|
---|
| 32 | JScrollPane pane = new JScrollPane(table);
|
---|
| 33 | pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
| 34 | pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
---|
| 35 | adjustmentSynchronizer.participateInSynchronizedScrolling(pane.getVerticalScrollBar());
|
---|
| 36 | return pane;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | protected JTable buildReferenceTagTable() {
|
---|
| 40 | JTable table = new JTable(
|
---|
| 41 | model.getTagTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME),
|
---|
| 42 | new TagTableColumnModel()
|
---|
| 43 | );
|
---|
| 44 | table.setName("table.referencetagtable");
|
---|
| 45 | table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
| 46 | selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
|
---|
| 47 | return table;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | protected JTable buildCurrentTagTable() {
|
---|
| 51 | JTable table = new JTable(
|
---|
| 52 | model.getTagTableModel(PointInTimeType.CURRENT_POINT_IN_TIME),
|
---|
| 53 | new TagTableColumnModel()
|
---|
| 54 | );
|
---|
| 55 | table.setName("table.currenttagtable");
|
---|
| 56 | table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
---|
| 57 | selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
|
---|
| 58 | return table;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | protected void build() {
|
---|
| 62 | setLayout(new GridBagLayout());
|
---|
| 63 | GridBagConstraints gc = new GridBagConstraints();
|
---|
| 64 |
|
---|
| 65 | // ---------------------------
|
---|
| 66 | gc.gridx = 0;
|
---|
| 67 | gc.gridy = 0;
|
---|
| 68 | gc.gridwidth = 1;
|
---|
| 69 | gc.gridheight = 1;
|
---|
| 70 | gc.weightx = 0.5;
|
---|
| 71 | gc.weighty = 0.0;
|
---|
| 72 | gc.insets = new Insets(5,5,5,0);
|
---|
| 73 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
| 74 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
| 75 | referenceInfoPanel = new VersionInfoPanel(model, PointInTimeType.REFERENCE_POINT_IN_TIME);
|
---|
| 76 | add(referenceInfoPanel,gc);
|
---|
| 77 |
|
---|
| 78 | gc.gridx = 1;
|
---|
| 79 | gc.gridy = 0;
|
---|
| 80 | gc.gridwidth = 1;
|
---|
| 81 | gc.gridheight = 1;
|
---|
| 82 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
| 83 | gc.weightx = 0.5;
|
---|
| 84 | gc.weighty = 0.0;
|
---|
| 85 | gc.anchor = GridBagConstraints.FIRST_LINE_START;
|
---|
| 86 | currentInfoPanel = new VersionInfoPanel(model, PointInTimeType.CURRENT_POINT_IN_TIME);
|
---|
| 87 | add(currentInfoPanel,gc);
|
---|
| 88 |
|
---|
| 89 | adjustmentSynchronizer = new AdjustmentSynchronizer();
|
---|
| 90 | selectionSynchronizer = new SelectionSynchronizer();
|
---|
| 91 |
|
---|
| 92 | // ---------------------------
|
---|
| 93 | gc.gridx = 0;
|
---|
| 94 | gc.gridy = 1;
|
---|
| 95 | gc.gridwidth = 1;
|
---|
| 96 | gc.gridheight = 1;
|
---|
| 97 | gc.weightx = 0.5;
|
---|
| 98 | gc.weighty = 1.0;
|
---|
| 99 | gc.fill = GridBagConstraints.BOTH;
|
---|
| 100 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
| 101 | add(embeddInScrollPane(buildReferenceTagTable()),gc);
|
---|
| 102 |
|
---|
| 103 | gc.gridx = 1;
|
---|
| 104 | gc.gridy = 1;
|
---|
| 105 | gc.gridwidth = 1;
|
---|
| 106 | gc.gridheight = 1;
|
---|
| 107 | gc.weightx = 0.5;
|
---|
| 108 | gc.weighty = 1.0;
|
---|
| 109 | gc.fill = GridBagConstraints.BOTH;
|
---|
| 110 | gc.anchor = GridBagConstraints.NORTHWEST;
|
---|
| 111 | add(embeddInScrollPane(buildCurrentTagTable()),gc);
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | public TagInfoViewer(HistoryBrowserModel model) {
|
---|
| 115 | setModel(model);
|
---|
| 116 | build();
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | protected void unregisterAsObserver(HistoryBrowserModel model) {
|
---|
| 120 | if (currentInfoPanel != null) {
|
---|
| 121 | model.deleteObserver(currentInfoPanel);
|
---|
| 122 | }
|
---|
| 123 | if (referenceInfoPanel != null) {
|
---|
| 124 | model.deleteObserver(referenceInfoPanel);
|
---|
| 125 | }
|
---|
| 126 | }
|
---|
| 127 | protected void registerAsObserver(HistoryBrowserModel model) {
|
---|
| 128 | if (currentInfoPanel != null) {
|
---|
| 129 | model.addObserver(currentInfoPanel);
|
---|
| 130 | }
|
---|
| 131 | if (referenceInfoPanel != null) {
|
---|
| 132 | model.addObserver(referenceInfoPanel);
|
---|
| 133 | }
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | public void setModel(HistoryBrowserModel model) {
|
---|
| 137 | if (this.model != null) {
|
---|
| 138 | unregisterAsObserver(model);
|
---|
| 139 | }
|
---|
| 140 | this.model = model;
|
---|
| 141 | if (this.model != null) {
|
---|
| 142 | registerAsObserver(model);
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | }
|
---|