/**
 * Copyright (C) 2014 Kasper Kronborg Isager and Sigrið Gyldenkærne Dalsgarð.
 */
package dk.itu.bookie.controller;

// General utilities
import java.awt.*;
import java.util.HashSet;
import java.util.Set;
import java.util.ResourceBundle;

// Net utilities
import java.net.URL;

// JavaFX layouts
import javafx.scene.layout.GridPane;

// JavaFX controls
import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.scene.control.TableColumn;

// FXML utilities
import javafx.fxml.FXML;
import javafx.fxml.Initializable;

// Components
import dk.itu.bookie.component.Seat;

// Models
import dk.itu.bookie.model.Showtime;

/**
 * Showtime controller class.
 *
 * @version 1.0.0
 */
public class ShowtimeController implements Initializable {
  private static ShowtimeController instance;

  private char[] alphabet = new char[]{
    'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
    'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
  };

  @FXML
  private TableView<Showtime> showtimes;

  @FXML
  private TableColumn movieColumn;

  @FXML
  private TableColumn auditoriumColumn;

  @FXML
  private TableColumn dateColumn;

  @FXML
  private TableColumn timeColumn;

  @FXML
  private GridPane auditorium;

  public ShowtimeController getInstance() {
    return ShowtimeController.instance;
  }

  public void initialize(final URL url, final ResourceBundle resourceBundle) {
    ShowtimeController.instance = this;

    this.bindTableColumnWidths();

    int rows = 10;
    int seats = 15;

    Set<Seat> selectedSeats = new HashSet<>();

    for (int row = 1; row <= (rows + 1); row++) {
      for (int seat = 1; seat <= (seats + 1); seat++) {
        if ((row > 1) && (seat > 1) || (seat == row)) {
          continue;
        }

        String text;

        if (row == 1) {
          text = String.format("%s", seat - 1);
        }
        else {
          text = String.format("%s", this.alphabet[row - 2]);
        }

        Label label = new Label(text);

        this.auditorium.add(label, seat, row);
      }
    }

    for (int row = 2; row <= (rows + 1); row++) {
      for (int seat = 2; seat <= (seats + 1); seat++) {
        Seat auditoriumSeat = new Seat(row, seat);

	this.bindSeatWidth(auditoriumSeat);

        auditoriumSeat.getState().addListener((e, ov, nv) -> {
          if (nv) {
            selectedSeats.add(auditoriumSeat);
          }
          else {
            selectedSeats.remove(auditoriumSeat);
          }
        });

        this.auditorium.add(auditoriumSeat, seat, row);
      }
    }
  }

  public void bindTableColumnWidths() {
    this.movieColumn.prefWidthProperty().bind(
      this.showtimes.widthProperty().multiply(0.30)
    );

    this.auditoriumColumn.prefWidthProperty().bind(
      this.showtimes.widthProperty().multiply(0.30)
    );

    this.dateColumn.prefWidthProperty().bind(
      this.showtimes.widthProperty().multiply(0.20)
    );

    this.timeColumn.prefWidthProperty().bind(
      this.showtimes.widthProperty().multiply(0.20)
    );
  }

  public void bindSeatWidth(final Seat seat) {
    int rows = 10;
    int seats = 15;

    seat.widthProperty().bind(
      this.showtimes.widthProperty().divide(seats)
    );

    seat.heightProperty().bind(
      this.showtimes.widthProperty().divide(seats)
    );
  }
}

@@ -466,16 +466,94 @@
 olumn;%0A%0A
+// JavaFX geometry%0Aimport javafx.geometry.HPos;%0Aimport javafx.geometry.VPos;%0A%0A
 // FXML 
@@ -2134,32 +2134,208 @@
 bel, seat, row);
+%0A%0A        // Center alignment the label within its column.%0A        this.auditorium.setHalignment(label, HPos.CENTER);%0A        this.auditorium.setValignment(label, VPos.CENTER);
 %0A      %7D%0A    %7D%0A%0A
@@ -2496,9 +2496,16 @@
 );%0A%0A
-%09
+        
 this
@@ -2533,16 +2533,23 @@
 riumSeat
+, seats
 );%0A%0A    
@@ -3375,34 +3375,15 @@
 seat
-) %7B%0A    int rows = 10;%0A   
+, final
  int
@@ -3384,31 +3384,27 @@
 al int seats
- = 15;%0A
+) %7B
 %0A    seat.wi

Fix grid pane cell alignment.