- Timestamp:
- 2011-02-02T23:03:00+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 18 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r3840 r3848 31 31 import org.openstreetmap.josm.Main; 32 32 import org.openstreetmap.josm.tools.ColorHelper; 33 import org.openstreetmap.josm.tools.Utils; 33 34 34 35 /** … … 668 669 669 670 synchronized public boolean putCollection(String key, Collection<String> val) { 670 return put(key, join("\u001e", val));671 return put(key, Utils.join("\u001e", val)); 671 672 } 672 673 673 674 synchronized private void putCollectionDefault(String key, Collection<String> val) { 674 putDefault(key, join("\u001e", val));675 putDefault(key, Utils.join("\u001e", val)); 675 676 } 676 677 … … 767 768 putCollection("pluginmanager.sites", sites); 768 769 } 769 770 /**771 * Joins a collection of strings into a single string with fields772 * separated by the value of sep.773 * @param sep the separator774 * @param values collection of strings, null strings are converted to the775 * empty string776 * @return null if values is null. The joined string otherwise.777 */778 public static String join(String sep, Collection<?> values) {779 if (values == null)780 return null;781 if (values.isEmpty())782 return "";783 StringBuilder s = null;784 for (Object a : values) {785 if (a == null) {786 a = "";787 }788 if(s != null) {789 s.append(sep).append(a.toString());790 } else {791 s = new StringBuilder(a.toString());792 }793 }794 return s.toString();795 }796 797 770 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java
r3801 r3848 10 10 import java.util.List; 11 11 12 import javax.swing.event.ChangeEvent; 12 13 import javax.swing.JPanel; 13 14 import javax.swing.JScrollPane; 15 import javax.swing.JTabbedPane; 14 16 import javax.swing.JTextArea; 17 import javax.swing.SingleSelectionModel; 18 import javax.swing.event.ChangeListener; 15 19 16 20 import org.openstreetmap.josm.Main; … … 24 28 import org.openstreetmap.josm.data.osm.User; 25 29 import org.openstreetmap.josm.data.osm.Way; 30 import org.openstreetmap.josm.gui.DefaultNameFormatter; 31 import org.openstreetmap.josm.gui.NavigatableComponent; 32 import org.openstreetmap.josm.gui.mappaint.ElemStyle; 33 import org.openstreetmap.josm.gui.mappaint.ElemStyles; 34 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 35 import org.openstreetmap.josm.gui.mappaint.MultiCascade; 36 import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList; 37 import org.openstreetmap.josm.gui.mappaint.StyleSource; 38 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 39 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 26 40 import org.openstreetmap.josm.tools.DateUtils; 27 41 import org.openstreetmap.josm.tools.GBC; … … 38 52 public class InspectPrimitiveDialog extends ExtendedDialog { 39 53 protected Collection<OsmPrimitive> primitives; 40 protected JTextArea textArea; 54 private JTextArea txtData; 55 private JTextArea txtMappaint; 56 boolean mappaintTabLoaded; 41 57 42 58 public InspectPrimitiveDialog(Collection<OsmPrimitive> primitives) { 43 59 super(Main.parent, tr("Advanced object info"), new String[] {"Close"}); 44 60 this.primitives = primitives; 45 setPreferredSize(new Dimension( 450, 350));61 setPreferredSize(new Dimension(750, 550)); 46 62 47 63 setButtonIcons(new String[] {"ok.png"}); 48 JPanel p = buildPanel(); 49 textArea.setText(buildText()); 50 setContent(p, false); 51 } 52 53 protected JPanel buildPanel() { 64 final JTabbedPane tabs = new JTabbedPane(); 65 JPanel pData = buildDataPanel(); 66 tabs.addTab(tr("data"), pData); 67 final JPanel pMapPaint = new JPanel(); 68 tabs.addTab(tr("map style"), pMapPaint); 69 tabs.getModel().addChangeListener(new ChangeListener() { 70 71 @Override 72 public void stateChanged(ChangeEvent e) { 73 if (!mappaintTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 1) { 74 mappaintTabLoaded = true; 75 buildMapPaintPanel(pMapPaint); 76 createMapPaintText(); 77 } 78 } 79 }); 80 txtData.setText(buildDataText()); 81 setContent(tabs, false); 82 } 83 84 protected JPanel buildDataPanel() { 54 85 JPanel p = new JPanel(new GridBagLayout()); 55 t extArea = new JTextArea();56 t extArea.setFont(new Font("Monospaced", textArea.getFont().getStyle(), textArea.getFont().getSize()));57 t extArea.setEditable(false);58 59 JScrollPane scroll = new JScrollPane(t extArea);86 txtData = new JTextArea(); 87 txtData.setFont(new Font("Monospaced", txtData.getFont().getStyle(), txtData.getFont().getSize())); 88 txtData.setEditable(false); 89 90 JScrollPane scroll = new JScrollPane(txtData); 60 91 61 92 p.add(scroll, GBC.std().fill()); … … 63 94 } 64 95 65 protected String build Text() {96 protected String buildDataText() { 66 97 StringBuilder s = new StringBuilder(); 67 98 for (Node n : new SubclassFilteredCollection<OsmPrimitive, Node>(primitives, OsmPrimitive.nodePredicate)) { … … 229 260 return us.toString(); 230 261 } 262 263 protected void buildMapPaintPanel(JPanel p) { 264 p.setLayout(new GridBagLayout()); 265 txtMappaint = new JTextArea(); 266 txtMappaint.setFont(new Font("Monospaced", txtMappaint.getFont().getStyle(), txtMappaint.getFont().getSize())); 267 txtMappaint.setEditable(false); 268 269 p.add(new JScrollPane(txtMappaint), GBC.std().fill()); 270 } 271 272 protected void createMapPaintText() { 273 final Collection<OsmPrimitive> sel = Main.main.getCurrentDataSet().getSelected(); 274 ElemStyles elemstyles = MapPaintStyles.getStyles(); 275 NavigatableComponent nc = Main.map.mapView; 276 double scale = nc.getDist100Pixel(); 277 278 for (OsmPrimitive osm : sel) { 279 txtMappaint.append("Styles Cache for \""+osm.getDisplayName(DefaultNameFormatter.getInstance())+"\":"); 280 281 MultiCascade mc = new MultiCascade(); 282 283 for (StyleSource s : elemstyles.getStyleSources()) { 284 if (s.active) { 285 txtMappaint.append("\n\n> applying "+getSort(s)+" style \""+s.getDisplayString()+"\n"); 286 s.apply(mc, osm, scale, null, false); 287 txtMappaint.append("\nRange:"+mc.range); 288 for (String key : mc.keySet()) { 289 txtMappaint.append("\n "+key+": \n"+mc.get(key)); 290 } 291 } else { 292 txtMappaint.append("\n\n> skipping \""+s.getDisplayString()+"\" (not active)"); 293 } 294 } 295 txtMappaint.append("\n\nList of generated Styles:\n"); 296 StyleList sl = elemstyles.get(osm, scale, nc); 297 for (ElemStyle s : sl) { 298 txtMappaint.append(" * "+s+"\n"); 299 } 300 txtMappaint.append("\n\n"); 301 } 302 } 303 304 private String getSort(StyleSource s) { 305 if (s instanceof XmlStyleSource) 306 return "xml"; 307 if (s instanceof MapCSSStyleSource) 308 return "mapcss"; 309 return "unkown"; 310 } 311 231 312 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r3843 r3848 7 7 import java.awt.Dimension; 8 8 import java.awt.Point; 9 import java.awt.Rectangle;10 9 import java.awt.event.ActionEvent; 11 10 import java.awt.event.KeyEvent; … … 22 21 import javax.swing.JTable; 23 22 import javax.swing.ListSelectionModel; 23 import javax.swing.SwingUtilities; 24 24 import javax.swing.UIManager; 25 25 import javax.swing.event.ListSelectionEvent; … … 29 29 import org.openstreetmap.josm.Main; 30 30 import org.openstreetmap.josm.gui.SideButton; 31 import org.openstreetmap.josm.gui.mappaint.ElemStyles;32 31 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 32 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintStyleLoader; 33 33 import org.openstreetmap.josm.gui.mappaint.StyleSource; 34 34 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; … … 151 151 model.fireTableDataChanged(); 152 152 } 153 ElemStyles.cacheIdx++;153 MapPaintStyles.getStyles().clearCached(); 154 154 Main.map.mapView.preferenceChanged(null); 155 155 Main.map.mapView.repaint(); … … 207 207 @Override 208 208 public void actionPerformed(ActionEvent e) { 209 int[] pos = tblStyles.getSelectedRows(); 210 for (int p : pos) { 211 StyleSource s = model.data.get(p); 212 s.loadStyleSource(); 213 } 214 ElemStyles.cacheIdx++; 215 Main.map.mapView.preferenceChanged(null); 216 Main.map.mapView.repaint(); 217 } 218 } 219 209 210 final int[] rows = tblStyles.getSelectedRows(); 211 List<StyleSource> sources = new ArrayList<StyleSource>(); 212 for (int p : rows) { 213 sources.add(model.data.get(p)); 214 } 215 Main.worker.submit(new MapPaintStyleLoader(sources)); 216 Main.worker.submit(new Runnable() { 217 @Override 218 public void run() { 219 SwingUtilities.invokeLater(new Runnable() { 220 @Override 221 public void run() { 222 if (rows.length == 1) { 223 model.fireTableCellUpdated(rows[0], 1); 224 } else { 225 model.fireTableDataChanged(); 226 } 227 MapPaintStyles.getStyles().clearCached(); 228 Main.map.mapView.preferenceChanged(null); 229 Main.map.mapView.repaint(); 230 } 231 }); 232 } 233 }); 234 } 235 } 236 220 237 class PopupMenuHandler extends PopupMenuLauncher { 221 238 @Override -
trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
r3836 r3848 21 21 22 22 public static AreaElemStyle create(Cascade c) { 23 Color color = c.get ("fill-color", null, Color.class);23 Color color = c.getColor("fill-color", null); 24 24 if (color == null) 25 25 return null; -
trunk/src/org/openstreetmap/josm/gui/mappaint/Cascade.java
r3836 r3848 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.awt.Color; 5 import java.util.Arrays; 4 6 import java.util.HashMap; 5 7 import java.util.Map; 8 9 import org.openstreetmap.josm.gui.mappaint.mapcss.CSSColors; 6 10 7 11 /** 8 12 * Simple map of properties with dynamic typing. 9 13 */ 10 public class Cascade {14 public class Cascade implements Cloneable { 11 15 12 16 public static final Cascade EMPTY_CASCADE = new Cascade(); … … 32 36 return res; 33 37 } 34 System.err.println(String.format("Warning: wrong type for mappaint property %s: %s expected, but %s found!", key, klass, o.getClass())); 38 System.err.println(String.format("Warning: wrong type for mappaint property %s: %s expected, but %s of type %s found!", key, klass, o, o.getClass())); 39 return def; 40 } 41 42 public Object get(String key) { 43 return prop.get(key); 44 } 45 46 public Float getFloat(String key, Float def) { 47 Object o = prop.get(key); 48 if (o == null) 49 return def; 50 if (o instanceof Float) 51 return (Float) o; 52 if (o instanceof Integer) 53 return new Float((Integer) o); 54 return def; 55 } 56 57 public Color getColor(String key, Color def) { 58 Object o = prop.get(key); 59 if (o == null) 60 return def; 61 if (o instanceof Color) 62 return (Color) o; 63 if (o instanceof String) { 64 Color clr = CSSColors.get((String) o); 65 if (clr != null) 66 return clr; 67 else 68 return def; 69 } 35 70 return def; 36 71 } … … 51 86 prop.remove(key); 52 87 } 88 89 @Override 90 public Cascade clone() { 91 @SuppressWarnings("unchecked") 92 HashMap<String, Object> clonedProp = (HashMap) ((HashMap) this.prop).clone(); 93 Cascade c = new Cascade(); 94 c.prop = clonedProp; 95 return c; 96 } 97 98 @Override 99 public String toString() { 100 StringBuilder res = new StringBuilder("Cascade{ "); 101 for (String key : prop.keySet()) { 102 res.append(key+":"); 103 Object val = prop.get(key); 104 if (val instanceof float[]) { 105 res.append(Arrays.toString((float[]) val)); 106 } else { 107 res.append(val+""); 108 } 109 res.append("; "); 110 } 111 return res.append("}").toString(); 112 } 53 113 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyle.java
r3836 r3848 17 17 18 18 protected ElemStyle(Cascade c) { 19 z_index = c.get ("z-index", 0f, Float.class);20 object_z_index = c.get ("object-z-index", 0f, Float.class);19 z_index = c.getFloat("z-index", 0f); 20 object_z_index = c.getFloat("object-z-index", 0f); 21 21 } 22 22 -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r3844 r3848 28 28 private boolean drawMultipolygon; 29 29 30 p ublic staticint cacheIdx;30 private int cacheIdx; 31 31 32 32 public ElemStyles() 33 33 { 34 34 styleSources = new ArrayList<StyleSource>(); 35 } 36 37 public void clearCached() { 38 cacheIdx++; 35 39 } 36 40 -
trunk/src/org/openstreetmap/josm/gui/mappaint/LineElemStyle.java
r3836 r3848 40 40 41 41 public static LineElemStyle createCasing(Cascade c) { 42 return createImpl(c, "casing-"); 42 LineElemStyle casing = createImpl(c, "casing-"); 43 if (casing != null) { 44 casing.object_z_index = -1; 45 } 46 return casing; 43 47 } 44 48 45 49 private static LineElemStyle createImpl(Cascade c, String prefix) { 46 Float width = c.get (prefix + "width", null, Float.class);50 Float width = c.getFloat(prefix + "width", null); 47 51 if (width == null) 48 52 return null; 49 53 50 float realWidth = c.get (prefix + "real-width", 0f, Float.class);51 Color color = c.get (prefix + "color", null, Color.class);54 float realWidth = c.getFloat(prefix + "real-width", 0f); 55 Color color = c.getColor(prefix + "color", null); 52 56 if (color == null) { 53 color = c.get (prefix + "fill-color", null, Color.class);57 color = c.getColor(prefix + "fill-color", null); 54 58 } 55 59 if (color == null) { 56 color = PaintColors.UNTAGGED _WAY.get();60 color = PaintColors.UNTAGGED.get(); 57 61 } 58 62 float[] dashes = c.get(prefix + "dashes", null, float[].class); 59 Color dashesBackground = c.get (prefix + "dashes-background-color", null, Color.class);63 Color dashesBackground = c.getColor(prefix + "dashes-background-color", null); 60 64 61 65 return new LineElemStyle(c, width, realWidth, color, dashes, dashesBackground); -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3843 r3848 14 14 15 15 import org.openstreetmap.josm.Main; 16 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 17 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 16 18 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource; 17 19 import org.openstreetmap.josm.gui.preferences.SourceEntry; 18 20 import org.openstreetmap.josm.gui.preferences.MapPaintPreference.MapPaintPrefMigration; 21 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 19 22 import org.openstreetmap.josm.io.MirroredInputStream; 20 23 import org.openstreetmap.josm.tools.ImageProvider; … … 83 86 84 87 for (SourceEntry entry : sourceEntries) { 85 StyleSource style = n ew XmlStyleSource(entry);88 StyleSource style = null; 86 89 try { 87 90 MirroredInputStream in = new MirroredInputStream(entry.url); 88 91 InputStream zip = in.getZipEntry("xml","style"); 89 92 if (zip != null) { 90 style.zipIcons = in.getFile(); 91 } 93 style = new XmlStyleSource(entry); 94 continue; 95 } 96 zip = in.getZipEntry("mapcss","style"); 97 if (zip != null) { 98 style = new MapCSSStyleSource(entry); 99 continue; 100 } 101 if (entry.url.toLowerCase().endsWith(".mapcss")) { 102 style = new MapCSSStyleSource(entry); 103 } else { 104 style = new XmlStyleSource(entry); 105 } 92 106 } catch(IOException e) { 93 107 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString())); 94 108 e.printStackTrace(); 95 style.hasError = true; 109 if (style != null) { 110 style.hasError = true; 111 } 96 112 } 97 styles.add(style); 113 if (style != null) { 114 styles.add(style); 115 } 98 116 } 99 117 for (StyleSource s : styles.getStyleSources()) { … … 101 119 } 102 120 } 121 122 public static class MapPaintStyleLoader extends PleaseWaitRunnable { 123 private boolean canceled; 124 private List<StyleSource> sources; 125 126 public MapPaintStyleLoader(List<StyleSource> sources) { 127 super(tr("Reloading style sources")); 128 this.sources = sources; 129 } 130 131 @Override 132 protected void cancel() { 133 canceled = true; 134 } 135 136 @Override 137 protected void finish() { 138 } 139 140 @Override 141 protected void realRun() { 142 ProgressMonitor monitor = getProgressMonitor(); 143 monitor.setTicksCount(sources.size()); 144 for (StyleSource s : sources) { 145 if (canceled) 146 return; 147 monitor.subTask(tr("loading style ''{0}''...", s.getDisplayString())); 148 s.loadStyleSource(); 149 monitor.worked(1); 150 } 151 } 152 } 153 103 154 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r3844 r3848 32 32 public class XmlStyleSource extends StyleSource { 33 33 34 p ublicfinal HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>();35 p ublicfinal HashMap<String, LinePrototype> lines = new HashMap<String, LinePrototype>();36 p ublicfinal HashMap<String, LinemodPrototype> modifiers = new HashMap<String, LinemodPrototype>();37 p ublicfinal HashMap<String, AreaPrototype> areas = new HashMap<String, AreaPrototype>();38 p ublicfinal LinkedList<IconPrototype> iconsList = new LinkedList<IconPrototype>();39 p ublicfinal LinkedList<LinePrototype> linesList = new LinkedList<LinePrototype>();40 p ublicfinal LinkedList<LinemodPrototype> modifiersList = new LinkedList<LinemodPrototype>();41 p ublicfinal LinkedList<AreaPrototype> areasList = new LinkedList<AreaPrototype>();34 protected final HashMap<String, IconPrototype> icons = new HashMap<String, IconPrototype>(); 35 protected final HashMap<String, LinePrototype> lines = new HashMap<String, LinePrototype>(); 36 protected final HashMap<String, LinemodPrototype> modifiers = new HashMap<String, LinemodPrototype>(); 37 protected final HashMap<String, AreaPrototype> areas = new HashMap<String, AreaPrototype>(); 38 protected final LinkedList<IconPrototype> iconsList = new LinkedList<IconPrototype>(); 39 protected final LinkedList<LinePrototype> linesList = new LinkedList<LinePrototype>(); 40 protected final LinkedList<LinemodPrototype> modifiersList = new LinkedList<LinemodPrototype>(); 41 protected final LinkedList<AreaPrototype> areasList = new LinkedList<AreaPrototype>(); 42 42 43 43 public XmlStyleSource(String url, String name, String shortdescription) { … … 49 49 } 50 50 51 protected void init() { 52 icons.clear(); 53 lines.clear(); 54 modifiers.clear(); 55 areas.clear(); 56 iconsList.clear(); 57 linesList.clear(); 58 modifiersList.clear(); 59 areasList.clear(); 60 } 61 51 62 @Override 52 63 public void loadStyleSource() { 64 init(); 53 65 try { 54 66 MirroredInputStream in = new MirroredInputStream(url); … … 57 69 if (zip != null) { 58 70 reader = new InputStreamReader(zip); 71 zipIcons = in.getFile(); 59 72 } else { 60 73 reader = new InputStreamReader(in); 74 zipIcons = null; 61 75 } 62 76 … … 288 302 def.putOrClear("dashes-background-color", p.line.dashedColor); 289 303 } 290 Float refWidth = def.get ("width", null, Float.class);304 Float refWidth = def.getFloat("width", null); 291 305 if (refWidth != null && p.linemods != null) { 292 306 int numOver = 0, numUnder = 0; -
trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java
r3797 r3848 21 21 22 22 import org.openstreetmap.josm.Main; 23 import org.openstreetmap.josm.data.osm.OsmPrimitive;24 import org.openstreetmap.josm.gui.layer.OsmDataLayer;25 23 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 26 24 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; … … 30 28 private SourceEditor sources; 31 29 private JCheckBox enableIconDefault; 32 private JCheckBox enableDefault;33 30 private JComboBox styleCombo = new JComboBox(); 34 31 … … 40 37 41 38 public void addGui(final PreferenceTabbedPane gui) { 42 enableDefault = new JCheckBox(tr("Enable built-in defaults"),43 Main.pref.getBoolean("mappaint.style.enable-defaults", true));44 39 enableIconDefault = new JCheckBox(tr("Enable built-in icon defaults"), 45 40 Main.pref.getBoolean("mappaint.icon.enable-defaults", true)); … … 168 163 169 164 public boolean ok() { 170 Boolean restart = Main.pref.put("mappaint.style.enable-defaults", enableDefault.isSelected());165 Boolean restart = false; 171 166 if(Main.pref.put("mappaint.icon.enable-defaults", enableIconDefault.isSelected())) { 172 167 restart = true; … … 178 173 && Main.isDisplayingMapView()) 179 174 { 180 for(OsmDataLayer l : Main.map.mapView.getLayersOfType(OsmDataLayer.class)) 181 { 182 for(OsmPrimitive osm : l.data.allPrimitives()) 183 { 184 osm.clearCached(); 185 } 186 } 175 MapPaintStyles.getStyles().clearCached(); 187 176 } 188 177 return restart; -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r3836 r3848 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools; 3 4 import java.util.Collection; 3 5 4 6 public class Utils { … … 80 82 } 81 83 84 /** 85 * Joins a list of strings (or objects that can be converted to string via 86 * Object.toString()) into a single string with fields separated by sep. 87 * @param sep the separator 88 * @param values collection of objects, null is converted to the 89 * empty string 90 * @return null if values is null. The joined string otherwise. 91 */ 92 public static String join(String sep, Collection<?> values) { 93 if (sep == null) 94 throw new IllegalArgumentException(); 95 if (values == null) 96 return null; 97 if (values.isEmpty()) 98 return ""; 99 StringBuilder s = null; 100 for (Object a : values) { 101 if (a == null) { 102 a = ""; 103 } 104 if(s != null) { 105 s.append(sep).append(a.toString()); 106 } else { 107 s = new StringBuilder(a.toString()); 108 } 109 } 110 return s.toString(); 111 } 82 112 }
Note:
See TracChangeset
for help on using the changeset viewer.