Mercurial > hg > RemoteEditor > REPSessionManager
changeset 320:83790b8b8174
*** empty log message ***
author | kono |
---|---|
date | Fri, 10 Oct 2008 14:10:15 +0900 |
parents | dfed28488274 |
children | d46f1e255919 |
files | rep/RPanel.java rep/SelectButtonEvent.java rep/Session.java rep/SessionList.java rep/SessionManager.java rep/SessionManagerGUIimpl.java rep/gui/ConnectionPanel.java rep/gui/DefaultTableModelTest.java rep/gui/JTableTest.java rep/gui/RPanel.java test/ConnectionPanel.java test/DefaultTableModelTest.java test/JTableTest.java test/TestGUI.java test/sematest/TestGUI.java |
diffstat | 15 files changed, 281 insertions(+), 353 deletions(-) [+] |
line wrap: on
line diff
--- a/rep/RPanel.java Thu Oct 09 17:26:55 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,185 +0,0 @@ -package rep; - -import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; - -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTable; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.table.DefaultTableModel; - -import rep.channel.REPSocketChannel; - -import java.util.*; - -public class RPanel extends JPanel implements ActionListener, MouseListener { - - /** - * - */ - private static final long serialVersionUID = 1L; - private JButton connectButton; - private JTextField textField; - private String host; - private JLabel label; - private JTextArea textArea; - //private JScrollPane viewerPane; - private JTable session_table; - private JScrollPane s_sp; - private JTable editor_table; - private JScrollPane e_sp; - private String[] session_column = {"HOST", "PORT", "FILE", "SID", "EID"}; - private String[] editor_column = {"EID", "SOCKET_CHANNEL"}; - private DefaultTableModel s_tableModel = new DefaultTableModel(session_column, 0); - private DefaultTableModel e_tableModel = new DefaultTableModel(editor_column, 0); - //LinkedList<SessionPlus> s_list = new LinkedList<SessionPlus>(); - LinkedList<EditorPlus> e_list = new LinkedList<EditorPlus>(); - private String s_host; - private String s_port; - private String s_file; - private String s_sid; - private String s_eid; - private String e_eid; - private String e_socketchannel; - private JButton selectButton; - private JButton closeButton; - private SessionManagerEventListener listener; - private LinkedList<Editor> editorList; - private LinkedList<Session> sessionList; - - public RPanel() { - connectButton = new JButton("Connect"); - textField = new JTextField("firefly.cr.ie.u-ryukyu.ac.jp"); - textArea = new JTextArea(); - label = new JLabel("test"); - session_table = new JTable(s_tableModel); - s_sp = new JScrollPane(session_table); - editor_table = new JTable(e_tableModel); - e_sp = new JScrollPane(editor_table); - selectButton = new JButton("Select Session"); - closeButton = new JButton("Close Session"); - - - connectButton.setBounds(160, 5, 100, 20); - textField.setBounds(5, 5, 150, 20); - textArea.setEditable(false); - textArea.setLineWrap(false); - session_table.setBounds(5,30,400,200); - s_sp.setPreferredSize(new Dimension(200, 200)); - s_sp.setBounds(5,30,400,100); - e_sp.setPreferredSize(new Dimension(200, 200)); - e_sp.setBounds(5,140,400,100); - selectButton.setBounds(430, 215, 130, 20); - closeButton.setBounds(430, 105, 130, 20); - - - this.setLayout(null); - this.add(textField); - this.add(connectButton); - this.add(label); - this.add(s_sp); - this.add(e_sp); - this.add(selectButton); - this.add(closeButton); - - connectButton.addActionListener(this); - selectButton.addActionListener(this); - closeButton.addActionListener(this); - editor_table.addMouseListener(this); - - } - - public void actionPerformed(ActionEvent event) { - if (event.getSource() == connectButton) { - host = textField.getText(); - listener.buttonPressed(new ConnectButtonEvent(listener, host)); - - }else if(event.getSource() == selectButton){ - //System.out.println("RPanel.actionPerformed() : editorSelectedRow = " + editor_table.getSelectedRow()); - listener.buttonPressed( - new SelectButtonEvent(editorList.get(editor_table.getSelectedRow()), - sessionList.get(session_table.getSelectedRow()), listener)); - }else if(event.getSource() == closeButton){ - listener.buttonPressed(new CloseButtonEvent(sessionList.get(session_table.getSelectedRow()), listener)); - } - } - - public void setTableEditor(int eid, REPSocketChannel<REPCommand> channel) { - //System.out.println("RPanel.setTableEditor() : channel = " + channel); - Vector<String> editor = new Vector<String>(); - e_eid = "Editor : " + eid; - e_socketchannel = "SocketChannel : " + channel; - editor.add(e_eid); - editor.add(e_socketchannel); - e_tableModel.addRow(editor); - } - - public void setTableSession(int sessionID, String string) { - //SessionPlus sp = new SessionPlus(sessionID, string); - //s_list.add(sp); - Vector<String> session = new Vector<String>(); - s_host = " "; - s_port = " "; - s_file = "" + string; - s_sid = "" + sessionID; - s_eid = " "; - session.add(s_host); - session.add(s_port); - session.add(s_file); - session.add(s_sid); - session.add(s_eid); - s_tableModel.addRow(session); - } - - public static void main(String[] args){ - new RPanel(); - } - - protected void setTableSession(LinkedList<Session> list) { - s_tableModel.setRowCount(0); - sessionList = list; - for(Session session : list){ - setTableSession(session.getSID(), session.getName()); - } - } - - protected void setTableEditor(LinkedList<Editor> list) { - e_tableModel.setRowCount(0); - editorList = list; - for(Forwarder editor : list){ - setTableEditor(editor.getEID(), editor.getChannel()); - } - } - - public void addREPActionListener(SessionManagerEventListener listener) { - this.listener = listener; - } - - public void mouseClicked(MouseEvent e) { - //System.out.println("RPanel.mouseClicked() : editorChannel = " + editorList.get(editor_table.getSelectedRow()).getChannel()); - } - - public void mouseEntered(MouseEvent e) { - - } - - public void mouseExited(MouseEvent e) { - - } - - public void mousePressed(MouseEvent e) { - - } - - public void mouseReleased(MouseEvent e) { - - } - -}
--- a/rep/SelectButtonEvent.java Thu Oct 09 17:26:55 2008 +0900 +++ b/rep/SelectButtonEvent.java Fri Oct 10 14:10:15 2008 +0900 @@ -2,32 +2,24 @@ import java.io.IOException; -import rep.channel.REPSocketChannel; - public class SelectButtonEvent implements SessionManagerEvent{ - private REPSocketChannel<REPCommand> editorChannel; private int sid; - private int eid; + private Forwarder editor; private SessionManager manager; public SelectButtonEvent(Forwarder editor, Session session, SessionManagerEventListener listener) { - this.editorChannel = editor.getChannel(); - this.eid = editor.getEID(); + this.editor = editor; this.sid = session.getSID(); this.manager = (SessionManager)listener; } - public REPSocketChannel<REPCommand> getEditorChannel() { - return editorChannel; - } - public int getSID() { return sid; } - public int getEID() { - return eid; + public Forwarder getEditor() { + return editor; } public void exec() {
--- a/rep/Session.java Thu Oct 09 17:26:55 2008 +0900 +++ b/rep/Session.java Fri Oct 10 14:10:15 2008 +0900 @@ -17,26 +17,24 @@ this(sid, editor); sessionName = name; } + public Session(Editor editor) { - masterEditor = editor; - this.sessionID = 0; - this.sessionName = editor.getName(); - if(editor.channel!=null) firstForwarder = editor; + this(0,editor.getName(),editor); } public Session(int sid, Forwarder editor) { sessionID = sid; - masterEditor = editor; - editorList.add(editor); - if(editor.channel!=null) firstForwarder = editor; - } - - public void addEditor(SessionManager manager,int editorID, REPSocketChannel<REPCommand> channel) { - Editor editor =new Editor(manager,editorID, channel); - addForwarder(editor); + if (editor!=null) { + // we have a master + masterEditor = editor; + editor.setSID(sid); + editorList.add(editor); + if(editor.channel!=null) firstForwarder = editor; + } } public void addForwarder(Forwarder forwarder) { + // add a forwarder and connect this to the session Forwarder last = (Forwarder)editorList.getLast(); forwarder.setNext(last.getNextForwarder()); last.setNext(forwarder); @@ -44,6 +42,12 @@ if(firstForwarder==null) firstForwarder = forwarder; } + public void addEditor(Editor editor) { + // add a not-connected editor in a sassion + // the editor is outside of this manager + editorList.add(editor); + } + public LinkedList<EditorPlus> getEditorList() { return editorList; } @@ -107,7 +111,7 @@ } public void hasOwner(boolean b) { - isOwner = true; + isOwner = b; } public Editor getEditor(REPSocketChannel<REPCommand> channel) { @@ -142,7 +146,5 @@ return firstForwarder; } - public void addEditor(Editor editor) { - editorList.add(editor); - } + }
--- a/rep/SessionList.java Thu Oct 09 17:26:55 2008 +0900 +++ b/rep/SessionList.java Fri Oct 10 14:10:15 2008 +0900 @@ -1,6 +1,5 @@ package rep; -import java.nio.channels.SocketChannel; import java.util.LinkedList; import rep.channel.REPSocketChannel; @@ -14,25 +13,6 @@ private int editorCount = 0; private String maxHost; - public SessionList(){ - makeDefaultSession(); - } - - public void add(REPSocketChannel<REPCommand> channel) { - - } - - public void makeDefaultSession(){ - } - - public int getEditorNumber() { - return 0; - - } - - public void add(REPSocketChannel<REPCommand> channel, int sid) { - - } public int addSession(REPSocketChannel<REPCommand> channel, String string) { sessionID++; @@ -40,21 +20,11 @@ } - public void addEditor(SessionManager manager,REPSocketChannel<REPCommand> channel, int sid, REPCommand repCmd) { - int editorID = repCmd.eid; - sessionLinkedList.get(sid-1).addEditor(manager,editorID, channel); //本当はforループで検索しないといけないよ。 - } - public int getNumberOfEditor() { editorCount++; return editorCount; } - - public void addSessionManager(SocketChannel channel, REPCommand repCmd) { - - } - public String getSessionList() { if (sessionLinkedList != null) { System.out.println(sessionLinkedList.toString()); @@ -63,11 +33,6 @@ return "{}"; } - - public void addEditor(SessionManager manager,REPSocketChannel<REPCommand> editorChannel, int sid, int eid) { - sessionLinkedList.get(sid-1).addEditor(manager,eid, editorChannel); - } - public void sendSelect(int sid) { REPSocketChannel<REPCommand> channel = sessionLinkedList.get(sid-1).getOwner().getChannel(); channel.write(new REPCommand(REP.SMCMD_SELECT, sid, 0, 0, 0, "")); @@ -156,10 +121,6 @@ return sessionID; } - public void addToRoutingTable(SocketChannel channel) { - - } - public Session getSession(int sid) { for(Session session : sessionLinkedList){ if(session.getSID() == sid){ @@ -181,12 +142,4 @@ sessionLinkedList = list; } - public void update(REPSocketChannel<REPCommand> channel, SessionList receivedSessionList) { - LinkedList<Session> list = receivedSessionList.getList(); - int i = 0; - for(Session session : list){ - session.getEditorList().get(0).setChannel(channel); - ++i; - } - } }
--- a/rep/SessionManager.java Thu Oct 09 17:26:55 2008 +0900 +++ b/rep/SessionManager.java Fri Oct 10 14:10:15 2008 +0900 @@ -221,7 +221,7 @@ //エディタとchannelは1対1 (ではない) //エディタが新しくputする場合は新しくソケットを作る // ここのeditorList はsessionのとは別物 - Editor editor1 = new Editor(this,editorList.size(),channel); + Editor editor1 = new Editor(this,-1,channel); editor1.setHost(myHost); editorList.add(editor1); @@ -238,6 +238,7 @@ case SMCMD_PUT: { //Sessionを生成 + // sessionIDってglobaly uniqueじゃないの? int sid = sessionList.size(); Editor editor2 = new Editor(this,0, channel); editorList.add(editor2); @@ -388,33 +389,23 @@ //他のSessionManagerへ中継する smList.sendExcept(channel, receivedCommand); - //リストのコピーをGUIに渡す - LinkedList<Session> sList = new LinkedList<Session>(sessionList); - LinkedList<Editor> eList = new LinkedList<Editor>(editorList); - //GUIに反映 - Runnable doRun = new DoGUIUpdate(sList, eList, gui); - gui.invokeLater(doRun); + updateGUI(); } break; case SMCMD_UPDATE_ACK: { + assert false; if(!hasSession(receivedCommand.sid)) { // accept new Session - Forwarder editor = new Forwarder(this); - editor.setChannel(channel); - - Session session = new Session(receivedCommand.sid,receivedCommand.string,editor); - session.addEditor(this, session.newEid(), channel); + Forwarder sm = new Forwarder(this); + sm.setChannel(channel); + Session session = new Session(receivedCommand.sid,receivedCommand.string,null); + session.addForwarder(sm); sessionList.add(session); - //リストのコピーをGUIに渡す - LinkedList<Session> sList = new LinkedList<Session>(sessionList); - LinkedList<Editor> eList = new LinkedList<Editor>(editorList); - //GUIに反映 - Runnable doRun = new DoGUIUpdate(sList, eList, gui); - gui.invokeLater(doRun); + updateGUI(); } smList.sendToSlave(receivedCommand); } @@ -451,6 +442,7 @@ return true; } + private boolean hasSession(int sid) { for(Session s:sessionList) { if (s.getSID()==sid) return true; @@ -555,21 +547,19 @@ } public void selectSession(SelectButtonEvent event) throws IOException { - REPSocketChannel<REPCommand> channel = event.getEditorChannel(); int sid = event.getSID(); - int eid = event.getEID(); Session session = getSession(sid); - Editor editor = editorList.get(eid); + Editor editor = (Editor)event.getEditor(); if(editor == null){ System.out.println("SessionManager.selectSession():editor = " + editor); return; } - + REPSocketChannel<REPCommand> channel = editor.getChannel(); - System.out.println("SessionManager.session.hasOnwer="+session.hasOwner()); if(session.hasOwner()){ + editor.setEID(session.newEid()); session.addForwarder(editor); REPCommand sendCommand = new REPCommand(); sendCommand.setCMD(REP.SMCMD_JOIN_ACK); @@ -579,10 +569,9 @@ channel.write(sendCommand); }else { sid = event.getSID(); - editor = new Editor(this,0,channel); editor.setHost(myHost); session = getSession(sid); - session.addEditor(this,0,channel); + session.addEditor(editor); Forwarder owner = session.getOwner(); REPCommand command = new REPCommand();
--- a/rep/SessionManagerGUIimpl.java Thu Oct 09 17:26:55 2008 +0900 +++ b/rep/SessionManagerGUIimpl.java Fri Oct 10 14:10:15 2008 +0900 @@ -5,6 +5,8 @@ import javax.swing.JFrame; import javax.swing.SwingUtilities; +import rep.gui.RPanel; + public class SessionManagerGUIimpl implements Runnable, SessionManagerGUI {
--- a/rep/gui/ConnectionPanel.java Thu Oct 09 17:26:55 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,60 +0,0 @@ -package rep.gui; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.JButton; -import javax.swing.JPanel; -import javax.swing.JTextField; - -import rep.ConnectionListener; - -public class ConnectionPanel extends JPanel implements ActionListener{ - - /** - * - */ - private static final long serialVersionUID = 1L; - private JButton button; - private JTextField textField; - public String host; - - public ConnectionPanel(ConnectionListener connectionlistener){ - button = new JButton("Connect"); - textField = new JTextField("localhost"); - - button.setBounds(160, 5, 100, 20); - textField.setBounds(5, 5, 150, 20); - - this.setLayout(null); - this.add(textField); - this.add( button); - - button.addActionListener(this); - } - - - public ConnectionPanel() { - button = new JButton("Connect"); - textField = new JTextField("localhost"); - - button.setBounds(160, 5, 100, 20); - textField.setBounds(5, 5, 150, 20); - - this.setLayout(null); - this.add(textField); - this.add( button); - - button.addActionListener(this); - } - - - public void actionPerformed(ActionEvent event) { - // TODO Auto-generated method stub - if (event.getSource() == button) { - host = textField.getText(); - System.out.println("pressed!"); - } - } - -}
--- a/rep/gui/DefaultTableModelTest.java Thu Oct 09 17:26:55 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -package rep.gui; import java.awt.*; import javax.swing.*; import javax.swing.table.*; class DefaultTableModelTest extends JFrame { /** * */ private static final long serialVersionUID = 1L; DefaultTableModelTest() { getContentPane().setLayout(new FlowLayout()); String[][] rowData = { { "A1", "B1", "C1" }, { "A2", "B2", "C2" }, { "A3", "B3", "C3" }, { "A4", "B4", "C4" }, }; String[] colNames = { "A", "B", "C" }; DefaultTableModel tm = new DefaultTableModel(rowData, colNames); JTable tb = new JTable(tm); JScrollPane sp = new JScrollPane(tb); sp.setPreferredSize(new Dimension(230, 80)); getContentPane().add(sp); String[] data = { "A5", "B5", "C5" }; tm.addRow(data); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("DefaultTableModelTest"); setSize(250, 120); setVisible(true); } public static void main(String[] args) { new DefaultTableModelTest(); } } \ No newline at end of file
--- a/rep/gui/JTableTest.java Thu Oct 09 17:26:55 2008 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -package rep.gui; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; class JTableTest extends JFrame implements ActionListener, FocusListener, ListSelectionListener{ /** * */ private static final long serialVersionUID = 1L; private JTable tb; JTableTest() { getContentPane().setLayout(new FlowLayout()); tb = new JTable(10, 5); tb.setValueAt("AAA", 0, 0); tb.setValueAt("BBB", 1, 1); tb.setValueAt("CCC", 2, 2); tb.addFocusListener(this); JScrollPane sp = new JScrollPane(tb); sp.setPreferredSize(new Dimension(230, 80)); getContentPane().add(sp); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("JTableTest"); setSize(250, 120); setVisible(true); } public static void main(String[] args) { new JTableTest(); } public void actionPerformed(ActionEvent event) { //if(event.getSource() == tb){ // int a = tb.getSelectedColumn(); // int b = tb.getSelectedRow(); // System.out.println("Selected item is " + a + ":" + b); //} } public void focusGained(FocusEvent event) { int column = tb.getSelectedColumn(); int row = tb.getSelectedRow(); System.out.println("Gained item is " + column + ":" + row); } public void focusLost(FocusEvent event) { } public void valueChanged(ListSelectionEvent event) { int column = tb.getSelectedColumn(); int row = tb.getSelectedRow(); Object value = tb.getValueAt(row, column); System.out.println("Gained item is " + column + ":" + row + "," + value); } } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rep/gui/RPanel.java Fri Oct 10 14:10:15 2008 +0900 @@ -0,0 +1,194 @@ +package rep.gui; + +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.table.DefaultTableModel; + +import rep.CloseButtonEvent; +import rep.ConnectButtonEvent; +import rep.Editor; +import rep.EditorPlus; +import rep.Forwarder; +import rep.REPCommand; +import rep.SelectButtonEvent; +import rep.Session; +import rep.SessionManagerEventListener; +import rep.channel.REPSocketChannel; + +import java.util.*; + +public class RPanel extends JPanel implements ActionListener, MouseListener { + + /** + * + */ + private static final long serialVersionUID = 1L; + private JButton connectButton; + private JTextField textField; + private String host; + private JLabel label; + private JTextArea textArea; + //private JScrollPane viewerPane; + private JTable session_table; + private JScrollPane s_sp; + private JTable editor_table; + private JScrollPane e_sp; + private String[] session_column = {"HOST", "PORT", "FILE", "SID", "EID"}; + private String[] editor_column = {"EID", "SOCKET_CHANNEL"}; + private DefaultTableModel s_tableModel = new DefaultTableModel(session_column, 0); + private DefaultTableModel e_tableModel = new DefaultTableModel(editor_column, 0); + //LinkedList<SessionPlus> s_list = new LinkedList<SessionPlus>(); + LinkedList<EditorPlus> e_list = new LinkedList<EditorPlus>(); + private String s_host; + private String s_port; + private String s_file; + private String s_sid; + private String s_eid; + private String e_eid; + private String e_socketchannel; + private JButton selectButton; + private JButton closeButton; + private SessionManagerEventListener listener; + private LinkedList<Editor> editorList; + private LinkedList<Session> sessionList; + + public RPanel() { + connectButton = new JButton("Connect"); + textField = new JTextField("firefly.cr.ie.u-ryukyu.ac.jp"); + textArea = new JTextArea(); + label = new JLabel("test"); + session_table = new JTable(s_tableModel); + s_sp = new JScrollPane(session_table); + editor_table = new JTable(e_tableModel); + e_sp = new JScrollPane(editor_table); + selectButton = new JButton("Select Session"); + closeButton = new JButton("Close Session"); + + + connectButton.setBounds(160, 5, 100, 20); + textField.setBounds(5, 5, 150, 20); + textArea.setEditable(false); + textArea.setLineWrap(false); + session_table.setBounds(5,30,400,200); + s_sp.setPreferredSize(new Dimension(200, 200)); + s_sp.setBounds(5,30,400,100); + e_sp.setPreferredSize(new Dimension(200, 200)); + e_sp.setBounds(5,140,400,100); + selectButton.setBounds(430, 215, 130, 20); + closeButton.setBounds(430, 105, 130, 20); + + + this.setLayout(null); + this.add(textField); + this.add(connectButton); + this.add(label); + this.add(s_sp); + this.add(e_sp); + this.add(selectButton); + this.add(closeButton); + + connectButton.addActionListener(this); + selectButton.addActionListener(this); + closeButton.addActionListener(this); + editor_table.addMouseListener(this); + + } + + public void actionPerformed(ActionEvent event) { + if (event.getSource() == connectButton) { + host = textField.getText(); + listener.buttonPressed(new ConnectButtonEvent(listener, host)); + + }else if(event.getSource() == selectButton){ + //System.out.println("RPanel.actionPerformed() : editorSelectedRow = " + editor_table.getSelectedRow()); + listener.buttonPressed( + new SelectButtonEvent(editorList.get(editor_table.getSelectedRow()), + sessionList.get(session_table.getSelectedRow()), listener)); + }else if(event.getSource() == closeButton){ + listener.buttonPressed(new CloseButtonEvent(sessionList.get(session_table.getSelectedRow()), listener)); + } + } + + public void setTableEditor(int eid, REPSocketChannel<REPCommand> channel) { + //System.out.println("RPanel.setTableEditor() : channel = " + channel); + Vector<String> editor = new Vector<String>(); + e_eid = "Editor : " + eid; + e_socketchannel = "SocketChannel : " + channel; + editor.add(e_eid); + editor.add(e_socketchannel); + e_tableModel.addRow(editor); + } + + public void setTableSession(int sessionID, String string) { + //SessionPlus sp = new SessionPlus(sessionID, string); + //s_list.add(sp); + Vector<String> session = new Vector<String>(); + s_host = " "; + s_port = " "; + s_file = "" + string; + s_sid = "" + sessionID; + s_eid = " "; + session.add(s_host); + session.add(s_port); + session.add(s_file); + session.add(s_sid); + session.add(s_eid); + s_tableModel.addRow(session); + } + + public static void main(String[] args){ + new RPanel(); + } + + protected void setTableSession(LinkedList<Session> list) { + s_tableModel.setRowCount(0); + sessionList = list; + for(Session session : list){ + setTableSession(session.getSID(), session.getName()); + } + } + + protected void setTableEditor(LinkedList<Editor> list) { + e_tableModel.setRowCount(0); + editorList = list; + for(Forwarder editor : list){ + setTableEditor(editor.getEID(), editor.getChannel()); + } + } + + public void addREPActionListener(SessionManagerEventListener listener) { + this.listener = listener; + } + + public void mouseClicked(MouseEvent e) { + //System.out.println("RPanel.mouseClicked() : editorChannel = " + editorList.get(editor_table.getSelectedRow()).getChannel()); + } + + public void mouseEntered(MouseEvent e) { + + } + + public void mouseExited(MouseEvent e) { + + } + + public void mousePressed(MouseEvent e) { + + } + + public void mouseReleased(MouseEvent e) { + + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/ConnectionPanel.java Fri Oct 10 14:10:15 2008 +0900 @@ -0,0 +1,42 @@ +package test; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JPanel; +import javax.swing.JTextField; + +public class ConnectionPanel extends JPanel implements ActionListener{ + + /** + * + */ + private static final long serialVersionUID = 1L; + private JButton button; + private JTextField textField; + public String host; + + public ConnectionPanel() { + button = new JButton("Connect"); + textField = new JTextField("localhost"); + + button.setBounds(160, 5, 100, 20); + textField.setBounds(5, 5, 150, 20); + + this.setLayout(null); + this.add(textField); + this.add( button); + + button.addActionListener(this); + } + + + public void actionPerformed(ActionEvent event) { + if (event.getSource() == button) { + host = textField.getText(); + //System.out.println("pressed!"); + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/DefaultTableModelTest.java Fri Oct 10 14:10:15 2008 +0900 @@ -0,0 +1,1 @@ +package test; import java.awt.*; import javax.swing.*; import javax.swing.table.*; class DefaultTableModelTest extends JFrame { /** * */ private static final long serialVersionUID = 1L; DefaultTableModelTest() { getContentPane().setLayout(new FlowLayout()); String[][] rowData = { { "A1", "B1", "C1" }, { "A2", "B2", "C2" }, { "A3", "B3", "C3" }, { "A4", "B4", "C4" }, }; String[] colNames = { "A", "B", "C" }; DefaultTableModel tm = new DefaultTableModel(rowData, colNames); JTable tb = new JTable(tm); JScrollPane sp = new JScrollPane(tb); sp.setPreferredSize(new Dimension(230, 80)); getContentPane().add(sp); String[] data = { "A5", "B5", "C5" }; tm.addRow(data); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("DefaultTableModelTest"); setSize(250, 120); setVisible(true); } public static void main(String[] args) { new DefaultTableModelTest(); } } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/JTableTest.java Fri Oct 10 14:10:15 2008 +0900 @@ -0,0 +1,1 @@ +package test; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; class JTableTest extends JFrame implements ActionListener, FocusListener, ListSelectionListener{ /** * */ private static final long serialVersionUID = 1L; private JTable tb; JTableTest() { getContentPane().setLayout(new FlowLayout()); tb = new JTable(10, 5); tb.setValueAt("AAA", 0, 0); tb.setValueAt("BBB", 1, 1); tb.setValueAt("CCC", 2, 2); tb.addFocusListener(this); JScrollPane sp = new JScrollPane(tb); sp.setPreferredSize(new Dimension(230, 80)); getContentPane().add(sp); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("JTableTest"); setSize(250, 120); setVisible(true); } public static void main(String[] args) { new JTableTest(); } public void actionPerformed(ActionEvent event) { //if(event.getSource() == tb){ // int a = tb.getSelectedColumn(); // int b = tb.getSelectedRow(); // System.out.println("Selected item is " + a + ":" + b); //} } public void focusGained(FocusEvent event) { int column = tb.getSelectedColumn(); int row = tb.getSelectedRow(); System.out.println("Gained item is " + column + ":" + row); } public void focusLost(FocusEvent event) { } public void valueChanged(ListSelectionEvent event) { int column = tb.getSelectedColumn(); int row = tb.getSelectedRow(); Object value = tb.getValueAt(row, column); System.out.println("Gained item is " + column + ":" + row + "," + value); } } \ No newline at end of file
--- a/test/TestGUI.java Thu Oct 09 17:26:55 2008 +0900 +++ b/test/TestGUI.java Fri Oct 10 14:10:15 2008 +0900 @@ -3,23 +3,20 @@ import java.awt.Container; import javax.swing.JFrame; -import rep.ConnectionListener; -import rep.gui.ConnectionPanel; public class TestGUI { private static JFrame frame; private static ConnectionPanel cp; - private static ConnectionListener listener; + //private static ConnectionListener listener; public TestGUI() { - // TODO Auto-generated constructor stub } public static void main(String[] args){ frame = new JFrame("SessionManager"); frame.setBounds(100, 100, 400, 100); - cp = new ConnectionPanel(listener); + cp = new ConnectionPanel(); Container cont = frame.getContentPane(); cont.add(cp);
--- a/test/sematest/TestGUI.java Thu Oct 09 17:26:55 2008 +0900 +++ b/test/sematest/TestGUI.java Fri Oct 10 14:10:15 2008 +0900 @@ -34,6 +34,7 @@ } public void update(LinkedList<Session> slist, LinkedList<Editor> elist) { + int i = 0; this.slist = slist; this.elist = elist; // fair and deterministic select session for an empty editor @@ -42,10 +43,11 @@ for(Editor e :elist) { if (!e.hasSession()) { SessionManagerEvent event = new SelectButtonEvent(e, s, manager); - ns.writeLog("Select session "+s.getSID()+" and editor "+e.getEID()); + ns.writeLog("Select session "+s.getSID()+" and editor "+i); manager.buttonPressed(event); s = slist.get(count++ % slist.size()); } + i++; } }