<commit_before>package cloud.swiftnode.ksecurity.module.kgui;

import cloud.swiftnode.ksecurity.KSecurity;
import cloud.swiftnode.ksecurity.module.kgui.abstraction.gui.KAlert;
import cloud.swiftnode.ksecurity.module.kgui.abstraction.gui.LogItem;
import cloud.swiftnode.ksecurity.module.kgui.listener.LogListener;
import cloud.swiftnode.ksecurity.util.Lang;
import cloud.swiftnode.ksecurity.util.Static;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import org.bukkit.Bukkit;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * Created by <NAME> on 2017-02-13.
 */
public class Controller implements Initializable {
    @FXML
    private TableView<LogItem> view;
    @FXML
    private TableColumn conColumn;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        resizeColumn(view, conColumn);
        Stage stage = KFX.getStage();
        stage.widthProperty().addListener(((observable, oldValue, newValue) ->
                resizeColumn(view, conColumn)));
        view.getItems().addListener((ListChangeListener<LogItem>) c -> Platform.runLater(() -> {
            ObservableList<LogItem> list = view.getItems();
            if (list.size() > 500) {
                list.remove(list.get(0));
            }
            view.scrollTo(list.size() - 1);
        }));
        Bukkit.getPluginManager().registerEvents(new LogListener(view), KSecurity.inst);
    }

    @SuppressWarnings("unchecked")
    private void resizeColumn(TableView view, TableColumn column) {
        Platform.runLater(() -> {
            double totalWidth = view.getWidth();
            double usedWidth = 0;
            for (TableColumn element : (Iterable<TableColumn>) view.getColumns()) {
                if (element == column)
                    continue;
                usedWidth += element.getWidth();
            }
            column.setPrefWidth(totalWidth - usedWidth);
        });
    }

    @FXML
    public void onClear() {
        view.getItems().clear();
    }

    @FXML
    public void onSave() {
        File file = Static.getLogFile();
        if (!file.getParentFile().isDirectory()) {
            file.getParentFile().mkdirs();
        }
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            for (LogItem item : view.getItems()) {
                writer.write(item.getTime() + ": " + item.getLog());
                writer.newLine();
            }
            writer.flush();
            new KAlert().setContextText(
                    Lang.SAVED_LOG.builder()
                            .single(Lang.Key.VALUE, file.getAbsolutePath()).build())
                    .show();
        } catch (Exception ex) {
            Static.consoleMsg(ex);
        }
    }
}<commit_msg>Open folder when save the log<commit_after>package cloud.swiftnode.ksecurity.module.kgui;

import cloud.swiftnode.ksecurity.KSecurity;
import cloud.swiftnode.ksecurity.module.kgui.abstraction.gui.KAlert;
import cloud.swiftnode.ksecurity.module.kgui.abstraction.gui.LogItem;
import cloud.swiftnode.ksecurity.module.kgui.listener.LogListener;
import cloud.swiftnode.ksecurity.util.Lang;
import cloud.swiftnode.ksecurity.util.Static;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import org.bukkit.Bukkit;

import java.awt.*;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * Created by <NAME> on 2017-02-13.
 */
public class Controller implements Initializable {
    @FXML
    private TableView<LogItem> view;
    @FXML
    private TableColumn conColumn;

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        resizeColumn(view, conColumn);
        Stage stage = KFX.getStage();
        stage.widthProperty().addListener(((observable, oldValue, newValue) ->
                resizeColumn(view, conColumn)));
        view.getItems().addListener((ListChangeListener<LogItem>) c -> Platform.runLater(() -> {
            ObservableList<LogItem> list = view.getItems();
            if (list.size() > 500) {
                list.remove(list.get(0));
            }
            view.scrollTo(list.size() - 1);
        }));
        Bukkit.getPluginManager().registerEvents(new LogListener(view), KSecurity.inst);
    }

    @SuppressWarnings("unchecked")
    private void resizeColumn(TableView view, TableColumn column) {
        Platform.runLater(() -> {
            double totalWidth = view.getWidth();
            double usedWidth = 0;
            for (TableColumn element : (Iterable<TableColumn>) view.getColumns()) {
                if (element == column)
                    continue;
                usedWidth += element.getWidth();
            }
            column.setPrefWidth(totalWidth - usedWidth);
        });
    }

    @FXML
    public void onClear() {
        view.getItems().clear();
    }

    @FXML
    public void onSave() {
        File file = Static.getLogFile();
        if (!file.getParentFile().isDirectory()) {
            file.getParentFile().mkdirs();
        }
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            for (LogItem item : view.getItems()) {
                writer.write(item.getTime() + ": " + item.getLog());
                writer.newLine();
            }
            writer.flush();
            new KAlert().setContextText(
                    Lang.SAVED_LOG.builder()
                            .single(Lang.Key.VALUE, file.getAbsolutePath()).build())
                    .setOnCloseRequest((e) -> {
                        if (!Desktop.isDesktopSupported()) {
                            return;
                        }
                        Desktop desktop = Desktop.getDesktop();
                        if (!desktop.isSupported(Desktop.Action.OPEN)) {
                            return;
                        }
                        try {
                            desktop.open(file.getParentFile());
                        } catch (IOException e1) {
                            Static.consoleMsg(e1);
                        }
                    })
                    .show();
        } catch (Exception ex) {
            Static.consoleMsg(ex);
        }
    }
}
{'fraction_non_alphanumeric': 0.11732007021650087, 'fraction_numerical': 0.004388531304856641, 'mean_word_length': 2.162349676225717, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '938393', 'n_tokens_mistral': 1931, 'n_tokens_neox': 1841, 'n_words': 341}