Mercurial > hg > RemoteEditor > REPSessionManager
changeset 8:b774b87cc2c1
*** empty log message ***
author | pin |
---|---|
date | Fri, 19 Oct 2007 15:34:27 +0900 |
parents | 5067a6a93d01 |
children | 2d4c2c19d2d0 |
files | rep/EditorPlus.java rep/REP.java rep/REPActionEvent.java rep/REPActionListener.java rep/REPCommand.java rep/RPanel.java rep/SessionList.java rep/SessionManager.java rep/SessionManagerGUI.java rep/SessionPlus.java |
diffstat | 10 files changed, 210 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/EditorPlus.java Fri Oct 19 15:34:27 2007 +0900 @@ -0,0 +1,23 @@ +package rep; + +import java.nio.channels.SocketChannel; + +public class EditorPlus { + + private int eid; + private SocketChannel channel; + public EditorPlus(int eid, SocketChannel channel) { + this.eid = eid; + this.channel = channel; + } + public String toString(){ + return ("Editor:" + eid); + } + public int getEID(){ + return eid; + } + public SocketChannel getChannel(){ + return channel; + + } +}
--- a/rep/REP.java Fri Oct 19 05:16:38 2007 +0900 +++ b/rep/REP.java Fri Oct 19 15:34:27 2007 +0900 @@ -29,8 +29,8 @@ public static final int SMCMD_QUIT_ACK = 54; public static final int SMCMD_SESSION = 60; public static final int SMCMD_SESSION_ACK = 61; - public static final int SMCMD_SESSION_JOIN = 62; - public static final int SMCMD_SESSION_JOIN_ACK = 63; + public static final int SMCMD_SM_JOIN = 62; + public static final int SMCMD_SM_JOIN_ACK = 63; public static final int SMCMD_UPDATE = 65; public static final int SMCMD_UPDATE_ACK = 66;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/REPActionEvent.java Fri Oct 19 15:34:27 2007 +0900 @@ -0,0 +1,33 @@ +package rep; + +import java.nio.channels.SocketChannel; + +public class REPActionEvent { + + private SocketChannel editorChannel; + private int sid; + private int eid; + + public REPActionEvent(EditorPlus plus, SessionPlus plus2) { + // TODO Auto-generated constructor stub + this.editorChannel = plus.getChannel(); + this.eid = plus.getEID(); + this.sid = plus2.getSID(); + } + + public SocketChannel getEditorChannel() { + // TODO Auto-generated method stub + return editorChannel; + } + + public int getSID() { + // TODO Auto-generated method stub + return sid; + } + + public int getEID() { + // TODO Auto-generated method stub + return eid; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/REPActionListener.java Fri Oct 19 15:34:27 2007 +0900 @@ -0,0 +1,5 @@ +package rep; + +public interface REPActionListener { + public void ActionOccured(REPActionEvent event); +}
--- a/rep/REPCommand.java Fri Oct 19 05:16:38 2007 +0900 +++ b/rep/REPCommand.java Fri Oct 19 15:34:27 2007 +0900 @@ -1,7 +1,7 @@ package rep; public class REPCommand { - public static REPCommand SMCMD_SESSION_JOIN = new REPCommand(REP.SMCMD_SESSION_JOIN, 0, 0, 0, 0, 0, ""); + public static REPCommand SMCMD_SESSION_JOIN = new REPCommand(REP.SMCMD_SM_JOIN, 0, 0, 0, 0, 0, ""); public int cmd; public int sid; public int eid;
--- a/rep/RPanel.java Fri Oct 19 05:16:38 2007 +0900 +++ b/rep/RPanel.java Fri Oct 19 15:34:27 2007 +0900 @@ -6,9 +6,11 @@ import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.nio.channels.SocketChannel; import javax.swing.AbstractButton; import javax.swing.JButton; +import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollBar; @@ -28,6 +30,10 @@ private SessionViewer sessionViewer; private JScrollPane viewerPane; private ConnectionListener listener; + private JComboBox comboEditor; + private JComboBox comboSession; + private JButton buttonSelect; + private REPActionListener actionListener; public RPanel() { button = new JButton("Connect"); @@ -38,6 +44,9 @@ sessionViewer = new SessionViewer(); viewerPane = new JScrollPane(sessionViewer.getTree()); //scrollBar = new JScrollBar(JScrollBar.VERTICAL); + comboEditor = new JComboBox(); + comboSession = new JComboBox(); + buttonSelect = new JButton("Select"); button.setBounds(160, 5, 100, 20); @@ -51,6 +60,9 @@ //scrollPane.setPreferredSize(new Dimension(200, 200)); //textArea.setBounds(5, 30, 200, 200); //textArea.add(scrollBar, BorderLayout.EAST); + comboEditor.setBounds(250, 50, 100, 50); + comboSession.setBounds(250, 100, 100, 50); + buttonSelect.setBounds(250, 180, 100, 20); this.setLayout(null); this.add(textField); @@ -60,8 +72,12 @@ //this.add(scrollPane, BorderLayout.CENTER); this.add(viewerPane, BorderLayout.CENTER); //this.add(label, BorderLayout.CENTER); + this.add(comboEditor); + this.add(comboSession); + this.add(buttonSelect); button.addActionListener(this); + buttonSelect.addActionListener(this); } public void addSessionTree(int SID){ @@ -72,7 +88,9 @@ if (event.getSource() == button) { host = textField.getText(); listener.connectionOccured(new ConnectionEvent(host)); - + }else if(event.getSource() == buttonSelect){ + actionListener.ActionOccured(new REPActionEvent((EditorPlus) comboEditor.getSelectedItem(), + (SessionPlus)comboSession.getSelectedItem())); } } @@ -81,4 +99,17 @@ this.listener = listener; } + public void setComboEditor(int eid, SocketChannel channel) { + //comboEditor.addItem("Editor:"+eid); + comboEditor.addItem(new EditorPlus(eid, channel)); + } + + public void REPActionListener(REPActionListener listener2) { + this.actionListener = listener2; + } + + public void setComboSession(int sessionID, String string) { + comboSession.addItem(new SessionPlus(sessionID, string)); + } + }
--- a/rep/SessionList.java Fri Oct 19 05:16:38 2007 +0900 +++ b/rep/SessionList.java Fri Oct 19 15:34:27 2007 +0900 @@ -94,7 +94,7 @@ } public void sendAddedSession(REPCommand repCmd) { - repCmd.setCMD(REP.SMCMD_SESSION_JOIN); + repCmd.setCMD(REP.SMCMD_SM_JOIN); REPPacketSend repSend = new REPPacketSend(smchannel); //repSend.send(repCmd); } @@ -107,4 +107,36 @@ return "{}"; } + public void sendToNextEditor(SocketChannel channel, REPCommand repCmd) { + Editor editor2 = null; + Editor editor3; + LinkedList <Editor> editorList = session3.get(repCmd.sid).getEditorList(); + for(Editor editor : editorList){ + SocketChannel channel2 = editor.getChannel(); + if(channel.equals(channel2)){ + editor2 = editor; + } + } + int size = editorList.size(); + Editor lastEditor = (Editor) editorList.getLast(); + if(size == 0){ + editor3 = null; + }else if(editor2 == lastEditor){ + editor3 = editorList.get(0); + }else{ + editor3 = editorList.get(editorList.indexOf(editor2)+1); + } + } + + public void addEditor(SocketChannel editorChannel, int sid, int eid) { + + session3.get(sid).addEditor(eid, editorChannel); + } + + public void sendSelect(int sid) { + SocketChannel channel = session3.get(sid).masterEditor.getChannel(); + REPPacketSend send = new REPPacketSend(channel); + send.send(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, 0, "")); + } + }
--- a/rep/SessionManager.java Fri Oct 19 05:16:38 2007 +0900 +++ b/rep/SessionManager.java Fri Oct 19 15:34:27 2007 +0900 @@ -25,7 +25,7 @@ int textsize; // textsize byte[] text;*/ -public class SessionManager implements ConnectionListener{ +public class SessionManager implements ConnectionListener, REPActionListener{ private SessionList sessionlist; @@ -95,49 +95,61 @@ if(repCmd == null) return; switch(repCmd.cmd){ case REP.SMCMD_JOIN: - int eid = sessionlist.getNumberOfEditor(); - repCmd.setEID(eid); - repCmd.setCMD(repCmd.cmd + 1); - repCmd.string = sessionlist.getSessionList(); - REPPacketSend repSend = new REPPacketSend(channel); + int eid = sessionlist.getNumberOfEditor(); //eidを取得 + sessionmanagerGUI.setComboEditor(eid, channel); //ComboBoxにEditorを追加 + repCmd.setEID(eid); //eidを決定して、 + repCmd.setCMD(repCmd.cmd + 1); //ACKを返す + repCmd.string = sessionlist.getSessionList(); //Session一覧を + REPPacketSend repSend = new REPPacketSend(channel); //Editor側へ送信 repSend.send(repCmd); break; case REP.SMCMD_JOIN_ACK: break; case REP.SMCMD_PUT: - int sessionID = sessionlist.addSession(channel, repCmd.string); - smList.update(sessionID, repCmd.string); - repCmd.setSID(sessionID); - repCmd.setCMD(repCmd.cmd + 1); + int sessionID = sessionlist.addSession(channel, repCmd.string); //SIDを取得 + smList.update(sessionID, repCmd.string); //updateコマンド:Session生成を通知 + sessionmanagerGUI.setComboSession(sessionID, repCmd.string); + repCmd.setSID(sessionID); //SIDをセット + repCmd.setCMD(repCmd.cmd + 1); //ACKを返す REPPacketSend repSend2 = new REPPacketSend(channel); repSend2.send(repCmd); - sessionlist.sendAddedSession(repCmd); + //sessionlist.sendAddedSession(repCmd); break; case REP.SMCMD_PUT_ACK: break; case REP.SMCMD_SELECT: - sessionlist.addEditor(channel, repCmd.sid, repCmd); + sessionlist.addEditor(channel, repCmd.sid, repCmd); //sessionlistへ追加 repCmd.setCMD(repCmd.cmd + 1); REPPacketSend repSend3 = new REPPacketSend(channel); - repSend3.send(repCmd); + repSend3.send(repCmd); //ACKを返す + break; + case REP.SMCMD_SELECT_ACK: + break; case REP.SMCMD_SESSION: - repCmd.setCMD(REP.SMCMD_SESSION_ACK); - sessionlist.addSessionManager(channel, repCmd); + //repCmd.setCMD(REP.SMCMD_SESSION_ACK); + //sessionlist.addSessionManager(channel, repCmd); break; - case REP.SMCMD_SESSION_JOIN: - smList.add(channel); - repCmd.setCMD(repCmd.cmd + 1); + case REP.SMCMD_SM_JOIN: + smList.add(channel); //SessionManagerのリストへ追加 + repCmd.setCMD(repCmd.cmd + 1); REPPacketSend repSend4 = new REPPacketSend(channel); - repSend4.send(repCmd); + repSend4.send(repCmd); //ACK + break; + case REP.SMCMD_SM_JOIN_ACK: + smList.add(channel); //SessionManagerのリストへ追加 break; - case REP.SMCMD_SESSION_JOIN_ACK: + case REP.SMCMD_UPDATE: + int sessionID2 = sessionlist.addSession(channel, repCmd.string); + //sessionlist.sendAddedSession(repCmd); + sessionmanagerGUI.setComboSession(sessionID2, repCmd.string); break; case REP.REPCMD_READ: sessionlist.sendCmd(channel, repCmd); break; default: - sessionlist.sendCmd(channel, repCmd); + sessionlist.sendCmd(channel, repCmd, true); + //sessionlist.sendToNextEditor(channel, repCmd); break; } @@ -160,6 +172,7 @@ th.start(); System.out.println(sessionmanagerGUI.toString()); sessionmanagerGUI.addConnectionListener(this); + sessionmanagerGUI.addREPActionListener(this); } private void connectSession(String host) { @@ -187,4 +200,16 @@ public void connectionOccured(ConnectionEvent event) { connectSession(event.getHost()); } + + public void ActionOccured(REPActionEvent event) { + // TODO Auto-generated method stub + System.out.println("Action!"); + SocketChannel editorChannel = event.getEditorChannel(); + int sid = event.getSID(); + int eid = event.getEID(); + sessionlist.addEditor(editorChannel, sid, eid); + REPPacketSend send = new REPPacketSend(editorChannel); + send.send(new REPCommand(REP.SMCMD_SELECT_ACK, sid, eid, 0,0,0,"")); + sessionlist.sendSelect(sid); + } }
--- a/rep/SessionManagerGUI.java Fri Oct 19 05:16:38 2007 +0900 +++ b/rep/SessionManagerGUI.java Fri Oct 19 15:34:27 2007 +0900 @@ -2,6 +2,8 @@ import java.awt.BorderLayout; import java.awt.Container; +import java.nio.channels.SocketChannel; + import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; @@ -47,4 +49,19 @@ System.out.println(""); rp.addConnectionListener(listener); } + + public void setComboEditor(int eid, SocketChannel channel) { + // TODO Auto-generated method stub + rp.setComboEditor(eid, channel); + } + + public void addREPActionListener(REPActionListener listener) { + // TODO Auto-generated method stub + rp.REPActionListener(listener); + } + + public void setComboSession(int sessionID, String string) { + // TODO Auto-generated method stub + rp.setComboSession(sessionID, string); + } } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/SessionPlus.java Fri Oct 19 15:34:27 2007 +0900 @@ -0,0 +1,18 @@ +package rep; + +public class SessionPlus { + + private String string; + private int sid; + public SessionPlus(int sessionID, String string) { + this.string = string; + this.sid = sessionID; + this.string = string; + } + public String toString(){ + return sid + ":" + string; + } + public int getSID(){ + return sid; + } +}