package moe.tristan.easyfxml.api;

import moe.tristan.easyfxml.util.Resources;
import moe.tristan.easyfxml.util.Stages;

import javafx.stage.Stage;

import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;

/**
 * Represents a stylesheet a supplier of Path. What this means is that any protocol is acceptable. Whether it is local
 * file-based or remote URI-based.
 * <p>
 *
 * @see Stages#setStylesheet(Stage, FxmlStylesheet)
 */
public interface FxmlStylesheet {

    /**
     * @return the CSS file that composes the stylesheet as a {@link Path}.
     * <p>
     * See {@link Resources#getResourcePath(String)}
     */
    Path getPath();

    /**
     * @return the CSS file in external form (i.e. with the file:/, http:/...) protocol info before it.
     * <p>
     * See {@link Resources#getResourceURL(String)} and {@link URL#toExternalForm()}
     */
    default String getExternalForm() {
        try {
            return getPath().toUri().toURL().toExternalForm();
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException(e);
        }
    }

}

@@ -112,16 +112,44 @@
 .Stages;
+%0Aimport io.vavr.control.Try;
 %0A%0Aimport
@@ -186,37 +186,19 @@
 ava.net.
-MalformedURLException
+URI
 ;%0Aimport
@@ -676,32 +676,275 @@
 ath();%0A%0A    /**%0A
+     * This method is a sample implementation that should work in almost all general cases.%0A     * An %7B@link java.io.IOException%7D can be thrown in very rare cases.%0A     *%0A     * If you encounter them, post an issue with system details.%0A     *%0A
      * @return t
@@ -1044,35 +1044,36 @@
 * %3Cp%3E%0A     *
- See %7B@link
+%0A     * @see
  Resources#g
@@ -1097,20 +1097,20 @@
 ing)
-%7D and %7B@link
+%0A     * @see
  URL
@@ -1126,17 +1126,16 @@
 alForm()
-%7D
 %0A     */
@@ -1186,13 +1186,36 @@
     
-try %7B
+return Try.of(this::getPath)
 %0A   
@@ -1227,163 +1227,115 @@
     
-return get
+.map(
 Path
-().
+::
 toUri
-().toURL().toExternalForm();%0A        %7D catch (MalformedURLException e) %7B%0A            throw new IllegalArgumentException(e);%0A        %7D
+)%0A            .mapTry(URI::toURL)%0A            .map(URL::toExternalForm)%0A            .get();
 %0A   

Remove useless catch case that wouldn't happen under normal operation.