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

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

new: history feature implemented

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