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.User; public class SetColorCommand implements Command { static boolean firstWhite = true; int color; public SetColorCommand() { } public SetColorCommand(int color) { this.color = color; } public int perform(Client client, User user) { if(color == 0xFFFFFF && user == client.getConnection().getUser() && client.getConnection().getUser().getBrush() != null && client.getConnection().getUser().getBrush().getOpacity() > 0 && firstWhite) { client.getUserInterface().println("Use eraser unless drawing white. :-)"); firstWhite = false; } return perform(user) ? Connection.SEND_OTHERS : Connection.SEND_NONE; } private boolean perform(User user) { if(user == null) { /** Signed in users only */ return false; } if(user.isViewer()) { return false; } user.setColor(color); return true; } public void decode(ByteBuffer in) { color = in.getInt(); } public void encode(ByteBuffer out) { out.putInt(color); } }