changeset 416:b7f42fc75a36

(no commit message)
author one
date Wed, 31 Dec 2008 14:47:39 +0900
parents 648c676bf9df
children 267f9748e826
files test/editortest/LogTarget.java test/editortest/Logger.java test/editortest/REPSimpleEditor.java test/editortest/REPText.java test/editortest/REPTextImpl.java test/editortest/TestEditor2.java test/editortest/TestSessionManager2.java
diffstat 7 files changed, 107 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/test/editortest/LogTarget.java	Tue Dec 09 16:34:41 2008 +0900
+++ b/test/editortest/LogTarget.java	Wed Dec 31 14:47:39 2008 +0900
@@ -2,6 +2,6 @@
 
 public interface LogTarget {
 
-	void printLog(Object obj);
+	void printLog(String msg);
 
 }
--- a/test/editortest/Logger.java	Tue Dec 09 16:34:41 2008 +0900
+++ b/test/editortest/Logger.java	Wed Dec 31 14:47:39 2008 +0900
@@ -1,1 +1,1 @@
-package test.editortest;

public class Logger {

	public static void print(Object obj){
		StackTraceElement e = new Exception().getStackTrace()[1];
		System.out.println(e.getClassName() + "." + e.getMethodName() + "() : " + obj.toString());
	}

	public static void print() {
		StackTraceElement e = new Exception().getStackTrace()[1];
		System.out.println(e.getClassName() + "." + e.getMethodName() + "()");
	}
	
	
	public static void printT(Object obj){
		System.out.println(Thread.currentThread().toString() + " : " + obj);
	}
	
	
	public static void print(LogTarget target, Object obj){
		target.printLog(obj);
	}
}
\ No newline at end of file
+package test.editortest;

public class Logger {

	public static void print(Object obj){
		StackTraceElement e = new Exception().getStackTrace()[1];
		System.out.println(e.getClassName() + "." + e.getMethodName() + "() : " + obj.toString());
	}

	public static void print() {
		StackTraceElement e = new Exception().getStackTrace()[1];
		System.out.println(e.getClassName() + "." + e.getMethodName() + "()");
	}
	
	
	public static void printT(Object obj){
		System.out.println(Thread.currentThread().toString() + " : " + obj);
	}
	
	
	public static void print(LogTarget target, Object obj){
		StackTraceElement e = new Exception().getStackTrace()[1];
		String msg = e.getClassName() + "." + e.getMethodName() + "() : " + obj.toString();
		if(target != null){
			target.printLog(msg);
		}
	}
}
\ No newline at end of file
--- a/test/editortest/REPSimpleEditor.java	Tue Dec 09 16:34:41 2008 +0900
+++ b/test/editortest/REPSimpleEditor.java	Wed Dec 31 14:47:39 2008 +0900
@@ -5,12 +5,16 @@
 import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.io.IOException;
+import java.net.InetSocketAddress;
 
 import javax.swing.JButton;
 import javax.swing.JFrame;
+import javax.swing.JLabel;
 import javax.swing.JScrollPane;
 import javax.swing.JSplitPane;
 import javax.swing.JTextArea;
+import javax.swing.JTextField;
 import javax.swing.JToolBar;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
@@ -19,6 +23,8 @@
 
 import rep.REP;
 import rep.REPCommand;
+import rep.REPCommandPacker;
+import rep.channel.REPSocketChannel;
 import test.Text;
 
 public class REPSimpleEditor extends JFrame implements DocumentListener, ActionListener, LogTarget{
@@ -41,11 +47,14 @@
 	private JScrollPane scrollPane1;
 	private JTextArea console;
 	private JScrollPane scrollPane2;
+	private JTextField lineField;
+	private JTextField textField;
+	private REPSocketChannel<REPCommand> channel;
 
 	public REPSimpleEditor(String title){
 		super(title);
 		setSize(new Dimension(640, 480));
-		this.setLayout(new BorderLayout());
+		setLayout(new BorderLayout());
 		
 		setToolBar();
 		setEditor();
@@ -62,16 +71,30 @@
 		putButton = new JButton("put");
 		joinButton = new JButton("join");
 		
-		//putButton.addActionListener(this);
-		//joinButton.addActionListener(this);
+		putButton.addActionListener(this);
+		joinButton.addActionListener(this);
+		
+		JLabel label1 = new JLabel("line");
+		JLabel label2 = new JLabel("text");
+		lineField = new JTextField();
+		textField = new JTextField();
+		
+		textField.addActionListener(this);
 		
 		toolbar.add(putButton);
 		toolbar.add(joinButton);
+		toolbar.addSeparator();
+		toolbar.add(label1);
+		toolbar.add(lineField);
+		toolbar.add(label2);
+		toolbar.add(textField);
+		
 		add(toolbar, BorderLayout.NORTH);
 	}
 
 	private void setEditor(){
 		textArea = new JTextArea();
+		textArea.setEditable(false);
 		textArea.setFont(new Font("Monaco", Font.PLAIN, textArea.getFont().getSize()));
 		document = textArea.getDocument();
 		document.addDocumentListener(this);
@@ -97,6 +120,11 @@
 		add(splitPane, BorderLayout.CENTER);
 	}
 
+	public void setButtonEnabled(boolean b) {
+		putButton.setEnabled(b);
+		joinButton.setEnabled(b);
+	}
+
 	private REPCommand createREPCommand(int offset, int length) {
 		REPCommand command = null;
 		try {
@@ -108,7 +136,6 @@
 		} catch (BadLocationException e1) {
 			e1.printStackTrace();
 		}
-		//Logger.printT(command);
 		return command;
 	}
 
@@ -131,23 +158,28 @@
 			repPut();
 		}else if(e.getSource() == joinButton){
 			repJoin();
+		}else if(e.getSource() == textField){
+			testEditor.addUserInput(new REPCommand(REP.REPCMD_INSERT_USER, 0, 0, 0, 0, textField.getText()));
+			lineField.setText("");
+			textField.setText("");
 		}
 	}
 
 	private void repJoin() {
-		testEditor = new TestEditor2("TestEditor", "localhost", 8766, false);
-		testEditor.setREPText(repText);
-		testEditor.setLogTarget(this);
-		testEditor.start();
+//		testEditor = new TestEditor2("TestEditor", "localhost", 8766, false);
+//		testEditor.setREPText(repText);
+//		testEditor.setLogTarget(this);
+//		testEditor.start();
 	}
 
 	private void repPut() {
 		setMasterText();
-		testEditor = new TestEditor2("TestEditor", "localhost", 8766, true);
-		testEditor.setText(repText.list());
-		testEditor.setREPText(repText);
-		testEditor.setLogTarget(this);
-		testEditor.start();
+		connectToSessionManager();
+//		testEditor = new TestEditor2("TestEditor", "localhost", 8766, true);
+//		testEditor.setText(repText.list());
+//		testEditor.setREPText(repText);
+//		testEditor.setLogTarget(this);
+//		testEditor.start();
 	}
 
 	private void setMasterText() {
@@ -157,9 +189,25 @@
 		textArea.append("DDDDD" + BR);
 	}
 
-	public void printLog(Object obj) {
-		String log = obj.toString();
-		console.append(log + BR);
+	private void connectToSessionManager() {
+		InetSocketAddress semaIP = new InetSocketAddress("localhost", 8766);
+		try {
+			channel = REPSocketChannel.<REPCommand>create(new REPCommandPacker());
+		} catch (IOException e) {
+			e.printStackTrace(); return;
+		}
+		try {
+			while (!channel.connect(semaIP)){
+				Logger.print("SeMa not listen to socket yet, wait");
+			}
+		} catch (IOException e) {
+			e.printStackTrace(); return;
+		}
+		
+	}
+
+	public void printLog(String msg) {
+		console.append(msg + BR);
 	}
 
 	public REPText getREPText() {
@@ -172,4 +220,8 @@
 		}
 	}
 
+	public void setTestEditor(TestEditor2 testEditor2) {
+		testEditor = testEditor2;
+	}
+
 }
--- a/test/editortest/REPText.java	Tue Dec 09 16:34:41 2008 +0900
+++ b/test/editortest/REPText.java	Wed Dec 31 14:47:39 2008 +0900
@@ -6,8 +6,14 @@
 	
 	public void insert(int lineno, String text);
 	
-	public String delete(int lineno, String text);
+	public String delete(int lineno);
+	
+	public List<String> list();
+	
+	public void addTextListener(REPTextListener listener);
 
-	public List<String> list();
+	public int size();
+
+	public String get(int i);
 
 }
--- a/test/editortest/REPTextImpl.java	Tue Dec 09 16:34:41 2008 +0900
+++ b/test/editortest/REPTextImpl.java	Wed Dec 31 14:47:39 2008 +0900
@@ -18,7 +18,7 @@
 		this.textArea = area;
 	}
 
-	public String delete(int lineno, String text) {
+	public String delete(int lineno) {
 		increaseLine(lineno);
 		
 		String deleted = "";
@@ -64,7 +64,7 @@
 		if(command.cmd == REP.REPCMD_INSERT){
 			insert(lineno, text);
 		}else if(command.cmd == REP.REPCMD_DELETE){
-			delete(lineno, text);
+			delete(lineno);
 		}else{
 			Logger.print(command);
 		}
@@ -86,4 +86,19 @@
 		return list;
 	}
 
+	public void addTextListener(REPTextListener listener) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public String get(int i) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public int size() {
+		// TODO Auto-generated method stub
+		return 0;
+	}
+
 }
--- a/test/editortest/TestEditor2.java	Tue Dec 09 16:34:41 2008 +0900
+++ b/test/editortest/TestEditor2.java	Wed Dec 31 14:47:39 2008 +0900
@@ -77,8 +77,9 @@
 		}
 		
 		simpleEditor = new REPSimpleEditor();
-		simpleEditor.setDefaultCloseOperation(REPSimpleEditor.EXIT_ON_CLOSE);
 		simpleEditor.setVisible(true);
+		simpleEditor.setButtonEnabled(false);
+		simpleEditor.setTestEditor(this);
 		simpleEditor.setText(text);
 		repText = simpleEditor.getREPText();
 		logTarget = simpleEditor;
@@ -189,7 +190,7 @@
 				break;
 			case REPCMD_DELETE_USER:
 				String del = text.delete(cmd.lineno);
-				del = repText.delete(cmd.lineno, cmd.string);
+				del = repText.delete(cmd.lineno);
 				cmd.setString(del);
 				sendCommand(cmd);
 				break;
@@ -242,7 +243,7 @@
 	private void forwardCommand(REPCommand cmd1) {
 		REPCommand cmd = new REPCommand(cmd1);
 		ns.writeLog(name +" forward "+cmd);
-		Logger.print(logTarget, "write : " + cmd);
+		//Logger.print(logTarget, "write : " + cmd);
 		channel.write(cmd);
 	}
 
@@ -263,7 +264,7 @@
 				String del=""; 
 				if(cmd.lineno<text.size()) {
 					del = text.delete(cmd.lineno);
-					del = repText.delete(cmd.lineno, cmd.string);
+					del = repText.delete(cmd.lineno);
 				}
 				cmd.setString(del);
 			}
@@ -357,4 +358,9 @@
 	public void setREPText(REPText repText) {
 		this.repText = repText;
 	}
+
+	public void addUserInput(REPCommand command) {
+		cmds.add(command);
+		if(selector!=null) selector.wakeup();
+	}
 }
--- a/test/editortest/TestSessionManager2.java	Tue Dec 09 16:34:41 2008 +0900
+++ b/test/editortest/TestSessionManager2.java	Wed Dec 31 14:47:39 2008 +0900
@@ -7,6 +7,7 @@
 import rep.channel.REPServerSocketChannel;
 import rep.gui.SessionManagerEvent;
 import rep.gui.SessionManagerGUI;
+import rep.handler.Editor;
 import test.sematest.TestGUI;
 
 
@@ -116,7 +117,7 @@
 		 *    isSimulation=false    socket based communication mode
 		 */
 		REPServerSocketChannel.isSimulation = false;
-		//Editor.noMergeMode = true;
+		Editor.noMergeMode = false;
 		// At least 3 TestEditors are required.
 		TestSessionManager2 test = new TestSessionManager2(1, 0, 3);
 		logger.setLogLevel(5);