groostav
11/12/2020, 8:49 PMresourceBundle.get("MizzspelledKey")
with "this lookup is suspicious" would be a step forwardmelatonina
11/12/2020, 9:35 PMgroostav
11/12/2020, 11:07 PMmelatonina
11/13/2020, 7:12 PMmelatonina
11/13/2020, 7:12 PMmelatonina
11/13/2020, 8:46 PMopen class SVGResources(
val baseName: String
) {
@OptIn(ExperimentalStdlibApi::class)
fun propertyNameToResourceName(propertyName: String) =
baseName + propertyName.splitCamelCaseToList().joinToString("_") { it.toLowerCase() } + ".svg"
operator fun getValue(thisRef: Any?, property: KProperty<*>) =
Resource(propertyNameToResourceName(property.name))
private val svgLoader = SvgLoader()
private fun loadSvg(resourceName: String): Group =
svgLoader.loadSvg(javaClass.getResourceAsStream(resourceName))
inner class Resource(val resourceName: String) {
fun load() = loadSvg(resourceName)
operator fun invoke() = load()
}
}
and then, something like this:
object Icons : SVGResources("/x/ay/z/") {
val play by Icons
val playSelection by Icons
val pause by Icons
val stop by Icons
val fastRewind by Icons
val fastForward by Icons
val skipPrevious by Icons
val skipNext by Icons
val zoomIn by Icons
val zoomOut by Icons
val folder by Icons
val add by Icons
val delete by Icons
val createNewFolder by Icons
val volume by Icons
val closeWindow by Icons
val refresh by Icons
val face by Icons
}
then I load the "zoom in" icon resource with Icons.zoomIn()
.melatonina
11/13/2020, 8:48 PMmelatonina
11/13/2020, 8:50 PMgroostav
11/13/2020, 9:44 PMgroostav
11/13/2020, 9:45 PMgroostav
11/13/2020, 9:45 PMgroostav
11/13/2020, 9:45 PM