/** Creates new form SVGViewer */ public SVGPlayer() { initComponents(); setSize(800, 600); svgDisplayPanel.setBgColor(Color.white); svgDisplayPanel.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent evt) { SVGDiagram diagram = svgDisplayPanel.getDiagram(); if (diagram == null) return; System.out.println("Picking at cursor (" + evt.getX() + ", " + evt.getY() + ")"); try { List paths = diagram.pick(new Point2D.Float(evt.getX(), evt.getY()), null); for (int i = 0; i < paths.size(); i++) { ArrayList path = (ArrayList) paths.get(i); System.out.println(pathToString(path)); } } catch (SVGException ex) { ex.printStackTrace(); } } }); svgDisplayPanel.setPreferredSize(getSize()); scrollPane_svgArea.setViewportView(svgDisplayPanel); playerDialog = new PlayerDialog(this); }
/** Creates new form SVGViewer */ public SVGViewer() { initComponents(); setSize(800, 600); svgDisplayPanel.setBgColor(Color.white); svgDisplayPanel.setPreferredSize(getSize()); panel_svgArea.add(svgDisplayPanel, BorderLayout.CENTER); // scrollPane_svgArea.setViewportView(svgDisplayPanel); }
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(); }
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
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(); }