import java.util.HashMap;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.layout.VBox;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;

public class ColorName extends Application {
    private HashMap<String, Color> hm;
    private Canvas canvas;
    private TextField input;

    @Override
    public void init() throws Exception {
        hm = new HashMap<>();
        hm.put("ž", Color.web("#f7acbc")); hm.put("Ô", Color.web("#ed1941"));
        hm.put("é", Color.web("#f26522")); hm.put("", Color.web("#f58f98"));
        hm.put("ę", Color.web("#aa2116")); hm.put("§", Color.web("#fedcbd"));
        hm.put("ō", Color.web("#f47920")); hm.put("", Color.web("#843900"));
        hm.put("Đ", Color.web("#ffd400")); hm.put("ęS", Color.web("#cbc547"));
        hm.put("éō", Color.web("#87943b")); hm.put("Î", Color.web("#45b97c"));
        hm.put("S", Color.web("#005344")); hm.put("", Color.web("#afdfe4"));
        hm.put("Â", Color.web("#009ad6")); hm.put("", Color.web("#145b7d"));
        hm.put("Ū", Color.web("#003a6c")); hm.put("äŋ", Color.web("#6ff0aa"));
        hm.put("Ą", Color.web("#afb4db")); hm.put("", Color.web("#8552a1"));
        hm.put("", Color.web("#fffffb")); hm.put("D", Color.web("#77787b"));
        hm.put("", Color.web("#130c0e")); hm.put("g", Color.web("#d7003a"));
    }

    @Override
    public void start(Stage stage) {
        stage.setTitle("FĖžO");

        input = new TextField("");
        input.setOnAction(e -> {
            paint(canvas.getGraphicsContext2D());
        });

        canvas = new Canvas(250, 120);
        GraphicsContext gc = canvas.getGraphicsContext2D();
        paint(gc);

        VBox root = new VBox();
        root.setAlignment(Pos.CENTER);
        root.getChildren().addAll(input, canvas);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    private void paint(GraphicsContext gc) {
        gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());

        String text = input.getText();;
        gc.setFont(Font.font("", FontWeight.BOLD, 64));
        int i;
        for (i = 0; i < text.length(); i++) {
            String c = text.substring(i, i + 1);
            Color color = hm.get(c);
            if (color == null) {
                color = Color.BLACK;
            }
            gc.setFill(color);
            gc.fillText(c, 64 * i, 100);
        }

    }

    public static void main(String... args) {
        launch(args);
    }
}
