- Timestamp:
- 2011-07-13T10:41:01+02:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r4200 r4230 290 290 } 291 291 292 synchronized public boolean getBoolean(final String key, final String specName, final boolean def) { 293 putDefault(key, Boolean.toString(def)); 294 String skey = key+"."+specName; 295 if(properties.containsKey(skey)) 296 return Boolean.parseBoolean(properties.get(skey)); 297 return properties.containsKey(key) ? Boolean.parseBoolean(properties.get(key)) : def; 298 } 299 292 300 /** 293 301 * Set a value for a certain setting. The changed setting is saved … … 608 616 } 609 617 618 synchronized public int getInteger(String key, String specName, int def) { 619 putDefault(key, Integer.toString(def)); 620 String v = get(key+"."+specName); 621 if(null == v) 622 v = get(key); 623 if(null == v) 624 return def; 625 626 try { 627 return Integer.parseInt(v); 628 } catch(NumberFormatException e) { 629 // fall out 630 } 631 return def; 632 } 633 610 634 synchronized public long getLong(String key, long def) { 611 635 putDefault(key, Long.toString(def)); -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListDialog.java
r4191 r4230 5 5 6 6 import java.awt.BorderLayout; 7 import java.awt.Color; 7 8 import java.awt.Component; 8 9 import java.awt.Dimension; … … 821 822 } 822 823 823 private staticclass LayerNameCellRenderer extends DefaultTableCellRenderer {824 private class LayerNameCellRenderer extends DefaultTableCellRenderer { 824 825 825 826 protected boolean isActiveLayer(Layer layer) { … … 838 839 if (isActiveLayer(layer)) { 839 840 label.setFont(label.getFont().deriveFont(Font.BOLD)); 841 } 842 if(Main.pref.getBoolean("dialog.layer.colorname", true)) { 843 Color c = layer.getColor(false); 844 if(c != null) { 845 Color oc = null; 846 for(Layer l : model.getLayers()) { 847 oc = l.getColor(false); 848 if(oc != null) { 849 if(oc.equals(c)) 850 oc = null; 851 else 852 break; 853 } 854 } 855 if(oc == null) /* not more than one color, don't use coloring */ 856 c = null; 857 } 858 /* Setting foreground properly handles null as default! */ 859 label.setForeground(c); 840 860 } 841 861 label.setIcon(layer.getIcon()); … … 1231 1251 * Never null, but can be empty. 1232 1252 */ 1233 p rotectedList<Layer> getLayers() {1253 public List<Layer> getLayers() { 1234 1254 if (Main.map == null || Main.map.mapView == null) 1235 1255 return Collections.<Layer>emptyList(); -
trunk/src/org/openstreetmap/josm/gui/dialogs/LayerListPopup.java
r3753 r4230 19 19 import org.openstreetmap.josm.gui.layer.Layer; 20 20 import org.openstreetmap.josm.gui.layer.Layer.LayerAction; 21 import org.openstreetmap.josm.gui.layer.Layer.MultiLayerAction; 21 22 import org.openstreetmap.josm.gui.layer.Layer.SeparatorLayerAction; 22 23 import org.openstreetmap.josm.tools.ImageProvider; … … 59 60 } else if (a instanceof LayerAction && ((LayerAction)a).supportLayers(selectedLayers)) { 60 61 separatorAdded = false; 62 if(a instanceof MultiLayerAction) 63 a = ((MultiLayerAction)a).getMultiLayerAction(selectedLayers); 61 64 actions.add(a); 62 65 } … … 66 69 separatorAdded = false; 67 70 for (Action a: selectedLayers.get(i).getMenuEntries()) { 68 if (a instanceof LayerAction && ((LayerAction)a).supportLayers(selectedLayers) && !actions.contains(a)) { 71 if (a instanceof LayerAction && !(a instanceof MultiLayerAction) 72 && ((LayerAction)a).supportLayers(selectedLayers) && !actions.contains(a)) { 69 73 if (!separatorAdded) { 70 74 separatorAdded = true; -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r4208 r4230 10 10 import java.awt.BasicStroke; 11 11 import java.awt.Color; 12 import java.awt.Component; 12 13 import java.awt.Dimension; 13 14 import java.awt.Graphics2D; … … 34 35 import javax.swing.ButtonGroup; 35 36 import javax.swing.Icon; 36 import javax.swing.JColorChooser;37 37 import javax.swing.JFileChooser; 38 38 import javax.swing.JLabel; 39 39 import javax.swing.JList; 40 import javax.swing.JMenuItem; 40 41 import javax.swing.JOptionPane; 41 42 import javax.swing.JPanel; … … 219 220 } 220 221 221 static public Color getColor(String name) { 222 return Main.pref.getColor(marktr("gps point"), name != null ? "layer " + name : null, Color.gray); 222 @Override 223 public Color getColor(boolean ignoreCustom) { 224 Color c = Main.pref.getColor(marktr("gps point"), "layer " + getName(), Color.gray); 225 226 return ignoreCustom || getColorMode() == colorModes.none ? c : null; 227 } 228 229 public colorModes getColorMode() { 230 try { 231 return colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", "layer "+getName(), 0)]; 232 } catch (Exception e) { 233 } 234 return colorModes.none; 235 } 236 237 /* for preferences */ 238 static public Color getGenericColor() { 239 return Main.pref.getColor(marktr("gps point"), Color.gray); 223 240 } 224 241 … … 230 247 LayerListDialog.getInstance().createDeleteLayerAction(), 231 248 SeparatorLayerAction.INSTANCE, 232 new CustomizeColor(), 233 new CustomizeLineDrawing(), 249 new CustomizeColor(this), 250 new CustomizeLineDrawing(this), 234 251 new ConvertToDataLayerAction(), 235 252 SeparatorLayerAction.INSTANCE, … … 243 260 new LayerSaveAction(this), 244 261 new LayerSaveAsAction(this), 245 new CustomizeColor(), 246 new CustomizeLineDrawing(), 262 new CustomizeColor(this), 263 new CustomizeLineDrawing(this), 247 264 new ImportImages(), 248 265 new ImportAudio(), … … 375 392 ****************************************************************/ 376 393 // Long startTime = System.currentTimeMillis(); 377 Color neutralColor = getColor( getName());394 Color neutralColor = getColor(true); 378 395 // also draw lines between points belonging to different segments 379 boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force"); 396 boolean forceLines = Main.pref.getBoolean("draw.rawgps.lines.force", "layer "+getName(), false); 380 397 // draw direction arrows on the lines 381 boolean direction = Main.pref.getBoolean("draw.rawgps.direction"); 398 boolean direction = Main.pref.getBoolean("draw.rawgps.direction", "layer "+getName(), false); 382 399 // don't draw lines if longer than x meters 383 int lineWidth = Main.pref.getInteger("draw.rawgps.linewidth",0); 400 int lineWidth = Main.pref.getInteger("draw.rawgps.linewidth", "layer "+getName(), 0); 384 401 385 402 int maxLineLength; 403 boolean lines; 386 404 if (this.isLocalFile) { 387 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", -1); 405 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length.local", "layer "+getName(), -1); 406 lines = Main.pref.getBoolean("draw.rawgps.lines.local", "layer "+getName(), true); 388 407 } else { 389 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", 200); 390 } 391 // draw line between points, global setting 392 boolean lines = (Main.pref.getBoolean("draw.rawgps.lines", true) || (Main.pref 393 .getBoolean("draw.rawgps.lines.localfiles") && this.isLocalFile)); 394 String linesKey = "draw.rawgps.lines.layer " + getName(); 395 // draw lines, per-layer setting 396 if (Main.pref.hasKey(linesKey)) { 397 lines = Main.pref.getBoolean(linesKey); 408 maxLineLength = Main.pref.getInteger("draw.rawgps.max-line-length", "layer "+getName(), 200); 409 lines = Main.pref.getBoolean("draw.rawgps.lines", "layer "+getName(), true); 398 410 } 399 411 // paint large dots for points 400 boolean large = Main.pref.getBoolean("draw.rawgps.large"); 401 boolean hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", true); 412 boolean large = Main.pref.getBoolean("draw.rawgps.large", "layer "+getName(), false); 413 int largesize = Main.pref.getInteger("draw.rawgps.large.size", "layer "+getName(), 3); 414 boolean hdopcircle = Main.pref.getBoolean("draw.rawgps.hdopcircle", "layer "+getName(), false); 402 415 // color the lines 403 colorModes colored = colorModes.none; 404 try { 405 colored = colorModes.values()[Main.pref.getInteger("draw.rawgps.colors", 0)]; 406 } catch (Exception e) { 407 } 416 colorModes colored = getColorMode(); 408 417 // paint direction arrow with alternate math. may be faster 409 boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection"); 418 boolean alternatedirection = Main.pref.getBoolean("draw.rawgps.alternatedirection", "layer "+getName(), false); 410 419 // don't draw arrows nearer to each other than this 411 int delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", 40); 420 int delta = Main.pref.getInteger("draw.rawgps.min-arrow-distance", "layer "+getName(), 40); 412 421 // allows to tweak line coloring for different speed levels. 413 int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", 45); 422 int colorTracksTune = Main.pref.getInteger("draw.rawgps.colorTracksTune", "layer "+getName(), 45); 414 423 415 424 if(lineWidth != 0) … … 640 649 } 641 650 if (large) { 642 g.fillRect(screen.x-1, screen.y-1, 3, 3);651 g.fillRect(screen.x-1, screen.y-1, largesize, largesize); 643 652 } 644 653 } // end for trkpnt … … 1296 1305 } 1297 1306 1298 private class CustomizeLineDrawing extends AbstractAction { 1299 1300 CustomizeLineDrawing() { 1307 private class CustomizeLineDrawing extends AbstractAction implements LayerAction, MultiLayerAction { 1308 List<Layer> layers; 1309 1310 public CustomizeLineDrawing(List<Layer> l) { 1311 this(); 1312 layers = l; 1313 } 1314 1315 public CustomizeLineDrawing(Layer l) { 1316 this(); 1317 layers = new LinkedList<Layer>(); 1318 layers.add(l); 1319 } 1320 1321 private CustomizeLineDrawing() { 1301 1322 super(tr("Customize line drawing"), ImageProvider.get("mapmode/addsegment")); 1323 } 1324 1325 @Override 1326 public boolean supportLayers(List<Layer> layers) { 1327 for(Layer layer: layers) { 1328 if(!(layer instanceof GpxLayer)) 1329 return false; 1330 } 1331 return true; 1332 } 1333 1334 @Override 1335 public Component createMenuComponent() { 1336 return new JMenuItem(this); 1337 } 1338 1339 @Override 1340 public Action getMultiLayerAction(List<Layer> layers) { 1341 return new CustomizeLineDrawing(layers); 1302 1342 } 1303 1343 1304 1344 @Override 1305 1345 public void actionPerformed(ActionEvent e) { 1346 /* FIXME: Add all the other GPX settings here as well. Unify with DrawingPreferences 1347 Each option should be able to "use global settings". Attention with the handling 1348 of local layer for the two local layer options! */ 1306 1349 JRadioButton[] r = new JRadioButton[3]; 1307 1350 r[0] = new JRadioButton(tr("Use global settings.")); … … 1314 1357 panel.add(b); 1315 1358 } 1316 String propName = "draw.rawgps.lines.layer " + getName(); 1359 String propbase = isLocalFile ? "draw.rawgps.lines.local" : "draw.rawgps.lines"; 1360 String propName = propbase + ".layer " + layers.get(0).getName(); 1317 1361 if (Main.pref.hasKey(propName)) { 1318 1362 group.setSelected(r[Main.pref.getBoolean(propName) ? 1 : 2].getModel(), true); … … 1329 1373 // continue 1330 1374 } 1331 if (group.getSelection() == r[0].getModel()) { 1332 Main.pref.put(propName, null); 1333 } else { 1334 Main.pref.put(propName, group.getSelection() == r[1].getModel()); 1375 for(Layer layer : layers) { 1376 propName = propbase + ".layer " + layer.getName(); 1377 if (group.getSelection() == r[0].getModel()) { 1378 Main.pref.put(propName, null); 1379 } else { 1380 Main.pref.put(propName, group.getSelection() == r[1].getModel()); 1381 } 1335 1382 } 1336 1383 Main.map.repaint(); 1337 1384 } 1338 }1339 1340 private class CustomizeColor extends AbstractAction {1341 1342 public CustomizeColor() {1343 super(tr("Customize Color"), ImageProvider.get("colorchooser"));1344 putValue("help", ht("/Action/LayerCustomizeColor"));1345 }1346 1347 @Override1348 public void actionPerformed(ActionEvent e) {1349 JColorChooser c = new JColorChooser(getColor(getName()));1350 Object[] options = new Object[] { tr("OK"), tr("Cancel"), tr("Default") };1351 int answer = JOptionPane.showOptionDialog(1352 Main.parent,1353 c,1354 tr("Choose a color"),1355 JOptionPane.OK_CANCEL_OPTION,1356 JOptionPane.PLAIN_MESSAGE,1357 null,1358 options, options[0]1359 );1360 switch (answer) {1361 case 0:1362 Main.pref.putColor("layer " + getName(), c.getColor());1363 break;1364 case 1:1365 return;1366 case 2:1367 Main.pref.putColor("layer " + getName(), null);1368 break;1369 }1370 Main.map.repaint();1371 }1372 1373 1385 } 1374 1386 -
trunk/src/org/openstreetmap/josm/gui/layer/Layer.java
r4183 r4230 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.awt.Color; 7 8 import java.awt.Component; 8 9 import java.awt.Graphics2D; … … 53 54 } 54 55 56 public interface MultiLayerAction { 57 Action getMultiLayerAction(List<Layer> layers); 58 } 59 60 55 61 /** 56 62 * Special class that can be returned by getMenuEntries when JSeparator needs to be created … … 128 134 */ 129 135 abstract public Icon getIcon(); 136 137 /** 138 * Return a Color for this layer. Return null when no color specified. 139 * @param ignoreCustom Custom color should return null, as no default color 140 * is used. When this is true, then even for custom coloring the base 141 * color is returned - mainly for layer internal use. 142 */ 143 public Color getColor(boolean ignoreCustom) { 144 return null; 145 } 130 146 131 147 /** -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r3754 r4230 24 24 import javax.swing.Icon; 25 25 import javax.swing.JCheckBoxMenuItem; 26 import javax.swing.JColorChooser;27 26 import javax.swing.JOptionPane; 28 27 import javax.swing.SwingUtilities; … … 39 38 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 40 39 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 40 import org.openstreetmap.josm.gui.layer.CustomizeColor; 41 41 import org.openstreetmap.josm.gui.layer.GpxLayer; 42 42 import org.openstreetmap.josm.gui.layer.Layer; … … 149 149 } 150 150 151 static public Color getColor(String name) 151 @Override 152 public Color getColor(boolean ignoreCustom) 152 153 { 154 String name = getName(); 153 155 return Main.pref.getColor(marktr("gps marker"), name != null ? "layer "+name : null, Color.gray); 156 } 157 158 /* for preferences */ 159 static public Color getGenericColor() 160 { 161 return Main.pref.getColor(marktr("gps marker"), Color.gray); 154 162 } 155 163 156 164 @Override public void paint(Graphics2D g, MapView mv, Bounds box) { 157 165 boolean showTextOrIcon = isTextOrIconShown(); 158 g.setColor(getColor( getName()));166 g.setColor(getColor(true)); 159 167 160 168 if (mousePressed) { … … 203 211 components.add(LayerListDialog.getInstance().createDeleteLayerAction()); 204 212 components.add(SeparatorLayerAction.INSTANCE); 205 components.add(new CustomizeColor()); 213 components.add(new CustomizeColor(this)); 206 214 components.add(SeparatorLayerAction.INSTANCE); 207 215 components.add(new SynchronizeAudio()); … … 396 404 } 397 405 398 399 406 @Override 400 407 public boolean supportLayers(List<Layer> layers) { 401 408 return layers.size() == 1 && layers.get(0) instanceof MarkerLayer; 402 }403 }404 405 private class CustomizeColor extends AbstractAction {406 407 public CustomizeColor() {408 super(tr("Customize Color"), ImageProvider.get("colorchooser"));409 putValue("help", ht("/Action/LayerCustomizeColor"));410 }411 412 @Override413 public void actionPerformed(ActionEvent e) {414 JColorChooser c = new JColorChooser(getColor(getName()));415 Object[] options = new Object[]{tr("OK"), tr("Cancel"), tr("Default")};416 int answer = JOptionPane.showOptionDialog(417 Main.parent,418 c,419 tr("Choose a color"),420 JOptionPane.OK_CANCEL_OPTION,421 JOptionPane.PLAIN_MESSAGE,422 null,423 options,424 options[0]425 );426 switch (answer) {427 case 0:428 Main.pref.putColor("layer "+getName(), c.getColor());429 break;430 case 1:431 return;432 case 2:433 Main.pref.putColor("layer "+getName(), null);434 break;435 }436 Main.map.repaint();437 409 } 438 410 } -
trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java
r4162 r4230 249 249 ConflictColors.getColors(); 250 250 Severity.getColors(); 251 MarkerLayer.get Color(null);252 GpxLayer.get Color(null);251 MarkerLayer.getGenericColor(); 252 GpxLayer.getGenericColor(); 253 253 OsmDataLayer.getOutsideColor(); 254 254 ImageryLayer.getFadeColor(); -
trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java
r4208 r4230 83 83 84 84 /* ensure that default is in data base */ 85 Boolean lf = Main.pref.getBoolean("draw.rawgps.lines.local files", false);85 Boolean lf = Main.pref.getBoolean("draw.rawgps.lines.local", true); 86 86 if(Main.pref.getBoolean("draw.rawgps.lines", true)) { 87 87 drawRawGpsLinesAll.setSelected(true); … … 158 158 159 159 // hdopCircleGpsPoints 160 hdopCircleGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.hdopcircle", true));160 hdopCircleGpsPoints.setSelected(Main.pref.getBoolean("draw.rawgps.hdopcircle", false)); 161 161 hdopCircleGpsPoints.setToolTipText(tr("Draw a circle form HDOP value.")); 162 162 panel.add(hdopCircleGpsPoints, GBC.eop().insets(20,0,0,0)); … … 296 296 Main.pref.put("draw.data.area_outline_only", outlineOnly.isSelected()); 297 297 Main.pref.put("draw.rawgps.lines", drawRawGpsLinesAll.isSelected()); 298 Main.pref.put("draw.rawgps.lines.local files",drawRawGpsLinesLocal.isSelected());298 Main.pref.put("draw.rawgps.lines.local", drawRawGpsLinesAll.isSelected() || drawRawGpsLinesLocal.isSelected()); 299 299 Main.pref.put("draw.rawgps.max-line-length", drawRawGpsMaxLineLength.getText()); 300 300 Main.pref.put("draw.rawgps.max-line-length.local", drawRawGpsMaxLineLengthLocal.getText());
Note:
See TracChangeset
for help on using the changeset viewer.