|
@@ -1,34 +1,37 @@
|
|
package ui.view;
|
|
package ui.view;
|
|
|
|
|
|
import java.awt.Image;
|
|
import java.awt.Image;
|
|
-import java.awt.Toolkit;
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
|
-import javax.swing.ImageIcon;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
|
|
|
public class Util {
|
|
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, int w, int h, int scale){
|
|
|
|
+ System.out.println("Scaled call: "+url);
|
|
|
|
+ return loadImage(origin,url).getScaledInstance(w, h, scale);
|
|
}
|
|
}
|
|
- static Image loadImage(Object origin, String url, int w, int h){//note: this may have to be a different class.
|
|
|
|
|
|
+ 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){//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();
|
|
|
|
|
|
+ static Image loadImage(Object origin, String url){
|
|
|
|
+ try {
|
|
|
|
+ return ImageIO.read(loadFile(origin, url));
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return null;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //TODO: This is a temporary solution. Fix.
|
|
|
|
- static File loadFile(Object origin, String url){//note: this may have to be a different class.
|
|
|
|
|
|
+ static File loadFile(Object origin, String url){
|
|
try{
|
|
try{
|
|
return new File(origin.getClass().getResource(url).getFile());
|
|
return new File(origin.getClass().getResource(url).getFile());
|
|
}catch(Exception e){
|
|
}catch(Exception e){
|
|
- return new File("res"+url);
|
|
|
|
|
|
+ boolean rootSymbol=false;//Whether url starts with a / or \
|
|
|
|
+ switch(url.charAt(0)){
|
|
|
|
+ case '/':case '\\':rootSymbol=true;
|
|
|
|
+ }
|
|
|
|
+ return new File("res"+(rootSymbol?"":"/")+url);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|