From dec0dc08adb71ea0066c93ddb4015374eae37577 Mon Sep 17 00:00:00 2001 From: kske Date: Wed, 24 Jul 2019 07:41:45 +0200 Subject: [PATCH] Added tools menu in MenuBar with FEN export menu item --- src/dev/kske/chess/ui/MenuBar.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/dev/kske/chess/ui/MenuBar.java b/src/dev/kske/chess/ui/MenuBar.java index b1fd6b3..62100a9 100644 --- a/src/dev/kske/chess/ui/MenuBar.java +++ b/src/dev/kske/chess/ui/MenuBar.java @@ -1,5 +1,8 @@ package dev.kske.chess.ui; +import java.awt.Toolkit; +import java.awt.datatransfer.StringSelection; + import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; @@ -27,6 +30,7 @@ public class MenuBar extends JMenuBar { initGameMenu(); initEngineMenu(); + initToolsMenu(); } private void initGameMenu() { @@ -92,6 +96,18 @@ public class MenuBar extends JMenuBar { add(engineMenu); } + private void initToolsMenu() { + JMenu toolsMenu = new JMenu("Tools"); + + JMenuItem exportFENMenuItem = new JMenuItem("Export board to FEN"); + exportFENMenuItem.addActionListener((evt) -> Toolkit.getDefaultToolkit() + .getSystemClipboard() + .setContents(new StringSelection(mainWindow.getGame().getBoard().toFEN()), null)); + toolsMenu.add(exportFENMenuItem); + + add(toolsMenu); + } + private void startGame(Game game) { mainWindow.setGame(game);