<commit_before>package codeOrchestra.colt.core.ui.components.fileset

import codeOrchestra.colt.core.ui.components.log.JSBridge
import codeOrchestra.groovyfx.FXBindable
import codeOrchestra.util.ProjectHelper
import javafx.application.Platform
import javafx.beans.value.ChangeListener
import javafx.collections.ListChangeListener
import javafx.event.ActionEvent
import javafx.event.EventHandler
import javafx.geometry.Side
import javafx.scene.control.*
import javafx.scene.input.DragEvent
import javafx.scene.layout.AnchorPane
import javafx.scene.web.WebEngine
import javafx.scene.web.WebEvent
import javafx.scene.web.WebView
import javafx.stage.DirectoryChooser
import javafx.stage.FileChooser
import netscape.javascript.JSObject

/*

<AnchorPane maxWidth="640" GridPane.columnIndex="0" GridPane.rowIndex="1">
    <children>
        <Label layoutY="23" text="Library Paths:" AnchorPane.leftAnchor="19" AnchorPane.rightAnchor="48" />
        <TextArea layoutY="46" prefHeight="30" wrapText="true" AnchorPane.leftAnchor="10" AnchorPane.rightAnchor="48" />
        <Button contentDisplay="graphic_only" focusTraversable="false" layoutY="46" prefHeight="30" prefWidth="30" styleClass="btn-add" text="Add" AnchorPane.rightAnchor="10" />
    </children>
</AnchorPane>

*/

/**
 * @author <NAME>
 */
class FilesetInput extends AnchorPane {

    @FXBindable String title = "Library Paths:"

    private Label label = new Label(layoutY: 23)
    private WebView webView = new WebView(id: "fileset-webview", layoutY: 47, prefHeight: 30);
    private TextArea focusRectangle = new TextArea(id: "fileset-webview-focus", layoutY: 46)
    private Button addButton = new Button(contentDisplay: ContentDisplay.GRAPHIC_ONLY, focusTraversable: false, layoutY: 46, prefHeight: 30, prefWidth: 30, text: "Add")
    private JSBridge bridge
    private boolean htmlLoaded
    private boolean layoutInited

    private File startDirectory = null

    @FXBindable boolean useMultiply = true
    @FXBindable boolean useFiles = true
    @FXBindable boolean useDirectory = true
    @FXBindable boolean useExcludes = true

    @FXBindable String files = ""

    FilesetInput() {
        setRightAnchor(addButton, 10)
        setLeftAnchor(label, 19)
        setRightAnchor(label, 48)

        setLeftAnchor(webView, 12)
        setRightAnchor(webView, 50)
        setLeftAnchor(focusRectangle, 10)
        setRightAnchor(focusRectangle, 48)

        addButton.styleClass.add("btn-add")
        label.textProperty().bind(titleProperty)
        children.addAll(label, webView, addButton, focusRectangle)

        focusRectangle.toBack()
        focusRectangle.prefHeightProperty().bind(webView.prefHeightProperty().add(2))
        webView.focusedProperty().addListener({ o, old, focused ->
            focusRectangle.styleClass.removeAll("fileset-webview-focus", "fileset-webview")
            focusRectangle.styleClass.add(focused ? "fileset-webview-focus" : "fileset-webview")
        } as ChangeListener)

        addButton.onAction = {
            ContextMenu cm = buildContextMenu()
            if (cm.items.size() > 1) {
                cm.show(addButton, Side.RIGHT, 0, 0)
            } else {
                cm.items.first().onAction.handle(null)
            }
        } as EventHandler

        // web engine

        String htmlPage = this.class.getResource("html/fileset-webview.html").toExternalForm()
        WebEngine engine = webView.engine
        engine.documentProperty().addListener({ o, oldValue, newValue ->
            htmlLoaded = true
            bridge = new JSBridge(webView.engine) {
                @Override
                void resize(int height) {
                    webView.prefHeight = height
                }
            }
            if (files) {
                setFilesetHtmlValue(files)
            }
        } as ChangeListener)
        engine.load(htmlPage)

        engine.onAlert = { WebEvent<String> event -><commit_msg>fileset in progress<commit_after>package codeOrchestra.colt.core.ui.components.fileset

import codeOrchestra.colt.core.ui.components.log.JSBridge
import codeOrchestra.groovyfx.FXBindable
import codeOrchestra.util.ProjectHelper
import javafx.application.Platform
import javafx.beans.value.ChangeListener
import javafx.collections.ListChangeListener
import javafx.event.ActionEvent
import javafx.event.EventHandler
import javafx.geometry.Side
import javafx.scene.control.*
import javafx.scene.input.DragEvent
import javafx.scene.layout.AnchorPane
import javafx.scene.web.WebEngine
import javafx.scene.web.WebEvent
import javafx.scene.web.WebView
import javafx.stage.DirectoryChooser
import javafx.stage.FileChooser
import netscape.javascript.JSObject

/*

<AnchorPane maxWidth="640" GridPane.columnIndex="0" GridPane.rowIndex="1">
    <children>
        <Label layoutY="23" text="Library Paths:" AnchorPane.leftAnchor="19" AnchorPane.rightAnchor="48" />
        <TextArea layoutY="46" prefHeight="30" wrapText="true" AnchorPane.leftAnchor="10" AnchorPane.rightAnchor="48" />
        <Button contentDisplay="graphic_only" focusTraversable="false" layoutY="46" prefHeight="30" prefWidth="30" styleClass="btn-add" text="Add" AnchorPane.rightAnchor="10" />
    </children>
</AnchorPane>

*/

/**
 * @author <NAME>
 */
class FilesetInput extends AnchorPane {

    @FXBindable String title = "Library Paths:"

    private Label label = new Label(layoutY: 23)
    private WebView webView = new WebView(id: "fileset-webview", layoutY: 47, prefHeight: 30);
    private TextArea focusRectangle = new TextArea(id: "fileset-webview-focus", layoutY: 46)
    private Button addButton = new Button(contentDisplay: ContentDisplay.GRAPHIC_ONLY, focusTraversable: false, layoutY: 46, prefHeight: 30, prefWidth: 30, text: "Add")
    private JSBridge bridge
    private boolean htmlLoaded
    private boolean layoutInited

    private File startDirectory = null

    @FXBindable boolean useMultiply = true
    @FXBindable boolean useFiles = true
    @FXBindable boolean useDirectory = true
    @FXBindable boolean useExcludes = true

    @FXBindable String files = ""

    FilesetInput() {
        setRightAnchor(addButton, 10)
        setLeftAnchor(label, 19)
        setRightAnchor(label, 48)

        setLeftAnchor(webView, 12)
        setRightAnchor(webView, 50)
        setLeftAnchor(focusRectangle, 10)
        setRightAnchor(focusRectangle, 48)

        addButton.styleClass.add("btn-add")
        label.textProperty().bind(titleProperty)
        children.addAll(label, webView, addButton, focusRectangle)

        focusRectangle.toBack()
        focusRectangle.prefHeightProperty().bind(webView.prefHeightProperty().add(2))
        webView.focusedProperty().addListener({ o, old, focused ->
            focusRectangle.styleClass.removeAll("fileset-webview-focus", "fileset-webview")
            focusRectangle.styleClass.add(focused ? "fileset-webview-focus" : "fileset-webview")
        } as ChangeListener)

        addButton.onAction = {
            ContextMenu cm = buildContextMenu()
            if (cm.items.size() > 1) {
                cm.show(addButton, Side.RIGHT, 0, 0)
            } else {
                cm.items.first().onAction.handle(null)
            }
        } as EventHandler

        // web engine

        String htmlPage = this.class.getResource("html/fileset-webview.html").toExternalForm()
        WebEngine engine = webView.engine
        engine.documentProperty().addListener({ o, oldValue, newValue ->
            htmlLoaded = true
            bridge = new JSBridge(webView.engine) {
                @Override
                void resize(int height) {
                    webView.prefHeight = height
                }
            }
            if (files) {
                setFilesetHtmlValue(files)
            }

            focusRectangle.styleClass.add(!focused ? "fileset-webview-focus" : "fileset-webview")
            Platform.runLater{
                focusRectangle.styleClass.removeAll("fileset-webview-focus", "fileset-webview")
                focusRectangle.styleClass.add(focused ? "fileset-webview-focus" : "fileset-webview")
                println "{focusRectangle.styleClass} = ${focusRectangle.styleClass}"
            }

        } as ChangeListener)
        engine.load(htmlPage)

        engine.onAlert = { WebEvent<String> event ->
{'fraction_non_alphanumeric': 0.10405877393713116, 'fraction_numerical': 0.014211730699747079, 'mean_word_length': 3.1088570014844135, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 29, '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': '3437257', 'n_tokens_mistral': 2506, 'n_tokens_neox': 2364, 'n_words': 474}