package dev.kske.chess.ui; import java.awt.Font; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.BiConsumer; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JLabel; /** * Project: Chess
* File: GameConfigurationDialog.java
* Created: 24.07.2019
* Author: Kai S. K. Engelbart */ public class GameConfigurationDialog { private GameConfigurationDialog() {} public static void show(BiConsumer action) { new JDialog() { private static final long serialVersionUID = -5768339760489440385L; { setTitle("Game Configuration"); setBounds(100, 100, 281, 142); setModal(true); setLocationRelativeTo(null); getContentPane().setLayout(null); List options = new ArrayList<>(Arrays.asList("Natural Player", "AI Player")); EngineUtil.getEngineInfos().forEach(info -> options.add(info.name)); JLabel lblWhite = new JLabel("White:"); lblWhite.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblWhite.setBounds(10, 11, 49, 14); getContentPane().add(lblWhite); JComboBox cbWhite = new JComboBox<>(); cbWhite.setModel(new DefaultComboBoxModel(options.toArray())); cbWhite.setBounds(98, 9, 159, 22); getContentPane().add(cbWhite); JLabel lblBlack = new JLabel("Black:"); lblBlack.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblBlack.setBounds(10, 38, 49, 14); getContentPane().add(lblBlack); JComboBox cbBlack = new JComboBox<>(); cbBlack.setModel(new DefaultComboBoxModel(options.toArray())); cbBlack.setBounds(98, 36, 159, 22); getContentPane().add(cbBlack); JButton btnStart = new JButton("Start"); btnStart.addActionListener((evt) -> { dispose(); action.accept(options.get(cbWhite.getSelectedIndex()), options.get(cbBlack.getSelectedIndex())); }); btnStart.setBounds(20, 73, 89, 23); getContentPane().add(btnStart); JButton btnCancel = new JButton("Cancel"); btnCancel.addActionListener((evt) -> dispose()); btnCancel.setBounds(157, 73, 89, 23); getContentPane().add(btnCancel); } }.setVisible(true); } }