private void loadURL(URL url) { boolean verbose = cmCheck_verbose.isSelected(); universe = new SVGUniverse(); universe.setVerbose(verbose); SVGDiagram diagram = null; if (!CheckBoxMenuItem_anonInputStream.isSelected()) { // Load from a disk with a valid URL URI uri = universe.loadSVG(url); if (verbose) System.err.println(uri.toString()); diagram = universe.getDiagram(uri); } else { // Load from a stream with no particular valid URL try { InputStream is = url.openStream(); URI uri = universe.loadSVG(is, "defaultName"); if (verbose) System.err.println(uri.toString()); diagram = universe.getDiagram(uri); } catch (Exception e) { e.printStackTrace(); } } svgDisplayPanel.setDiagram(diagram); repaint(); }
@Override protected void realRun() throws IOException, OsmTransferException { LatLon center = Main.getProjection().eastNorth2latlon(Main.map.mapView.getCenter()); scale = Settings.getScaleNumerator() / Settings.getScaleDivisor() / Math.cos(Math.toRadians(center.lat())); this.center = projection.latlon2eastNorth(center); try { SVGUniverse universe = new SVGUniverse(); universe.setVerbose(Main.pref.getBoolean("importvec.verbose", false)); for (File f : files) { if (f.isDirectory()) continue; if (canceled) { return; } SVGDiagram diagram = universe.getDiagram(f.toURI()); ShapeElement root = diagram.getRoot(); if (root == null) { throw new IOException("Can't find root SVG element"); } Rectangle2D bbox = root.getBoundingBox(); this.center = this.center.add(-bbox.getCenterX() * scale, bbox.getCenterY() * scale); processElement(root, null); } } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException(e); } LinkedList<Command> cmds = new LinkedList<>(); for (Node n : nodes) { cmds.add(new AddCommand(n)); } for (Way w : ways) { cmds.add(new AddCommand(w)); } Main.main.undoRedo.add(new SequenceCommand("Import primitives", cmds)); }