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.

64 lines
1.3 KiB

package com.jotuntech.sketcher.client.command;
import java.nio.ByteBuffer;
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.Layer;
import com.jotuntech.sketcher.common.User;
public class SetLayerCommand implements Command {
Integer layerKey;
public SetLayerCommand() {
}
public SetLayerCommand(Integer layerKey) {
this.layerKey = layerKey;
}
public int perform(Client client, User user) {
if(user == null) {
return Connection.SEND_NONE;
}
if(user.isViewer()) {
return Connection.SEND_NONE;
}
Canvas canvas = client.getCanvas();
if(canvas == null) {
return Connection.SEND_NONE;
}
Layer layer = canvas.getLayerMap().get(layerKey);
if(layer == null) {
return Connection.SEND_NONE;
}
if(user.getLayer() == layer) {
return Connection.SEND_NONE;
}
user.setLayer(layer);
if(user == client.getConnection().getUser()) {
client.getUserInterface().updateLayer();
}
return Connection.SEND_OTHERS;
}
public void decode(ByteBuffer in) {
layerKey = in.getInt();
}
public void encode(ByteBuffer out) {
out.putInt(layerKey);
}
}