Преглед изворни кода

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 година
родитељ
комит
0f524c8c4c
1 измењених фајлова са 18 додато и 6 уклоњено
  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 {
 	
-	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){
 		return loadImage(origin,url,w,h, Image.SCALE_SMOOTH);
 	}
 	static Image loadImage(Object origin, String url){
+		File f= loadFile(origin, url);
+		if(debug)System.out.println("Loading image: "+url);
 		try {
-			return ImageIO.read(loadFile(origin, url));
+			return ImageIO.read(f);
 		} catch (IOException e) {
 			e.printStackTrace();
-			return null;
 		}
+		return null;
 	}
 	static File loadFile(Object origin, String url){
+		String forcedSeparator="/";
+		url=url.replace("\\", forcedSeparator);
+		File o;
+		if(debug)System.out.print("Loading file: "+url+" ");
 		try{
-			return new File(origin.getClass().getResource(url).getFile());
+			o=new File(origin.getClass().getResource(url).getFile());
 		}catch(Exception e){
 			boolean rootSymbol=false;//Whether url starts with a / or \
 			switch(url.charAt(0)){
 			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;
 	}
 }