fix bug: show icon fro external stop

This commit is contained in:
judy0131 2020-12-15 05:22:35 -05:00
parent 5bb7d64efd
commit 62e2010df8
2 changed files with 45 additions and 10 deletions

View File

@ -1,20 +1,29 @@
package cn.piflow.conf.util
import java.io.{BufferedInputStream, FileInputStream}
import java.io.{BufferedInputStream, ByteArrayOutputStream, FileInputStream}
import com.sksamuel.scrimage.Image
object ImageUtil {
def getImage(imagePath:String) : Array[Byte] = {
try{
val classLoader = this.getClass.getClassLoader
val imageInputStream = classLoader.getResourceAsStream(imagePath)
val input = new BufferedInputStream(imageInputStream)
Image.fromStream(input).bytes
}catch {
case ex => println(ex); Array[Byte]()
def getImage(imagePath:String, bundle:String = "") : Array[Byte] = {
if(bundle == ""){
try{
val classLoader = this.getClass.getClassLoader
val imageInputStream = classLoader.getResourceAsStream(imagePath)
val input = new BufferedInputStream(imageInputStream)
return Image.fromStream(input).bytes
}catch {
case ex => {
println(ex);
Array[Byte]()
}
}
}else{
val pluginManager = PluginManager.getInstance
return pluginManager.getConfigurableStopIcon(imagePath, bundle)
}
}

View File

@ -1,12 +1,13 @@
package cn.piflow.conf.util
import java.io.File
import java.io.{BufferedInputStream, File}
import java.net.{MalformedURLException, URL}
import java.util
import java.net.URL
import cn.piflow.conf.ConfigurableStop
import cn.piflow.util.PropertyUtil
import com.sksamuel.scrimage.Image
import org.clapper.classutil.ClassFinder
import scala.collection.mutable.{Map => MMap}
@ -62,6 +63,31 @@ class PluginManager {
null
}
def getConfigurableStopIcon(imagePath:String, bundleName:String): Array[Byte] = {
val it = pluginMap.keys.iterator
while (it.hasNext) {
val plugin = it.next
try {
val forName = Class.forName(bundleName, true, getLoader(plugin))
val ins = forName.newInstance.asInstanceOf[ConfigurableStop]
val imageInputStream = getLoader(plugin).getResourceAsStream(imagePath)
val input = new BufferedInputStream(imageInputStream)
return Image.fromStream(input).bytes
} catch {
case e: IllegalAccessException =>
e.printStackTrace()
case e: InstantiationException =>
e.printStackTrace()
case e: ClassNotFoundException =>
System.err.println(bundleName + " can not be found in " + plugin)
//e.printStackTrace();
}
}
null
}
def getPluginConfigurableStops(): List[ConfigurableStop] = {
var stopList = List[ConfigurableStop]()