view src/main/java/jp/ac/u_ryukyu/alicevnc/CreateWindow.java @ 34:aace9df1462e

refactor
author sugi
date Thu, 13 Nov 2014 16:09:09 +0900
parents 6f5986d8ecd5
children 9354e8a1d03b
line wrap: on
line source

package jp.ac.u_ryukyu.alicevnc;

import jp.ac.u_ryukyu.ie.cr.DecodeInfomation;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.rfb.IRepaintController;
import com.glavsoft.rfb.encoding.PixelFormat;
import com.glavsoft.rfb.protocol.Protocol;
import com.glavsoft.rfb.protocol.ProtocolSettings;
import com.glavsoft.viewer.Viewer;
import com.glavsoft.viewer.cli.Parser;
import com.glavsoft.viewer.swing.ParametersHandler;
import com.glavsoft.viewer.swing.SwingViewerWindow;
import com.glavsoft.viewer.swing.SwingViewerWindowFactory;

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

public class CreateWindow extends CodeSegment {

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

    public CreateWindow(String key){
        info.setKey(key, "initMessage");
    }

    public void run() {
        PixelFormat pixelFormat = null;
        int width = 0;
        int height = 0;
        String name = "defalut";

        Parser parser = new Parser();
        ParametersHandler.completeParserOptions(parser);
        if (parser.isSet(ParametersHandler.ARG_HELP)) {
            System.exit(0);
        }
        Viewer viewer = new Viewer(parser);
        SwingViewerWindowFactory viewerWindowFactory = new SwingViewerWindowFactory(true, false, viewer);
        ProtocolSettings settings = ProtocolSettings.getDefaultSettings();

        Protocol context = new Protocol(null, null, null, settings);
        context.setMessageQueue(new MyMessageQueue());

        DecodeInfomation message = info.asClass(DecodeInfomation.class);
        pixelFormat = message.getPixelFormat();
        width = message.width;
        height = message.height;
        name = message.name;
        ods.update("initMessage", message);

        context.setPixelFormat(pixelFormat);
        context.setFbWidth(width);
        context.setFbHeight(height);
        context.setRemoteDesktopName(name);

        SwingViewerWindow viewerWindow = viewerWindowFactory.createViewerWindow(context, settings, viewer.getUiSettings(), null, null);
        settings.setViewOnly(true);
        IRepaintController repaintController = viewerWindow.getSurface();
        Renderer renderer = repaintController.createRenderer(null, width, height, context.getPixelFormat());
        RenderAndControllerHolder holder = new RenderAndControllerHolder(renderer, repaintController, viewerWindow);
        ods.put("holder", holder);

        new ReceiveUpdateRectangle();
    }

}