Sketcher2 source code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.3 KiB

package com.jotuntech.sketcher.client.command;
import java.lang.reflect.InvocationTargetException;
import java.nio.ByteBuffer;
import javax.swing.SwingUtilities;
import com.jotuntech.sketcher.client.Client;
import com.jotuntech.sketcher.client.Command;
import com.jotuntech.sketcher.client.Connection;
import com.jotuntech.sketcher.common.Canvas;
import com.jotuntech.sketcher.common.Log;
import com.jotuntech.sketcher.common.User;
public class CanvasCommand implements Command {
protected int width, height;
public CanvasCommand() {
}
public CanvasCommand(int width, int height) {
this.width = width;
this.height = height;
}
public int perform(final Client client, User user) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
/** Create and set new canvas */
client.setCanvas(new Canvas(width, height));
Log.info("Created canvas.");
}
});
} catch (InterruptedException e) {
Log.error(e);
} catch (InvocationTargetException e) {
Log.error(e);
}
/** Return silently */
return Connection.SEND_NONE;
}
public void decode(ByteBuffer in) {
width = in.getInt();
height = in.getInt();
}
public void encode(ByteBuffer out) {
out.putInt(width);
out.putInt(height);
}
}