|
@@ -11,6 +11,7 @@ import java.io.InputStream;
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
|
public class Util {
|
|
public class Util {
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 30x30 pixel FileNotFound Icon, which can be shown without using I/O operations
|
|
* 30x30 pixel FileNotFound Icon, which can be shown without using I/O operations
|
|
*/
|
|
*/
|
|
@@ -59,17 +60,21 @@ public class Util {
|
|
}
|
|
}
|
|
|
|
|
|
static InputStream loadStream(Object origin, String url){
|
|
static InputStream loadStream(Object origin, String url){
|
|
-
|
|
|
|
InputStream o=origin.getClass().getResourceAsStream(url);
|
|
InputStream o=origin.getClass().getResourceAsStream(url);
|
|
if(o!=null)return o;
|
|
if(o!=null)return o;
|
|
else{
|
|
else{
|
|
- System.out.println("Loading of resource \""+url+"\" as stream failed.\nWill attempt to load as File.");
|
|
|
|
|
|
+ System.out.println("Loading of \""+url+"\" as local resource failed.\nWill attempt to load as File.");
|
|
boolean rootSymbol=false; //Whether url starts with a / or \
|
|
boolean rootSymbol=false; //Whether url starts with a / or \
|
|
- switch(url.charAt(0)){ //So we can make sure to consttruct res/path correctly.
|
|
|
|
|
|
+ switch(url.charAt(0)){ //So we can make sure to construct res/path correctly.
|
|
case '/':case '\\':rootSymbol=true;
|
|
case '/':case '\\':rootSymbol=true;
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- return new FileInputStream("res"+(rootSymbol?"":"/")+url);
|
|
|
|
|
|
+ //I am checking, whether the requested File is an internal resource.
|
|
|
|
+ //If it is, res/url has to be used, otherwise url.
|
|
|
|
+ //Mixed separators should cause problems. Will fix later.
|
|
|
|
+ File f=new File(url);
|
|
|
|
+ if(!f.exists()||!f.getAbsolutePath().equals(url))url="res"+(rootSymbol?"":"/")+url;
|
|
|
|
+ return new FileInputStream(url);
|
|
} catch (FileNotFoundException e1) {
|
|
} catch (FileNotFoundException e1) {
|
|
e1.printStackTrace();
|
|
e1.printStackTrace();
|
|
}
|
|
}
|