View Javadoc
1   /*
2    * Created on 2005-maj-14
3    */
4   package net.sourceforge.jsh3modtool.mod;
5   
6   import java.awt.image.BufferedImage;
7   import java.io.IOException;
8   import java.io.InputStream;
9   
10  import javax.imageio.ImageIO;
11  
12  import net.sourceforge.jsh3modtool.modpackage.ModPackage;
13  import net.sourceforge.jsh3modtool.util.ImageFactory;
14  
15  /***
16   * Default mod screen shot.
17   * This class utilizes a mod package to extract the image.
18   * 
19   * @author redsolo
20   */
21  class DefaultModScreenShot implements ModScreenShot
22  {
23      privateModPackage modPackage/package-summary.html">ong> ModPackage modPackage;
24      private String entryNameInPackage;
25      private String description;
26      private String name;
27  
28      /***
29       * @param modPackage
30       * @param entryName
31       * @param description
32       * @param name the name of the screenshot
33       */
34      publicDefaultModScreenShot(ModPackage modPackage, String entryName,/package-summary.html">ong> DefaultModScreenShot(ModPackage modPackage, String entryName,
35              String description, String name)
36      {
37          super();
38          this.modPackage = modPackage;
39          this.entryNameInPackage = entryName;
40          this.name = name;
41          if (name == null)
42          {
43          	this.name = getName(entryName);
44          } else
45          {
46          	this.name = name;
47          }
48          if (description == null)
49          {
50          	this.description = name;
51          } else
52          {
53          	this.description = description;
54          }
55      }
56      
57      private String getName(String filepath)
58      {
59      	String name;
60      	int endPos = filepath.lastIndexOf('/');
61      	if (endPos == -1)
62      	{
63      		name = filepath;
64      	} else
65      	{
66      		name = filepath.substring(endPos + 1);
67      	}
68      	return name;
69      }
70     
71      public InputStream getImageData() throws IOException 
72      {
73          return modPackage.getEntry(entryNameInPackage);
74      }
75      
76      public String getDescription()
77      {
78          return description;
79      }
80  
81      public String getName()
82      {
83          return name;
84      }
85  }