Mercurial > hg > RemoteEditor > REPSessionManager
view rep/Editor.java @ 131:617a47cb0150
*** empty log message ***
author | pin |
---|---|
date | Wed, 27 Aug 2008 18:17:16 +0900 |
parents | 790c8dd42a7b |
children | 70fc1e70652c |
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 myChannel; private REPSocketChannel 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 channel){ this.eid = editorNo; this.myChannel = channel; } public Editor(REPSocketChannel channel) { this.myChannel = channel; setHostAndPort(myChannel); } public Editor() { } private void setHostAndPort(REPSocketChannel 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 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); } }