示例#1
0
  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();
  }
示例#2
0
  private void loadURL(URL url) {
    boolean verbose = cmCheck_verbose.isSelected();

    //                SVGUniverse universe = new SVGUniverse();
    SVGUniverse universe = SVGCache.getSVGUniverse();
    SVGDiagram diagram = null;
    URI uri;

    if (!CheckBoxMenuItem_anonInputStream.isSelected()) {
      // Load from a disk with a valid URL
      uri = universe.loadSVG(url);

      if (verbose) System.err.println("Loading document " + uri.toString());

      diagram = universe.getDiagram(uri);
    } else {
      // Load from a stream with no particular valid URL
      try {
        InputStream is = url.openStream();
        uri = universe.loadSVG(is, "defaultName");

        if (verbose) System.err.println("Loading document " + uri.toString());
      } catch (Exception e) {
        e.printStackTrace();
        return;
      }
    }
    /*
    ByteArrayOutputStream bs = new ByteArrayOutputStream();
    ObjectOutputStream os = new ObjectOutputStream(bs);
    os.writeObject(universe);
    os.close();

    ByteArrayInputStream bin = new ByteArrayInputStream(bs.toByteArray());
    ObjectInputStream is = new ObjectInputStream(bin);
    universe = (SVGUniverse)is.readObject();
    is.close();
    */

    diagram = universe.getDiagram(uri);

    svgDisplayPanel.setDiagram(diagram);
    repaint();
  }
示例#3
0
  private static void paintImage(
      final Graphics2D g, final Dimension dim, final SVGUniverse uni, final URI svgURI) {
    final Object oldAliasHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    g.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING,
        antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);

    final SVGDiagram diagram = uni.getDiagram(svgURI);
    if (diagram == null) {
      return;
    }

    if (!scaleToFit) {
      try {
        diagram.render(g);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint);
      } catch (final SVGException e) {
        throw new RuntimeException(e);
      }
      return;
    }

    final int width = dim.width;
    final int height = dim.height;

    final Rectangle2D.Double rect = new Rectangle2D.Double();
    diagram.getViewRect(rect);

    scaleXform.setToScale(width / rect.width, height / rect.height);

    final AffineTransform oldXform = g.getTransform();
    g.transform(scaleXform);

    try {
      diagram.render(g);
    } catch (final SVGException e) {
      throw new RuntimeException(e);
    }

    g.setTransform(oldXform);

    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint);
  }
 @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));
 }