diff options
author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-24 15:25:58 -0500 |
---|---|---|
committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-24 15:25:58 -0500 |
commit | cd6b39590b8aced78fc2f6ed0c345fb9af1960c0 (patch) | |
tree | 807bc48adeb2a78a3f1d9b93f3471012509b5e51 /src/com/fourisland/fourpuzzle/util/ObjectLoader.java | |
parent | a581d9b4136bb633771e5e881bbee5a36247b0e0 (diff) | |
download | fourpuzzle-cd6b39590b8aced78fc2f6ed0c345fb9af1960c0.tar.gz fourpuzzle-cd6b39590b8aced78fc2f6ed0c345fb9af1960c0.tar.bz2 fourpuzzle-cd6b39590b8aced78fc2f6ed0c345fb9af1960c0.zip |
Replaced checked exceptions with RuntimeException
Diffstat (limited to 'src/com/fourisland/fourpuzzle/util/ObjectLoader.java')
-rw-r--r-- | src/com/fourisland/fourpuzzle/util/ObjectLoader.java | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java index c14a8a1..b149ddd 100644 --- a/src/com/fourisland/fourpuzzle/util/ObjectLoader.java +++ b/src/com/fourisland/fourpuzzle/util/ObjectLoader.java | |||
@@ -11,8 +11,13 @@ import java.awt.Image; | |||
11 | import java.awt.Toolkit; | 11 | import java.awt.Toolkit; |
12 | import java.awt.image.BufferedImage; | 12 | import java.awt.image.BufferedImage; |
13 | import java.awt.image.FilteredImageSource; | 13 | import java.awt.image.FilteredImageSource; |
14 | import java.io.IOException; | ||
15 | import java.io.InputStream; | ||
14 | import java.util.HashMap; | 16 | import java.util.HashMap; |
17 | import java.util.logging.Level; | ||
18 | import java.util.logging.Logger; | ||
15 | import javax.imageio.ImageIO; | 19 | import javax.imageio.ImageIO; |
20 | import javax.sound.midi.InvalidMidiDataException; | ||
16 | import javax.sound.midi.MidiSystem; | 21 | import javax.sound.midi.MidiSystem; |
17 | import javax.sound.midi.Sequence; | 22 | import javax.sound.midi.Sequence; |
18 | import org.jdesktop.application.ResourceMap; | 23 | import org.jdesktop.application.ResourceMap; |
@@ -25,13 +30,25 @@ public class ObjectLoader { | |||
25 | 30 | ||
26 | private static HashMap<String,Object> objectCache = new HashMap<String,Object>(); | 31 | private static HashMap<String,Object> objectCache = new HashMap<String,Object>(); |
27 | 32 | ||
28 | public static BufferedImage getImage(String type, String name) throws Exception | 33 | public static BufferedImage getImage(String type, String name) |
29 | { | 34 | { |
30 | if (!objectCache.containsKey(type + "/" + name)) | 35 | if (!objectCache.containsKey(type + "/" + name)) |
31 | { | 36 | { |
32 | ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); | 37 | ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); |
33 | String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png"; | 38 | String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png"; |
34 | BufferedImage bImg = ImageIO.read(rm.getClassLoader().getResourceAsStream(filename)); | 39 | InputStream str = rm.getClassLoader().getResourceAsStream(filename); |
40 | |||
41 | if (str == null) | ||
42 | { | ||
43 | throw new ResourceNotFoundException(type, name); | ||
44 | } | ||
45 | |||
46 | BufferedImage bImg = null; | ||
47 | try { | ||
48 | bImg = ImageIO.read(str); | ||
49 | } catch (IOException ex) { | ||
50 | Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); | ||
51 | } | ||
35 | 52 | ||
36 | addToObjectCache(type,name,bImg); | 53 | addToObjectCache(type,name,bImg); |
37 | } | 54 | } |
@@ -39,13 +56,26 @@ public class ObjectLoader { | |||
39 | return (BufferedImage) objectCache.get(type + "/" + name); | 56 | return (BufferedImage) objectCache.get(type + "/" + name); |
40 | } | 57 | } |
41 | 58 | ||
42 | public static BufferedImage getImage(String type, String name, int transparencyColor) throws Exception | 59 | public static BufferedImage getImage(String type, String name, int transparencyColor) |
43 | { | 60 | { |
44 | if (!objectCache.containsKey(type + "/" + name)) | 61 | if (!objectCache.containsKey(type + "/" + name)) |
45 | { | 62 | { |
46 | ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); | 63 | ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); |
47 | String filename = rm.getResourcesDir() + type + "/" + name + ".png"; | 64 | String filename = rm.getResourcesDir() + type.toLowerCase() + "/" + name + ".png"; |
48 | BufferedImage bImg = ImageIO.read(rm.getClassLoader().getResourceAsStream(filename)); | 65 | InputStream str = rm.getClassLoader().getResourceAsStream(filename); |
66 | |||
67 | if (str == null) | ||
68 | { | ||
69 | throw new ResourceNotFoundException(type, name); | ||
70 | } | ||
71 | |||
72 | BufferedImage bImg = null; | ||
73 | try { | ||
74 | bImg = ImageIO.read(str); | ||
75 | } catch (IOException ex) { | ||
76 | Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); | ||
77 | } | ||
78 | |||
49 | bImg = new BufferedImage(bImg.getWidth(), bImg.getHeight(), BufferedImage.TYPE_INT_RGB); | 79 | bImg = new BufferedImage(bImg.getWidth(), bImg.getHeight(), BufferedImage.TYPE_INT_RGB); |
50 | Image image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(bImg.getSource(), new TransparentImageFilter(transparencyColor))); | 80 | Image image = Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(bImg.getSource(), new TransparentImageFilter(transparencyColor))); |
51 | bImg.createGraphics().drawImage(image, 0, 0, null); | 81 | bImg.createGraphics().drawImage(image, 0, 0, null); |
@@ -65,7 +95,7 @@ public class ObjectLoader { | |||
65 | return map; | 95 | return map; |
66 | }*/ | 96 | }*/ |
67 | 97 | ||
68 | public static void addToObjectCache(String type, String name, Object object) throws Exception | 98 | public static void addToObjectCache(String type, String name, Object object) |
69 | { | 99 | { |
70 | if (objectCache.size() >= 100) | 100 | if (objectCache.size() >= 100) |
71 | { | 101 | { |
@@ -75,13 +105,26 @@ public class ObjectLoader { | |||
75 | objectCache.put(type + "/" + name, object); | 105 | objectCache.put(type + "/" + name, object); |
76 | } | 106 | } |
77 | 107 | ||
78 | public static Sequence getMusic(String name) throws Exception | 108 | public static Sequence getMusic(String name) |
79 | { | 109 | { |
80 | if (!objectCache.containsKey("Music/" + name)) | 110 | if (!objectCache.containsKey("Music/" + name)) |
81 | { | 111 | { |
82 | ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); | 112 | ResourceMap rm = PuzzleApplication.INSTANCE.getContext().getResourceManager().getResourceMap(); |
83 | String filename = rm.getResourcesDir() + "music/" + name + ".mid"; | 113 | String filename = rm.getResourcesDir() + "music/" + name + ".mid"; |
84 | Sequence seq = MidiSystem.getSequence(rm.getClassLoader().getResourceAsStream(filename)); | 114 | InputStream str = rm.getClassLoader().getResourceAsStream(filename); |
115 | if (str == null) | ||
116 | { | ||
117 | throw new ResourceNotFoundException("Music", name); | ||
118 | } | ||
119 | |||
120 | Sequence seq = null; | ||
121 | try { | ||
122 | seq = MidiSystem.getSequence(str); | ||
123 | } catch (InvalidMidiDataException ex) { | ||
124 | Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); | ||
125 | } catch (IOException ex) { | ||
126 | Logger.getLogger(ObjectLoader.class.getName()).log(Level.SEVERE, null, ex); | ||
127 | } | ||
85 | 128 | ||
86 | addToObjectCache("Music", name, seq); | 129 | addToObjectCache("Music", name, seq); |
87 | } | 130 | } |