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