changeset 34:7d80c9318695

*** empty log message ***
author pin
date Wed, 31 Jan 2007 02:06:52 +0900
parents 96306e8dc217
children 0c5701885b09
files bin/remoteeditor/editors/RemoteEditor$1.class bin/remoteeditor/editors/RemoteEditor.class plugin.xml src/remoteeditor/action/RemoteEditorAction.java src/remoteeditor/command/REPCommand.java src/remoteeditor/command/REPCommandEvent.java src/remoteeditor/command/REPCommandListener.java src/remoteeditor/editors/RemoteEditor.java src/remoteeditor/network/REPPacketReceive.java src/remoteeditor/network/REPPacketSend.java src/sample/merge/Rep_Cmd.java src/sample/merge/Translate.java
diffstat 12 files changed, 291 insertions(+), 9 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/plugin.xml	Tue Jan 23 17:25:55 2007 +0900
+++ b/plugin.xml	Wed Jan 31 02:06:52 2007 +0900
@@ -14,5 +14,19 @@
             name="Remote Editor">
       </editor>
    </extension>
-
+   
+   <extension point="org.eclipse.ui.actionSets">
+   	<actionSet
+   		label="RemoteEditor"
+   		id="RemoteEditor.actionSet">
+   		<action
+   			label="RemoteEditor"
+   			icon="icons/R-01.gif"
+   			id="RemoteEdotor.action"
+   			toolbarPath="RemoteEditorGroup"
+   			class="remoteeditor.action.RemoteEditorAction">
+   		</action>
+   	</actionSet>
+   </extension>
+   
 </plugin>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/remoteeditor/action/RemoteEditorAction.java	Wed Jan 31 02:06:52 2007 +0900
@@ -0,0 +1,57 @@
+package remoteeditor.action;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.internal.Workbench;
+import org.eclipse.ui.internal.WorkbenchPage;
+
+public class RemoteEditorAction implements IWorkbenchWindowActionDelegate {
+	
+	public RemoteEditorAction(){
+		
+	}
+
+	public void dispose() {
+
+	}
+
+	public void init(IWorkbenchWindow window) {
+
+	}
+
+	public void run(IAction action) {
+		IWorkbench workbench = PlatformUI.getWorkbench();
+		IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
+		IWorkbenchPage workbenchPage = workbenchWindow.getActivePage();
+		IEditorPart editorPart = workbenchPage.getActiveEditor();
+		
+		System.out.println(editorPart.getEditorInput().toString());
+		IEditorInput editorinput = editorPart.getEditorInput();
+		
+		workbenchPage.closeEditor(editorPart, true);
+		
+		//System.out.println(editorinput.getName());
+		
+		try {
+			editorPart = workbenchPage.openEditor(editorinput, "remoteeditor.editors.RemoteEditor");
+			System.out.println("test");
+		} catch (PartInitException e) {
+			e.printStackTrace();
+		}
+		
+
+	}
+
+	public void selectionChanged(IAction action, ISelection selection) {
+
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/remoteeditor/command/REPCommand.java	Wed Jan 31 02:06:52 2007 +0900
@@ -0,0 +1,29 @@
+package remoteeditor.command;
+
+public class REPCommand {
+	public int cmd;
+	public int sid;
+	public int eid;
+	public int seq;
+	public int len;
+	public int lineno;
+	public boolean stat;
+	
+	public  String string;
+	private int textsiz;
+	
+	public REPCommand(int cmd,int sid,int eid, int seq, int lineno, int textsiz, String string) {
+		this.cmd = cmd;
+		this.sid = sid;
+		this.eid = eid;
+		this.seq = seq;
+		this.textsiz = textsiz;
+		this.lineno = lineno;
+		this.string = string;
+	}
+
+	public String toString(){
+		String repCmdString = new String(cmd + "," + sid + "," + eid + "," + seq + "," + lineno + "," + textsiz + string);
+		return repCmdString;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/remoteeditor/command/REPCommandEvent.java	Wed Jan 31 02:06:52 2007 +0900
@@ -0,0 +1,11 @@
+package remoteeditor.command;
+
+public class REPCommandEvent {
+	REPCommand repcommand;
+	public REPCommandEvent(REPCommand cmd){
+		repcommand = cmd;
+	}
+	public REPCommand getCommand(){
+		return repcommand;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/remoteeditor/command/REPCommandListener.java	Wed Jan 31 02:06:52 2007 +0900
@@ -0,0 +1,5 @@
+package remoteeditor.command;
+
+public interface REPCommandListener {
+	public void CommandReceived(REPCommandEvent event);
+}
--- a/src/remoteeditor/editors/RemoteEditor.java	Tue Jan 23 17:25:55 2007 +0900
+++ b/src/remoteeditor/editors/RemoteEditor.java	Wed Jan 31 02:06:52 2007 +0900
@@ -1,5 +1,12 @@
 package remoteeditor.editors;
 
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.nio.channels.SocketChannel;
+import java.util.LinkedList;
+import java.util.List;
+
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
 import org.eclipse.jface.text.ITextListener;
@@ -8,24 +15,51 @@
 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;
 import remoteeditor.network.RSocketEvent;
 import remoteeditor.network.RSocketListener;
+import sample.merge.Translate;
 
 
-public class RemoteEditor extends TextEditor implements ITextListener, RSocketListener{
+public class RemoteEditor extends TextEditor implements ITextListener, REPCommandListener{
 	
 	private ISourceViewer viewer;
 	private IDocument document;
-	REP rep;
+	
+	REPPacketReceive repreceive;
+	REPPacketSend repsend;
+	Translate trans = new Translate();
+	
+	
 	int numberOfLinesOld;
 	int offset_con;
+	private SocketChannel sc;
 
 	public RemoteEditor() {
 		super();
 		
-		rep = new REP();
-		rep.addSocketListener(this);
+		int port = 8765;
+		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);
+		repreceive.addCommandListener(this);
+		repsend = new REPPacketSend(sc);
+		joinPart();
 	}
 	
 	public void createPartControl(Composite parent) {
@@ -37,7 +71,7 @@
 	}
 	
 	public void dispose() {
-		rep.dispose();
+		//rep.dispose();
 		super.dispose();
 	}
 	public void textChanged(TextEvent event) {
@@ -73,7 +107,7 @@
 		}else {
 			cmd = REP.REP_DELETE_CMD;
 		}
-		rep.sendCmd(cmd, line, length, lineText);
+		//rep.sendCmd(cmd, line, length, lineText);
 		numberOfLinesOld = numberOfLinesNew;
 	}
 	
@@ -102,4 +136,13 @@
 			e.printStackTrace();
 		}
 	}
+	
+	public void joinPart(){
+		String string = "test.txt";
+		repsend.send(new REPCommand(REP.REP_JOIN_CMD,0,0,0,0,string.length(),string));
+	}
+
+	public void CommandReceived(REPCommandEvent event) {
+		System.out.println("test2");
+	}
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/remoteeditor/network/REPPacketReceive.java	Wed Jan 31 02:06:52 2007 +0900
@@ -0,0 +1,81 @@
+package remoteeditor.network;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+import remoteeditor.command.REPCommand;
+import remoteeditor.command.REPCommandEvent;
+import remoteeditor.command.REPCommandListener;
+
+public class REPPacketReceive implements Runnable{
+	
+	SocketChannel socketchannel;
+	private int HEADER_SIZE = 24;
+	private REPCommandListener commandlistener;
+	
+	public REPPacketReceive(SocketChannel sc){
+		socketchannel = sc;
+	}
+
+	
+	public REPCommand unpack() {
+		System.out.println("test1");
+		ByteBuffer header = ByteBuffer.allocateDirect(HEADER_SIZE);
+		long len = 0;
+		header.clear();
+		try {
+			len = socketchannel.read(header);
+		} catch (IOException e1) {
+			e1.printStackTrace();
+		}  // limit = read length
+		if (len !=HEADER_SIZE) {
+			System.out.println("‚Ä‚·");
+			// this can't happen
+		}
+		header.rewind();  // position = 0
+
+		String text = "";
+		int cmd = header.getInt();
+		int sid = header.getInt();
+		int eid = header.getInt();
+		int seqid = header.getInt();
+		int lineno = header.getInt();
+		int textsiz = header.getInt()/2;
+		
+		ByteBuffer textBuffer = ByteBuffer.allocateDirect(textsiz*2);
+
+		try {
+			len = socketchannel.read(textBuffer);
+		} catch (IOException e1) {
+			e1.printStackTrace();
+		}  // limit = read length
+		if (len != textsiz * 2) {
+			// this can't happen
+			System.out.println("‚ ‚Æ");
+		}
+		textBuffer.rewind();
+		for(int i=0;i<textsiz;i++) {
+			text +=textBuffer.getChar();
+		}
+		String string = text;
+		System.out.println(string);
+		REPCommand repcommand = new REPCommand(cmd, sid, eid, seqid, lineno, textsiz, string);
+		System.out.println(repcommand.toString());
+		return repcommand;
+	}
+	
+	public void addCommandListener(REPCommandListener listener){
+		commandlistener = listener;
+		Thread th = new Thread(this);
+		th.start();
+	}
+
+	public void run() {
+		while(socketchannel.isConnected()){
+			//unpack();
+			commandlistener.CommandReceived(new REPCommandEvent(unpack()));
+		}
+	}
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/remoteeditor/network/REPPacketSend.java	Wed Jan 31 02:06:52 2007 +0900
@@ -0,0 +1,37 @@
+package remoteeditor.network;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+import remoteeditor.command.REPCommand;
+
+public class REPPacketSend {
+	SocketChannel socketchannel;
+	
+	public REPPacketSend(SocketChannel sc){
+		socketchannel = sc;
+	}
+	
+	public ByteBuffer pack(REPCommand command){
+    	
+    	ByteBuffer buffer = ByteBuffer.allocateDirect(24+(command.string).length()*2);
+    	buffer.clear();  // position = 0 
+    	buffer.putInt(command.cmd); buffer.putInt(command.sid); buffer.putInt(command.eid);
+    	buffer.putInt(command.seq); buffer.putInt(command.lineno); 
+    	buffer.putInt(command.string.length()*2); 
+    	for(int i=0;i<command.string.length();i++) {
+			buffer.putChar(command.string.charAt(i));
+		}	
+    	buffer.flip();    // limit = current position, position = 0
+		return buffer;
+	}
+	
+	public void send(REPCommand command){
+		try {
+			socketchannel.write(pack(command));
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+}
--- a/src/sample/merge/Rep_Cmd.java	Tue Jan 23 17:25:55 2007 +0900
+++ b/src/sample/merge/Rep_Cmd.java	Wed Jan 31 02:06:52 2007 +0900
@@ -12,7 +12,7 @@
 	public  String string;
 	private int textsiz;
 	
-	public Rep_Cmd(int cmd,int sid,int eid, int seq, int lineno, int textsiz, String string) throws Exception {
+	public Rep_Cmd(int cmd,int sid,int eid, int seq, int lineno, int textsiz, String string) {
 		this.cmd = cmd;
 		this.sid = sid;
 		this.eid = eid;
--- a/src/sample/merge/Translate.java	Tue Jan 23 17:25:55 2007 +0900
+++ b/src/sample/merge/Translate.java	Wed Jan 31 02:06:52 2007 +0900
@@ -7,10 +7,15 @@
 	List <Rep_Cmd> userList;
 	List <Rep_Cmd> tokenList;
 	private boolean REP_IGNORE = true;
+	
+	public Translate(){
+		
+	}
+	
 	public Translate(List<Rep_Cmd> userList, List<Rep_Cmd> tokenList){
 		this.userList = userList;
 		this.tokenList = tokenList;
-		merge();
+		//merge();
 	}
 
 	void addUserList(){}