Commits

shemnon committed 79ab21b

bring over new controls form deploy

Comments (0)

Files changed (1)

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

 import javafx.beans.binding.Bindings;
 import javafx.beans.property.SimpleStringProperty;
 import javafx.beans.property.StringProperty;
+import javafx.event.ActionEvent;
+import javafx.event.EventHandler;
 import javafx.geometry.Insets;
 import javafx.geometry.Pos;
 import javafx.scene.Scene;
 import javafx.scene.control.Button;
+import javafx.scene.control.Label;
 import javafx.scene.control.TextField;
 import javafx.scene.layout.*;
 import javafx.scene.paint.Color;
 import javafx.scene.text.Text;
-import javafx.scene.text.TextAlignment;
 import javafx.stage.Stage;
 import org.bitbucket.shemnon.mdnode.MarkdownNode;
 import org.pegdown.Extensions;
  * Time: 12:22 AM
  */
 public class Preso extends Application {
-    
+
     StringProperty presentationFile = new SimpleStringProperty("preso.md");
-    
+    StringProperty cssFile = new SimpleStringProperty("/org/bitbucket/shemnon/preso/css/PresoGit.css");
+
     @Override
     public void start(Stage stage) throws Exception {
 
-        
+
         Deck deck = new Deck();
         deck.setAlignment(null);
         VBox.setVgrow(deck, Priority.ALWAYS);
         deck.setMinSize(1280, 720);
 
-        createSlides(deck);
-        
+        EventHandler<ActionEvent> reloadDeck = event -> createSlides(deck);
+        reloadDeck.handle(null);
+
         deck.setPrimaryNodeIndex(0);
         deck.setStyle("-fx-skin: 'com.github.shemnon.deckcontrol.skin.ShiftDeckSkin'");
 
+        Button first = new Button("|<");
+        first.setOnAction(event -> deck.setPrimaryNodeIndex(0));
+
         Button left = new Button("<<");
         left.setOnAction(event -> deck.previousNode());
+
         Button right = new Button(">>");
         right.setOnAction(event -> deck.nextNode());
 
+        Button last = new Button(">|");
+        last.setOnAction(event -> deck.setPrimaryNodeIndex(deck.getNodes().size()-1));
+
         Pane spacer = new Pane();
         spacer.setPrefSize(0, 0);
         HBox.setHgrow(spacer, Priority.ALWAYS);
-        
-        TextField filename = new TextField();
-        filename.textProperty().bindBidirectional(presentationFile);        
-        
+
+        TextField cssTextField = new TextField();
+        cssTextField.textProperty().bindBidirectional(cssFile);
+        cssTextField.setOnAction(reloadDeck);
+
+        TextField filenameTextField = new TextField();
+        filenameTextField.textProperty().bindBidirectional(presentationFile);
+        filenameTextField.setOnAction(reloadDeck);
+
         Button loadButton = new Button("Load");
         loadButton.setOnAction(event -> createSlides(deck));
 
-        Text currentText = new Text();
-        currentText.textProperty().bind(Bindings.convert(Bindings.add(1, deck.primaryNodeIndexProperty())));
-        Text slashText = new Text("/");
-        Text slideCountText = new Text();
-        slideCountText.textProperty().bind(Bindings.convert(Bindings.size(deck.nodesProperty())));
-        
-        HBox buttons = new HBox(left, right, spacer, filename, loadButton, currentText, slashText, slideCountText);
+        Text posText = new Text();
+        posText.textProperty().bind(
+                Bindings.concat(
+                        Bindings.convert(Bindings.add(1, deck.primaryNodeIndexProperty())),
+                        "/",
+                        Bindings.convert(Bindings.size(deck.nodesProperty()))));
+
+        HBox buttons = new HBox(first, left, right, last, spacer,
+                new Label("CSS:"), cssTextField,
+                new Label("Slides:"), filenameTextField,
+                loadButton,
+                posText);
         buttons.setSpacing(10);
         buttons.setAlignment(Pos.BASELINE_LEFT);
-        
+
         VBox vbox = new VBox(new StackPane(deck), buttons);
         vbox.setPadding(new Insets(10, 10, 10, 10));
         vbox.setSpacing(10);
         //vbox.setStyle("-fx-background-color: linear-gradient(from 0% 0% to 0% 100%, white 0%, #e0e0e0 100%)");
         vbox.setStyle("-fx-background-color: white");
-        
+
+        vbox.setOnMouseClicked(event -> right.fire());
+
         Scene scene = new Scene(vbox);
         scene.setFill(Color.YELLOW);
-        
+
         stage.setScene(scene);
-        stage.setTitle("[CON2935] - Styling Your Custom Components with CSS in JavaFX ");
+        stage.setTitle("[CON2106] - Building and Deploying JavaFX Applications with Gradle or Maven (or Ant!)");
         stage.show();
-        stage.setOnCloseRequest(event -> { Platform.exit();  System.exit(0); } ); 
+        stage.setOnCloseRequest(event -> { Platform.exit();  System.exit(0); } );
     }
 
     private void createSlides(Deck deck) {
         int pos = deck.getPrimaryNodeIndex();
-        
+
         deck.getNodes().clear();
-        
+
         String s = presentationFile.get();
         File f = new File(s);
         InputStream is;
         try {
             is = new FileInputStream(f);
         } catch (FileNotFoundException fne) {
-            is = getClass().getResourceAsStream(s); 
+            is = getClass().getResourceAsStream(s);
         }
-        
+
         if (is == null) {
             try {
                 is = new ByteArrayInputStream(("# ERROR\n\nCould not load file `" + s + "`\n\n------\n").getBytes("UTF-8"));
                 // this won't happen.  Really.  Ever.
             }
         }
-        
+
         try (BufferedReader br = new BufferedReader(new InputStreamReader(is))) {
             String slide = "";
             String line = br.readLine();
                     MarkdownNode mdn = new MarkdownNode();
                     mdn.setValue(slide);
                     mdn.setParserFlags(Extensions.HARDWRAPS | Extensions.TABLES);
-                    mdn.getStylesheets().setAll("/org/bitbucket/shemnon/preso/css/PresoGit.css");
+                    mdn.getStylesheets().setAll(cssFile.get());
 
                     deck.getNodes().add(mdn);
                     slide = "";
         } catch (IOException ioe) {
             ioe.printStackTrace();
         }
-        
+
         if (pos < deck.getNodes().size()) {
             deck.setPrimaryNodeIndex(pos);
         } else {