~tapaal-contributor/tapaal/add-java-info-1890600

« back to all changes in this revision

Viewing changes to src/net/tapaal/resourcemanager/ResourceManager.java

merged in lp:~yrke/tapaal/updateResourceManager-2 fixing loading of images

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package dk.aau.cs.io;
 
1
package net.tapaal.resourcemanager;
2
2
 
3
3
import java.awt.Image;
4
4
import java.io.IOException;
 
5
import java.net.URL;
 
6
import java.util.Objects;
5
7
 
6
8
import javax.imageio.ImageIO;
7
9
import javax.swing.ImageIcon;
9
11
import pipe.gui.CreateGui;
10
12
 
11
13
public class ResourceManager {
 
14
    public static final String imgPath = "resources/Images/";
 
15
 
12
16
        private static ImageIcon satisfiedIcon = loadIcon("satisfied.png");
13
17
        private static ImageIcon notSatisfiedIcon = loadIcon("notsatisfied.png");
14
18
        private static ImageIcon inconclusiveIcon = loadIcon("maybe1.png");
18
22
        
19
23
        private static ImageIcon loadIcon(String name) {
20
24
                try {
21
 
                        return new ImageIcon(ImageIO.read(Thread.currentThread().getContextClassLoader().getResource(CreateGui.imgPath + name)).getScaledInstance(52, 52, Image.SCALE_SMOOTH));
 
25
                        return new ImageIcon(ImageIO.read(Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource(imgPath + name))).getScaledInstance(52, 52, Image.SCALE_SMOOTH));
22
26
                } catch (IOException | IllegalArgumentException e) {
23
27
                        e.printStackTrace();
24
28
                }
25
29
        return null;
26
30
        }
 
31
 
 
32
    public static ImageIcon getIcon(String name) {
 
33
        return Objects.requireNonNull(getIconIfExists(name), "Icon " + name + " not found");
 
34
    }
 
35
 
 
36
    public static ImageIcon getIconIfExists(String name) {
 
37
        URL resourceURL = Thread.currentThread().getContextClassLoader().getResource(ResourceManager.imgPath + name);
 
38
        if (resourceURL == null) return null;
 
39
 
 
40
        return new ImageIcon(resourceURL);
 
41
    }
27
42
        
28
43
        public static ImageIcon satisfiedIcon(){
29
44
                return satisfiedIcon;