|
@@ -3,7 +3,10 @@ package ui.view;
|
|
|
import java.awt.Image;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
@@ -47,7 +50,7 @@ public class Util {
|
|
|
|
|
|
static Image loadImage(Object origin, String url){
|
|
|
try {
|
|
|
- return ImageIO.read(loadFile(origin, url));
|
|
|
+ return ImageIO.read(loadStream(origin, url));
|
|
|
} catch (IOException e) {
|
|
|
System.err.println("Warning: '" + url + "' loading failed!");
|
|
|
e.printStackTrace();
|
|
@@ -55,15 +58,29 @@ public class Util {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static File loadFile(Object origin, String url){
|
|
|
- try{
|
|
|
- return new File(origin.getClass().getResource(url).getFile());
|
|
|
- }catch(Exception e){
|
|
|
- boolean rootSymbol=false;//Whether url starts with a / or \
|
|
|
- switch(url.charAt(0)){
|
|
|
+ static InputStream loadStream(Object origin, String url){
|
|
|
+
|
|
|
+ InputStream o=origin.getClass().getResourceAsStream(url);
|
|
|
+ if(o!=null)return o;
|
|
|
+ else{
|
|
|
+ System.out.println("Loading of resource \""+url+"\" as stream failed.\nWill attempt to load as File.");
|
|
|
+ boolean rootSymbol=false; //Whether url starts with a / or \
|
|
|
+ switch(url.charAt(0)){ //So we can make sure to consttruct res/path correctly.
|
|
|
case '/':case '\\':rootSymbol=true;
|
|
|
}
|
|
|
- return new File("res"+(rootSymbol?"":"/")+url);
|
|
|
+ try {
|
|
|
+ return new FileInputStream("res"+(rootSymbol?"":"/")+url);
|
|
|
+ } catch (FileNotFoundException e1) {
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ System.out.println("Test");
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e1) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|
|
|
}
|