changeset 222:18d6a7140fa3

*** empty log message ***
author pin
date Sun, 31 Aug 2008 12:31:00 +0900
parents 6cd4aab9fea3
children 3680d8357429
files rep/ConnectButtonEvent.java rep/ConnectionEvent.java rep/ConnectionListener.java rep/REPActionEvent.java rep/REPActionListener.java rep/RPanel.java rep/SelectButtonEvent.java rep/SessionManager.java rep/SessionManagerEventListener.java rep/SessionManagerGUI.java test/sematest/PutTester.java
diffstat 11 files changed, 112 insertions(+), 179 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rep/ConnectButtonEvent.java	Sun Aug 31 12:31:00 2008 +0900
@@ -0,0 +1,21 @@
+package rep;
+
+public class ConnectButtonEvent implements SessionManagerEvent{
+
+	private String host;
+	private SessionManager manager;
+
+	public ConnectButtonEvent(SessionManagerEventListener listener, String host) {
+		this.manager = (SessionManager)listener;
+		this.host = host;
+	}
+
+	public String getHost() {
+		return host;
+	}
+
+	public void exec() {
+		manager.connectSession(host);
+	}
+
+}
--- a/rep/ConnectionEvent.java	Sun Aug 31 12:06:07 2008 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-package rep;
-
-public class ConnectionEvent implements SessionManagerEvent{
-
-	private String host;
-	private SessionManager manager;
-
-	public ConnectionEvent(SessionManager manager, String host) {
-		this.manager = manager;
-		this.host = host;
-	}
-
-	public String getHost() {
-		return host;
-	}
-
-	public void exec() {
-		manager.connectSession(host);
-	}
-
-}
--- a/rep/ConnectionListener.java	Sun Aug 31 12:06:07 2008 +0900
+++ b/rep/ConnectionListener.java	Sun Aug 31 12:31:00 2008 +0900
@@ -1,5 +1,5 @@
 package rep;
 
 public interface ConnectionListener {
-	public void connectionOccured(ConnectionEvent event);
+	public void connectionOccured(ConnectButtonEvent event);
 }
--- a/rep/REPActionEvent.java	Sun Aug 31 12:06:07 2008 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-package rep;
-
-import rep.channel.REPSocketChannel;
-
-public class REPActionEvent<P> implements SessionManagerEvent{
-
-	private REPSocketChannel<P> editorChannel;
-	private int sid;
-	private int eid;
-	private SessionManager manager;
-
-	public REPActionEvent(EditorPlus<P> plus, SessionPlus plus2, SessionManager manager) {
-		this.editorChannel = plus.getChannel();
-		this.eid = plus.getEID();
-		this.sid = plus2.getSID();
-		this.manager = manager;
-	}
-
-	public REPSocketChannel<P> getEditorChannel() {
-		return editorChannel;
-	}
-
-	public int getSID() {
-		return sid;
-	}
-
-	public int getEID() {
-		return eid;
-	}
-
-	public void exec() {
-		manager.selectSession(this);
-	}
-
-}
--- a/rep/REPActionListener.java	Sun Aug 31 12:06:07 2008 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,9 +0,0 @@
-package rep;
-
-//implemented class is SessionManager.
-
-public interface REPActionListener<P> {
-	
-	public void selectOccured(REPActionEvent<P> event);
-
-}
--- a/rep/RPanel.java	Sun Aug 31 12:06:07 2008 +0900
+++ b/rep/RPanel.java	Sun Aug 31 12:31:00 2008 +0900
@@ -10,7 +10,6 @@
 import javax.swing.JTable;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
-import javax.swing.SwingUtilities;
 import javax.swing.table.DefaultTableModel;
 
 import rep.channel.REPSocketChannel;
@@ -46,14 +45,9 @@
 	private String s_eid;
 	private String e_eid;
 	private String e_socketchannel;
-	private SessionManager listener;
-	//private JComboBox comboEditor;
-	//private JComboBox comboSession;
 	private JButton buttonSelect;
-	private REPActionListener<REPCommand> actionListener;
-	private List<Session> sessionList;
-	private List<Editor> editorList;
-	private SessionManager manager;
+	//private SessionManager manager;
+	private SessionManagerEventListener listener;
 
 	public RPanel() {
 		button = new JButton("Connect");
@@ -91,48 +85,16 @@
 		buttonSelect.addActionListener(this);
 
 	}
-	
-	public RPanel(SessionManager manager) {
-		this();
-		this.manager = manager;
-		sessionList = manager.getSessionList();
-		editorList = manager.getEditorList();
-	}
 
 	public void actionPerformed(ActionEvent event) {
 		if (event.getSource() == button) {
 			host = textField.getText();
-			listener.connectionOccured(new ConnectionEvent(listener, host));
+			listener.buttonPressed(new ConnectButtonEvent(listener, host));
 		}else if(event.getSource() == buttonSelect){
-			/*
-			actionListener.ActionOccured(new REPActionEvent((EditorPlus) comboEditor.getSelectedItem(),
-					(SessionPlus)comboSession.getSelectedItem()));
-			*/
-			//actionListener.selectOccured(new REPActionEvent<REPCommand>((EditorPlus<REPCommand>) e_list.get(editor_table.getSelectedRow()),
-			//		(SessionPlus)s_list.get(session_table.getSelectedRow()), listener));
-			manager.selectOccured(new REPActionEvent<REPCommand>((EditorPlus<REPCommand>) e_list.get(editor_table.getSelectedRow()),
-					(SessionPlus)s_list.get(session_table.getSelectedRow()), manager));
+			listener.buttonPressed(new SelectButtonEvent<REPCommand>((EditorPlus<REPCommand>) e_list.get(editor_table.getSelectedRow()),
+					(SessionPlus)s_list.get(session_table.getSelectedRow()), listener));
 		}
 	}
-
-	public void addConnectionListener(ConnectionListener listener) {
-		System.out.println(listener.toString());
-		this.listener = (SessionManager) listener;
-	}
-	
-
-	public void setComboEditor(int eid, REPSocketChannel<REPCommand> channel) {
-		//comboEditor.addItem("Editor:"+eid);
-		//comboEditor.addItem(new EditorPlus<REPCommand>(eid, channel));
-	}
-
-	public void addREPActionListener(REPActionListener<REPCommand> listener2) {
-		this.actionListener = listener2;
-	}
-
-	public void setComboSession(int sessionID, String string) {
-		//comboSession.addItem(new SessionPlus(sessionID, string));
-	}
 	
 	public void setTableEditor(int eid, REPSocketChannel<REPCommand> channel) {
 		System.out.println("RPanel.setTableEditor()");
@@ -181,4 +143,8 @@
 		}
 	}
 
+	public void addREPActionListener(SessionManagerEventListener listener) {
+		this.listener = listener;
+	}
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rep/SelectButtonEvent.java	Sun Aug 31 12:31:00 2008 +0900
@@ -0,0 +1,35 @@
+package rep;
+
+import rep.channel.REPSocketChannel;
+
+public class SelectButtonEvent<P> implements SessionManagerEvent{
+
+	private REPSocketChannel<P> editorChannel;
+	private int sid;
+	private int eid;
+	private SessionManager manager;
+
+	public SelectButtonEvent(EditorPlus<P> plus, SessionPlus plus2, SessionManagerEventListener listener) {
+		this.editorChannel = plus.getChannel();
+		this.eid = plus.getEID();
+		this.sid = plus2.getSID();
+		this.manager = (SessionManager)listener;
+	}
+
+	public REPSocketChannel<P> getEditorChannel() {
+		return editorChannel;
+	}
+
+	public int getSID() {
+		return sid;
+	}
+
+	public int getEID() {
+		return eid;
+	}
+
+	public void exec() {
+		manager.selectSession(this);
+	}
+
+}
--- a/rep/SessionManager.java	Sun Aug 31 12:06:07 2008 +0900
+++ b/rep/SessionManager.java	Sun Aug 31 12:31:00 2008 +0900
@@ -4,8 +4,6 @@
 import java.net.InetSocketAddress;
 import java.nio.channels.SelectableChannel;
 import java.nio.channels.SelectionKey;
-import java.nio.channels.Selector;
-
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
@@ -39,7 +37,7 @@
 byte[] text;
 */
 
-public class SessionManager implements ConnectionListener, REPActionListener{
+public class SessionManager implements SessionManagerEventListener{
 	
 	private LinkedList<Session> sessionList;
 	private SessionManagerGUI gui;
@@ -49,7 +47,6 @@
 	private boolean isMaster = true;
 	private List<Editor> editorList;
 	private String maxHost;
-	private boolean isSimulation;
 	private List<PacketSet> waitingCommandInMerge;
 	private BlockingQueue<SessionManagerEvent> waitingQueue;
 	private static int temp_port;
@@ -89,7 +86,8 @@
 				}
 				continue;
 			}
-			System.out.println(selector.select());
+			int i = selector.select();
+			System.out.println(i);
 			select();
 		}
 	}
@@ -470,9 +468,10 @@
 	}
 
 	private void startGUI(SessionManager sm) {
-		gui = new SessionManagerGUI(this);
+		gui = new SessionManagerGUI();
 		Thread th = new Thread( gui ); 
 		th.start();
+		gui.addREPActionListener(this);
 	}
 
 	public void connectSession(String host) {
@@ -522,28 +521,28 @@
 		return host;
 	}
 
-	public void connectionOccured(ConnectionEvent event) {
-		try {
-			waitingQueue.put(event);
-		} catch (InterruptedException e) {
-		}
-		selector.wakeup();
-	}
+//	public void connectionOccured(SessionManagerEvent event) {
+//		try {
+//			waitingQueue.put(event);
+//		} catch (InterruptedException e) {
+//		}
+//		selector.wakeup();
+//	}
+//
+//	public void selectOccured(SessionManagerEvent event) {
+//		try {
+//			waitingQueue.put(event);
+//		} catch (InterruptedException e) {
+//			e.printStackTrace();
+//		}
+//		selector.wakeup();
+//	}
 
-	public void selectOccured(REPActionEvent event) {
-		try {
-			waitingQueue.put(event);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-		selector.wakeup();
-	}
-
-	public void selectSession(REPActionEvent event) {
+	public void selectSession(SelectButtonEvent event) {
 		REPSocketChannel<REPCommand> channel = event.getEditorChannel();
 		int sid = event.getSID();
 		Session session = getSession(sid);
-		selector.wakeup();
+		//selector.wakeup();
 		if(session.hasOwner()){
 			Editor editor = new Editor(channel);
 			session.addEditor(new Editor(channel));
@@ -575,13 +574,19 @@
 	}
 
 	public List<Session> getSessionList() {
-		// TODO Auto-generated method stub
 		return sessionList;
 	}
 
 	public List<Editor> getEditorList() {
-		// TODO Auto-generated method stub
 		return editorList;
 	}
 
+	public void buttonPressed(SessionManagerEvent event) {
+		try {
+			waitingQueue.put(event);
+		} catch (InterruptedException e) {}
+		selector.wakeup();
+
+	}
+
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rep/SessionManagerEventListener.java	Sun Aug 31 12:31:00 2008 +0900
@@ -0,0 +1,9 @@
+package rep;
+
+//implemented class is SessionManager.
+
+public interface SessionManagerEventListener<P> {
+	
+	public void buttonPressed(SessionManagerEvent event);
+
+}
--- a/rep/SessionManagerGUI.java	Sun Aug 31 12:06:07 2008 +0900
+++ b/rep/SessionManagerGUI.java	Sun Aug 31 12:31:00 2008 +0900
@@ -1,40 +1,28 @@
 package rep;
 
 import java.awt.Container;
-import java.awt.event.ComponentListener;
 import java.util.LinkedList;
-
 import javax.swing.JFrame;
-import rep.channel.REPSocketChannel;
 
 
 public class SessionManagerGUI implements Runnable{
 	
-	private SessionManager manager;
-	
 	public static void main(String[] args){
 		SessionManagerGUI gui = new SessionManagerGUI();
 		Thread th = new Thread( gui ); 
 		th.start();
 	}
 
-	public SessionManagerGUI(SessionManager manager) {
-		this.manager = manager;
-		rp = new RPanel(manager);
-	}
-
 	public SessionManagerGUI() {
-		// TODO Auto-generated constructor stub
+		rp = new RPanel();
 	}
 
 	private RPanel rp;
-	//private ConnectionPanel rp;
 	private JFrame frame;
 
 	public void run() {
 		frame = new JFrame("SessionManager");
 		frame.setBounds(100, 100, 600, 300);
-		//rp =  new ConnectionPanel();
 		Container cont = frame.getContentPane();
 		cont.add(rp);
 
@@ -43,38 +31,13 @@
 		
 	}
 
-	public void addConnectionListener(ConnectionListener listener) {
-		//System.out.println(rp.toString());
-		System.out.print("waiting for launching GUI.");
-		while(rp == null){
-			System.out.print(".");
-			try {
-				Thread.sleep(200);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-		}
-		System.out.println("");
-		rp.addConnectionListener(listener);
+	public void update(LinkedList<Session> slist, LinkedList<Editor> elist) {
+		rp.setTableSession(slist);
+		rp.setTableEditor(elist);
 	}
 
-	public void setComboEditor(int eid, REPSocketChannel channel) {
-		rp.setComboEditor(eid, channel);
-		//rp.setTableEditor(eid, channel);
-	}
-
-	public void addREPActionListener(REPActionListener<REPCommand> listener) {
-		rp.addREPActionListener(listener);
-	}
-
-	public void setComboSession(int sessionID, String string) {
-		rp.setComboSession(sessionID, string);
-		//rp.setTableSession(sessionID, string);
-	}
-
-	public void update(LinkedList<Session> list, LinkedList<Editor> list2) {
-		rp.setTableSession(list);
-		rp.setTableEditor(list2);
+	public void addREPActionListener(SessionManager manager) {
+		rp.addREPActionListener(manager);
 	}
 
 }
\ No newline at end of file
--- a/test/sematest/PutTester.java	Sun Aug 31 12:06:07 2008 +0900
+++ b/test/sematest/PutTester.java	Sun Aug 31 12:31:00 2008 +0900
@@ -4,7 +4,6 @@
 
 import rep.REP;
 import rep.REPCommand;
-import rep.channel.REPServerSocketChannel;
 import rep.channel.REPSocketChannel;
 
 public class PutTester extends Tester {