# HG changeset patch # User dimolto # Date 1292736336 -32400 # Node ID 6c194d94fc4329a228c0dfa059f5818fd760fd3e # Parent a853f36c238ce4ce42807432db78aa1efcb1f347# Parent 12259860a143ecefd64205fa2b8ef5533990d9d2 Merge with 12259860a143ecefd64205fa2b8ef5533990d9d2 diff -r 12259860a143 -r 6c194d94fc43 src/remoteeditor/editors/REPEditor.java --- a/src/remoteeditor/editors/REPEditor.java Sat Dec 18 18:23:28 2010 +0900 +++ b/src/remoteeditor/editors/REPEditor.java Sun Dec 19 14:25:36 2010 +0900 @@ -30,16 +30,12 @@ private boolean hasInputLock = true; private boolean master; private boolean syncEnable = true; + private REPCommand quit = null; public REPEditor(REPText repText, boolean master){ this.repText = repText; this.master = master; repText.addTextListener(this); - if(master){ - userCommand.add(new REPCommand(REP.SMCMD_PUT,0,0,0,0,name +"-file")); - }else{ - userCommand.add(new REPCommand(REP.SMCMD_JOIN, 0, 0, 0, 0, name)); - } } public void textDeleted(REPTextEvent event) { @@ -134,78 +130,21 @@ } } - public void handle(REPCommand command) { - Logger.print(command); - if(command == null) return; - switch(command.cmd){ - case REPCMD_DELETE: - if(command.eid != eid){ - String del = repText.delete(command.lineno); - command.setString(del); - } - forward(command); - break; - case REPCMD_INSERT: - if(command.eid != eid){ - repText.insert(command.lineno, command.string); - } - forward(command); - break; - case REPCMD_NOP: - case REPCMD_INSERT_ACK: - case REPCMD_DELETE_ACK: - forward(command); - break; - case SMCMD_PUT_ACK: - sid = command.sid; - eid = command.eid; - name += "(eid="+eid+",sid="+sid+")"; - inputLock = false; - break; - case SMCMD_JOIN_ACK : - sid = command.sid; - eid = command.eid; - name += "(eid="+eid+",sid="+sid+")"; - inputLock = false; - break; - case SMCMD_START_MERGE : - // lock user input during merge (optional) - inputLock = hasInputLock; - repText.startMerge(this); - command.cmd = REP.SMCMD_START_MERGE_ACK; - send(command); - break; - case SMCMD_END_MERGE : - inputLock = false; - repText.endMerge(); - break; - case SMCMD_SYNC: - // start contents sync with newly joined editor - command.cmd = REP.SMCMD_SYNC_ACK; - forward(command); - //if (cmd.eid==eid) { - if (master && syncEnable ) { - syncCounter = 1; - timeout = 1; - } - break; - } - } + private void userInput() { - Logger.print(); REPCommand command = userCommand.poll(); if(command != null){ switch(command.cmd){ case REPCMD_DELETE_USER: - send(command); + sendCommand(command); break; case REPCMD_INSERT_USER: - send(command); + sendCommand(command); break; case SMCMD_PUT: case SMCMD_JOIN: - send(command); + sendCommand(command); break; } }else{ @@ -215,12 +154,107 @@ } } - private void forward(REPCommand command) { + private void handle(REPCommand cmd) { + if (cmd==null) return; + switch(cmd.cmd) { + case REPCMD_INSERT : + if (cmd.eid!=eid) { + repText.insert(cmd.lineno, cmd.string); + } + forwardCommand(cmd); + break; + case REPCMD_DELETE : + if (cmd.eid!=eid) { + String del=""; + if(cmd.lineno