Repackage classes from com.threerings.cocktail.miso to

com.threerings.miso.  Moved ImageManager to com.threerings.media.
Removed unused StripImage.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@62 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Walter Korman
2001-07-18 21:45:42 +00:00
parent 9abae9810b
commit c4654e2a11
22 changed files with 59 additions and 113 deletions
@@ -0,0 +1,99 @@
//
// $Id: ImageManager.java,v 1.1 2001/07/18 21:45:42 shaper Exp $
package com.threerings.media;
import com.threerings.cocktail.miso.Log;
import java.awt.*;
import java.awt.image.*;
import java.util.Hashtable;
/**
* The ImageManager class provides a single point of access for image
* retrieval and caching.
*
* <p> <b>Note:</b> The ImageManager must be initialized with a root
* AWT component before images can be retrieved, in the interest of
* allowing for proper preparation of images for optimal storage and
* eventual display.
*/
public class ImageManager
{
public static Toolkit tk = Toolkit.getDefaultToolkit();
/**
* Initialize the ImageManager with a root component to which
* images will later be rendered.
*/
public static void init (Component root)
{
_root = root;
tk = root.getToolkit();
}
/**
* Load the image from the specified filename and cache it for
* faster retrieval henceforth.
*/
public static Image getImage (String fname)
{
if (_root == null) {
Log.warning("Attempt to get image without valid root component.");
return null;
}
// TODO: fix this to properly find the file within the
// classpath. getResourceAsStream() returns an InputStream,
// but java.awt.Toolkit.createImage() can only take one of a
// byte[], String, URL, or ImageProducer.
fname = "/home/shaper/workspace/cocktail/" + fname;
Image img = (Image)_imgs.get(fname);
if (img != null) {
Log.info("Retrieved image from cache [fname=" + fname + "].");
return img;
}
Log.info("Loading image into cache [fname=" + fname + "].");
img = tk.createImage(fname);
MediaTracker tracker = new MediaTracker(_root);
tracker.addImage(img, 0);
try {
tracker.waitForID(0);
if (tracker.isErrorAny()) {
Log.warning("Error loading image [fname=" + fname + "].");
return null;
} else {
_imgs.put(fname, img);
}
} catch (Exception e) {
e.printStackTrace();
}
return img;
}
/**
* Creates a new image representing the specified rectangular
* section cropped from the specified full image object.
*/
public static BufferedImage getImageCropped (Image fullImg, int x, int y,
int width, int height)
{
BufferedImage img =
new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = img.createGraphics();
g2.drawImage(fullImg, -x, -y, null);
return img;
}
protected static Component _root;
protected static Hashtable _imgs = new Hashtable();
}
+4 -4
View File
@@ -1,7 +1,7 @@
//
// $Id: Tile.java,v 1.3 2001/07/16 00:45:07 shaper Exp $
// $Id: Tile.java,v 1.4 2001/07/18 21:45:42 shaper Exp $
package com.threerings.cocktail.miso.tile;
package com.threerings.miso.tile;
import java.awt.Image;
import java.awt.image.BufferedImage;
@@ -31,7 +31,7 @@ public class Tile
* Construct a new tile with the specified identifiers. Intended
* only for use by the TileManager. Do not use this method.
*
* @see com.threerings.cocktail.miso.TileManager#getTile
* @see com.threerings.miso.TileManager#getTile
*/
public Tile (short tsid, short tid)
{
@@ -43,7 +43,7 @@ public class Tile
* Construct a new tile with the specified identifiers. Intended
* only for use by the TileManager. Do not use this method.
*
* @see com.threerings.cocktail.miso.TileManager#getTile
* @see com.threerings.miso.TileManager#getTile
*/
public Tile (int tsid, int tid)
{
@@ -1,9 +1,9 @@
//
// $Id: TileManager.java,v 1.5 2001/07/17 17:21:33 shaper Exp $
// $Id: TileManager.java,v 1.6 2001/07/18 21:45:42 shaper Exp $
package com.threerings.cocktail.miso.tile;
package com.threerings.miso.tile;
import com.threerings.cocktail.miso.Log;
import com.threerings.miso.Log;
import com.samskivert.util.ConfigUtil;
import com.samskivert.util.IntMap;
@@ -1,10 +1,10 @@
//
// $Id: TileSet.java,v 1.6 2001/07/17 17:21:33 shaper Exp $
// $Id: TileSet.java,v 1.7 2001/07/18 21:45:42 shaper Exp $
package com.threerings.cocktail.miso.tile;
package com.threerings.miso.tile;
import com.threerings.cocktail.miso.Log;
import com.threerings.cocktail.miso.media.ImageManager;
import com.threerings.miso.Log;
import com.threerings.media.ImageManager;
import java.awt.Image;
import java.awt.Graphics2D;
@@ -25,7 +25,7 @@ import java.awt.image.*;
* the tile at the top-left of the image is tile id 0 and tiles are
* numbered left to right, top to bottom, in ascending order.
*
* @see com.threerings.cocktail.miso.TileManager
* @see com.threerings.miso.TileManager
*/
public class TileSet
{
@@ -1,7 +1,7 @@
//
// $Id: TileSetManager.java,v 1.3 2001/07/17 17:21:33 shaper Exp $
// $Id: TileSetManager.java,v 1.4 2001/07/18 21:45:42 shaper Exp $
package com.threerings.cocktail.miso.tile;
package com.threerings.miso.tile;
import java.io.InputStream;
import java.io.IOException;
@@ -1,7 +1,7 @@
//
// $Id: TileSetManagerImpl.java,v 1.2 2001/07/17 17:21:33 shaper Exp $
// $Id: TileSetManagerImpl.java,v 1.3 2001/07/18 21:45:42 shaper Exp $
package com.threerings.cocktail.miso.tile;
package com.threerings.miso.tile;
import com.samskivert.util.IntMap;
@@ -1,7 +1,7 @@
//
// $Id: TileSetParser.java,v 1.1 2001/07/17 17:21:33 shaper Exp $
// $Id: TileSetParser.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
package com.threerings.cocktail.miso.tile;
package com.threerings.miso.tile;
import java.io.InputStream;
import java.io.IOException;
@@ -1,9 +1,9 @@
//
// $Id: XMLTileSetParser.java,v 1.1 2001/07/17 17:21:33 shaper Exp $
// $Id: XMLTileSetParser.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
package com.threerings.cocktail.miso.tile;
package com.threerings.miso.tile;
import com.threerings.cocktail.miso.Log;
import com.threerings.miso.Log;
import com.samskivert.util.StringUtil;
@@ -1,9 +1,9 @@
//
// $Id: MathUtil.java,v 1.1 2001/07/16 00:45:07 shaper Exp $
// $Id: MathUtil.java,v 1.2 2001/07/18 21:45:42 shaper Exp $
package com.threerings.cocktail.miso.util;
package com.threerings.miso.util;
import com.threerings.cocktail.miso.Log;
import com.threerings.miso.Log;
import java.awt.Point;