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