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

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

Improved history feature

File size: 4.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.BorderLayout;
8import java.awt.FlowLayout;
9import java.awt.event.ActionEvent;
10import java.awt.event.WindowAdapter;
11import java.awt.event.WindowEvent;
12
13import javax.swing.AbstractAction;
14import javax.swing.JDialog;
15import javax.swing.JOptionPane;
16import javax.swing.JPanel;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.data.osm.history.History;
20import org.openstreetmap.josm.data.osm.history.HistoryDataSet;
21import org.openstreetmap.josm.data.osm.history.HistoryDataSetListener;
22import org.openstreetmap.josm.gui.SideButton;
23import org.openstreetmap.josm.gui.dialogs.HistoryDialog;
24import org.openstreetmap.josm.tools.ImageProvider;
25
26/**
27 * This is non-modal dialog, always showing on top, which displays history information
28 * about a given {@see OsmPrimitive}.
29 *
30 */
31public class HistoryBrowserDialog extends JDialog implements HistoryDataSetListener{
32
33 /** the embedded browser */
34 private HistoryBrowser browser;
35
36 /**
37 * displays the title for this dialog
38 *
39 * @param h the current history
40 */
41 protected void renderTitle(History h) {
42 String title = "";
43 switch(h.getEarliest().getType()) {
44 case NODE: title = marktr("History for node {0}"); break;
45 case WAY: title = marktr("History for way {0}"); break;
46 case RELATION: title = marktr("History for relation {0}"); break;
47 }
48 setTitle(tr(
49 title,
50 Long.toString(h.getId())
51 ));
52 }
53
54 /**
55 * builds the GUI
56 *
57 */
58 protected void build() {
59 setLayout(new BorderLayout());
60 browser = new HistoryBrowser();
61 add(browser, BorderLayout.CENTER);
62
63 JPanel pnl = new JPanel();
64 pnl.setLayout(new FlowLayout(FlowLayout.CENTER));
65
66 SideButton btn = new SideButton(new ReloadAction());
67 btn.setName("btn.reload");
68 pnl.add(btn);
69
70 btn = new SideButton(new CloseAction());
71 btn.setName("btn.close");
72 pnl.add(btn);
73 add(pnl, BorderLayout.SOUTH);
74
75 setSize(800, 500);
76 }
77
78 /**
79 * constructor
80 *
81 * @param history the history to be displayed
82 */
83 public HistoryBrowserDialog(History history) {
84 super(JOptionPane.getFrameForComponent(Main.parent), false);
85 build();
86 setHistory(history);
87 renderTitle(history);
88 HistoryDataSet.getInstance().addHistoryDataSetListener(this);
89 addWindowListener(new WindowClosingAdapter());
90 }
91
92 /**
93 * sets the current history
94 * @param history
95 */
96 protected void setHistory(History history) {
97 browser.populate(history);
98 }
99
100 public void historyUpdated(HistoryDataSet source, long primitiveId) {
101 if (primitiveId == browser.getHistory().getId()) {
102 browser.populate(source.getHistory(primitiveId));
103 } else if (primitiveId == 0) {
104 browser.populate(source.getHistory(browser.getHistory().getId()));
105 }
106 }
107
108 class CloseAction extends AbstractAction {
109 public CloseAction() {
110 putValue(NAME, tr("Close"));
111 putValue(SHORT_DESCRIPTION, tr("Close the dialog"));
112 putValue(SMALL_ICON, ImageProvider.get("ok"));
113 }
114
115 public void actionPerformed(ActionEvent e) {
116 HistoryDataSet.getInstance().removeHistoryDataSetListener(HistoryBrowserDialog.this);
117 HistoryBrowserDialogManager.getInstance().hide(HistoryBrowserDialog.this);
118 }
119 }
120
121 class ReloadAction extends AbstractAction {
122 public ReloadAction() {
123 putValue(NAME, tr("Reload"));
124 putValue(SHORT_DESCRIPTION, tr("Reload the history from the server"));
125 putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh"));
126 }
127
128 public void actionPerformed(ActionEvent e) {
129 HistoryLoadTask task = new HistoryLoadTask();
130 task.add(browser.getHistory());
131 Main.worker.submit(task);
132 }
133 }
134
135 class WindowClosingAdapter extends WindowAdapter {
136 @Override
137 public void windowClosing(WindowEvent e) {
138 HistoryDataSet.getInstance().removeHistoryDataSetListener(HistoryBrowserDialog.this);
139 HistoryBrowserDialogManager.getInstance().hide(HistoryBrowserDialog.this);
140 }
141 }
142
143 public HistoryBrowser getHistoryBrowser() {
144 return browser;
145 }
146}
Note: See TracBrowser for help on using the repository browser.