MCPcopy
hub / github.com/antlr/antlr4 / generateSVGFile

Method generateSVGFile

tool/src/org/antlr/v4/gui/TreeViewer.java:555–589  ·  view source on GitHub ↗
(TreeViewer viewer, JFrame dialog)

Source from the content-addressed store, hash-verified

553 }
554
555 private static void generateSVGFile(TreeViewer viewer, JFrame dialog) {
556
557 try {
558 JFileChooser fileChooser = getFileChooser(".svg", "SVG files");
559
560 int returnValue = fileChooser.showSaveDialog(dialog);
561 if (returnValue == JFileChooser.APPROVE_OPTION) {
562 File svgFile = fileChooser.getSelectedFile();
563 // save the new svg file here!
564 BufferedWriter writer = new BufferedWriter(new FileWriter(svgFile));
565 // HACK: multiplying with 1.1 should be replaced wit an accurate number
566 writer.write("<svg width=\"" + viewer.getSize().getWidth() * 1.1 + "\" height=\"" + viewer.getSize().getHeight() * 1.1 + "\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">");
567 viewer.paintSVG(writer);
568 writer.write("</svg>");
569 writer.flush();
570 writer.close();
571 try {
572 // Try to open the parent folder using the OS' native file manager.
573 Desktop.getDesktop().open(svgFile.getParentFile());
574 } catch (Exception ex) {
575 // We could not launch the file manager: just show a popup that we
576 // succeeded in saving the PNG file.
577 JOptionPane.showMessageDialog(dialog, "Saved SVG to: "
578 + svgFile.getAbsolutePath());
579 ex.printStackTrace();
580 }
581 }
582 } catch (Exception ex) {
583 JOptionPane.showMessageDialog(dialog,
584 "Could not export to SVG: " + ex.getMessage(),
585 "Error",
586 JOptionPane.ERROR_MESSAGE);
587 ex.printStackTrace();
588 }
589 }
590
591 private static File generateNonExistingFile(String extension) {
592

Callers 1

actionPerformedMethod · 0.95

Calls 7

getFileChooserMethod · 0.95
paintSVGMethod · 0.80
openMethod · 0.80
writeMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected