Mercurial > hg > RemoteEditor > REPSessionManager
changeset 280:a549bd4dadb8
*** empty log message ***
author | kono |
---|---|
date | Sat, 27 Sep 2008 15:59:11 +0900 |
parents | e58695b5118d |
children | c3969dd625b2 |
files | rep/Session.java rep/SessionManager.java rep/SessionManagerGUI.java rep/SessionManagerGUIimpl.java test/sematest/TestSessionManager.java test/sematest/testGUI.java |
diffstat | 6 files changed, 68 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/Session.java Sat Sep 27 14:48:02 2008 +0900 +++ b/rep/Session.java Sat Sep 27 15:59:11 2008 +0900 @@ -1,11 +1,8 @@ package rep; -import java.nio.channels.SelectionKey; import java.util.Iterator; import java.util.LinkedList; import java.util.List; - -import rep.channel.REPSelectionKey; import rep.channel.REPSocketChannel; public class Session {
--- a/rep/SessionManager.java Sat Sep 27 14:48:02 2008 +0900 +++ b/rep/SessionManager.java Sat Sep 27 15:59:11 2008 +0900 @@ -43,7 +43,7 @@ public class SessionManager implements SessionManagerEventListener{ private LinkedList<Session> sessionList; - private SessionManagerGUIimpl gui; + private SessionManagerGUI gui; private REPSelector<REPCommand> selector; private SessionManagerList smList; private String myHost; @@ -62,8 +62,16 @@ public void openSelector() throws IOException{ selector = REPSelector.<REPCommand>create(); } - - public void init(int port) throws InterruptedException, IOException { + + public void init(int port, SessionManagerGUI gui) throws IOException, InterruptedException { + this.gui = gui; + openSelector(); + init(port); + mainLoop(); + } + + + private void init(int port) throws InterruptedException, IOException { REPServerSocketChannel<REPCommand> ssc = REPServerSocketChannel.<REPCommand>open(new REPCommandPacker()); ssc.configureBlocking(false); //reuse address 必須 @@ -79,9 +87,9 @@ waitingQueue = new LinkedBlockingQueue<SessionManagerEvent>(); //デフォルトのSessionを作っておく(テスト用に?) - if(sessionList.size() > 0) System.out.println("Error : SessionManager.init():"); - Session defaultSession = new Session(sessionList.size(), "DefaultSession.txt", new Editor(0,null)); - sessionList.add(defaultSession); + //if(sessionList.size() > 0) System.out.println("Error : SessionManager.init():"); + //Session defaultSession = new Session(sessionList.size(), "DefaultSession.txt", new Editor(0,null)); + //sessionList.add(defaultSession); } @@ -405,10 +413,10 @@ //リストのコピーをGUIに渡す LinkedList<Session> sList = new LinkedList<Session>(sessionList); LinkedList<Editor> eList = new LinkedList<Editor>(editorList); - for(Editor editor : eList){ - System.out.println("SessionManager.guiUpdate() : channel = " + editor.getChannel()); - } - +// for(Editor editor : eList){ +// System.out.println("SessionManager.guiUpdate() : channel = " + editor.getChannel()); +// } +// //GUIに反映 Runnable doRun = new DoGUIUpdate(sList, eList, gui); gui.invokeLater(doRun); @@ -487,20 +495,11 @@ temp_port = port; send_port = port_s; SessionManager sm = new SessionManager(port); - sm.openSelector(); - sm.init(port); - sm.startGUI(sm); - sm.mainLoop(); + sm.init(port,new SessionManagerGUIimpl(sm)); + } - public void startGUI(SessionManager sm) { - gui = new SessionManagerGUIimpl(); - Thread th = new Thread( gui ); - th.start(); - gui.addREPActionListener(this); - } - public void connectSession(String host) { int port = DEFAULT_PORT; port = send_port;
--- a/rep/SessionManagerGUI.java Sat Sep 27 14:48:02 2008 +0900 +++ b/rep/SessionManagerGUI.java Sat Sep 27 15:59:11 2008 +0900 @@ -6,7 +6,5 @@ public void update(LinkedList<Session> slist, LinkedList<Editor> elist); - public void addREPActionListener(SessionManager manager); - void invokeLater(Runnable doRun) ; } \ No newline at end of file
--- a/rep/SessionManagerGUIimpl.java Sat Sep 27 14:48:02 2008 +0900 +++ b/rep/SessionManagerGUIimpl.java Sat Sep 27 15:59:11 2008 +0900 @@ -9,13 +9,23 @@ public class SessionManagerGUIimpl implements Runnable, SessionManagerGUI { public static void main(String[] args){ - SessionManagerGUIimpl gui = new SessionManagerGUIimpl(); + SessionManagerGUIimpl gui = new SessionManagerGUIimpl(new SessionManagerEventListener() { + public void buttonPressed(SessionManagerEvent event) { + } + public void closeSession(SessionManagerEvent event) { + } + public void selectSession(SelectButtonEvent selectButtonEvent) { + } + }); Thread th = new Thread( gui ); th.start(); } - public SessionManagerGUIimpl() { + public SessionManagerGUIimpl(SessionManagerEventListener manager) { rp = new RPanel(); + rp.addREPActionListener(manager); + Thread th = new Thread(this); + th.start(); } private RPanel rp; @@ -40,12 +50,6 @@ rp.setTableEditor(elist); } - /* (non-Javadoc) - * @see rep.SessionManagerGUIint#addREPActionListener(rep.SessionManager) - */ - public void addREPActionListener(SessionManager manager) { - rp.addREPActionListener(manager); - } public void invokeLater(Runnable doRun) { SwingUtilities.invokeLater(doRun);
--- a/test/sematest/TestSessionManager.java Sat Sep 27 14:48:02 2008 +0900 +++ b/test/sematest/TestSessionManager.java Sat Sep 27 15:59:11 2008 +0900 @@ -76,8 +76,7 @@ SessionManager sm = new SessionManager(port); sm.openSelector(); - sm.init(port); - sm.startGUI(sm); + sm.init(port,new testGUI(sm)); logger.writeLog("TestSessionManager.startSessionManager() : start SessionManager"); isStart = true; sm.mainLoop();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/sematest/testGUI.java Sat Sep 27 15:59:11 2008 +0900 @@ -0,0 +1,35 @@ +package test.sematest; + +import java.util.LinkedList; + +import rep.Editor; +import rep.Session; +import rep.SessionManagerEventListener; +import rep.SessionManagerGUI; + +/** + * @author kono + * Dummy GUI for test + * + * perform auto select operation + */ + +public class testGUI implements SessionManagerGUI { + public LinkedList<Session> slist; + public LinkedList<Editor> elist; + SessionManagerEventListener manager; + + public testGUI(SessionManagerEventListener manager) { + this.manager = manager; + } + + public void invokeLater(Runnable doRun) { + doRun.run(); + } + + public void update(LinkedList<Session> slist, LinkedList<Editor> elist) { + this.slist = slist; + this.elist = elist; + } + +}