?? omrasterobject.java
字號:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/omGraphics/OMRasterObject.java,v $// $RCSfile: OMRasterObject.java,v $// $Revision: 1.8.2.4 $// $Date: 2005/01/10 16:59:45 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.omGraphics;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Image;import java.awt.Point;import java.awt.Toolkit;import java.awt.geom.AffineTransform;import java.awt.image.AreaAveragingScaleFilter;import java.awt.image.BufferedImage;import java.awt.image.FilteredImageSource;import java.awt.image.ImageConsumer;import java.awt.image.ImageFilter;import java.awt.image.ImageObserver;import java.awt.image.ImageProducer;import java.awt.image.MemoryImageSource;import java.awt.image.PixelGrabber;import java.awt.image.RenderedImage;import java.io.IOException;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.Serializable;import com.bbn.openmap.image.ImageHelper;import com.bbn.openmap.proj.Projection;import com.bbn.openmap.util.Debug;/** * The OMRasterObject is the parent class for OMRaster and OMBitmap * objects. It manages some of the same functions that both classes * require in order to create image pixel data from bytes or integers. * * <P> * An ImageFilter may be applied to OMRasterObjects. These can be * scale filters, color filters, or maybe (?hopefully?) projection * filters. These filters won't change the original image data, and * the original can be reconstructed by resetting the filter to null, * and generating the object. * <P> * * For all classes in the OMRasterObject family, a java.awt.Shape * object is created for the border of the image. This Shape object is * used for distance calculations. If the OMRasterObject is * selected(), however, this Shape will be rendered with the OMGraphic * parameters that are set in the OMGraphic. */public abstract class OMRasterObject extends OMGraphic implements Serializable, ImageObserver { /** * The direct colormodel, for OMRasters, means the integer values * passed in as pixels, already reflect the RGB color values each * pixel should display. */ public final static int COLORMODEL_DIRECT = 0; /** * The indexed colormodel, for OMRasters, means that the byte * array passed in for the pixels has to be resolved with a * colortable in order to create a integer array of RGB pixels. */ public final static int COLORMODEL_INDEXED = 1; /** * The ImageIcon colormodel means that the image is externally * set, and we just want to to display the image at the given * location. */ public final static int COLORMODEL_IMAGEICON = 2; /** If scaling the image, use the slower, smoothing algorithm. */ public final static int SMOOTH_SCALING = 0; /** * If scaling the image, use the faster, replicating/clipping * algorithm. */ public final static int FAST_SCALING = 1; /** * colorModel helps figure out what kind of updates are necessary, * by knowing what kind of image we're dealing with. For the * images created with a ImageIcon, the attribute updates that * don't relate to position will not take affect. */ protected int colorModel = COLORMODEL_DIRECT; /** * The pixels are used for the image that is drawn on the window. * The pixels are either passed in as an int[] in some * constructors of the OMRaster, or it is constructed in the * OMBitmap and in OMRasters that have a colortable. */ protected int[] pixels = null; /** * Horizontal location of the upper left corner of the image, or * the x offset from the lon for that corner, in pixels. */ protected int x = 0; /** * Vertical location of the upper left corner of the image, or the * y offset from the lat for that corner, in pixels. */ protected int y = 0; /** * The latitude of the upper left corner for the image, in decimal * degrees. */ protected float lat = 0.0f; /** * The longitude of the upper left corner for the image, in * decimal degrees. */ protected float lon = 0.0f; /** * The width of the image, in pixels. This always reflects the * width of the original image, even if a filter is applied to the * image. */ protected int width = 0; /** * The height of the image, in pixels. This always reflects the * height of the original image, even if a filter is applied to * the image. */ protected int height = 0; /** * The byte info for the image. OMBitmaps use each bit as an * indication to use the lineColor or the fillColor for each pixel * (like a XBitmap). OMRasters only use the bits when the image * being created follows the indexed colormodel. Then, the bits * hold the colortable indexes that each pixel needs to have a * color substituted in later. */ protected byte[] bits = null; /** The bitmap is drawn to the graphics. */ protected transient Image bitmap = null; /** * Projected window pixel location of the upper left corner of the * image. */ protected Point point1 = null; /** * Projected window pixel location of the lower right corner of * the image. */ protected Point point2 = null; /** * The width of the image after scaling, if you want the image to * be a different size than the source. */ protected int filteredWidth = 0; /** * The height of the image after scaling, if you want the image to * be a different size than the source. */ protected int filteredHeight = 0; /** The image filter to use on the constructed image. */ protected ImageFilter imageFilter = null; /** * Set if the projection has had attributes change that require a * repositioning of the image, not a regeneration. */ protected boolean needToReposition = true; /** * Pixel height of the current projection. Used for efficient * zoom-in scaling. */ int projHeight; /** * Pixel width of the current projection. Used for efficient * zoom-in scaling. */ int projWidth; /** the angle by which the image is to be rotated, in radians */ protected double rotationAngle; protected boolean DEBUG = false; /** * A Contructor that sets the graphic type to raster, render type * to unknown, line type to unknown, and the declutter type to * none. */ public OMRasterObject() { super(RENDERTYPE_UNKNOWN, LINETYPE_UNKNOWN, DECLUTTERTYPE_NONE); DEBUG = Debug.debugging("omraster"); } /** * A Contructor that sets the graphic type, render type, line type * and the declutter type to the values you pass in. See OMGraphic * for the definitions of these attributes. * * @param rType render type * @param lType line type * @param dcType declutter type */ public OMRasterObject(int rType, int lType, int dcType) { super(rType, lType, dcType); DEBUG = Debug.debugging("omraster"); } /** * The color model is set based on the constructor. This setting * controls what parameter changes are posiible for different * models of images. * * @param cm the colormode that describes how the colors are being * set - COLORMODEL_DIRECT, COLORMODEL_INDEXED, or * COLORMODEL_IMAGEICON. */ protected void setColorModel(int cm) { colorModel = cm; } /** * Get the color model type of the image. * * @return COLORMODEL_DIRECT, COLORMODEL_INDEXED, or * COLORMODEL_IMAGEICON. */ public int getColorModel() { return colorModel; } /** * Set the flag for the object that lets the render method (which * draws the object) know that the object needs to be repositioned * first. */ public void setNeedToReposition(boolean value) { needToReposition = value; } /** Return the reposition status. */ public boolean getNeedToReposition() { return needToReposition; } /** * Set the angle by which the image is to rotated. * * @param angle the number of radians the image is to be rotated. * Measured clockwise from horizontal. */ public void setRotationAngle(double angle) { this.rotationAngle = angle; setNeedToRegenerate(true); } /** * Get the current rotation of the image. * * @return the image rotation. */ public double getRotationAngle() { return rotationAngle; } /** * Compute the raster objects pixels, based on the color model and * the byte values. * * @return true if everything goes OK (height*width = * pixel.length, etc.). */ protected abstract boolean computePixels(); /** * Called from within render(). This method should call rotate() * on the provided Graphics2D object, setting the rotation angle * and the rotation point. By default, the rotation angle is * whatever is set in the OMRasterObject, and the rotation point * is the offset point plus half the image width in the horizonal * direction, and half the image in the vertical direction. */ protected void rotate(Graphics2D g) { int w = width; int h = height; if (shape != null) { java.awt.Rectangle rect = shape.getBounds(); w = (int) rect.getWidth(); h = (int) rect.getHeight(); } ((Graphics2D) g).rotate(rotationAngle, point1.x + w / 2, point1.y + h / 2); } /** * Render the raster on the java.awt.Graphics * * @param g java.awt.Graphics to draw the image on. */ public void render(Graphics g) { if (getNeedToRegenerate() || getNeedToReposition() || !isVisible()) { if (DEBUG) { Debug.output("OMRasterObject.render(): need to regenerate or not visible!"); } return; } //copy the graphic, so our transform doesn't cascade to // others... g = g.create(); // Just a little check to find out if someone is rushing // things. If a Image isn't fully loaded, the getWidth will // return -1. This is just a courtesy notification in case // someone isn't seeing their image, and don't know why. if (colorModel == COLORMODEL_IMAGEICON && (getWidth() == -1)) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -