Browse Source

Added debug mode. Altered parameters for Util.loadImage

Go to ui.view.Util.java and set debug to true to enable debug output.
Also renamed Util.loadImage(object, String, int, int, int)'s last
parameter to "hints" for consistency with
java.awt.Image.getScaledInstance
Ludwig Tietze 7 years ago
parent
commit
0f524c8c4c
1 changed files with 18 additions and 6 deletions
  1. 18 6
      src/ui/view/Util.java

+ 18 - 6
src/ui/view/Util.java

@@ -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;
 	}
 	}
 }
 }