changeset 123:286a8a1b33cd

ƒ}[ƒWƒƒ[‚ÌEclipseã‚Å‚ÌŽÀ‘•
author kent
date Sun, 23 Dec 2007 18:17:31 +0900 (2007-12-23)
parents 43da9d272beb
children f18510fc40e2
files src/sample/merge/Merger.java
diffstat 1 files changed, 65 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/sample/merge/Merger.java	Sun Dec 23 18:09:57 2007 +0900
+++ b/src/sample/merge/Merger.java	Sun Dec 23 18:17:31 2007 +0900
@@ -1,43 +1,90 @@
 package sample.merge;
 
 import remoteeditor.command.REPCommand;
+import remoteeditor.command.REPCommandEvent;
 import remoteeditor.network.*;
+import remoteeditor.command.*;
 
-public class Merger {
-	private REPPacketReceive receiver;
+public class Merger implements REPCommandListener {
+	//private REPPacketReceive receiver;
 	private REPPacketSend sender;
+	private int eid;
+	private REPCommandListener editor;
 
 //	private RemoteEditor;
 	private Translater translater;
 
-	public Merger(){
-//		translater = new Translater();
+	public Merger(int _eid, REPCommandListener _editor, REPPacketSend _sender){
+		editor = _editor;
+		sender = _sender;
+		eid = _eid;
+		translater = new TranslaterImp1(_eid);
+	}
+
+	public void CommandReceived(REPCommandEvent event){
+		REPCommand cmd = event.getCommand();
+		REPCommand[] cmds;
+
+		if ( checkMergingRequirement(cmd) ) {
+			editor.CommandReceived(new REPCommandEvent(cmd));
+			return ;
+		}
+
+
+		if (cmd.eid==eid){
+			cmds = translater.catchOwnCommand(cmd);
+			for (int i=0; i<cmds.length; i++){
+				editor.CommandReceived(new REPCommandEvent(cmds[i]));
+			}
+		} else {
+			cmds = translater.transReceiveCmd(cmd);
+			for (int i=0; i<cmds.length; i++){
+				editor.CommandReceived(new REPCommandEvent(cmds[i]));
+				sender.send(cmd);
+			}
+		}
+		return ;
 	}
 
+	public void CommandSend(REPCommand cmd){
+		REPCommand[] cmds;
+		cmd.eid = eid;
+		cmds = translater.transSendCmd(cmd);
+
+		for (int i=0; i<cmds.length; i++){
+			sender.send(cmds[i]);
+		}
+	}
+
+	/*   */
+	private boolean checkMergingRequirement(REPCommand cmd){
+		if (cmd.cmd>REP.SMCMD_JOIN) return false;
+		else if (cmd.cmd==REP.REPCMD_INSERT
+				 || cmd.cmd==REP.REPCMD_DELETE
+				 || cmd.cmd==REP.REPCMD_REPLACE )
+			return true;
+		else
+			return false;
+	}
+
+/*
 	public void pushRemoteCmd(REPCommand cmd){
-		cmd = translater.transReceiveCmd(cmd);
+		REPCommand[] cmds;
+		cmds = translater.transReceiveCmd(cmd);
 		if (cmd==null) return;
 		
-		sender.send(cmd);
-		edit(cmd);
+		for (int i=0; i<cmds.length; i++){
+			sender.send(cmds[i]);
+			edit(cmds[i]);
+		}
 	}
 
 	public void pushEditorCmd(REPCommand cmd){
 		cmd = translater.transSendCmd(cmd);
 		sender.send(cmd);
 	}
+*/
 
-	private void edit(REPCommand cmd){
-		if (cmd.cmd==REP.REPCMD_NOP) return;
-		else if (cmd.cmd==REP.REPCMD_INSERT)
-			;
-		else if (cmd.cmd==REP.REPCMD_DELETE)
-			;
-		else if (cmd.cmd==REP.REPCMD_REPLACE)
-			;
-
-//		editor.changeText( , );
-	}
 }
 
 /*