Пример #1
0
  private void panel_svgAreaMouseReleased(
      java.awt.event.MouseEvent evt) // GEN-FIRST:event_panel_svgAreaMouseReleased
      { // GEN-HEADEREND:event_panel_svgAreaMouseReleased
    SVGDiagram diagram = svgDisplayPanel.getDiagram();
    List pickedElements;
    try {
      pickedElements = diagram.pick(new Point(evt.getX(), evt.getY()), null);
    } catch (SVGException ex) {
      ex.printStackTrace();
      return;
    }

    System.out.println("Pick results:");
    for (Iterator it = pickedElements.iterator(); it.hasNext(); ) {
      ArrayList path = (ArrayList) it.next();

      System.out.print("  Path: ");

      for (Iterator it2 = path.iterator(); it2.hasNext(); ) {
        SVGElement ele = (SVGElement) it2.next();

        System.out.print("" + ele.getId() + "(" + ele.getClass().getName() + ") ");
      }
      System.out.println();
    }
  } // GEN-LAST:event_panel_svgAreaMouseReleased
Пример #2
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);
  }
Пример #3
0
 @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));
 }