|
@@ -8,29 +8,41 @@ import javax.imageio.ImageIO;
|
|
|
|
|
|
public class Util {
|
|
public class Util {
|
|
|
|
|
|
- static Image loadImage(Object origin, String url, int w, int h, int scale){
|
|
|
|
- return loadImage(origin,url).getScaledInstance(w, h, scale);
|
|
|
|
|
|
+ private static final boolean debug=true;
|
|
|
|
+
|
|
|
|
+ static Image loadImage(Object origin, String url, int w, int h, int hints){
|
|
|
|
+ Image o= loadImage(origin,url);
|
|
|
|
+ System.out.println("Scaling image: w="+w+" h="+h);
|
|
|
|
+ return o.getScaledInstance(w, h, hints);
|
|
}
|
|
}
|
|
static Image loadImage(Object origin, String url, int w, int h){
|
|
static Image loadImage(Object origin, String url, int w, int h){
|
|
return loadImage(origin,url,w,h, Image.SCALE_SMOOTH);
|
|
return loadImage(origin,url,w,h, Image.SCALE_SMOOTH);
|
|
}
|
|
}
|
|
static Image loadImage(Object origin, String url){
|
|
static Image loadImage(Object origin, String url){
|
|
|
|
+ File f= loadFile(origin, url);
|
|
|
|
+ if(debug)System.out.println("Loading image: "+url);
|
|
try {
|
|
try {
|
|
- return ImageIO.read(loadFile(origin, url));
|
|
|
|
|
|
+ return ImageIO.read(f);
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- return null;
|
|
|
|
}
|
|
}
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
static File loadFile(Object origin, String url){
|
|
static File loadFile(Object origin, String url){
|
|
|
|
+ String forcedSeparator="/";
|
|
|
|
+ url=url.replace("\\", forcedSeparator);
|
|
|
|
+ File o;
|
|
|
|
+ if(debug)System.out.print("Loading file: "+url+" ");
|
|
try{
|
|
try{
|
|
- return new File(origin.getClass().getResource(url).getFile());
|
|
|
|
|
|
+ o=new File(origin.getClass().getResource(url).getFile());
|
|
}catch(Exception e){
|
|
}catch(Exception e){
|
|
boolean rootSymbol=false;//Whether url starts with a / or \
|
|
boolean rootSymbol=false;//Whether url starts with a / or \
|
|
switch(url.charAt(0)){
|
|
switch(url.charAt(0)){
|
|
case '/':case '\\':rootSymbol=true;
|
|
case '/':case '\\':rootSymbol=true;
|
|
}
|
|
}
|
|
- return new File("res"+(rootSymbol?"":"/")+url);
|
|
|
|
|
|
+ o=new File("res"+(rootSymbol?"":"/")+url);
|
|
}
|
|
}
|
|
|
|
+ if(debug)System.out.println("Size: "+o.length());
|
|
|
|
+ return o;
|
|
}
|
|
}
|
|
}
|
|
}
|