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.history.History;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * HistoryBrowser is an UI component which displays history information about an {@see OsmPrimitive}.
|
---|
19 | *
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public class HistoryBrowser extends JPanel {
|
---|
23 |
|
---|
24 | /** the model */
|
---|
25 | private HistoryBrowserModel model;
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * embedds table in a {@see JScrollPane}
|
---|
29 | *
|
---|
30 | * @param table the table
|
---|
31 | * @return the {@see JScrollPane} with the embedded table
|
---|
32 | */
|
---|
33 | protected JScrollPane embeddInScrollPane(JTable table) {
|
---|
34 | JScrollPane pane = new JScrollPane(table);
|
---|
35 | pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
|
---|
36 | pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
|
---|
37 | return pane;
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * creates the table which shows the list of versions
|
---|
42 | *
|
---|
43 | * @return the panel with the version table
|
---|
44 | */
|
---|
45 | protected JPanel createVersionTablePanel() {
|
---|
46 | JPanel pnl = new JPanel();
|
---|
47 | pnl.setLayout(new BorderLayout());
|
---|
48 |
|
---|
49 | VersionTable tbl = new VersionTable(model);
|
---|
50 | pnl.add(embeddInScrollPane(tbl), BorderLayout.CENTER);
|
---|
51 | return pnl;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * creates the panel which shows information about two different versions
|
---|
56 | * of the same {@see OsmPrimitive}.
|
---|
57 | *
|
---|
58 | * @return the panel
|
---|
59 | */
|
---|
60 | protected JPanel createVersionComparePanel() {
|
---|
61 | JTabbedPane pane = new JTabbedPane();
|
---|
62 | pane.add(new TagInfoViewer(model));
|
---|
63 | pane.setTitleAt(0, tr("Tags"));
|
---|
64 |
|
---|
65 | pane.add(new NodeListViewer(model));
|
---|
66 | pane.setTitleAt(1, tr("Nodes"));
|
---|
67 |
|
---|
68 | pane.add(new RelationMemberListViewer(model));
|
---|
69 | pane.setTitleAt(2, tr("Members"));
|
---|
70 |
|
---|
71 | JPanel pnl = new JPanel();
|
---|
72 | pnl.setLayout(new BorderLayout());
|
---|
73 | pnl.add(pane, BorderLayout.CENTER);
|
---|
74 | return pnl;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /**
|
---|
78 | * builds the GUI
|
---|
79 | */
|
---|
80 | protected void build() {
|
---|
81 | JPanel left;
|
---|
82 | JPanel right;
|
---|
83 | setLayout(new BorderLayout());
|
---|
84 | JSplitPane pane = new JSplitPane(
|
---|
85 | JSplitPane.HORIZONTAL_SPLIT,
|
---|
86 | left = createVersionTablePanel(),
|
---|
87 | right = createVersionComparePanel()
|
---|
88 | );
|
---|
89 | add(pane, BorderLayout.CENTER);
|
---|
90 |
|
---|
91 | pane.setOneTouchExpandable(true);
|
---|
92 | pane.setDividerLocation(150);
|
---|
93 |
|
---|
94 | Dimension minimumSize = new Dimension(100, 50);
|
---|
95 | left.setMinimumSize(minimumSize);
|
---|
96 | right.setMinimumSize(minimumSize);
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * constructor
|
---|
101 | */
|
---|
102 | public HistoryBrowser() {
|
---|
103 | model = new HistoryBrowserModel();
|
---|
104 | build();
|
---|
105 | }
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * constructor
|
---|
109 | * @param history the history of an {@see OsmPrimitive}
|
---|
110 | */
|
---|
111 | public HistoryBrowser(History history) {
|
---|
112 | this();
|
---|
113 | populate(history);
|
---|
114 | }
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * populates the browser with the history of a specific {@see OsmPrimitive}
|
---|
118 | *
|
---|
119 | * @param history the history
|
---|
120 | */
|
---|
121 | public void populate(History history) {
|
---|
122 | model.setHistory(history);
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * replies the {@see History} currently displayed by this browser
|
---|
127 | *
|
---|
128 | * @return the current history
|
---|
129 | */
|
---|
130 | public History getHistory() {
|
---|
131 | return model.getHistory();
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * replies the model used by this browser
|
---|
136 | * @return the model
|
---|
137 | */
|
---|
138 | public HistoryBrowserModel getModel() {
|
---|
139 | return model;
|
---|
140 | }
|
---|
141 | }
|
---|