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.JTable;
|
---|
14 |
|
---|
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 {@see 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 | * embedds table in a {@see JScrollPane}
|
---|
35 | *
|
---|
36 | * @param table the table
|
---|
37 | * @return the {@see JScrollPane} with the embedded table
|
---|
38 | */
|
---|
39 | protected JScrollPane embeddInScrollPane(JTable table) {
|
---|
40 | JScrollPane pane = new JScrollPane(table);
|
---|
41 | pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
42 | pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
---|
43 | return pane;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * creates the table which shows the list of versions
|
---|
48 | *
|
---|
49 | * @return the panel with the version table
|
---|
50 | */
|
---|
51 | protected JPanel createVersionTablePanel() {
|
---|
52 | JPanel pnl = new JPanel();
|
---|
53 | pnl.setLayout(new BorderLayout());
|
---|
54 |
|
---|
55 | VersionTable tbl = new VersionTable(model);
|
---|
56 | pnl.add(embeddInScrollPane(tbl), BorderLayout.CENTER);
|
---|
57 | return pnl;
|
---|
58 | }
|
---|
59 |
|
---|
60 | /**
|
---|
61 | * creates the panel which shows information about two different versions
|
---|
62 | * of the same {@see OsmPrimitive}.
|
---|
63 | *
|
---|
64 | * @return the panel
|
---|
65 | */
|
---|
66 | protected JPanel createVersionComparePanel() {
|
---|
67 | tpViewers = new JTabbedPane();
|
---|
68 |
|
---|
69 | // create the viewers, but don't add them yet.
|
---|
70 | // see populate()
|
---|
71 | //
|
---|
72 | tagInfoViewer = new TagInfoViewer(model);
|
---|
73 | nodeListViewer = new NodeListViewer(model);
|
---|
74 | relationMemberListViewer = new RelationMemberListViewer(model);
|
---|
75 | coordinateInfoViewer = new CoordinateInfoViewer(model);
|
---|
76 | JPanel pnl = new JPanel();
|
---|
77 | pnl.setLayout(new BorderLayout());
|
---|
78 | pnl.add(tpViewers, BorderLayout.CENTER);
|
---|
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(200);
|
---|
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 {@see 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 {@see 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 {@see 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 | }
|
---|