changeset 184:736fd137d9a3

*** empty log message ***
author pin
date Sat, 20 Sep 2008 10:59:20 +0900
parents 54a9dba5ce2a
children 42563c465a6e
files bin/remoteeditor/editors/RemoteEditor$1.class bin/remoteeditor/editors/RemoteEditor.class src/remoteeditor/editors/RemoteEditor.java
diffstat 3 files changed, 17 insertions(+), 112 deletions(-) [+]
line wrap: on
line diff
Binary file bin/remoteeditor/editors/RemoteEditor$1.class has changed
Binary file bin/remoteeditor/editors/RemoteEditor.class has changed
--- a/src/remoteeditor/editors/RemoteEditor.java	Fri Sep 12 13:52:26 2008 +0900
+++ b/src/remoteeditor/editors/RemoteEditor.java	Sat Sep 20 10:59:20 2008 +0900
@@ -8,6 +8,7 @@
 
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextInputListener;
 import org.eclipse.jface.text.ITextListener;
 import org.eclipse.jface.text.TextEvent;
 import org.eclipse.jface.text.source.ISourceViewer;
@@ -23,7 +24,7 @@
 import sample.merge.Translate;
 
 
-public class RemoteEditor extends TextEditor implements ITextListener, REPCommandListener{
+public class RemoteEditor extends TextEditor implements ITextListener, REPCommandListener, ITextInputListener{
 	
 	private ISourceViewer viewer;
 	private IDocument document;
@@ -59,10 +60,11 @@
 		super.createPartControl(parent);
 		viewer = getSourceViewer();
 		viewer.addTextListener(this);
+		viewer.addTextInputListener(this);
 		document = viewer.getDocument();
 		filename = this.getEditorInput().getName();
 		numberOfLinesOld = document.getNumberOfLines();
-		
+
 		int port = 8766;
 		String host = "localhost";
 		InetSocketAddress addr = new InetSocketAddress(host, port);
@@ -183,114 +185,6 @@
 		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) {
-		int undoCmd = 0;
-		String undoString = null;
-		REPCommand undoCommand;
-		REPPacketSend send = new REPPacketSend(sc);
-		
-		if(cmd == REP.REPCMD_INSERT){
-			undoCmd = REP.REPCMD_DELETE;
-			undoString = "";
-			
-		}else if(cmd == REP.REPCMD_REPLACE){
-			undoCmd = REP.REPCMD_REPLACE;
-			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);
-			}
-			undoString = sb.toString();
-			
-		}else if(cmd == REP.REPCMD_DELETE){
-			undoCmd = REP.REPCMD_INSERT;
-			undoString = replacedText;
-		}
-		
-		undoCommand = new REPCommand(undoCmd, mysid, 0, -1, line, undoString.length(), undoString);
-		send.send(undoCommand);
-	}
-
-	private void sendDelete(int line) throws BadLocationException {
-		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 {
-		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 {
-		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_INSERT, mysid, myeid, myseq, line, lineText.length(), lineText);
-		repsend.send(usercmd);
-		}
-	}
-
 	private void changeText(int kindOfCmd, int lineNo, int LineLength, String text) throws Exception{
 		System.out.println("Replace Text : " + text);
 		final int offset = document.getLineOffset(lineNo-1);
@@ -325,7 +219,6 @@
 //	}*/
 	
 	public void joinPart(){
-		//String string = "test.txt";
 		repsend.send(new REPCommand(REP.SMCMD_JOIN, 0, 0, 0, 0, 0, myHostAndPort));
 	}
 	
@@ -346,7 +239,6 @@
 		}else{
 			tokenCmdList.add(receivedCommand);
 		}
-		//System.out.println("received command : " + receivedCommand.toString());
 		commandManager(receivedCommand);
 	}
 
@@ -498,4 +390,17 @@
 			repsend.send(new REPCommand(REP.REPCMD_READ_ACK, mysid, desteid, myseq, i, text.length(), text));
 		}
 	}
+
+	public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
+		System.out.println("---------- old Input ----------");
+		System.out.println(oldInput.get());
+		System.out.println();
+		System.out.println("---------- new Input ----------");
+		System.out.println(newInput.get());
+	}
+
+	public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
+		// TODO Auto-generated method stub
+		
+	}
 }