1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.history;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.BorderLayout;
|
---|
8 | import java.awt.FlowLayout;
|
---|
9 | import java.awt.event.ActionEvent;
|
---|
10 |
|
---|
11 | import javax.swing.AbstractAction;
|
---|
12 | import javax.swing.JButton;
|
---|
13 | import javax.swing.JDialog;
|
---|
14 | import javax.swing.JOptionPane;
|
---|
15 | import javax.swing.JPanel;
|
---|
16 |
|
---|
17 | import org.openstreetmap.josm.Main;
|
---|
18 | import org.openstreetmap.josm.data.osm.history.History;
|
---|
19 | import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * This is non-modal dialog, always showing on top, which displays history information
|
---|
23 | * about a given {@see OsmPrimitive}.
|
---|
24 | *
|
---|
25 | */
|
---|
26 | public class HistoryBrowserDialog extends JDialog {
|
---|
27 |
|
---|
28 | /** the embedded browser */
|
---|
29 | private HistoryBrowser browser;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * displays the title for this dialog
|
---|
33 | *
|
---|
34 | * @param h the current history
|
---|
35 | */
|
---|
36 | protected void renderTitle(History h) {
|
---|
37 | String title = "";
|
---|
38 | switch(h.getEarliest().getType()) {
|
---|
39 | case NODE: title = marktr("History for node {0}"); break;
|
---|
40 | case WAY: title = marktr("History for way {0}"); break;
|
---|
41 | case RELATION: title = marktr("History for relation {0}"); break;
|
---|
42 | }
|
---|
43 | setTitle(tr(
|
---|
44 | title,
|
---|
45 | Long.toString(h.getId())
|
---|
46 | ));
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * builds the GUI
|
---|
51 | *
|
---|
52 | */
|
---|
53 | protected void build() {
|
---|
54 | setLayout(new BorderLayout());
|
---|
55 | browser = new HistoryBrowser();
|
---|
56 | add(browser, BorderLayout.CENTER);
|
---|
57 |
|
---|
58 | JPanel pnl = new JPanel();
|
---|
59 | pnl.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
---|
60 |
|
---|
61 | JButton btn = new JButton(new CloseAction());
|
---|
62 | btn.setName("btn.close");
|
---|
63 | pnl.add(btn);
|
---|
64 | add(pnl, BorderLayout.SOUTH);
|
---|
65 |
|
---|
66 | setSize(800, 500);
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * constructor
|
---|
71 | *
|
---|
72 | * @param history the history to be displayed
|
---|
73 | */
|
---|
74 | public HistoryBrowserDialog(History history) {
|
---|
75 | super(JOptionPane.getFrameForComponent(Main.parent), false);
|
---|
76 | build();
|
---|
77 | setHistory(history);
|
---|
78 | renderTitle(history);
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * sets the current history
|
---|
83 | * @param history
|
---|
84 | */
|
---|
85 | protected void setHistory(History history) {
|
---|
86 | browser.populate(history);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * registers this dialog with the registry of history dialogs
|
---|
91 | *
|
---|
92 | * @see HistoryDialog#registerHistoryBrowserDialog(long, HistoryBrowserDialog)
|
---|
93 | */
|
---|
94 | protected void register() {
|
---|
95 | HistoryDialog.registerHistoryBrowserDialog(browser.getHistory().getId(), this);
|
---|
96 | }
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * unregisters this dialog from the registry of history dialogs
|
---|
100 | *
|
---|
101 | * @see HistoryDialog#unregisterHistoryBrowserDialog(long)
|
---|
102 | */
|
---|
103 | protected void unregister() {
|
---|
104 | HistoryDialog.unregisterHistoryBrowserDialog(browser.getHistory().getId());
|
---|
105 | }
|
---|
106 |
|
---|
107 | @Override
|
---|
108 | public void setVisible(boolean visible) {
|
---|
109 | if (visible) {
|
---|
110 | register();
|
---|
111 | toFront();
|
---|
112 | } else {
|
---|
113 | unregister();
|
---|
114 | }
|
---|
115 | super.setVisible(visible);
|
---|
116 | }
|
---|
117 |
|
---|
118 | class CloseAction extends AbstractAction {
|
---|
119 | public CloseAction() {
|
---|
120 | putValue(NAME, tr("Close"));
|
---|
121 | putValue(SHORT_DESCRIPTION, tr("Close the dialog"));
|
---|
122 | }
|
---|
123 |
|
---|
124 | public void actionPerformed(ActionEvent e) {
|
---|
125 | setVisible(false);
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | public HistoryBrowser getHistoryBrowser() {
|
---|
130 | return browser;
|
---|
131 | }
|
---|
132 | }
|
---|