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

📄 bufferedupdatestrategy.java

📁 开源(Open Source)项目JHotDraw的文档和源程序
💻 JAVA
字号:
/*
 * @(#)BufferedUpdateStrategy.java 5.2
 *
 */

package CH.ifa.draw.standard;

import java.awt.*;
import java.awt.image.*;
import CH.ifa.draw.framework.*;

/**
 * The BufferedUpdateStrategy implements an update
 * strategy that first draws a view into a buffer
 * followed by copying the buffer to the DrawingView.
 * @see DrawingView
 */

public  class BufferedUpdateStrategy
        implements Painter {

    /**
    * The offscreen image
    */
    transient private Image   fOffscreen;
    private int     fImagewidth = -1;
    private int     fImageheight = -1;

    /*
     * Serialization support.
     */
    private static final long serialVersionUID = 6489532222954612824L;
    private int bufferedUpdateSerializedDataVersion = 1;

    /**
    * Draws the view contents.
    */
    public void draw(Graphics g, DrawingView view) {
        // create the buffer if necessary
        Dimension d = view.getSize();
        if ((fOffscreen == null) || (d.width != fImagewidth)
            || (d.height != fImageheight)) {
            fOffscreen = view.createImage(d.width, d.height);
            fImagewidth = d.width;
            fImageheight = d.height;
        }

        // let the view draw on offscreen buffer
        Graphics g2 = fOffscreen.getGraphics();
        view.drawAll(g2);

        g.drawImage(fOffscreen, 0, 0, view);
    }
}

⌨️ 快捷键说明

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