Back to index

moin  1.9.0~rc2
BufferedUpdateStrategy.java
Go to the documentation of this file.
00001 /*
00002  * @(#)BufferedUpdateStrategy.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import java.awt.*;
00009 import java.awt.image.*;
00010 import CH.ifa.draw.framework.*;
00011 
00019 public  class BufferedUpdateStrategy
00020         implements Painter {
00021 
00025     transient private Image   fOffscreen;
00026     private int     fImagewidth = -1;
00027     private int     fImageheight = -1;
00028 
00029     /*
00030      * Serialization support.
00031      */
00032     private static final long serialVersionUID = 6489532222954612824L;
00033     private int bufferedUpdateSerializedDataVersion = 1;
00034 
00038     public void draw(Graphics g, DrawingView view) {
00039         // create the buffer if necessary
00040         Dimension d = view.getSize();
00041         if ((fOffscreen == null) || (d.width != fImagewidth)
00042             || (d.height != fImageheight)) {
00043             fOffscreen = view.createImage(d.width, d.height);
00044             fImagewidth = d.width;
00045             fImageheight = d.height;
00046         }
00047 
00048         // let the view draw on offscreen buffer
00049         Graphics g2 = fOffscreen.getGraphics();
00050         view.drawAll(g2);
00051 
00052         g.drawImage(fOffscreen, 0, 0, view);
00053     }
00054 }