Mercurial > hg > RemoteEditor > Eclipse
changeset 182:f8eab56045c5
*** empty log message ***
author | pin |
---|---|
date | Tue, 09 Sep 2008 17:39:45 +0900 |
parents | 54c438d246a4 |
children | 54a9dba5ce2a |
files | bin/remoteeditor/editors/RemoteEditor$1.class bin/remoteeditor/editors/RemoteEditor.class src/remoteeditor/editors/RemoteEditor.java |
diffstat | 3 files changed, 96 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/src/remoteeditor/editors/RemoteEditor.java Sun Aug 31 11:20:58 2008 +0900 +++ b/src/remoteeditor/editors/RemoteEditor.java Tue Sep 09 17:39:45 2008 +0900 @@ -1,13 +1,8 @@ package remoteeditor.editors; import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.nio.CharBuffer; import java.nio.channels.SocketChannel; -import java.util.Enumeration; import java.util.LinkedList; import java.util.List; @@ -17,10 +12,6 @@ import org.eclipse.jface.text.TextEvent; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IWorkbench; -import org.eclipse.ui.PlatformUI; import org.eclipse.ui.editors.text.TextEditor; import remoteeditor.command.REPCommand; @@ -29,9 +20,6 @@ import remoteeditor.network.REP; import remoteeditor.network.REPPacketReceive; import remoteeditor.network.REPPacketSend; -import remoteeditor.network.RSocketEvent; -import remoteeditor.network.RSocketListener; -import remoteeditor.ui.REPSelectWindow; import sample.merge.Translate; @@ -47,8 +35,6 @@ List <REPCommand> tokenCmdList = new LinkedList<REPCommand>(); Translate trans = new Translate(userCmdList, tokenCmdList); - //Translate trans = new Translate(); - int numberOfLinesOld; int offset_con; @@ -144,58 +130,101 @@ System.out.println("input = " + inputText + " : " + inputText.length()); int line = 0; - int offset = 0; + int lineOffset = 0; int length = 0; - int cmd = 0; int numberOfLinesNew = 0; String lineText = null; try { line = document.getNumberOfLines(0, textOffset); // lineno を取得してます。 - offset = document.getLineOffset(line-1); + lineOffset = document.getLineOffset(line-1); length = document.getLineLength(line-1); - lineText = document.get(offset, length); + lineText = document.get(lineOffset, length); numberOfLinesNew = document.getNumberOfLines(); } catch (BadLocationException e1) { e1.printStackTrace(); } + + String beforeText = getBeforeText(line, lineOffset, inputText, replacedText); + + if(numberOfLinesNew == numberOfLinesOld){ + sendDelete(line, beforeText); + sendInsert(line, lineText); + } + if(numberOfLinesNew > numberOfLinesOld){ //insert, delete, replace 行数で判断 - cmd = REP.REPCMD_INSERT; - try { - sendInsert(line); - createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line); - } catch (BadLocationException e) { - e.printStackTrace(); - } + sendInsert(replacedText, inputText, textOffset, line, lineOffset); }else if(numberOfLinesNew == numberOfLinesOld){ - cmd = REP.REPCMD_REPLACE; - try { - sendReplace(line); - createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line); - } catch (BadLocationException e) { - e.printStackTrace(); - } + sendReplace(replacedText, inputText, textOffset, line, lineOffset); + }else { - cmd = REP.REPCMD_DELETE; - try { - sendDelete(line); - createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line); - } catch (BadLocationException e) { - e.printStackTrace(); - } + sendDelete(replacedText, inputText, textOffset, line, lineOffset); + } + + numberOfLinesOld = document.getNumberOfLines(); + } + + private void sendInsert(int line, String lineText) { + // TODO Auto-generated method stub + + } + + private void sendDelete(int line, String beforeText) { + // TODO Auto-generated method stub + + } + + private String getBeforeText(int line, int offset, String inputText, String replacedText) { + String lineText = null; + try { + int lineOffset = document.getLineOffset(line-1); + int length = document.getLineLength(line-1); + lineText = document.get(lineOffset, length); + } catch (BadLocationException e) { + e.printStackTrace(); + } + StringBuffer sb = new StringBuffer(lineText); + sb.delete(offset, offset + inputText.length()); + + if(replacedText != null){ + sb.insert(offset, replacedText); } - //rep.sendCmd(cmd, line, length, lineText); -// if(!lock){ -// REPCommand usercmd = new REPCommand(cmd, mysid, myeid, myseq, line, lineText.length(), lineText); -// repsend.send(usercmd); -// //translate.addUserList(usercmd); -// trans.addUserList(usercmd); -// //System.out.println("User List" + userCmdList.toString()); -// //System.out.println("Token List" + tokenCmdList.toString()); -// }else{ } - //numberOfLinesOld = numberOfLinesNew; - numberOfLinesOld = document.getNumberOfLines(); + String beforeText = sb.toString(); + return beforeText; + } + + private void sendDelete(String replacedText, String inputText, int textOffset, int line, int offset) { + int cmd; + cmd = REP.REPCMD_DELETE; + try { + sendDelete(line); + createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + private void sendReplace(String replacedText, String inputText, int textOffset, int line, int offset) { + int cmd; + cmd = REP.REPCMD_REPLACE; + try { + sendReplace(line); + createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line); + } catch (BadLocationException e) { + e.printStackTrace(); + } + } + + private void sendInsert(String replacedText, String inputText, int textOffset, int line, int offset) { + int cmd; + cmd = REP.REPCMD_INSERT; + try { + sendInsert(line); + createUndoCommand(cmd, textOffset - offset, replacedText, inputText, line); + } catch (BadLocationException e) { + e.printStackTrace(); + } } private void createUndoCommand(int cmd, int offset, String replacedText, String inputText, int line) { @@ -220,18 +249,11 @@ } StringBuffer sb = new StringBuffer(lineText); sb.delete(offset, offset + inputText.length()); - //undoString = sb.toString(); + if(replacedText != null){ sb.insert(offset, replacedText); } undoString = sb.toString(); - //sb.insert(offset, inputText); - //if(replacedText == null){ - // sb.delete(offset, inputText.length()); - //}else { - //sb.replace(offset, inputText.length(), replacedText); - //} - //undoString = sb.toString(); }else if(cmd == REP.REPCMD_DELETE){ undoCmd = REP.REPCMD_INSERT; @@ -243,29 +265,25 @@ } private void sendDelete(int line) throws BadLocationException { - if(!lock){ - int offset = document.getLineOffset(line-1); - int length = document.getLineLength(line-1); - String lineText = document.get(offset, length); - REPCommand usercmd = new REPCommand(REP.REPCMD_REPLACE, mysid, myeid, myseq, line, lineText.length(), lineText); - repsend.send(usercmd); - - offset = document.getLineOffset(line); - length = document.getLineLength(line); - lineText = document.get(offset, length); - usercmd = new REPCommand(REP.REPCMD_DELETE, mysid, myeid, myseq, line, lineText.length(), lineText); - repsend.send(usercmd); - } + int offset = document.getLineOffset(line-1); + int length = document.getLineLength(line-1); + String lineText = document.get(offset, length); + REPCommand usercmd = new REPCommand(REP.REPCMD_REPLACE, mysid, myeid, myseq, line, lineText.length(), lineText); + repsend.send(usercmd); + + offset = document.getLineOffset(line); + length = document.getLineLength(line); + lineText = document.get(offset, length); + usercmd = new REPCommand(REP.REPCMD_DELETE, mysid, myeid, myseq, line, lineText.length(), lineText); + repsend.send(usercmd); } private void sendReplace(int line) throws BadLocationException { - if(!lock){ - int offset = document.getLineOffset(line-1); - int length = document.getLineLength(line-1); - String lineText = document.get(offset, length); - REPCommand usercmd = new REPCommand(REP.REPCMD_REPLACE, mysid, myeid, myseq, line, lineText.length(), lineText); - repsend.send(usercmd); - } + int offset = document.getLineOffset(line-1); + int length = document.getLineLength(line-1); + String lineText = document.get(offset, length); + REPCommand usercmd = new REPCommand(REP.REPCMD_REPLACE, mysid, myeid, myseq, line, lineText.length(), lineText); + repsend.send(usercmd); } private void sendInsert(int line) throws BadLocationException {