/*
 * Copyright (C) 2016 Satomichi Nishihara
 *
 * This file is distributed under the terms of the
 * GNU General Public License. See the file `LICENSE'
 * in the root directory of the present distribution,
 * or http://www.gnu.org/copyleft/gpl.txt .
 */

package burai.com.periodic;

import javafx.geometry.Pos;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.scene.layout.GridPane;
import burai.app.QEFXMain;
import burai.atoms.element.ElementUtil;

public class PeriodicTable extends Dialog<ElementButton> {

    private GridPane gridPane;

    public PeriodicTable() {
        super();

        DialogPane dialogPane = this.getDialogPane();
        QEFXMain.initializeStyleSheets(dialogPane.getStylesheets());
        QEFXMain.initializeDialogOwner(this);

        this.setResizable(false);
        this.setTitle("Periodic Table");
        dialogPane.setHeaderText("Select an element.");
        dialogPane.getButtonTypes().addAll(ButtonType.CANCEL);

        this.createGridPane();
        dialogPane.setContent(this.gridPane);

        this.setResultConverter(buttonType -> {
            return null;
        });
    }

    private void createGridPane() {
        this.gridPane = new GridPane();
        this.gridPane.setHgap(0.0);
        this.gridPane.setVgap(0.0);
        this.gridPane.setAlignment(Pos.CENTER);

        String[] elementNames = ElementUtil.listAllElements();
        for (String elementName : elementNames) {
            ElementButton elementButton = new ElementButton(elementName);
            elementButton.setDialog(this);
            this.gridPane.add(elementButton, elementButton.getY() - 1, elementButton.getX() - 1);
        }
    }
}

@@ -289,16 +289,110 @@
 dic;%0D%0A%0D%0A
+import java.util.Map;%0D%0A%0D%0Aimport burai.app.QEFXMain;%0D%0Aimport burai.atoms.element.ElementUtil;%0D%0A
 import j
@@ -412,16 +412,16 @@
 y.Pos;%0D%0A
-
 import j
@@ -572,77 +572,8 @@
 ne;%0D
-%0Aimport burai.app.QEFXMain;%0D%0Aimport burai.atoms.element.ElementUtil;%0D
 %0A%0D%0Ap
@@ -693,24 +693,110 @@
 cTable() %7B%0D%0A
+        this(null);%0D%0A    %7D%0D%0A%0D%0A    public PeriodicTable(Map%3CString, String%3E styles) %7B%0D%0A
         supe
@@ -1197,32 +1197,38 @@
 .createGridPane(
+styles
 );%0D%0A        dial
@@ -1393,16 +1393,42 @@
 ridPane(
+Map%3CString, String%3E styles
 ) %7B%0D%0A   
@@ -1776,24 +1776,24 @@
 mentName);%0D%0A
-
             
@@ -1820,24 +1820,285 @@
 log(this);%0D%0A
+%0D%0A            if (styles != null && !styles.isEmpty()) %7B%0D%0A                String style = styles.get(elementName);%0D%0A                if (style != null && !style.isEmpty()) %7B%0D%0A                    elementButton.setStyle(style);%0D%0A                %7D%0D%0A            %7D%0D%0A%0D%0A
             

update PeriodicTable