view src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveUpdateRectangle.java @ 10:65d989192d63

change Protocol aliceVNCMessage
author YU
date Thu, 18 Sep 2014 21:07:46 +0900
parents c05d3b89b446
children aff2d0bb9c50
line wrap: on
line source

package jp.ac.u_ryukyu.alicevnc;

import java.util.ArrayList;

import com.glavsoft.exceptions.TransportException;
import com.glavsoft.rfb.encoding.EncodingType;
import com.glavsoft.rfb.encoding.decoder.AliceVNCMessage;
import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle;
import com.glavsoft.rfb.encoding.decoder.ZRLEDecoder;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;

public class ReceiveUpdateRectangle extends CodeSegment{

    private Receiver info = ids.create(CommandType.PEEK);
    private Receiver info1 = ids.create(CommandType.TAKE);
    private Receiver info2= ids.create(CommandType.PEEK); 

    public ReceiveUpdateRectangle(){
        info.setKey("Holder");
        info1.setKey("aliceVNCMessage");
        info2.setKey("_CLIST");
    }

    @Override
    public void run() {
        try {
            RenderAndControllerHolder holder = info.asClass(RenderAndControllerHolder.class);
            AliceVNCMessage message = info1.asClass(AliceVNCMessage.class);

            if (message.getEncodingType() == EncodingType.ZRLE){
                ZRLEDecoder decoder = new ZRLEDecoder();
                decoder.decode(message, holder.getRenderer());
                FramebufferUpdateRectangle rect = new FramebufferUpdateRectangle(
                        message.x, message.y, message.width, message.height);

                rect.encodingType = EncodingType.byId(message.encodingTypeId);

                holder.getRepaintController().repaintBitmap(rect);


            } else if (message.getEncodingType() == EncodingType.DESKTOP_SIZE) {

                
                holder.setRenderer(
                        holder.getRepaintController().createRenderer(null ,message.width, 
                                message.height, holder.getRenderer().pixelFormat)
                                );
                

            } 

            @SuppressWarnings("unchecked")
            ArrayList<String> clist = info2.asClass(ArrayList.class);
            for (String node : clist){
                if (!"parent".equals(node))
                    ods.put(node, "aliceVNCMessage", info1.getVal());
            }
            new ReceiveUpdateRectangle();

        } catch (TransportException e) {
            e.printStackTrace();
        }
    }

}