- Timestamp:
- 2015-06-19T21:17:27+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
r8308 r8498 7 7 import java.awt.Dimension; 8 8 import java.awt.GridBagLayout; 9 import java.text.Collator; 9 10 import java.util.ArrayList; 10 11 import java.util.Collection; 11 12 import java.util.Collections; 12 13 import java.util.List; 14 import java.util.Locale; 15 import java.util.Map; 13 16 import java.util.Map.Entry; 17 import java.util.TreeMap; 14 18 15 19 import javax.swing.JPanel; … … 62 66 protected transient List<OsmPrimitive> primitives; 63 67 protected transient OsmDataLayer layer; 64 private JosmTextArea txtMappaint;65 68 private boolean mappaintTabLoaded; 69 private boolean editcountTabLoaded; 66 70 67 71 public InspectPrimitiveDialog(Collection<OsmPrimitive> primitives, OsmDataLayer layer) { … … 74 78 setButtonIcons(new String[]{"ok.png"}); 75 79 final JTabbedPane tabs = new JTabbedPane(); 76 JPanel pData = buildDataPanel(); 77 tabs.addTab(tr("data"), pData); 80 81 tabs.addTab(tr("data"), genericMonospacePanel(new JPanel(), buildDataText())); 82 78 83 final JPanel pMapPaint = new JPanel(); 79 84 tabs.addTab(tr("map style"), pMapPaint); … … 84 89 if (!mappaintTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 1) { 85 90 mappaintTabLoaded = true; 86 buildMapPaintPanel(pMapPaint); 87 createMapPaintText(); 91 genericMonospacePanel(pMapPaint, buildMapPaintText()); 88 92 } 89 93 } 90 94 }); 95 96 final JPanel pEditCounts = new JPanel(); 97 tabs.addTab(tr("edit counts"), pEditCounts); 98 tabs.getModel().addChangeListener(new ChangeListener() { 99 100 @Override 101 public void stateChanged(ChangeEvent e) { 102 if (!editcountTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 2) { 103 editcountTabLoaded = true; 104 genericMonospacePanel(pEditCounts, buildListOfEditorsText()); 105 } 106 } 107 }); 108 91 109 setContent(tabs, false); 92 110 } 93 111 94 protected JPanel buildDataPanel() { 95 JPanel p = new JPanel(new GridBagLayout()); 96 JosmTextArea txtData = new JosmTextArea(); 97 txtData.setFont(GuiHelper.getMonospacedFont(txtData)); 98 txtData.setEditable(false); 99 txtData.setText(buildDataText()); 100 txtData.setSelectionStart(0); 101 txtData.setSelectionEnd(0); 102 103 JScrollPane scroll = new JScrollPane(txtData); 104 105 p.add(scroll, GBC.std().fill()); 112 protected JPanel genericMonospacePanel(JPanel p, String s) { 113 p.setLayout(new GridBagLayout()); 114 JosmTextArea jte = new JosmTextArea(); 115 jte.setFont(GuiHelper.getMonospacedFont(jte)); 116 jte.setEditable(false); 117 jte.append(s); 118 p.add(new JScrollPane(jte), GBC.std().fill()); 106 119 return p; 107 120 } … … 322 335 } 323 336 324 protected void buildMapPaintPanel(JPanel p) { 325 p.setLayout(new GridBagLayout()); 326 txtMappaint = new JosmTextArea(); 327 txtMappaint.setFont(GuiHelper.getMonospacedFont(txtMappaint)); 328 txtMappaint.setEditable(false); 329 330 p.add(new JScrollPane(txtMappaint), GBC.std().fill()); 331 } 332 333 protected void createMapPaintText() { 337 protected String buildMapPaintText() { 334 338 final Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getAllSelected(); 335 339 ElemStyles elemstyles = MapPaintStyles.getStyles(); … … 337 341 double scale = nc.getDist100Pixel(); 338 342 343 final StringBuilder txtMappaint = new StringBuilder(); 339 344 MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock(); 340 345 try { … … 350 355 txtMappaint.append(tr("\nRange:{0}", mc.range)); 351 356 for (Entry<String, Cascade> e : mc.getLayers()) { 352 txtMappaint.append("\n " + e.getKey() + ": \n" +e.getValue());357 txtMappaint.append("\n ").append(e.getKey()).append(": \n").append(e.getValue()); 353 358 } 354 359 } else { … … 359 364 StyleList sl = elemstyles.get(osm, scale, nc); 360 365 for (ElemStyle s : sl) { 361 txtMappaint.append(" * " + s +"\n");366 txtMappaint.append(" * ").append(s).append("\n"); 362 367 } 363 368 txtMappaint.append("\n\n"); … … 380 385 } 381 386 } 387 return txtMappaint.toString(); 388 } 389 390 /* Future Ideas: 391 Calculate the most recent edit date from o.getTimestamp(). 392 Sort by the count for presentation, so the most active editors are on top. 393 Count only tagged nodes (so empty way nodes don't inflate counts). 394 */ 395 protected String buildListOfEditorsText() { 396 final StringBuilder s = new StringBuilder(); 397 final Map<String, Integer> editCountByUser = new TreeMap<>(Collator.getInstance(Locale.getDefault())); 398 399 // Count who edited each selected object 400 for (OsmPrimitive o : primitives) { 401 if (o.getUser() != null) { 402 String username = o.getUser().getName(); 403 Integer oldCount = editCountByUser.get(username); 404 if (oldCount == null) { 405 editCountByUser.put(username, 1); 406 } else { 407 editCountByUser.put(username, oldCount + 1); 408 } 409 } 410 } 411 412 // Print the count in sorted order 413 s.append(trn("{0} user last edited the selection:", "{0} users last edited the selection:", 414 editCountByUser.size(), editCountByUser.size())); 415 s.append("\n\n"); 416 for (Map.Entry<String, Integer> entry : editCountByUser.entrySet()) { 417 final String username = entry.getKey(); 418 final Integer editCount = entry.getValue(); 419 s.append(String.format("%6d %s\n", editCount, username)); 420 } 421 return s.toString(); 382 422 } 383 423
Note:
See TracChangeset
for help on using the changeset viewer.