From 62e2010df8d3ad9d089a11bd83c8bad92e998c02 Mon Sep 17 00:00:00 2001 From: judy0131 Date: Tue, 15 Dec 2020 05:22:35 -0500 Subject: [PATCH] fix bug: show icon fro external stop --- .../scala/cn/piflow/conf/util/ImageUtil.scala | 27 ++++++++++++------ .../cn/piflow/conf/util/PluginManager.scala | 28 ++++++++++++++++++- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/piflow-configure/src/main/scala/cn/piflow/conf/util/ImageUtil.scala b/piflow-configure/src/main/scala/cn/piflow/conf/util/ImageUtil.scala index 996337e..e771689 100644 --- a/piflow-configure/src/main/scala/cn/piflow/conf/util/ImageUtil.scala +++ b/piflow-configure/src/main/scala/cn/piflow/conf/util/ImageUtil.scala @@ -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) } } diff --git a/piflow-configure/src/main/scala/cn/piflow/conf/util/PluginManager.scala b/piflow-configure/src/main/scala/cn/piflow/conf/util/PluginManager.scala index 770df6a..8eabc98 100644 --- a/piflow-configure/src/main/scala/cn/piflow/conf/util/PluginManager.scala +++ b/piflow-configure/src/main/scala/cn/piflow/conf/util/PluginManager.scala @@ -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]()