# HG changeset patch # User pin # Date 1225189159 -32400 # Node ID f77ea6bba91cd272a64b3d386c8d96cd69d4e9cd # Parent 5572e6ef4b39a263faa9f9020f3563e2c39d5806 *** empty log message *** diff -r 5572e6ef4b39 -r f77ea6bba91c bin/remoteeditor/editors/RemoteEditor$1.class Binary file bin/remoteeditor/editors/RemoteEditor$1.class has changed diff -r 5572e6ef4b39 -r f77ea6bba91c bin/remoteeditor/editors/RemoteEditor.class Binary file bin/remoteeditor/editors/RemoteEditor.class has changed diff -r 5572e6ef4b39 -r f77ea6bba91c bin/remoteeditor/network/REP.class Binary file bin/remoteeditor/network/REP.class has changed diff -r 5572e6ef4b39 -r f77ea6bba91c src/remoteeditor/editors/RemoteEditor.java --- a/src/remoteeditor/editors/RemoteEditor.java Tue Oct 21 17:28:06 2008 +0900 +++ b/src/remoteeditor/editors/RemoteEditor.java Tue Oct 28 19:19:19 2008 +0900 @@ -107,6 +107,7 @@ case REP.SMCMD_JOIN_ACK: mysid = command.sid; myeid = command.eid; + sendSync(); break; case REP.SMCMD_PUT_ACK: @@ -129,6 +130,7 @@ } catch (Exception e) { e.printStackTrace(); } + repsend.send(command); break; case REP.REPCMD_DELETE: @@ -138,12 +140,19 @@ } catch (BadLocationException e1) { e1.printStackTrace(); } + repsend.send(command); break; } } + private void sendSync() { + REPCommand command = new REPCommand(REP.SMCMD_SYNC, mysid, myeid, this.myseq++, 0, 0, ""); + repsend.send(command); + } + private void receiveSync(REPCommand command) { + if(this.myeid != 1) return; int lines = document.getNumberOfLines(); for(int i = 0; i < lines; i++){ @@ -161,7 +170,11 @@ } } - private void deleteText(int lineNo, int len, String string) throws BadLocationException { + private void deleteText(final int lineNo, final int len, final String text) throws BadLocationException { + if(document.getNumberOfLines() < lineNo+1){ + increaseLine(); + deleteText(lineNo, len, text); + } final int offset = document.getLineOffset(lineNo); final int replaceLength = document.getLineLength(lineNo); @@ -179,9 +192,13 @@ }); } - private void insertText(int lineNo, int j, String text) throws BadLocationException { + private void insertText(final int lineNo, final int len, final String text) throws BadLocationException { + if(document.getNumberOfLines() < lineNo+1){ + increaseLine(); + insertText(lineNo, len, text); + } final int offset = document.getLineOffset(lineNo); - final String changedText = text; + final String changedText = text + BR; viewer.getTextWidget().getDisplay().syncExec(new Runnable() { public void run() { @@ -191,6 +208,22 @@ others = false; } catch (BadLocationException e) { e.printStackTrace(); + + } + } + }); + } + + private void increaseLine(){ + viewer.getTextWidget().getDisplay().syncExec(new Runnable() { + public void run() { + try { + others = true; + document.replace(document.getLength(), 0, BR); + others = false; + } catch (BadLocationException e) { + e.printStackTrace(); + } } }); @@ -210,13 +243,25 @@ e.printStackTrace(); } - String text = getLineText(lineno, bDoc); + String text = ""; + try{ + String str = new String(getLineText(lineno, bDoc)); + String[] splited = str.split(BR); + if(splited.length > 0){ + text = splited[0]; + }else{ + text = ""; + } + }catch(Exception e){ + e.printStackTrace(); + } sendDelete(lineno, text); if(replacedText.contains(BR)){ - String text2 = getLineText(lineno+1, bDoc); + String text2 = getLineText(lineno+1, bDoc).split(BR)[0]; sendDelete(lineno, text2); } + } @@ -232,13 +277,24 @@ } catch (BadLocationException e) { e.printStackTrace(); } - - String text = getLineText(lineno, doc); - sendInsert(lineno, text); + + try{ + String text = getLineText(lineno, doc).split(BR)[0]; + sendInsert(lineno, text); - if(numberOfLines > numberOfLinesOld){ - String text2 = getLineText(lineno+1, doc); - sendInsert(lineno+1, text2); + if(numberOfLines > numberOfLinesOld){ + String text2; + String str = new String(getLineText(lineno+1, doc)); + String[] split = str.split(BR); + if(split.length > 0){ + text2 = getLineText(lineno+1, doc).split(BR)[0]; + }else{ + text2 = ""; + } + sendInsert(lineno+1, text2); + } + }catch (Exception e){ + e.printStackTrace(); } numberOfLinesOld = numberOfLines; } diff -r 5572e6ef4b39 -r f77ea6bba91c src/remoteeditor/network/REP.java --- a/src/remoteeditor/network/REP.java Tue Oct 21 17:28:06 2008 +0900 +++ b/src/remoteeditor/network/REP.java Tue Oct 28 19:19:19 2008 +0900 @@ -45,7 +45,7 @@ public static final int MERGE_EID = -2; - public static final int SMCMD_SYNC = 82; + public static final int SMCMD_SYNC = 83; //public static final int SMCMD_START_MERGE = 73; //public static final int SMCMD_START_MERGE_ACK = 74;