1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.dialogs;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Dimension;
|
---|
7 | import java.awt.Font;
|
---|
8 | import java.awt.GridBagLayout;
|
---|
9 | import java.util.Collection;
|
---|
10 | import java.util.List;
|
---|
11 |
|
---|
12 | import javax.swing.JPanel;
|
---|
13 | import javax.swing.JScrollPane;
|
---|
14 | import javax.swing.JTextArea;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.Main;
|
---|
17 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
18 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
19 | import org.openstreetmap.josm.data.osm.DatasetCollection;
|
---|
20 | import org.openstreetmap.josm.data.osm.Node;
|
---|
21 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
22 | import org.openstreetmap.josm.data.osm.Relation;
|
---|
23 | import org.openstreetmap.josm.data.osm.RelationMember;
|
---|
24 | import org.openstreetmap.josm.data.osm.User;
|
---|
25 | import org.openstreetmap.josm.data.osm.Way;
|
---|
26 | import org.openstreetmap.josm.tools.DateUtils;
|
---|
27 | import org.openstreetmap.josm.tools.GBC;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Panel to inspect one or more OsmPrimitives.
|
---|
31 | *
|
---|
32 | * Gives an unfiltered view of the object's internal state.
|
---|
33 | * Might be useful for power users to give more detailed bug reports and
|
---|
34 | * to better understand the JOSM data representation.
|
---|
35 | *
|
---|
36 | * TODO: show conflicts
|
---|
37 | */
|
---|
38 | public class InspectPrimitiveDialog extends ExtendedDialog {
|
---|
39 | protected Collection<OsmPrimitive> primitives;
|
---|
40 | protected JTextArea textArea;
|
---|
41 |
|
---|
42 | public InspectPrimitiveDialog(Collection<OsmPrimitive> primitives) {
|
---|
43 | super(Main.parent, tr("Advanced object info"), new String[] {"Close"});
|
---|
44 | this.primitives = primitives;
|
---|
45 | setPreferredSize(new Dimension(450, 350));
|
---|
46 |
|
---|
47 | setButtonIcons(new String[] {"ok.png"});
|
---|
48 | JPanel p = buildPanel();
|
---|
49 | textArea.setText(buildText());
|
---|
50 | setContent(p, false);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected JPanel buildPanel() {
|
---|
54 | JPanel p = new JPanel(new GridBagLayout());
|
---|
55 | textArea = new JTextArea();
|
---|
56 | textArea.setFont(new Font("Monospaced", textArea.getFont().getStyle(), textArea.getFont().getSize()));
|
---|
57 | textArea.setEditable(false);
|
---|
58 |
|
---|
59 | JScrollPane scroll = new JScrollPane(textArea);
|
---|
60 |
|
---|
61 | p.add(scroll, GBC.std().fill());
|
---|
62 | return p;
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected String buildText() {
|
---|
66 | StringBuffer s = new StringBuffer();
|
---|
67 | for (Node n : new DatasetCollection<Node>(primitives, OsmPrimitive.nodePredicate)) {
|
---|
68 | s.append("Node id="+n.getUniqueId());
|
---|
69 | if (!checkDataSet(n)) {
|
---|
70 | s.append(" not in data set");
|
---|
71 | continue;
|
---|
72 | }
|
---|
73 | if (n.isIncomplete()) {
|
---|
74 | s.append(" incomplete\n");
|
---|
75 | addWayReferrer(s, n);
|
---|
76 | addRelationReferrer(s, n);
|
---|
77 | continue;
|
---|
78 | }
|
---|
79 | s.append(String.format(" lat=%s; lon=%s; ", Double.toString(n.getCoor().lat()), Double.toString(n.getCoor().lon())));
|
---|
80 | addCommon(s, n);
|
---|
81 | addAttributes(s, n);
|
---|
82 | addWayReferrer(s, n);
|
---|
83 | addRelationReferrer(s, n);
|
---|
84 | s.append('\n');
|
---|
85 | }
|
---|
86 |
|
---|
87 | for (Way w : new DatasetCollection<Way>(primitives, OsmPrimitive.wayPredicate)) {
|
---|
88 | s.append("Way id="+ w.getUniqueId());
|
---|
89 | if (!checkDataSet(w)) {
|
---|
90 | s.append(" not in data set");
|
---|
91 | continue;
|
---|
92 | }
|
---|
93 | if (w.isIncomplete()) {
|
---|
94 | s.append(" incomplete\n");
|
---|
95 | addRelationReferrer(s, w);
|
---|
96 | continue;
|
---|
97 | }
|
---|
98 | s.append(String.format(" %d nodes; ", w.getNodes().size()));
|
---|
99 | addCommon(s, w);
|
---|
100 | addAttributes(s, w);
|
---|
101 | addRelationReferrer(s, w);
|
---|
102 |
|
---|
103 | s.append(" nodes:\n");
|
---|
104 | for (Node n : w.getNodes()) {
|
---|
105 | s.append(String.format(" %d\n", n.getUniqueId()));
|
---|
106 | }
|
---|
107 | s.append('\n');
|
---|
108 | }
|
---|
109 |
|
---|
110 | for (Relation r : new DatasetCollection<Relation>(primitives, OsmPrimitive.relationPredicate)) {
|
---|
111 | s.append("Relation id="+r.getUniqueId());
|
---|
112 | if (!checkDataSet(r)) {
|
---|
113 | s.append(" not in data set");
|
---|
114 | continue;
|
---|
115 | }
|
---|
116 | if (r.isIncomplete()) {
|
---|
117 | s.append(" incomplete\n");
|
---|
118 | addRelationReferrer(s, r);
|
---|
119 | continue;
|
---|
120 | }
|
---|
121 | s.append(String.format(" %d members; ",r.getMembersCount()));
|
---|
122 | addCommon(s, r);
|
---|
123 | addAttributes(s, r);
|
---|
124 | addRelationReferrer(s, r);
|
---|
125 |
|
---|
126 | s.append(" members:\n");
|
---|
127 | for (RelationMember m : r.getMembers() ) {
|
---|
128 | s.append(String.format(" %d %s\n", m.getMember().getUniqueId(), m.getRole()));
|
---|
129 | }
|
---|
130 | s.append('\n');
|
---|
131 | }
|
---|
132 |
|
---|
133 | return s.toString().trim();
|
---|
134 | }
|
---|
135 |
|
---|
136 | protected void addCommon(StringBuffer s, OsmPrimitive o) {
|
---|
137 | s.append(String.format("Data set: %X; User: [%s]; ChangeSet id: %H; Timestamp: %s, Version: %d",
|
---|
138 | o.getDataSet().hashCode(),
|
---|
139 | userString(o.getUser()),
|
---|
140 | o.getChangesetId(),
|
---|
141 | DateUtils.fromDate(o.getTimestamp()),
|
---|
142 | o.getVersion()));
|
---|
143 |
|
---|
144 | /* selected state is left out: not interesting as it is always selected */
|
---|
145 | if (o.isDeleted()) {
|
---|
146 | s.append("; deleted");
|
---|
147 | }
|
---|
148 | if (!o.isVisible()) {
|
---|
149 | s.append("; deleted-on-server");
|
---|
150 | }
|
---|
151 | if (o.isModified()) {
|
---|
152 | s.append("; modified");
|
---|
153 | }
|
---|
154 | if (o.isDisabledAndHidden()) {
|
---|
155 | s.append("; filtered/hidden");
|
---|
156 | }
|
---|
157 | if (o.isDisabled()) {
|
---|
158 | s.append("; filtered/disabled");
|
---|
159 | }
|
---|
160 | if (o.hasDirectionKeys()) {
|
---|
161 | s.append("; has direction keys");
|
---|
162 | if (o.reversedDirection()) {
|
---|
163 | s.append(" (reversed)");
|
---|
164 | }
|
---|
165 | }
|
---|
166 | s.append("\n");
|
---|
167 | }
|
---|
168 |
|
---|
169 | protected void addAttributes(StringBuffer s, OsmPrimitive o) {
|
---|
170 | if (o.hasKeys()) {
|
---|
171 | s.append(" tags:\n");
|
---|
172 | for (String key: o.keySet()) {
|
---|
173 | s.append(String.format(" \"%s\"=\"%s\"\n", key, o.get(key)));
|
---|
174 | }
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 | protected void addWayReferrer(StringBuffer s, Node n) {
|
---|
179 | // add way referrer
|
---|
180 | List<OsmPrimitive> refs = n.getReferrers();
|
---|
181 | DatasetCollection<Way> wayRefs = new DatasetCollection<Way>(refs, OsmPrimitive.wayPredicate);
|
---|
182 | if (wayRefs.size() > 0) {
|
---|
183 | s.append(" way referrer:\n");
|
---|
184 | for (Way w : wayRefs) {
|
---|
185 | s.append(" "+w.getUniqueId()+"\n");
|
---|
186 | }
|
---|
187 | }
|
---|
188 | }
|
---|
189 |
|
---|
190 | protected void addRelationReferrer(StringBuffer s, OsmPrimitive o) {
|
---|
191 | List<OsmPrimitive> refs = o.getReferrers();
|
---|
192 | DatasetCollection<Relation> relRefs = new DatasetCollection<Relation>(refs, OsmPrimitive.relationPredicate);
|
---|
193 | if (relRefs.size() > 0) {
|
---|
194 | s.append(" relation referrer:\n");
|
---|
195 | for (Relation r : relRefs) {
|
---|
196 | s.append(" "+r.getUniqueId()+"\n");
|
---|
197 | }
|
---|
198 | }
|
---|
199 | }
|
---|
200 |
|
---|
201 | /**
|
---|
202 | * See if primitive is in a data set properly.
|
---|
203 | * This does not hold for primitives that are new and deleted.
|
---|
204 | */
|
---|
205 | protected boolean checkDataSet(OsmPrimitive o) {
|
---|
206 | DataSet ds = o.getDataSet();
|
---|
207 | if (ds == null)
|
---|
208 | return false;
|
---|
209 | return ds.getPrimitiveById(o) != null;
|
---|
210 | }
|
---|
211 |
|
---|
212 | protected String userString(User user) {
|
---|
213 | if (user == null)
|
---|
214 | return "<null>";
|
---|
215 |
|
---|
216 | List<String> names = user.getNames();
|
---|
217 |
|
---|
218 | StringBuffer us = new StringBuffer();
|
---|
219 |
|
---|
220 | us.append("id:"+user.getId());
|
---|
221 | if (names.size() == 1) {
|
---|
222 | us.append(" name:"+user.getName());
|
---|
223 | }
|
---|
224 | else if (names.size() > 1) {
|
---|
225 | us.append(String.format(" %d names:%s", names.size(), user.getName()));
|
---|
226 | }
|
---|
227 | return us.toString();
|
---|
228 | }
|
---|
229 | }
|
---|