source: josm/trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java@ 2070

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

fixed #3383: changeset tags in history dialog

File size: 3.0 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.event.ActionEvent;
8import java.awt.event.MouseEvent;
9import java.text.SimpleDateFormat;
10import java.util.Observable;
11import java.util.Observer;
12
13import javax.swing.JLabel;
14import javax.swing.JPanel;
15
16import org.openstreetmap.josm.actions.AbstractInfoAction;
17import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
18import org.openstreetmap.josm.tools.ImageProvider;
19
20/**
21 * VersionInfoPanel is an UI component which displays the basic properties of a version
22 * of a {@see OsmPrimitive}.
23 *
24 */
25public class VersionInfoPanel extends JPanel implements Observer{
26
27 private PointInTimeType pointInTimeType;
28 private HistoryBrowserModel model;
29 private JLabel lblInfo;
30
31 protected void build() {
32 setLayout(new BorderLayout());
33 lblInfo = new JLabel();
34 lblInfo.setHorizontalAlignment(JLabel.LEFT);
35 add(lblInfo, BorderLayout.CENTER);
36 }
37
38 protected HistoryOsmPrimitive getPrimitive() {
39 if (model == null || pointInTimeType == null)
40 return null;
41 return model.getPointInTime(pointInTimeType);
42 }
43
44 protected String getInfoText() {
45 HistoryOsmPrimitive primitive = getPrimitive();
46 if (primitive == null)
47 return "";
48 String url = AbstractInfoAction.getBaseBrowseUrl() + "/changeset/" + primitive.getChangesetId();
49 String text = tr(
50 "<html>Version <strong>{0}</strong> created on <strong>{1}</strong> by <strong>{2}</strong> in changeset <strong>{3}</strong>",
51 Long.toString(primitive.getVersion()),
52 new SimpleDateFormat().format(primitive.getTimestamp()),
53 primitive.getUser(),
54 primitive.getChangesetId()
55 );
56 return text;
57 }
58
59 public VersionInfoPanel() {
60 pointInTimeType = null;
61 model = null;
62 build();
63 }
64
65 /**
66 * constructor
67 *
68 * @param model the model (must not be null)
69 * @param pointInTimeType the point in time this panel visualizes (must not be null)
70 * @exception IllegalArgumentException thrown, if model is null
71 * @exception IllegalArgumentException thrown, if pointInTimeType is null
72 *
73 */
74 public VersionInfoPanel(HistoryBrowserModel model, PointInTimeType pointInTimeType) throws IllegalArgumentException {
75 if (pointInTimeType == null)
76 throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "pointInTimeType"));
77 if (model == null)
78 throw new IllegalArgumentException(tr("parameter ''{0}'' must not be null", "model"));
79
80 this.model = model;
81 this.pointInTimeType = pointInTimeType;
82 model.addObserver(this);
83 build();
84 }
85
86 public void update(Observable o, Object arg) {
87 lblInfo.setText(getInfoText());
88 }
89}
Note: See TracBrowser for help on using the repository browser.