<commit_before>package logbook.internal.gui;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.imageio.ImageIO;

import org.controlsfx.control.Notifications;

import javafx.beans.property.ObjectProperty;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.SplitPane;
import javafx.scene.control.SplitPane.Divider;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.SortType;
import javafx.scene.control.TableColumnBase;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
import logbook.bean.AppConfig;
import logbook.bean.WindowLocation;
import logbook.internal.log.LogWriter;
import logbook.plugin.PluginServices;

/**
 * JavaFx Tools
 *
 */
public class Tools {

    /**
     * window
     *
     */
    public static class Windows {

        /**
         * ウインドウの設定
         * @param stage Stage
         * @throws IOException 入出力例外が発生した場合
         */
        public static void setIcon(Stage stage) throws IOException {
            // アイコン
            String[] uris = {
                    "logbook/gui/icon_256x256.png",
                    "logbook/gui/icon_128x128.png",
                    "logbook/gui/icon_64x64.png",
                    "logbook/gui/icon_48x48.png",
                    "logbook/gui/icon_32x32.png",
                    "logbook/gui/icon_16x16.png" };

            for (String uri : uris) {
                try (InputStream is = PluginServices.getResourceAsStream(uri)) {
                    stage.getIcons().add(new Image(is));
                }
            }
        }

        /**
         * デフォルトの閉じるアクション
         * @param controller WindowController
         */
        public static void defaultCloseAction(WindowController controller) {
            this.defaultCloseAction(controller, null);
        }

        /**
         * デフォルトの閉じるアクション
         * @param controller WindowController
         * @param subkey String
         */
        public static void defaultCloseAction(WindowController controller, String subkey) {
            if (controller.getWindow() != null) {
                EventHandler<WindowEvent> action = e -> {
                    String key = controller.getClass().getCanonicalName()+ Optional.ofNullable(subkey).map(str -> "#"+ str).orElse("");
                    AppConfig.get()
                            .getWindowLocationMap()
                            .put(key, controller.getWindowLocation());
                };
                controller.getWindow()
                        .addEventHandler(WindowEvent.WINDOW_HIDDEN, action);
            }
        }

        /**
         * デフォルトのウインドウ設定
         * @param controller WindowController
         */
        public static void defaultOpenAction(WindowController controller) {
            this.defaultOpenAction(controller, null);
        }

        /**
         * デフォルトのウインドウ設定
         * @param controller WindowController
         * @param subkey String<commit_msg>static method への this を削除<commit_after>package logbook.internal.gui;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import javax.imageio.ImageIO;

import org.controlsfx.control.Notifications;

import javafx.beans.property.ObjectProperty;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.embed.swing.SwingFXUtils;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.SnapshotParameters;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ButtonType;
import javafx.scene.control.SplitPane;
import javafx.scene.control.SplitPane.Divider;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.SortType;
import javafx.scene.control.TableColumnBase;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.image.WritableImage;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.paint.Color;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import javafx.stage.Window;
import javafx.stage.WindowEvent;
import javafx.util.Duration;
import logbook.bean.AppConfig;
import logbook.bean.WindowLocation;
import logbook.internal.log.LogWriter;
import logbook.plugin.PluginServices;

/**
 * JavaFx Tools
 *
 */
public class Tools {

    /**
     * window
     *
     */
    public static class Windows {

        /**
         * ウインドウの設定
         * @param stage Stage
         * @throws IOException 入出力例外が発生した場合
         */
        public static void setIcon(Stage stage) throws IOException {
            // アイコン
            String[] uris = {
                    "logbook/gui/icon_256x256.png",
                    "logbook/gui/icon_128x128.png",
                    "logbook/gui/icon_64x64.png",
                    "logbook/gui/icon_48x48.png",
                    "logbook/gui/icon_32x32.png",
                    "logbook/gui/icon_16x16.png" };

            for (String uri : uris) {
                try (InputStream is = PluginServices.getResourceAsStream(uri)) {
                    stage.getIcons().add(new Image(is));
                }
            }
        }

        /**
         * デフォルトの閉じるアクション
         * @param controller WindowController
         */
        public static void defaultCloseAction(WindowController controller) {
            defaultCloseAction(controller, null);
        }

        /**
         * デフォルトの閉じるアクション
         * @param controller WindowController
         * @param subkey String
         */
        public static void defaultCloseAction(WindowController controller, String subkey) {
            if (controller.getWindow() != null) {
                EventHandler<WindowEvent> action = e -> {
                    String key = controller.getClass().getCanonicalName()+ Optional.ofNullable(subkey).map(str -> "#"+ str).orElse("");
                    AppConfig.get()
                            .getWindowLocationMap()
                            .put(key, controller.getWindowLocation());
                };
                controller.getWindow()
                        .addEventHandler(WindowEvent.WINDOW_HIDDEN, action);
            }
        }

        /**
         * デフォルトのウインドウ設定
         * @param controller WindowController
         */
        public static void defaultOpenAction(WindowController controller) {
            defaultOpenAction(controller, null);
        }

        /**
         * デフォルトのウインドウ設定
         * @param controller WindowController
         * @param subkey String
{'fraction_non_alphanumeric': 0.09874285714285715, 'fraction_numerical': 0.0064, 'mean_word_length': 2.5850061450225317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6193214', 'n_tokens_mistral': 2600, 'n_tokens_neox': 2533, 'n_words': 451}