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