Skip to content

Commit

Permalink
load icon from http while not be found by path
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcent committed Dec 16, 2019
1 parent 67876bd commit 8395177
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Binary file added assets/close.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ok.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 16 additions & 2 deletions idea-plugin/src/main/kotlin/com/itangcent/idea/icons/EasyIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.intellij.util.ReflectionUtil
import com.itangcent.common.utils.invokeMethod
import org.jetbrains.annotations.NonNls
import java.awt.Component
import java.net.URL
import javax.swing.AbstractButton
import javax.swing.Icon

Expand Down Expand Up @@ -37,10 +38,12 @@ object EasyIcons {
val UpFolder = tryLoad("/nodes/upFolder.png") // 16x16

val Close = tryLoad("/notification/close.png",
"/actions/close.png") // 16x16
"/actions/close.png")
?: tryLoadByUrl(URL("https://github.com/tangcent/easy-api/blob/master/assets/close.png"))

val OK = tryLoad("/general/inspectionsOK.png",
"/process/state/GreenOK.png") // 16x16
"/process/state/GreenOK.png")
?: tryLoadByUrl(URL("https://github.com/tangcent/easy-api/blob/master/assets/ok.png"))

val Export = tryLoad(
"/actions/export.png",
Expand Down Expand Up @@ -71,6 +74,17 @@ object EasyIcons {

return IconLoader.findIcon(path, callerClass)
}

private fun tryLoadByUrl(vararg paths: URL): Icon? {
for (path in paths) {
try {
IconLoader.findIcon(path)?.let { return it }
} catch (e: Exception) {
}
}
return null
}

}

fun Icon?.iconOnly(component: Component?) {
Expand Down

0 comments on commit 8395177

Please sign in to comment.