source: josm/trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowser.java@ 5440

Last change on this file since 5440 was 5440, checked in by Don-vip, 12 years ago

fix #7716 - History shows same version number, wrong date, user, and CT for modified objects

  • Property svn:eol-style set to native
File size: 4.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.BorderLayout;
7import java.awt.Dimension;
8
9import javax.swing.JPanel;
10import javax.swing.JScrollPane;
11import javax.swing.JSplitPane;
12import javax.swing.JTabbedPane;
13import javax.swing.JTable;
14
15import org.openstreetmap.josm.data.osm.OsmPrimitive;
16import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
17import org.openstreetmap.josm.data.osm.history.History;
18
19/**
20 * HistoryBrowser is an UI component which displays history information about an {@link OsmPrimitive}.
21 *
22 *
23 */
24public class HistoryBrowser extends JPanel {
25
26 /** the model */
27 private HistoryBrowserModel model;
28 private TagInfoViewer tagInfoViewer;
29 private NodeListViewer nodeListViewer;
30 private RelationMemberListViewer relationMemberListViewer;
31 private CoordinateInfoViewer coordinateInfoViewer;
32 private JTabbedPane tpViewers;
33 private VersionTable versionTable;
34
35 /**
36 * embedds table in a {@link JScrollPane}
37 *
38 * @param table the table
39 * @return the {@link JScrollPane} with the embedded table
40 */
41 protected JScrollPane embeddInScrollPane(JTable table) {
42 JScrollPane pane = new JScrollPane(table);
43 pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
44 pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
45 return pane;
46 }
47
48 /**
49 * creates the table which shows the list of versions
50 *
51 * @return the panel with the version table
52 */
53 protected JPanel createVersionTablePanel() {
54 JPanel pnl = new JPanel();
55 pnl.setLayout(new BorderLayout());
56
57 versionTable = new VersionTable(model);
58 pnl.add(embeddInScrollPane(versionTable), BorderLayout.CENTER);
59 return pnl;
60 }
61
62 /**
63 * creates the panel which shows information about two different versions
64 * of the same {@link OsmPrimitive}.
65 *
66 * @return the panel
67 */
68 protected JPanel createVersionComparePanel() {
69 tpViewers = new JTabbedPane();
70
71 // create the viewers, but don't add them yet.
72 // see populate()
73 //
74 tagInfoViewer = new TagInfoViewer(model);
75 nodeListViewer = new NodeListViewer(model);
76 relationMemberListViewer = new RelationMemberListViewer(model);
77 coordinateInfoViewer = new CoordinateInfoViewer(model);
78 JPanel pnl = new JPanel();
79 pnl.setLayout(new BorderLayout());
80 pnl.add(tpViewers, BorderLayout.CENTER);
81 return pnl;
82 }
83
84 /**
85 * builds the GUI
86 */
87 protected void build() {
88 JPanel left;
89 JPanel right;
90 setLayout(new BorderLayout());
91 JSplitPane pane = new JSplitPane(
92 JSplitPane.HORIZONTAL_SPLIT,
93 left = createVersionTablePanel(),
94 right = createVersionComparePanel()
95 );
96 add(pane, BorderLayout.CENTER);
97
98 pane.setOneTouchExpandable(true);
99 pane.setDividerLocation(300);
100
101 Dimension minimumSize = new Dimension(100, 50);
102 left.setMinimumSize(minimumSize);
103 right.setMinimumSize(minimumSize);
104 }
105
106 /**
107 * constructor
108 */
109 public HistoryBrowser() {
110 model = new HistoryBrowserModel();
111 build();
112 }
113
114 /**
115 * constructor
116 * @param history the history of an {@link OsmPrimitive}
117 */
118 public HistoryBrowser(History history) {
119 this();
120 populate(history);
121 }
122
123 /**
124 * populates the browser with the history of a specific {@link OsmPrimitive}
125 *
126 * @param history the history
127 */
128 public void populate(History history) {
129 model.setHistory(history);
130
131 tpViewers.removeAll();
132
133 tpViewers.add(tagInfoViewer);
134 tpViewers.setTitleAt(0, tr("Tags"));
135
136 if (history.getEarliest().getType().equals(OsmPrimitiveType.NODE)) {
137 tpViewers.add(coordinateInfoViewer);
138 tpViewers.setTitleAt(1, tr("Coordinates"));
139 } else if (history.getEarliest().getType().equals(OsmPrimitiveType.WAY)) {
140 tpViewers.add(nodeListViewer);
141 tpViewers.setTitleAt(1, tr("Nodes"));
142 } else if (history.getEarliest().getType().equals(OsmPrimitiveType.RELATION)) {
143 tpViewers.add(relationMemberListViewer);
144 tpViewers.setTitleAt(1, tr("Members"));
145 }
146 revalidate();
147 }
148
149 /**
150 * replies the {@link History} currently displayed by this browser
151 *
152 * @return the current history
153 */
154 public History getHistory() {
155 return model.getHistory();
156 }
157
158 /**
159 * replies the model used by this browser
160 * @return the model
161 */
162 public HistoryBrowserModel getModel() {
163 return model;
164 }
165}
Note: See TracBrowser for help on using the repository browser.