arcgissamples\scenario\map\Display.java
/* Copyright 2010 ESRI * * All rights reserved under the copyright laws of the United States * and applicable international laws, treaties, and conventions. * * You may freely redistribute and use this sample code, with or * without modification, provided you include the original copyright * notice and use restrictions. * * See the use restrictions. * */ package arcgissamples.scenario.map; import java.awt.Dimension; /**This class is used for rendering offscreen image */ public class Display { java.awt.Image offscrn = null; int width = 0; int height = 0; java.awt.Graphics2D gx; ImagePainter observer = new ImagePainter(); public void display() { } /** Draws the image on the specified graphics object. If dispose is set to true * the image is flushed to free the resources * @param g * @param dx1 * @param dy1 * @param wd * @param ht * @param dispose */ public void paint(java.awt.Graphics g, int dx1, int dy1, int wd, int ht, boolean dispose) { observer.start(offscrn, g, dx1, dy1, wd, ht, dispose); } /**Returns the display screen size * @return */ @SuppressWarnings("unused") private Dimension getSize() { return new Dimension(width, height); } /**Returns the offscreen graphics object * @return java.awt.Graphics2D */ public java.awt.Graphics2D getGraphics() { if (gx == null) gx = (java.awt.Graphics2D) offscrn.getGraphics(); return gx; } /**Creates buffered image * @param w * @param h * @return */ private static java.awt.image.BufferedImage createImage(int w, int h) { return new java.awt.image.BufferedImage(w, h, java.awt.image.BufferedImage.TYPE_INT_RGB); } /**Sets the width and height for offscreen image * * @param w * @param h */ public void setSize(int w, int h) { width = w; height = h; if (w > 0 && h > 0) { if (offscrn != null) offscrn.flush(); offscrn = createImage(width, height); gx = (java.awt.Graphics2D) offscrn.getGraphics(); } } }