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

Last change on this file since 10212 was 10179, checked in by Don-vip, 8 years ago

sonar - squid:AssignmentInSubExpressionCheck - Assignments should not be made from within sub-expressions

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