Ticket #6629: coloring.patch
| File coloring.patch, 15.5 KB (added by , 15 years ago) |
|---|
-
org/openstreetmap/josm/gui/layer/CustomizeColor.java
62 62 63 63 @Override 64 64 public void actionPerformed(ActionEvent e) { 65 JColorChooser c = new JColorChooser(layers.get(0).getColor(false)); 65 Color cl=layers.get(0).getColor(false); if (cl==null) cl=Color.gray; 66 JColorChooser c = new JColorChooser(cl); 66 67 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")}; 67 68 int answer = JOptionPane.showOptionDialog( 68 69 Main.parent, -
org/openstreetmap/josm/gui/layer/GpxLayer.java
25 25 import java.util.Collection; 26 26 import java.util.Collections; 27 27 import java.util.Comparator; 28 import java.util.Date; 29 import java.util.HashMap; 28 30 import java.util.LinkedList; 29 31 import java.util.List; 32 import java.util.Map; 30 33 import java.util.concurrent.Future; 31 34 32 35 import javax.swing.AbstractAction; 33 36 import javax.swing.Action; 34 37 import javax.swing.Box; 35 38 import javax.swing.ButtonGroup; 39 import javax.swing.ButtonModel; 36 40 import javax.swing.Icon; 37 41 import javax.swing.JFileChooser; 38 42 import javax.swing.JLabel; … … 229 233 230 234 public colorModes getColorMode() { 231 235 try { 232 return colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", "layer "+getName(), 0)]; 236 int i; 237 if (isLocalFile) 238 i=Main.pref.getInteger("draw.rawgps.colors.local", "layer "+getName(), 0); 239 else 240 i=Main.pref.getInteger("draw.rawgps.colors", "layer "+getName(), 0); 241 return colorModes.values()[i]; 233 242 } catch (Exception e) { 234 243 } 235 244 return colorModes.none; … … 249 258 SeparatorLayerAction.INSTANCE, 250 259 new CustomizeColor(this), 251 260 new CustomizeLineDrawing(this), 261 new CustomizeColorMode(this), 252 262 new ConvertToDataLayerAction(), 253 263 SeparatorLayerAction.INSTANCE, 254 264 new RenameLayerAction(getAssociatedFile(), this), … … 262 272 new LayerSaveAsAction(this), 263 273 new CustomizeColor(this), 264 274 new CustomizeLineDrawing(this), 275 new CustomizeColorMode(this), 265 276 new ImportImages(), 266 277 new ImportAudio(), 267 278 new MarkersFromNamedPoins(), … … 375 386 376 387 // the different color modes 377 388 enum colorModes { 378 none, velocity, dilution, direction 389 none, velocity, dilution, direction, time 379 390 } 380 391 381 392 @Override … … 447 458 ********** STEP 2b - RE-COMPUTE CACHE DATA ********************* 448 459 ****************************************************************/ 449 460 if (!computeCacheInSync) { // don't compute if the cache is good 450 Float minval = null;451 Float maxval = null;461 double minval = +1e10; 462 double maxval = -1e10; 452 463 WayPoint oldWp = null; 453 464 if (colorModeDynamic) { 454 465 if (colored == colorModes.velocity) { … … 461 472 continue; 462 473 } 463 474 if (oldWp != null && trkPnt.time > oldWp.time) { 464 Float vel = new Float(c.greatCircleDistance(oldWp.getCoor()) / (trkPnt.time - oldWp.time)); 465 if(maxval == null || vel > maxval) maxval = vel; 466 if(minval == null || vel < minval) minval = vel; 475 double vel = c.greatCircleDistance(oldWp.getCoor()) 476 / (trkPnt.time - oldWp.time); 477 if(vel > maxval) maxval = vel; 478 if(vel < minval) minval = vel; 467 479 } 468 480 oldWp = trkPnt; 469 481 } … … 475 487 for (WayPoint trkPnt : segment.getWayPoints()) { 476 488 Object val = trkPnt.attr.get("hdop"); 477 489 if (val != null) { 478 Float hdop = (Float) val;479 if( maxval == null ||hdop > maxval) maxval = hdop;480 if( minval == null ||hdop < minval) minval = hdop;490 double hdop = ((Float) val).doubleValue(); 491 if(hdop > maxval) maxval = hdop; 492 if(hdop < minval) minval = hdop; 481 493 } 482 494 } 483 495 } … … 485 497 } 486 498 oldWp = null; 487 499 } 500 if (colored == colorModes.time) { 501 for (GpxTrack trk : data.tracks) { 502 for (GpxTrackSegment segment : trk.getSegments()) { 503 for (WayPoint trkPnt : segment.getWayPoints()) { 504 double t=trkPnt.time; 505 if (t==0) continue; // skip non-dated trackpoints 506 if(t > maxval) maxval = t; 507 if(t < minval) minval = t; 508 } 509 } 510 } 511 } 512 488 513 for (GpxTrack trk : data.tracks) { 489 514 for (GpxTrackSegment segment : trk.getSegments()) { 490 515 if (!forceLines) { // don't draw lines between segments, unless forced to … … 498 523 trkPnt.customColoring = neutralColor; 499 524 if(colored == colorModes.dilution && trkPnt.attr.get("hdop") != null) { 500 525 float hdop = ((Float) trkPnt.attr.get("hdop")).floatValue(); 501 int hdoplvl = Math.round(colorModeDynamic ? ((hdop-minval)*255/(maxval-minval))526 int hdoplvl =(int) Math.round(colorModeDynamic ? ((hdop-minval)*255/(maxval-minval)) 502 527 : (hdop <= 0 ? 0 : hdop * hdopfactor)); 503 528 // High hdop is bad, but high values in colors are green. 504 529 // Therefore inverse the logic … … 507 532 } 508 533 if (oldWp != null) { 509 534 double dist = c.greatCircleDistance(oldWp.getCoor()); 510 535 boolean noDraw=false; 511 536 switch (colored) { 512 537 case velocity: 513 538 double dtime = trkPnt.time - oldWp.time; 514 539 if(dtime > 0) { 515 540 float vel = (float) (dist / dtime); 516 int velColor = Math.round(colorModeDynamic ? ((vel-minval)*255/(maxval-minval))541 int velColor =(int) Math.round(colorModeDynamic ? ((vel-minval)*255/(maxval-minval)) 517 542 : (vel <= 0 ? 0 : vel / colorTracksTune * 255)); 518 543 trkPnt.customColoring = colors[velColor > 255 ? 255 : velColor]; 519 544 } else { … … 529 554 trkPnt.customColoring = colors_cyclic[(int) (dirColor)]; 530 555 } 531 556 break; 557 case time: 558 if (trkPnt.time>0){ 559 int tColor = (int) Math.round((trkPnt.time-minval)*255/(maxval-minval)); 560 trkPnt.customColoring = colors[tColor]; 561 } else { 562 trkPnt.customColoring = neutralColor; 563 } 564 break; 532 565 } 533 534 if ( maxLineLength == -1 || dist <= maxLineLength) {566 567 if (!noDraw && (maxLineLength == -1 || dist <= maxLineLength)) { 535 568 trkPnt.drawLine = true; 536 569 trkPnt.dir = (int) oldWp.getCoor().heading(trkPnt.getCoor()); 537 570 } else { … … 1417 1450 } 1418 1451 } 1419 1452 1453 private class CustomizeColorMode extends AbstractAction implements LayerAction, MultiLayerAction { 1454 List<Layer> layers; 1455 1456 public CustomizeColorMode(List<Layer> l) { 1457 this(); 1458 layers = l; 1459 } 1460 1461 public CustomizeColorMode(Layer l) { 1462 this(); 1463 layers = new LinkedList<Layer>(); 1464 layers.add(l); 1465 } 1466 1467 private CustomizeColorMode() { 1468 super(tr("Customize color mode"), ImageProvider.get("mapmode/addsegment")); 1469 } 1470 1471 @Override 1472 public boolean supportLayers(List<Layer> layers) { 1473 for(Layer layer: layers) { 1474 if(!(layer instanceof GpxLayer)) 1475 return false; 1476 } 1477 return true; 1478 } 1479 1480 @Override 1481 public Component createMenuComponent() { 1482 return new JMenuItem(this); 1483 } 1484 1485 @Override 1486 public Action getMultiLayerAction(List<Layer> layers) { 1487 return new CustomizeLineDrawing(layers); 1488 } 1489 1490 @Override 1491 public void actionPerformed(ActionEvent e) { 1492 1493 JRadioButton[] r = new JRadioButton[6]; 1494 Map<ButtonModel,Integer> propVals = new HashMap<ButtonModel,Integer> ();; 1495 1496 r[0] = new JRadioButton(tr("Use global settings.")); 1497 r[1] = new JRadioButton(tr("Single Color (can be customized for named layers)")); 1498 r[2] = new JRadioButton(tr("Velocity (red = slow, green = fast)")); 1499 r[3] = new JRadioButton(tr("Direction (red = west, yellow = north, green = east, blue = south)")); 1500 r[4] = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)")); 1501 r[5] = new JRadioButton(tr("Track date")); 1502 propVals.put(r[1].getModel(), 0); 1503 propVals.put(r[2].getModel(), 1); 1504 propVals.put(r[4].getModel(), 2); 1505 propVals.put(r[3].getModel(), 3); 1506 propVals.put(r[5].getModel(), 4); 1507 ButtonGroup group = new ButtonGroup(); 1508 Box panel = Box.createVerticalBox(); 1509 for (JRadioButton b : r) { 1510 group.add(b); 1511 panel.add(b); 1512 } 1513 String propbase = isLocalFile ? "draw.rawgps.colors.local" : "draw.rawgps.colors"; 1514 String propName = propbase + ".layer " + layers.get(0).getName(); 1515 if (Main.pref.hasKey(propName)) { 1516 int v = Main.pref.getInteger(propName,-1); 1517 for (int i=1;i<6;i++) { 1518 if (propVals.get(r[i].getModel()).intValue()==v) 1519 group.setSelected(r[i].getModel(), true); 1520 } 1521 } else { 1522 group.setSelected(r[0].getModel(), true); 1523 } 1524 int answer = JOptionPane.showConfirmDialog(Main.parent, panel, 1525 tr("Select color mode"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); 1526 if (answer == JOptionPane.CANCEL_OPTION || answer == JOptionPane.CLOSED_OPTION) return; 1527 for(Layer layer : layers) { 1528 propName = propbase + ".layer " + layer.getName(); 1529 if (group.getSelection() == r[0].getModel()) { 1530 Main.pref.put(propName, null); 1531 } else { 1532 Main.pref.putInteger(propName, propVals.get(group.getSelection())); 1533 } 1534 } 1535 Main.map.repaint(); 1536 } 1537 } 1538 1420 1539 private class MarkersFromNamedPoins extends AbstractAction { 1421 1540 1422 1541 public MarkersFromNamedPoins() { -
org/openstreetmap/josm/gui/preferences/DrawingPreference.java
46 46 private JRadioButton colorTypeVelocity = new JRadioButton(tr("Velocity (red = slow, green = fast)")); 47 47 private JRadioButton colorTypeDirection = new JRadioButton(tr("Direction (red = west, yellow = north, green = east, blue = south)")); 48 48 private JRadioButton colorTypeDilution = new JRadioButton(tr("Dilution of Position (red = high, green = low, if available)")); 49 private JRadioButton colorTypeTime = new JRadioButton(tr("Track date")); 49 50 private JRadioButton colorTypeNone = new JRadioButton(tr("Single Color (can be customized for named layers)")); 50 51 private JComboBox colorTypeVelocityTune = new JComboBox(new String[] {tr("Car"), tr("Bicycle"), tr("Foot")}); 51 52 private JCheckBox directionHint = new JCheckBox(tr("Draw Direction Arrows")); … … 173 174 colorGroup.add(colorTypeVelocity); 174 175 colorGroup.add(colorTypeDirection); 175 176 colorGroup.add(colorTypeDilution); 177 colorGroup.add(colorTypeTime); 176 178 177 179 colorTypeVelocity.addChangeListener(new ChangeListener(){ 178 180 public void stateChanged(ChangeEvent e) { … … 199 201 case 3: 200 202 colorTypeDirection.setSelected(true); 201 203 break; 204 case 4: 205 colorTypeTime.setSelected(true); 206 break; 202 207 } 203 208 204 209 colorTypeNone.setToolTipText(tr("All points and track segments will have the same color. Can be customized in Layer Manager.")); 205 210 colorTypeVelocity.setToolTipText(tr("Colors points and track segments by velocity.")); 206 211 colorTypeDirection.setToolTipText(tr("Colors points and track segments by direction.")); 207 212 colorTypeDilution.setToolTipText(tr("Colors points and track segments by dilution of position (HDOP). Your capture device needs to log that information.")); 213 colorTypeTime.setToolTipText(tr("Colors points and track segments by its timestamp.")); 208 214 209 215 // color Tracks by Velocity Tune 210 216 int ccts = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45); … … 220 226 panel.add(colorTypeVelocityTune, GBC.eop().insets(5,0,0,5)); 221 227 panel.add(colorTypeDirection, GBC.eol().insets(40,0,0,0)); 222 228 panel.add(colorTypeDilution, GBC.eol().insets(40,0,0,0)); 229 panel.add(colorTypeTime, GBC.eol().insets(40,0,0,0)); 230 223 231 colorDynamic.setToolTipText(tr("Draw direction arrows for lines, connecting GPS points.")); 224 232 colorDynamic.setSelected(Main.pref.getBoolean("draw.rawgps.colors.dynamic", false)); 225 233 colorDynamic.setEnabled(colorTypeVelocity.isSelected() || colorTypeDilution.isSelected()); … … 319 327 Main.pref.putInteger("draw.rawgps.colors", 2); 320 328 } else if(colorTypeDirection.isSelected()) { 321 329 Main.pref.putInteger("draw.rawgps.colors", 3); 330 } else if(colorTypeTime.isSelected()) { 331 Main.pref.putInteger("draw.rawgps.colors", 4); 322 332 } else { 323 333 Main.pref.putInteger("draw.rawgps.colors", 0); 324 334 }
