changeset 192:c921022bf494

(no commit message)
author one
date Wed, 31 Dec 2008 14:41:15 +0900
parents e22430832991
children 3133040ee4f4
files bin/remoteeditor/Activator.class bin/remoteeditor/MyDialog.class bin/remoteeditor/editors/RemoteEditor$1.class bin/remoteeditor/editors/RemoteEditor.class bin/remoteeditor/network/REP.class bin/remoteeditor/network/RSocketEvent.class bin/remoteeditor/network/RSocketListener.class bin/remoteeditor/ui/CommitDialog$TextBox.class bin/remoteeditor/ui/CommitDialog.class bin/remoteeditor/ui/RepInputDialog.class bin/remoteeditor/ui/TestDialog.class src/remoteeditor/editors/REPText.java src/remoteeditor/editors/RemoteEditor.java
diffstat 4 files changed, 0 insertions(+), 342 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/REPText.java	Mon Nov 10 01:14:22 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-package remoteeditor.editors;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.swt.widgets.Display;
-
-public class REPText {
-	
-	public REPText(Display display, IDocument document){
-		
-	}
-	
-	public void insert(int line, String text){
-		
-	}
-	
-	public void delete(int line, String text){
-		
-	}
-
-}
--- a/src/remoteeditor/editors/RemoteEditor.java	Mon Nov 10 01:14:22 2008 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,322 +0,0 @@
-package remoteeditor.editors;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.nio.channels.SocketChannel;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.ui.editors.text.TextEditor;
-
-import remoteeditor.command.REPCommand;
-import remoteeditor.command.REPCommandEvent;
-import remoteeditor.command.REPCommandListener;
-import remoteeditor.network.REP;
-import remoteeditor.network.REPPacketReceive;
-import remoteeditor.network.REPPacketSend;
-
-
-public class RemoteEditor extends TextEditor implements REPCommandListener, IDocumentListener{
-	
-	private ISourceViewer viewer;
-	private IDocument document;
-	
-	private REPPacketReceive repreceive;
-	private REPPacketSend repsend;
-	
-	private int numberOfLinesOld;
-	private SocketChannel sc;
-	private int myeid = 0;
-	private int myseq = 0;
-	private int mysid = 0;
-	private String filename = "afro";
-	private String BR = System.getProperty("line.separator");
-	public  boolean others = false;
-	
-	public RemoteEditor() {
-		super();
-	}
-	
-	public void createPartControl(Composite parent) {
-		super.createPartControl(parent);
-		viewer = getSourceViewer();
-		document = viewer.getDocument();
-		filename = this.getEditorInput().getName();
-		numberOfLinesOld = document.getNumberOfLines();
-		
-		document.addDocumentListener(this);
-
-		int port = 8766;
-		String host = "localhost";
-		InetSocketAddress addr = new InetSocketAddress(host, port);
-		try {
-			sc = SocketChannel.open();
-			sc.configureBlocking(true);
-			sc.connect(addr);
-			while(!sc.finishConnect()){
-				System.out.println("afro");
-			}
-		}catch (IOException e) {
-			e.printStackTrace();
-		}
-
-		repreceive = new REPPacketReceive(sc);
-		repsend = new REPPacketSend(sc);
-		
-		repreceive.addCommandListener(this);
-		if(document.getLength() < 1){
-			repJoin();
-		}else {
-			repPut();
-		}
-	}
-
-	public void dispose() {
-		super.dispose();
-	}
-	
-	public void repJoin(){
-		repsend.send(new REPCommand(REP.SMCMD_JOIN, 0, 0, 0, 0, 0, ""));
-	}
-	
-	public void repPut(){
-		if(this.getEditorInput() != null) filename = this.getEditorInput().getName();
-		repsend.send(new REPCommand(REP.SMCMD_PUT, mysid, myeid, myseq, 0, filename.length(), filename));
-	}
-	
-	
-	public void repSelect(){
-		repsend.send(new REPCommand(REP.SMCMD_SELECT, mysid, myeid, myseq, 0, 0, ""));
-	}
-
-	public void CommandReceived(REPCommandEvent event) {
-		REPCommand receivedCommand = event.getCommand();
-		if(receivedCommand.eid == myeid){
-			System.out.println("my REP Command.");
-		}else{
-
-		}
-		manage(receivedCommand);
-	}
-
-	private void manage(REPCommand command) {
-		switch(command.cmd){
-		case REP.SMCMD_JOIN_ACK:
-			mysid = command.sid;
-			myeid = command.eid;
-			sendSync();
-			break;
-			
-		case REP.SMCMD_PUT_ACK:
-			mysid = command.sid;
-			myeid = command.eid;
-			break;
-			
-		case REP.SMCMD_SELECT_ACK:
-			mysid = command.sid;
-			break;
-			
-		case REP.SMCMD_SYNC:
-			receiveSync(command);
-			break;
-			
-		case REP.REPCMD_INSERT:
-			try {
-					if(command.eid == myeid) break;	//mergerを導入する時に消す
-					insertText(command.lineno, command.len, command.string);
-				} catch (Exception e) {
-					e.printStackTrace();
-				}
-				repsend.send(command);
-			break;
-
-		case REP.REPCMD_DELETE:
-			try {
-					if(command.eid == myeid) break;//mergerを導入する時に消す
-					deleteText(command.lineno, command.len, command.string);
-				} 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++){
-			
-			String text = null;
-			try {
-				text = document.get(document.getLineOffset(i), document.getLineLength(i));
-			} catch (BadLocationException e) {
-				e.printStackTrace();
-			}
-			REPCommand deleteCommand = new REPCommand(REP.REPCMD_DELETE, mysid, myeid, myseq++, i, text.length(), text);
-			repsend.send(deleteCommand);
-			REPCommand insertCommand = new REPCommand(REP.REPCMD_INSERT, mysid, myeid, myseq++, i, text.length(), text);
-			repsend.send(insertCommand);
-			
-		}
-	}
-
-	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);
-		
-		viewer.getTextWidget().getDisplay().syncExec(new Runnable() {
-			public void run() {
-				try {
-					others = true;
-					document.replace(offset, replaceLength, "");
-					others = false;
-				} catch (BadLocationException e) {
-					e.printStackTrace();
-				}
-			}
-		});
-	}
-
-	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 + BR;
-
-		viewer.getTextWidget().getDisplay().syncExec(new Runnable() {
-			public void run() {
-				try {
-					others = true;
-					document.replace(offset, 0, changedText);
-					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();
-
-				}
-			}
-		});
-	}
-
-	public void documentAboutToBeChanged(DocumentEvent event) {
-		if(others == true) return;
-		
-		IDocument bDoc = event.getDocument();
-		int lineno = 0;
-		String replacedText = null;
-		
-		try {
-			lineno = bDoc.getLineOfOffset(event.getOffset());
-			replacedText = bDoc.get(event.getOffset(), event.getLength());
-		} catch (BadLocationException e) {
-			e.printStackTrace();
-		}
-		
-		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).split(BR)[0];
-			sendDelete(lineno, text2);
-		}
-
-		
-	}	
-	
-	public void documentChanged(DocumentEvent event) {
-		if(others == true) return;
-		
-		IDocument doc = event.getDocument();
-		int numberOfLines = doc.getNumberOfLines();
-		int lineno = 0;
-		
-		try {
-			lineno = doc.getLineOfOffset(event.getOffset());
-		} catch (BadLocationException e) {
-			e.printStackTrace();
-		}
-
-		try{
-			String text = getLineText(lineno, doc).split(BR)[0];
-			sendInsert(lineno, text);
-
-			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;
-	}
-
-	private void sendInsert(int lineno, String text) {
-		REPCommand command = new REPCommand(REP.REPCMD_INSERT, mysid, myeid, this.myseq++, lineno, text.length(), text);
-		repsend.send(command);
-	}
-
-	private void sendDelete(int lineno, String text) {
-		REPCommand command = new REPCommand(REP.REPCMD_DELETE, mysid, myeid, this.myseq++, lineno, text.length(), text);
-		repsend.send(command);
-		//System.out.println("RemoteEditor.sendDelete() : command = " + command.toString());
-	}
-
-	private String getLineText(int lineno, IDocument document2) {
-		String text = null;
-		try{
-			int lineOffset = document2.getLineOffset(lineno);
-			int length = document2.getLineLength(lineno);
-			text = document2.get(lineOffset, length);
-		}catch(BadLocationException e){		}
-		return text;
-	}
-}