MCPcopy Index your code
hub / github.com/processing/processing / handlePrint

Method handlePrint

app/src/processing/app/ui/Editor.java:2735–2799  ·  view source on GitHub ↗

Handler for File → Print.

()

Source from the content-addressed store, hash-verified

2733 * Handler for File → Print.
2734 */
2735 public void handlePrint() {
2736 statusNotice(Language.text("editor.status.printing"));
2737
2738 StringBuilder html = new StringBuilder("<html><body>");
2739 for (SketchCode tab : sketch.getCode()) {
2740 html.append("<b>" + tab.getPrettyName() + "</b><br>");
2741 html.append(textarea.getTextAsHtml((SyntaxDocument)tab.getDocument()));
2742 html.append("<br>");
2743 }
2744 html.setLength(html.length() - 4); // Don't want last <br>.
2745 html.append("</body></html>");
2746 JTextPane jtp = new JTextPane();
2747 // Needed for good line wrapping; otherwise one very long word breaks
2748 // wrapping for the whole document.
2749 jtp.setEditorKit(new HTMLEditorKit() {
2750 public ViewFactory getViewFactory() {
2751 return new HTMLFactory() {
2752 public View create(Element e) {
2753 View v = super.create(e);
2754 if (!(v instanceof javax.swing.text.html.ParagraphView))
2755 return v;
2756 else
2757 return new javax.swing.text.html.ParagraphView(e) {
2758 protected SizeRequirements calculateMinorAxisRequirements(
2759 int axis, SizeRequirements r) {
2760 r = super.calculateMinorAxisRequirements(axis, r);
2761 r.minimum = 1;
2762 return r;
2763 }
2764 };
2765 }
2766 };
2767 }
2768 });
2769 jtp.setFont(new Font(Preferences.get("editor.font.family"), Font.PLAIN, 10));
2770 jtp.setText(html.toString().replace("\n", "<br>") // Not in a <pre>.
2771 .replaceAll("(?<!&nbsp;)&nbsp;", " ")); // Allow line wrap.
2772
2773 //printerJob = null;
2774 if (printerJob == null) {
2775 printerJob = PrinterJob.getPrinterJob();
2776 }
2777 if (pageFormat != null) {
2778 //System.out.println("setting page format " + pageFormat);
2779 printerJob.setPrintable(jtp.getPrintable(null, null), pageFormat);
2780 } else {
2781 printerJob.setPrintable(jtp.getPrintable(null, null));
2782 }
2783 // set the name of the job to the code name
2784 printerJob.setJobName(sketch.getCurrentCode().getPrettyName());
2785
2786 if (printerJob.printDialog()) {
2787 try {
2788 printerJob.print();
2789 statusNotice(Language.text("editor.status.printing.done"));
2790
2791 } catch (PrinterException pe) {
2792 statusError(Language.text("editor.status.printing.error"));

Callers 1

actionPerformedMethod · 0.95

Calls 15

statusNoticeMethod · 0.95
textMethod · 0.95
getMethod · 0.95
statusErrorMethod · 0.95
getCodeMethod · 0.80
getPrettyNameMethod · 0.80
getTextAsHtmlMethod · 0.80
getCurrentCodeMethod · 0.80
printMethod · 0.65
appendMethod · 0.45
getDocumentMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected