From d62472532d83ab0c16d3a3e3461c76681d083958 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 16 Jul 2012 22:46:05 +0200 Subject: [PATCH] Adjust rendering on fly --- .../src/net/osmand/MapCreatorVersion.java | 2 +- .../osmand/swing/NativePreferencesDialog.java | 31 +++++++++- .../osmand/swing/NativeSwingRendering.java | 57 ++++++++++++++++--- .../src/net/osmand/swing/OsmExtractionUI.java | 6 +- OsmAnd/AndroidManifest.xml | 2 +- OsmAnd/res/values/no_translate.xml | 2 +- 6 files changed, 84 insertions(+), 16 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/MapCreatorVersion.java b/DataExtractionOSM/src/net/osmand/MapCreatorVersion.java index 07e8890dcd..48b98e0bab 100644 --- a/DataExtractionOSM/src/net/osmand/MapCreatorVersion.java +++ b/DataExtractionOSM/src/net/osmand/MapCreatorVersion.java @@ -5,7 +5,7 @@ import java.net.URLEncoder; public class MapCreatorVersion { - public static String APP_VERSION = "0.8.1"; //$NON-NLS-1$ + public static String APP_VERSION = "0.8.2"; //$NON-NLS-1$ public static final String APP_DESCRIPTION = "alpha"; //$NON-NLS-1$ public static final String APP_MAP_CREATOR_NAME = "OsmAndMapCreator"; //$NON-NLS-1$ diff --git a/DataExtractionOSM/src/net/osmand/swing/NativePreferencesDialog.java b/DataExtractionOSM/src/net/osmand/swing/NativePreferencesDialog.java index f85ca344b4..85236d583b 100644 --- a/DataExtractionOSM/src/net/osmand/swing/NativePreferencesDialog.java +++ b/DataExtractionOSM/src/net/osmand/swing/NativePreferencesDialog.java @@ -12,15 +12,12 @@ import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; -import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; -import net.osmand.data.preparation.MapZooms; - public class NativePreferencesDialog extends JDialog { private static final long serialVersionUID = -4862884032977071296L; @@ -32,6 +29,9 @@ public class NativePreferencesDialog extends JDialog { private JTextField renderingStyleFile; private boolean okPressed; + private JTextField renderingPropertiesTxt; + private static String renderingProperties = "nightMode=false, appMode=default, noPolygons=false, hmRendered=false"; + public NativePreferencesDialog(Component parent){ super(JOptionPane.getFrameForComponent(parent), true); @@ -119,18 +119,43 @@ public class NativePreferencesDialog extends JDialog { constr.gridx = 1; constr.gridy = 3; l.setConstraints(renderingStyleFile, constr); + + label = new JLabel("Rendering properties : "); + panel.add(label); + constr = new GridBagConstraints(); + constr.ipadx = 5; + constr.gridx = 0; + constr.gridy = 4; + constr.anchor = GridBagConstraints.WEST; + l.setConstraints(label, constr); + + renderingPropertiesTxt = new JTextField(); + renderingPropertiesTxt.setText(renderingProperties); + panel.add(renderingPropertiesTxt); + constr = new GridBagConstraints(); + constr.weightx = 1; + constr.fill = GridBagConstraints.HORIZONTAL; + constr.ipadx = 5; + constr.gridx = 1; + constr.gridy = 4; + l.setConstraints(renderingPropertiesTxt, constr); panel.setMaximumSize(new Dimension(Short.MAX_VALUE, panel.getPreferredSize().height)); } + public static String getRenderingProperties() { + return renderingProperties; + } + private void addListeners(){ okButton.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent e) { saveProperties(); okPressed = true; + renderingProperties = renderingPropertiesTxt.getText(); setVisible(false); } diff --git a/DataExtractionOSM/src/net/osmand/swing/NativeSwingRendering.java b/DataExtractionOSM/src/net/osmand/swing/NativeSwingRendering.java index 2e61913f63..5260f00b2b 100644 --- a/DataExtractionOSM/src/net/osmand/swing/NativeSwingRendering.java +++ b/DataExtractionOSM/src/net/osmand/swing/NativeSwingRendering.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.HashMap; import java.util.Iterator; import javax.imageio.ImageIO; @@ -15,19 +16,23 @@ import org.xml.sax.SAXException; import resources._R; +import net.osmand.Algoritms; import net.osmand.NativeLibrary; import net.osmand.RenderingContext; import net.osmand.osm.MapUtils; +import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRuleSearchRequest; +import net.osmand.render.RenderingRuleStorageProperties; import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver; public class NativeSwingRendering extends NativeLibrary { RenderingRulesStorage storage; + private HashMap renderingProps; private static NativeSwingRendering defaultLoadedLibrary; - public void loadRuleStorage(String path) throws SAXException, IOException{ + public void loadRuleStorage(String path, String renderingProperties) throws SAXException, IOException{ RenderingRulesStorage storage = new RenderingRulesStorage(); final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() { @Override @@ -47,12 +52,20 @@ public class NativeSwingRendering extends NativeLibrary { } else { storage.parseRulesFromXmlInputStream(new FileInputStream(path), resolver); } + renderingProps = new HashMap(); + String[] props = renderingProperties.split(","); + for (String s : props) { + int i = s.indexOf('='); + if (i > 0) { + renderingProps.put(s.substring(0, i).trim(), s.substring(i + 1).trim()); + } + } this.storage = storage; } public NativeSwingRendering(){ try { - loadRuleStorage(null); + loadRuleStorage(null, ""); } catch (SAXException e) { throw new RuntimeException(e); } catch (IOException e) { @@ -71,9 +84,28 @@ public class NativeSwingRendering extends NativeLibrary { return _R.getIconData(data); } }; - rctx.nightMode = true; - + rctx.nightMode = "true".equals(renderingProps.get("nightMode")); RenderingRuleSearchRequest request = new RenderingRuleSearchRequest(storage); + request.setBooleanFilter(request.ALL.R_NIGHT_MODE, rctx.nightMode); + for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) { + String res = renderingProps.get(customProp.getAttrName()); + if (!Algoritms.isEmpty(res)) { + if (customProp.isString()) { + request.setStringFilter(customProp, res); + } else if (customProp.isBoolean()) { + request.setBooleanFilter(customProp, "true".equalsIgnoreCase(res)); + } else { + try { + request.setIntFilter(customProp, Integer.parseInt(res)); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + } + } + request.setIntFilter(request.ALL.R_MINZOOM, zoom); + request.saveState(); + NativeSearchResult res = searchObjectsForRendering(sleft, sright, stop, sbottom, zoom, request, true, rctx, "Nothing found"); @@ -81,9 +113,20 @@ public class NativeSwingRendering extends NativeLibrary { rctx.topY = (float) (((double)stop)/ MapUtils.getPowZoom(31-zoom)); rctx.width = (int) ((sright - sleft) / MapUtils.getPowZoom(31 - zoom - 8)); rctx.height = (int) ((sbottom - stop) / MapUtils.getPowZoom(31 - zoom - 8)); - rctx.shadowRenderingMode = 2; - rctx.shadowRenderingColor = 0xff969696; - rctx.defaultColor = 0xfff1eee8; + + request.clearState(); + + if(request.searchRenderingAttribute(RenderingRuleStorageProperties.A_DEFAULT_COLOR)) { + rctx.defaultColor = request.getIntPropertyValue(request.ALL.R_ATTR_COLOR_VALUE); + System.out.println("!"+ Integer.toHexString(rctx.defaultColor)); + } + request.clearState(); + request.setIntFilter(request.ALL.R_MINZOOM, zoom); + if(request.searchRenderingAttribute(RenderingRuleStorageProperties.A_SHADOW_RENDERING)) { + rctx.shadowRenderingMode = request.getIntPropertyValue(request.ALL.R_ATTR_INT_VALUE); + rctx.shadowRenderingColor = request.getIntPropertyValue(request.ALL.R_SHADOW_COLOR); + + } rctx.zoom = zoom; long search = time + System.currentTimeMillis(); final RenderingGenerationResult rres = NativeSwingRendering.generateRenderingIndirect(rctx, res.nativeHandler, diff --git a/DataExtractionOSM/src/net/osmand/swing/OsmExtractionUI.java b/DataExtractionOSM/src/net/osmand/swing/OsmExtractionUI.java index b229c49063..3b9595d477 100644 --- a/DataExtractionOSM/src/net/osmand/swing/OsmExtractionUI.java +++ b/DataExtractionOSM/src/net/osmand/swing/OsmExtractionUI.java @@ -228,7 +228,7 @@ public class OsmExtractionUI implements IMapLocationListener { NativePreferencesDialog dlg = new NativePreferencesDialog(frame); dlg.showDialog(); if(dlg.isOkPressed()) { - initNativeRendering(); + initNativeRendering(NativePreferencesDialog.getRenderingProperties()); } else { showOfflineIndex.setSelected(false); } @@ -239,14 +239,14 @@ public class OsmExtractionUI implements IMapLocationListener { }); } - private void initNativeRendering() { + private void initNativeRendering(String renderingProperties) { String fl = DataExtractionSettings.getSettings().getNativeLibFile(); if (fl != null) { NativeSwingRendering lib = NativeSwingRendering.loadLibrary(fl); if (lib != null) { try { lib.initFilesInDir(new File(DataExtractionSettings.getSettings().getBinaryFilesDir())); - lib.loadRuleStorage(DataExtractionSettings.getSettings().getRenderXmlPath()); + lib.loadRuleStorage(DataExtractionSettings.getSettings().getRenderXmlPath(), renderingProperties); mapPanel.setNativeLibrary(lib); mapPanel.repaint(); } catch (SAXException e) { diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 2750b007ef..f3fcc14f68 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="net.osmand.plus" android:installLocation="auto" android:versionName="@string/app_version" android:versionCode="65"> diff --git a/OsmAnd/res/values/no_translate.xml b/OsmAnd/res/values/no_translate.xml index aba4afd250..58a2de04a3 100644 --- a/OsmAnd/res/values/no_translate.xml +++ b/OsmAnd/res/values/no_translate.xml @@ -1,7 +1,7 @@ OsmAnd~ - 0.8.0 alpha + 0.8.2 alpha UA-28342846-2 10