source: josm/trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialog.java@ 1987

Last change on this file since 1987 was 1987, checked in by Gubaer, 15 years ago

removed all occurences of setAlwaysOnTop(). See http://josm.openstreetmap.de/wiki/JosmWinMgtDemoApplication

File size: 3.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.BorderLayout;
7import java.awt.FlowLayout;
8import java.awt.event.ActionEvent;
9
10import javax.swing.AbstractAction;
11import javax.swing.JButton;
12import javax.swing.JDialog;
13import javax.swing.JOptionPane;
14import javax.swing.JPanel;
15
16import org.openstreetmap.josm.Main;
17import org.openstreetmap.josm.data.osm.history.History;
18import 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 */
25public 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 build();
72 setHistory(history);
73 renderTitle(history);
74 }
75
76 /**
77 * sets the current history
78 * @param history
79 */
80 protected void setHistory(History history) {
81 browser.populate(history);
82 }
83
84 /**
85 * registers this dialog with the registry of history dialogs
86 *
87 * @see HistoryDialog#registerHistoryBrowserDialog(long, HistoryBrowserDialog)
88 */
89 protected void register() {
90 HistoryDialog.registerHistoryBrowserDialog(browser.getHistory().getId(), this);
91 }
92
93 /**
94 * unregisters this dialog from the registry of history dialogs
95 *
96 * @see HistoryDialog#unregisterHistoryBrowserDialog(long)
97 */
98 protected void unregister() {
99 HistoryDialog.unregisterHistoryBrowserDialog(browser.getHistory().getId());
100 }
101
102 @Override
103 public void setVisible(boolean visible) {
104 if (visible) {
105 register();
106 toFront();
107 } else {
108 unregister();
109 }
110 super.setVisible(visible);
111 }
112
113 class CloseAction extends AbstractAction {
114 public CloseAction() {
115 putValue(NAME, tr("Close"));
116 putValue(SHORT_DESCRIPTION, tr("Close the dialog"));
117 }
118
119 public void actionPerformed(ActionEvent e) {
120 setVisible(false);
121 }
122 }
123
124 public HistoryBrowser getHistoryBrowser() {
125 return browser;
126 }
127}
Note: See TracBrowser for help on using the repository browser.