Package org.livesub.ui

Source Code of org.livesub.ui.GoToDialog

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.livesub.ui;

import static javafx.application.Application.launch;
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.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import org.livesub.input.Caption;
import org.livesub.player.Player;
import org.livesub.utils.Utils;
import org.livesub.utils.doublelinkedlist.DoubleLinkedNode;

/**
*
* @author vasilis
*/
public class GoToDialog extends Stage {
   
    Player player;
    int captionKey;
   
    private RadioButton goToNumber, goToTime;
    private TextField keyField, hField, mField, sField, msField;
   
    private boolean approveOption;

    public GoToDialog(Player player) {
        this.player = player;
        approveOption = false;
    }
   
    public void start() {
        final Stage primaryStage = this;
        GridPane grid = new GridPane();
       
        grid.setAlignment(Pos.CENTER);
        grid.setHgap(2);
        grid.setVgap(10);
        grid.setPadding(new Insets(10, 25, 10, 25));
       
        ToggleGroup group = new ToggleGroup();
        goToNumber = new RadioButton("Go To Number:");
        goToNumber.setSelected(true);
        goToNumber.setToggleGroup(group);
        goToTime = new RadioButton("Go To Time:");
        goToTime.setToggleGroup(group);
       
        keyField = new TextField();
        hField = new TextField("00");
        mField = new TextField("00");
        sField = new TextField("00");
        msField = new TextField("000");
       
        Label separator1 = new Label(":");
        Label separator2 = new Label(":");
        Label msSeparator = new Label(",");
       
        Button cancelButton = new Button("Cancel");
        cancelButton.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent t) {
                primaryStage.close();
            }
        });
       
        Button okButton = new Button("OK");
        okButton.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent t) {
                okButtonListener();
                approveOption = true;
                setCaptionKey();
                primaryStage.close();
            }
        });
       
        HBox hbBtn = new HBox(10);
        hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
        hbBtn.getChildren().add(cancelButton);
        hbBtn.getChildren().add(okButton);
       
        grid.add(goToNumber, 1, 1, 7, 1);
        grid.add(goToTime, 1, 3, 7, 1);
        grid.add(keyField, 2, 2, 7, 1);
        grid.add(hField, 2, 4);
        grid.add(separator1, 3, 4);
        grid.add(mField, 4, 4);
        grid.add(separator2, 5, 4);
        grid.add(sField, 6, 4);
        grid.add(msSeparator, 7, 4);
        grid.add(msField, 8, 4);
        grid.add(hbBtn, 1, 6, 8, 1);
       
        Scene scene = new Scene(grid, 300, 250);
       
        scene.getStylesheets().add("org/livesub/styles/GlobalStyle.css");
       
        primaryStage.setResizable(false);
        primaryStage.setTitle("Go To");
        primaryStage.setScene(scene);
        primaryStage.show();
    }
   
    public static void main(String[] args) {
        launch(args);
    }
   
    private int goToTime(long goToTime) {
        DoubleLinkedNode<Caption> search = player.getSubtitleList().getFirst();
       
        while(search.getElement() != null) {
            if(search.getElement().getAppear() >= goToTime) {
                break;
            } else {
                search = search.getNext();
            }
        }

        return search.getIndex();

    }
   
    private void okButtonListener(){
        if(goToNumber.isSelected() && !keyField.getText().equals("")){
            captionKey = Integer.parseInt(keyField.getText());
        } else if(!hField.getText().equals("") && !mField.getText().equals("") && !sField.getText().equals("") && !msField.getText().equals("")){
            int hour = Integer.parseInt(hField.getText());
            int min = Integer.parseInt(mField.getText());
            int sec = Integer.parseInt(sField.getText());
            int ms = Integer.parseInt(msField.getText());
            String timeFormatted = String.format("%02d:%02d:%02d,%04d", hour, min, sec, ms);
            long time = Utils.dateParseRegExp(timeFormatted);
            captionKey = goToTime(time);
        }
    }
   
    public void setCaptionKey(){
        if(approveOption){
            player.goTo(captionKey);
        }
    }
   
}
TOP

Related Classes of org.livesub.ui.GoToDialog

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.