package project_2;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Modality;
import javafx.stage.Stage;

public class PrintValid {

	/*
	 * This Class Print the valid equations in a tableView
	 * */
	
	
	LinkedList<Equation> validEquation;

	public PrintValid(LinkedList<Equation> validEquation) {
		this.validEquation = validEquation;
	}

	Stage stage = new Stage();
	GridPane pane =new GridPane();

	private TableView<Equation> table = new TableView<Equation>();
	private TableColumn<Equation, String> leftEquation =new TableColumn<Equation, String>("Left Equation");
	private TableColumn<Equation, String> LeftPostfix = new TableColumn<Equation, String>("Left Postfix");
	private TableColumn<Equation, String> resultLeft = new TableColumn<Equation, String>("Result Left");
	private TableColumn<Equation, String> rightEquation =new TableColumn<Equation, String>("Right Equation");
	private TableColumn<Equation, String> rightPostfix = new TableColumn<Equation, String>("Right Postfix");
	private TableColumn<Equation, String> resultRight = new TableColumn<Equation, String>("Result Right");
	private TableColumn<Equation, Boolean> isEqual = new TableColumn<Equation, Boolean>("Is Equals");

	public void show(){

		stage.initModality(Modality.APPLICATION_MODAL);

		pane.setAlignment(Pos.CENTER);
		pane.setHgap(15);
		pane.setVgap(15);
		
		leftEquation.setCellValueFactory(new PropertyValueFactory<>("leftEquation"));
		leftEquation.setMinWidth(200);
		
		LeftPostfix.setCellValueFactory(new PropertyValueFactory<>("postfixLeft"));
		LeftPostfix.setMinWidth(200);
		resultLeft.setCellValueFactory(new PropertyValueFactory<>("resultLeft"));
		
		
		rightEquation.setCellValueFactory(new PropertyValueFactory<>("rightEquation"));
		rightEquation.setMinWidth(200);
		
		rightPostfix.setCellValueFactory(new PropertyValueFactory<>("postfixRight"));
		rightPostfix.setMinWidth(200);
		resultRight.setCellValueFactory(new PropertyValueFactory<>("resultRight"));
		
		isEqual.setCellValueFactory(new PropertyValueFactory<>("isEquals"));
		
		table.setItems(get());
		

		table.getColumns().addAll(leftEquation,LeftPostfix,resultLeft,rightEquation,rightPostfix,resultRight,isEqual);
		pane.add(table,0, 0);
		Scene s = new Scene(pane,1500,600);
		s.getStylesheets().addAll(this.getClass().getResource("application.css").toExternalForm());
		stage.setScene(s);
		stage.setTitle("Valid Equation");
		stage.show();
	}
	public  ObservableList<Equation> get(){
		ObservableList<Equation> array = FXCollections.observableArrayList();

		for (int i = 0; i <validEquation.getSize() ; i++) {
			array.add(validEquation.getIndexData(i));
		}

		return array;

	}
}
