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
56 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.BitmapLayer;
|
|
import com.jotuntech.sketcher.common.Layer;
|
|
import com.jotuntech.sketcher.common.User;
|
|
|
|
public class CreateLayerCommand implements Command {
|
|
int layerKey;
|
|
int type;
|
|
String name;
|
|
|
|
public CreateLayerCommand() {
|
|
|
|
}
|
|
|
|
public CreateLayerCommand(int layerKey, int type, String name) {
|
|
this.layerKey = layerKey;
|
|
this.type = type;
|
|
this.name = name;
|
|
}
|
|
|
|
public int perform(Client client, User user) {
|
|
Layer l = new BitmapLayer(name);
|
|
client.getCanvas().getLayerMap().put(layerKey, l);
|
|
|
|
if(user != null) {
|
|
client.getUserInterface().println(user.getName() + " created layer " + l.getName());
|
|
}
|
|
|
|
return Connection.SEND_ALL;
|
|
}
|
|
|
|
public void decode(ByteBuffer in) {
|
|
layerKey = in.getInt();
|
|
type = in.get();
|
|
StringBuffer nameBuffer = new StringBuffer();
|
|
while(in.remaining() >= 2) {
|
|
nameBuffer.append(in.getChar());
|
|
}
|
|
name = nameBuffer.toString();
|
|
}
|
|
|
|
public void encode(ByteBuffer out) {
|
|
out.putInt(layerKey);
|
|
out.put((byte) type);
|
|
for(int i = 0; i < name.length(); i++) {
|
|
out.putChar(name.charAt(i));
|
|
}
|
|
}
|
|
|
|
}
|
|
|