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