Commits

shemnon committed cc01c94

printing WIP

Comments (0)

Files changed (1)

src/main/java/org/bitbucket/shemnon/preso/deploy/Preso.java

 import javafx.event.EventHandler;
 import javafx.geometry.Insets;
 import javafx.geometry.Pos;
+import javafx.scene.Node;
 import javafx.scene.Scene;
 import javafx.scene.control.Button;
 import javafx.scene.control.ComboBox;
 
 import java.io.*;
 
+import javafx.print.*;
+
 /**
  * Created with IntelliJ IDEA.
  * User: shemnon
         spacer.setPrefSize(0, 0);
         HBox.setHgrow(spacer, Priority.ALWAYS);
         
+        Button printButton = new Button("Print");
+        printButton.setOnAction(a -> printPreso(deck));
+        
         TextField cssTextField = new TextField();
         cssTextField.textProperty().bindBidirectional(cssFile);
         cssTextField.setOnAction(reloadDeck);
                     Bindings.convert(Bindings.size(deck.nodesProperty()))));
         
         HBox buttons = new HBox(first, left, right, last, spacer, 
+                printButton,
                 new Label("CSS:"), cssTextField,
                 new Label("Slides:"), filenameTextField, 
                 loadButton, 
             deck.setPrimaryNodeIndex(deck.getNodes().size() - 1);
         }
     }
+    
+    
+    public void printPreso(Deck deck) {
+
+        PrinterJob job = PrinterJob.createPrinterJob();
+        job.showPageSetupDialog(deck.getScene().getWindow());
+        job.showPrintDialog(deck.getScene().getWindow());
+
+        Printer printer = job.getPrinter();
+        PageLayout _1Up = printer.getDefaultPageLayout();
+
+        double smallestScale = 1.0;
+
+        for (Node n : deck.getNodes()) {
+            smallestScale = Math.min(smallestScale, _1Up.getPrintableWidth() / n.getBoundsInParent().getWidth());
+            smallestScale = Math.min(smallestScale, _1Up.getPrintableHeight() / n.getBoundsInParent().getHeight());
+        }
+
+
+        for (Node n : deck.getNodes()) {
+            job.printPage(n);
+        }
+        job.endJob();
+    }
 }