source: josm/trunk/src/org/openstreetmap/josm/gui/history/TagInfoViewer.java@ 2017

Last change on this file since 2017 was 2017, checked in by Gubaer, 15 years ago

removed OptionPaneUtil
cleanup of deprecated Layer API
cleanup of deprecated APIs in OsmPrimitive and Way
cleanup of imports

File size: 5.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;
11import 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 */
23public 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}
Note: See TracBrowser for help on using the repository browser.