<commit_before>/*
 * Copyright (C) 2019 <NAME> <<EMAIL>>
 * and other copyright owners as documented in the project's IP log.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package tv.dotstart.beacon.util

import com.jfoenix.controls.JFXDecorator
import javafx.fxml.FXMLLoader
import javafx.scene.Node
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.stage.Stage
import javafx.stage.StageStyle
import java.io.FileNotFoundException
import java.nio.charset.StandardCharsets
import java.nio.file.NoSuchFileException

/**
 * @author [<NAME>](mailto:<EMAIL>)
 */

/**
 * Loads an FXML resource from the given location.
 */
fun <T : Any> fxml(path: String): T {
  val classLoader = Thread.currentThread().contextClassLoader
  val resource = classLoader.getResource("fxml/$path")
      ?: throw FileNotFoundException("No such FXML resource: $path")

  val loader = FXMLLoader(resource)
  loader.charset = StandardCharsets.UTF_8
  return loader.load()
}

/**
 * Creates an undecorated window from the given FXML resource.
 */
fun Stage.splashWindow(path: String): Scene {
  this.initStyle(StageStyle.UNDECORATED)

  val node = fxml<Parent>(path)

  val scene = Scene(node)
  this.scene = scene
  return scene
}

/**
 * Creates a decorated window from the given FXML resource.
 */
fun Stage.window(path: String, fullScreen: Boolean = false, maximizable: Boolean = true,
    minimizable: Boolean = true): Scene {
  val node = fxml<Node>(path)

  val decorator = JFXDecorator(this, node, fullScreen, maximizable, minimizable)

  val scene = Scene(decorator)
  this.scene = scene
  return scene
}<commit_msg>Added the JFoenix default stylesheets to all decorated windows.<commit_after>/*
 * Copyright (C) 2019 <NAME> <<EMAIL>>
 * and other copyright owners as documented in the project's IP log.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package tv.dotstart.beacon.util

import com.jfoenix.assets.JFoenixResources
import com.jfoenix.controls.JFXDecorator
import javafx.fxml.FXMLLoader
import javafx.scene.Node
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.stage.Stage
import javafx.stage.StageStyle
import java.io.FileNotFoundException
import java.nio.charset.StandardCharsets

/**
 * @author [<NAME>](mailto:<EMAIL>)
 */

/**
 * Loads an FXML resource from the given location.
 */
fun <T : Any> fxml(path: String): T {
  val classLoader = Thread.currentThread().contextClassLoader
  val resource = classLoader.getResource("fxml/$path")
      ?: throw FileNotFoundException("No such FXML resource: $path")

  val loader = FXMLLoader(resource)
  loader.charset = StandardCharsets.UTF_8
  return loader.load()
}

/**
 * Creates an undecorated window from the given FXML resource.
 */
fun Stage.splashWindow(path: String): Scene {
  this.initStyle(StageStyle.UNDECORATED)

  val node = fxml<Parent>(path)

  val scene = Scene(node)
  this.scene = scene
  return scene
}

/**
 * Creates a decorated window from the given FXML resource.
 */
fun Stage.window(path: String, fullScreen: Boolean = false, maximizable: Boolean = true,
    minimizable: Boolean = true): Scene {
  val node = fxml<Node>(path)

  val decorator = JFXDecorator(this, node, fullScreen, maximizable, minimizable)

  val scene = Scene(decorator)

  scene.stylesheets.addAll(
      JFoenixResources.load("css/jfoenix-fonts.css").toExternalForm(),
      JFoenixResources.load("css/jfoenix-design.css").toExternalForm()
  )

  this.scene = scene
  return scene
}
{'fraction_non_alphanumeric': 0.10031208203299152, 'fraction_numerical': 0.004012483281319661, 'mean_word_length': 4.254098360655738, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 10}, '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': '6717638', 'n_tokens_mistral': 1347, 'n_tokens_neox': 1305, 'n_words': 441}