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

Last change on this file since 9526 was 9453, checked in by simon04, 8 years ago

fix #12364 - History dialog: fix initial panning to coordinates

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