⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplerenderedimage.java

📁 It is all about project scheduling. GanttProject is a tool for creating a project schedule by means
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     if (propertyNames == null) {         return null;     }     prefix = prefix.toLowerCase();     Vector names = new Vector();     for (int i = 0; i < propertyNames.length; i++) {         if (propertyNames[i].startsWith(prefix)) {             names.addElement(propertyNames[i]);         }     }     if (names.size() == 0) {         return null;     }     // Copy the strings from the Vector over to a String array.     String prefixNames[] = new String[names.size()];     int count = 0;     for (Iterator it = names.iterator(); it.hasNext(); ) {         prefixNames[count++] = (String)it.next();     }     return prefixNames; } // Utility methods. /**  * Converts a pixel's X coordinate into a horizontal tile index  * relative to a given tile grid layout specified by its X offset  * and tile width.  */ public static int XToTileX(int x, int tileGridXOffset, int tileWidth) {     x -= tileGridXOffset;     if (x < 0) {         x += 1 - tileWidth; // Force round to -infinity     }     return x/tileWidth; } /**  * Converts a pixel's Y coordinate into a vertical tile index  * relative to a given tile grid layout specified by its Y offset  * and tile height.  */ public static int YToTileY(int y, int tileGridYOffset, int tileHeight) {     y -= tileGridYOffset;     if (y < 0) {         y += 1 - tileHeight; // Force round to -infinity     }     return y/tileHeight; } /**  * Converts a pixel's X coordinate into a horizontal tile index.  * This is a convenience method.  No attempt is made to detect  * out-of-range coordinates.  *  * @param x the X coordinate of a pixel.  * @return the X index of the tile containing the pixel.  */ public int XToTileX(int x) {     return XToTileX(x, getTileGridXOffset(), getTileWidth()); } /**  * Converts a pixel's Y coordinate into a vertical tile index.   * This is a convenience method.  No attempt is made to detect  * out-of-range coordinates.  *  * @param y the Y coordinate of a pixel.  * @return the Y index of the tile containing the pixel.  */ public int YToTileY(int y) {     return YToTileY(y, getTileGridYOffset(), getTileHeight()); } /**  * Converts a horizontal tile index into the X coordinate of its  * upper left pixel relative to a given tile grid layout specified  * by its X offset and tile width.  */ public static int tileXToX(int tx, int tileGridXOffset, int tileWidth) {     return tx*tileWidth + tileGridXOffset; } /**  * Converts a vertical tile index into the Y coordinate of  * its upper left pixel relative to a given tile grid layout  * specified by its Y offset and tile height.  */ public static int tileYToY(int ty, int tileGridYOffset, int tileHeight) {     return ty*tileHeight + tileGridYOffset; } /**  * Converts a horizontal tile index into the X coordinate of its  * upper left pixel.  This is a convenience method.  No attempt is made  * to detect out-of-range indices.  *  * @param tx the horizontal index of a tile.  * @return the X coordinate of the tile's upper left pixel.  */ public int tileXToX(int tx) {     return tx*tileWidth + tileGridXOffset; } /**  * Converts a vertical tile index into the Y coordinate of its  * upper left pixel.  This is a convenience method.  No attempt is made  * to detect out-of-range indices.  *  * @param ty the vertical index of a tile.  * @return the Y coordinate of the tile's upper left pixel.  */ public int tileYToY(int ty) {     return ty*tileHeight + tileGridYOffset; } public Vector getSources() {     return null; } /**  * Returns the entire image in a single Raster.  For images with  * multiple tiles this will require making a copy.  *  * <p> The returned Raster is semantically a copy.  This means  * that updates to the source image will not be reflected in the  * returned Raster.  For non-writable (immutable) source images,  * the returned value may be a reference to the image's internal  * data.  The returned Raster should be considered non-writable;  * any attempt to alter its pixel data (such as by casting it to  * WritableRaster or obtaining and modifying its DataBuffer) may  * result in undefined behavior.  The copyData method should be  * used if the returned Raster is to be modified.  *  * @return a Raster containing a copy of this image's data.  */ public Raster getData() {     Rectangle rect = new Rectangle(getMinX(), getMinY(),                                    getWidth(), getHeight());     return getData(rect); } /**  * Returns an arbitrary rectangular region of the RenderedImage  * in a Raster.  The rectangle of interest will be clipped against  * the image bounds.  *  * <p> The returned Raster is semantically a copy.  This means  * that updates to the source image will not be reflected in the  * returned Raster.  For non-writable (immutable) source images,  * the returned value may be a reference to the image's internal  * data.  The returned Raster should be considered non-writable;  * any attempt to alter its pixel data (such as by casting it to  * WritableRaster or obtaining and modifying its DataBuffer) may  * result in undefined behavior.  The copyData method should be  * used if the returned Raster is to be modified.  *  * @param bounds the region of the RenderedImage to be returned.  */ public Raster getData(Rectangle bounds) {     int startX = XToTileX(bounds.x);     int startY = YToTileY(bounds.y);     int endX = XToTileX(bounds.x + bounds.width - 1);     int endY = YToTileY(bounds.y + bounds.height - 1);     Raster tile;     if ((startX == endX) && (startY == endY)) {         tile = getTile(startX, startY);         return tile.createChild(bounds.x, bounds.y,                                 bounds.width, bounds.height,                                 bounds.x, bounds.y, null);     } else {         // Create a WritableRaster of the desired size         SampleModel sm =             sampleModel.createCompatibleSampleModel(bounds.width,                                                    bounds.height);         // Translate it         WritableRaster dest =             Raster.createWritableRaster(sm, bounds.getLocation());         for (int j = startY; j <= endY; j++) {             for (int i = startX; i <= endX; i++) {                 tile = getTile(i, j);                 Rectangle intersectRect =                     bounds.intersection(tile.getBounds());                 Raster liveRaster = tile.createChild(intersectRect.x,                                                      intersectRect.y,                                                      intersectRect.width,                                                      intersectRect.height,                                                      intersectRect.x,                                                      intersectRect.y,                                                      null);                 dest.setDataElements(0, 0, liveRaster);             }         }         return dest;     } } /**  * Copies an arbitrary rectangular region of the RenderedImage  * into a caller-supplied WritableRaster.  The region to be  * computed is determined by clipping the bounds of the supplied  * WritableRaster against the bounds of the image.  The supplied  * WritableRaster must have a SampleModel that is compatible with  * that of the image.  *  * <p> If the raster argument is null, the entire image will  * be copied into a newly-created WritableRaster with a SampleModel  * that is compatible with that of the image.  *  * @param dest a WritableRaster to hold the returned portion of  *        the image.  * @return a reference to the supplied WritableRaster, or to a   *         new WritableRaster if the supplied one was null.  */ public WritableRaster copyData(WritableRaster dest) {     Rectangle bounds;     Raster tile;                      if (dest == null) {         bounds = getBounds();         Point p = new Point(minX, minY);         /* A SampleModel to hold the entire image. */         SampleModel sm = sampleModel.createCompatibleSampleModel(                                      width, height);         dest = Raster.createWritableRaster(sm, p);     } else {         bounds = dest.getBounds();     }          int startX = XToTileX(bounds.x);     int startY = YToTileY(bounds.y);     int endX = XToTileX(bounds.x + bounds.width - 1);     int endY = YToTileY(bounds.y + bounds.height - 1);              for (int j = startY; j <= endY; j++) {         for (int i = startX; i <= endX; i++) {             tile = getTile(i, j);             Rectangle intersectRect =                 bounds.intersection(tile.getBounds());             Raster liveRaster = tile.createChild(intersectRect.x,                                                  intersectRect.y,                                                  intersectRect.width,                                                  intersectRect.height,                                                  intersectRect.x,                                                  intersectRect.y,                                                  null);             /*              * WritableRaster.setDataElements takes into account of              * inRaster's minX and minY and add these to x and y. Since              * liveRaster has the origin at the correct location, the              * following call should not again give these coordinates in              * places of x and y.              */             dest.setDataElements(0, 0, liveRaster);         }     }     return dest; }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -