Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public final class IndirectCanvas extends PixelCanvas implements ImageProducer, ImageObserver {
- private ColorModel model;
- private ImageConsumer consumer;
- public synchronized void addConsumer(ImageConsumer ic) {
- consumer = ic;
- ic.setDimensions(width, height);
- ic.setProperties(null);
- ic.setColorModel(model);
- ic.setHints(ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES | ImageConsumer.SINGLEPASS);
- }
- public synchronized boolean isConsumer(ImageConsumer ic) {
- return ic == consumer;
- }
- public synchronized void notifyConsumer(int x, int y, int w, int h) {
- if(consumer != null) {
- consumer.setPixels(x, y, w, h, model, pixels, 0, width);
- consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
- }
- }
- public synchronized void notifyConsumer() {
- if(consumer != null) {
- consumer.setPixels(0, 0, width, height, model, pixels, 0, width);
- consumer.imageComplete(ImageConsumer.SINGLEFRAMEDONE);
- }
- }
- public synchronized void removeConsumer(ImageConsumer ic) {
- if(ic == consumer)
- consumer = null;
- }
- public void draw(Graphics graphics, int x, int y, int w, int h) {
- notifyConsumer(x, y, w, h);
- Shape old_clip = graphics.getClip();
- graphics.clipRect(x, y, w, h);
- graphics.drawImage(render, 0, 0, this);
- graphics.setClip(old_clip);
- }
- public void draw(Graphics graphics, int x, int y) {
- notifyConsumer();
- graphics.drawImage(render, x, y, this);
- }
- public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
- return true;
- }
- public void prepare(Component c, int w, int h) {
- width = w;
- height = h;
- pixels = new int[w * h + 1];
- model = new DirectColorModel(32, 0xff0000, 0xff00, 0xff);
- render = c.createImage(this);
- // I still have noi idea why this is done 3 times...
- notifyConsumer();
- c.prepareImage(render, this);
- notifyConsumer();
- c.prepareImage(render, this);
- notifyConsumer();
- c.prepareImage(render, this);
- // initDrawingArea();
- }
- public void requestTopDownLeftRightResend(ImageConsumer ic) {
- }
- public void startProduction(ImageConsumer ic) {
- addConsumer(ic);
- }
- }
Add Comment
Please, Sign In to add comment