Mercurial > hg > RemoteEditor > REPSessionManager
view rep/Editor.java @ 140:01062be677e9
*** empty log message ***
author | kono |
---|---|
date | Wed, 27 Aug 2008 20:23:39 +0900 |
parents | 70fc1e70652c |
children | abaf502e6d8f |
line wrap: on
line source
package rep; import java.nio.channels.SocketChannel; import java.util.LinkedList; import java.util.StringTokenizer; import rep.channel.REPSocketChannel; public class Editor { private int eid; private REPSocketChannel<REPCommand> myChannel; private REPSocketChannel<REPCommand> nextChannel; private String host; private String port; //public int getEID; private String file; private LinkedList<REPCommand> undoCommandList = new LinkedList<REPCommand>(); private LinkedList<Integer> temp = new LinkedList<Integer>(); public Editor(int editorNo, REPSocketChannel<REPCommand> channel){ this.eid = editorNo; this.myChannel = channel; } public Editor(REPSocketChannel<REPCommand> channel) { this.myChannel = channel; setHostAndPort(myChannel); } public Editor() { } private void setHostAndPort(REPSocketChannel<REPCommand> myChannel2) { String socketString = myChannel2.socket().getRemoteSocketAddress().toString(); String[] split = socketString.split("/"); int length = split.length; String hostAndPort = split[length-1]; split = hostAndPort.split(":"); host = split[0]; port = split[1]; } public REPSocketChannel<REPCommand> getChannel() { return myChannel; } public void setHost(String host){ this.host = host; } public void setPort(String port){ this.port = port; } public String getHost(){ return host; } public String getPort(){ return port; } public int getEID() { return eid; } public void setEID(int eid) { this.eid = eid; } public String toString(){ return (host + ":" + port + ":" + file); //return ("eid:" + eid + ":" + myChannel.socket().getLocalSocketAddress().toString()); } public String getName() { return file; } public void setName(String string) { file = string; } public void send(REPCommand repCmd) { REPPacketSend send = new REPPacketSend(myChannel); send.send(repCmd); } public void setChannel(REPSocketChannel channel) { myChannel = channel; } public void addUndoCommand(REPCommand command) { if(command.cmd == REP.SMCMD_GET_UNDO_ACK){ command.setCMD((temp.get(0)).intValue()); temp.remove(); } undoCommandList.addFirst(command); System.out.println(undoCommandList); // if(undoCommandList.size() > 10){ // for(REPCommand undoCommand : undoCommandList){ // send(undoCommand); // } // undoCommandList.clear(); // } } public void undo() { // TODO Auto-generated method stub for(REPCommand undoCommand : undoCommandList){ send(undoCommand); } undoCommandList.clear(); } public void setKindOfUndoCmd(int cmd) { // TODO Auto-generated method stub temp .add(cmd); } }