このアーカイブは同期化されません。 mixi の日記が更新されても、このアーカイブには反映されません。
そろそろテストや調査をしたいので、
RFBDisplay を実装したクラスを作ってみる。
後々既定の実装を持つ抽象クラスとして使えるように、
BaseRFBDisplay という名前にしておこう。
BaseRFBDisplay のメッセージのハンドラ(メソッド)では、
昨日改造した RFBContext に状態を格納することで、
RFBContext 単独で通信状態を保存できるようにする。
========== BaseRFBDisplay.java ==========
package jp.loafer.rfb.server;
import java.io.IOException;
import jp.loafer.rfb.RFBContext;
import jp.loafer.rfb.io.RFBOutputStream;
import jp.loafer.rfb.message.ColorEntry;
import jp.loafer.rfb.message.PixelFormat;
import jp.loafer.rfb.message.client.*;
/**
* BaseRFBDisplay クラス。
* @author kes
*/
public class BaseRFBDisplay implements RFBDisplay {
/**
* 仮想画面を作成。
* @param width 画面の幅。
* @param height 画面の高さ。
* @param name 画面の名前。
*/
public BaseRFBDisplay(int width, int height, String name) {
this(width, height, name, null);
}
/**
* 仮想画面を作成。
* @param width 画面の幅。
* @param height 画面の高さ。
* @param name 画面の名前。
* @param defaultPixelFormat 画面の既定の画素形式。
*/
public BaseRFBDisplay(int width, int height,
String name, PixelFormat defaultPixelFormat) {
if (width <= 0 || height <= 0)
throw new IllegalArgumentException("Invalid size.");
this.width = width;
this.height = height;
this.name = name;
if (defaultPixelFormat == null) {
// 既定は 24 ビット RGB
this.defaultPixelFormat = new PixelFormat(
32, 24, true, true,
0xff, 0xff, 0xff, 16, 8, 0);
} else {
this.defaultPixelFormat = defaultPixelFormat;
}
}
/**
* @see RFBDisplay#getWidth()
*/
public int getWidth() {
return width;
}
/**
* @see RFBDisplay#getHeight()
*/
public int getHeight() {
return height;
}
/**
* @see RFBDisplay#getName()
*/
public String getName() {
return name;
}
/**
* @see RFBDisplay#getDefaultPixelFormat()
*/
public PixelFormat getDefaultPixelFormat() {
return defaultPixelFormat;
}
/**
* @see RFBDisplay#initialize(RFBContext, RFBOutputStream)
*/
@SuppressWarnings("hiding")
public void initialize(RFBContext context, RFBOutputStream out) throws IOException {
this.context = context;
this.out = out;
context.setPixelFormat(defaultPixelFormat);
context.setFixedColors(null);
}
/**
* @see RFBDisplay#handleSetPixelFormat(SetPixelFormatMessage)
*/
public void handleSetPixelFormat(SetPixelFormatMessage message) throws IOException {
System.out.println(message);
context.setPixelFormat(message.getFormat());
// context.setFixedColors(null);
}
/**
* @see RFBDisplay#handleFixColorMapEntries(FixColorMapEntriesMessage)
*/
public void handleFixColorMapEntries(FixColorMapEntriesMessage message) throws IOException {
System.out.println(message);
// 固定された色を記憶
ColorEntry[] fixedColors;
fixedColors = context.getFixedColors();
if (fixedColors == null) {
fixedColors = new ColorEntry[context.getPixelFormat().getDepth()];
}
ColorEntry[] newColors = message.getColors();
int offset = message.getFirstIndex();
for (int i = 0; i < newColors.length; ++i) {
fixedColors[offset + i] = newColors[i];
}
context.setFixedColors(fixedColors);
}
/**
* @see RFBDisplay#handleSetEncodings(SetEncodingsMessage)
*/
public void handleSetEncodings(SetEncodingsMessage message) throws IOException {
System.out.println(message);
context.setEncodingTypes(message.getEncodingTypes());
}
/**
* @see RFBDisplay#handleFramebufferUpdateRequest(FramebufferUpdateRequestMessage)
*/
public void handleFramebufferUpdateRequest(FramebufferUpdateRequestMessage message) throws IOException {
System.out.println(message);
}
/**
* @see RFBDisplay#handleKeyEvent(KeyEventMessage)
*/
public void handleKeyEvent(KeyEventMessage message) throws IOException {
System.out.println(message);
}
/**
* @see RFBDisplay#handlePointerEvent(PointerEventMessage)
*/
public void handlePointerEvent(PointerEventMessage message) throws IOException {
System.out.println(message);
}
/**
* @see RFBDisplay#handleClientCutText(ClientCutTextMessage)
*/
public void handleClientCutText(ClientCutTextMessage message) throws IOException {
System.out.println(message);
clipboardText = message.getText();
}
/**
* @see RFBDisplay#handleCustomMessage(ClientMessage)
*/
public void handleCustomMessage(ClientMessage message) throws IOException {
System.out.println(message);
}
// コンストラクタパラメータ
protected int width;
protected int height;
protected String name;
protected PixelFormat defaultPixelFormat;
// RFB オブジェクト
protected RFBContext context;
protected RFBOutputStream out;
// ステート
protected String clipboardText;
}
========== end of BaseRFBDisplay.java ==========
結構長くなった。
SetPixelFormat、FixColourMapEntries、SetEncodings では、
その内容を RFBContext に格納しておく。
FixColourMapEntries は実質未サポートで良いのだが、
一応、仕様通りに解釈しておいた。
ClientCutText では、テキストをクラス内に記憶させておく。
後々別のメッセージハンドラで利用するかも知れない。
残りのメッセージは、今のところ空白としておく。
また、全てのメッセージハンドラに、
System.out.println(message); を追加しておいた。
これで受信したメッセージをテストすることができる。
まあ、先に toString を実装しないといけないのだが。