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

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

fixed #3739: History dialog displays anonymous users as "User: ". Should be "User: <anonymous>" or similar
Added context-sensitive help to the HistoryBrowser

File size: 4.5 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.FlowLayout;
7import java.awt.GridBagConstraints;
8import java.awt.GridBagLayout;
9import java.io.UnsupportedEncodingException;
10import java.net.URLEncoder;
11import java.text.SimpleDateFormat;
12import java.util.Observable;
13import java.util.Observer;
14import java.util.logging.Logger;
15
16import javax.swing.JLabel;
17import javax.swing.JPanel;
18
19import org.openstreetmap.josm.actions.AbstractInfoAction;
20import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive;
21import org.openstreetmap.josm.tools.UrlLabel;
22
23/**
24 * VersionInfoPanel is an UI component which displays the basic properties of a version
25 * of a {@see OsmPrimitive}.
26 *
27 */
28public class VersionInfoPanel extends JPanel implements Observer{
29 static private final Logger logger = Logger.getLogger(VersionInfoPanel.class.getName());
30
31 private PointInTimeType pointInTimeType;
32 private HistoryBrowserModel model;
33 private JLabel lblInfo;
34 private UrlLabel lblUser;
35 private UrlLabel lblChangeset;
36
37 protected void build() {
38 JPanel pnl1 = new JPanel();
39 pnl1.setLayout(new FlowLayout(FlowLayout.LEFT));
40 lblInfo = new JLabel();
41 lblInfo.setHorizontalAlignment(JLabel.LEFT);
42 pnl1.add(lblInfo);
43
44 JPanel pnl2 = new JPanel();
45 pnl2.setLayout(new FlowLayout(FlowLayout.LEFT));
46 lblUser = new UrlLabel();
47 pnl2.add(new JLabel(tr("User")));
48 pnl2.add(lblUser);
49 pnl2.add(new JLabel(tr("Changeset")));
50 lblChangeset = new UrlLabel();
51 pnl2.add(lblChangeset);
52
53 setLayout(new GridBagLayout());
54 GridBagConstraints gc = new GridBagConstraints();
55 gc.anchor = GridBagConstraints.NORTHWEST;
56 gc.fill = GridBagConstraints.HORIZONTAL;
57 gc.weightx = 1.0;
58 gc.weighty = 0.0;
59 add(pnl1, gc);
60 gc.gridy = 1;
61 add(pnl2, gc);
62 }
63
64 protected HistoryOsmPrimitive getPrimitive() {
65 if (model == null || pointInTimeType == null)
66 return null;
67 return model.getPointInTime(pointInTimeType);
68 }
69
70 protected String getInfoText() {
71 HistoryOsmPrimitive primitive = getPrimitive();
72 if (primitive == null)
73 return "";
74 String text = tr(
75 "<html>Version <strong>{0}</strong> created on <strong>{1}</strong></html>",
76 Long.toString(primitive.getVersion()),
77 new SimpleDateFormat().format(primitive.getTimestamp())
78 );
79 return text;
80 }
81
82 public VersionInfoPanel() {
83 pointInTimeType = null;
84 model = null;
85 build();
86 }
87
88 /**
89 * constructor
90 *
91 * @param model the model (must not be null)
92 * @param pointInTimeType the point in time this panel visualizes (must not be null)
93 * @exception IllegalArgumentException thrown, if model is null
94 * @exception IllegalArgumentException thrown, if pointInTimeType is null
95 *
96 */
97 public VersionInfoPanel(HistoryBrowserModel model, PointInTimeType pointInTimeType) throws IllegalArgumentException {
98 if (pointInTimeType == null)
99 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "pointInTimeType"));
100 if (model == null)
101 throw new IllegalArgumentException(tr("Parameter ''{0}'' must not be null.", "model"));
102
103 this.model = model;
104 this.pointInTimeType = pointInTimeType;
105 model.addObserver(this);
106 build();
107 }
108
109 public void update(Observable o, Object arg) {
110 lblInfo.setText(getInfoText());
111
112 String url = AbstractInfoAction.getBaseBrowseUrl() + "/changeset/" + getPrimitive().getChangesetId();
113 lblChangeset.setUrl(url);
114 lblChangeset.setDescription(Long.toString(getPrimitive().getChangesetId()));
115
116 try {
117 if (getPrimitive().getUid() != -1) {
118 url = AbstractInfoAction.getBaseUserUrl() + "/" + URLEncoder.encode(getPrimitive().getUser(), "UTF-8").replaceAll("\\+", "%20");
119 lblUser.setUrl(url);
120 } else {
121 lblUser.setUrl(null);
122 }
123 } catch(UnsupportedEncodingException e) {
124 e.printStackTrace();
125 lblUser.setUrl(null);
126 }
127 String username = getPrimitive().getUser();
128 lblUser.setDescription(username);
129 }
130}
Note: See TracBrowser for help on using the repository browser.