Browse Source

Altered resource loading, old code kept in comments

Ludwig Tietze 7 years ago
parent
commit
fbf1a6106d
1 changed files with 31 additions and 0 deletions
  1. 31 0
      src/ui/view/Util.java

+ 31 - 0
src/ui/view/Util.java

@@ -0,0 +1,31 @@
+package ui.view;
+
+import java.awt.Image;
+import java.awt.Toolkit;
+import java.io.File;
+
+import javax.swing.ImageIcon;
+
+public class Util {
+	
+	static Image loadImage(Object origin, String url, int w, int h, int scale){//note: this may have to be a different class.
+		return loadImage(origin,url)
+				.getScaledInstance(w, h, scale);
+	}
+	static Image loadImage(Object origin, String url){//note: this may have to be a different class.
+		System.out.println(url);
+		try{
+			return new ImageIcon(origin.getClass().getResource(url)).getImage();
+		}catch(Exception e){
+			return new ImageIcon(Toolkit.getDefaultToolkit().createImage("res"+url)).getImage();
+		}
+	}
+	//TODO: This is a temporary solution. Fix.
+	static File loadFile(Object origin, String url){//note: this may have to be a different class.
+		try{
+			return new File(origin.getClass().getResource(url).getFile());
+		}catch(Exception e){
+			return new File("res"+url);
+		}
+	}
+}