Mercurial > hg > RemoteEditor > REPSessionManager
view rep/RPanel.java @ 228:e6c7a56ff7f1
*** empty log message ***
author | pin |
---|---|
date | Sun, 31 Aug 2008 15:27:04 +0900 |
parents | cbd67817e9cd |
children | 2a185042dcd0 |
line wrap: on
line source
package rep; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; 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 { /** * */ 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<REPCommand>> e_list = new LinkedList<EditorPlus<REPCommand>>(); 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 SessionManager manager; private SessionManagerEventListener listener; 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"); 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(450, 180, 100, 20); this.setLayout(null); this.add(textField); this.add(connectButton); this.add(label); this.add(s_sp); this.add(e_sp); this.add(selectButton); connectButton.addActionListener(this); selectButton.addActionListener(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<REPCommand>((EditorPlus<REPCommand>) e_list.get(editor_table.getSelectedRow()), (SessionPlus)s_list.get(session_table.getSelectedRow()), listener)); } } public void setTableEditor(int eid, REPSocketChannel<REPCommand> channel) { System.out.println("RPanel.setTableEditor()"); EditorPlus<REPCommand> ep = new EditorPlus<REPCommand>(eid, channel); e_list.add(ep); 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); for(Session session : list){ setTableSession(session.getSID(), session.getName()); } } protected void setTableEditor(LinkedList<Editor> list) { e_tableModel.setRowCount(0); for(Editor editor : list){ System.out.println(editor.getChannel()); setTableEditor(editor.getEID(), editor.getChannel()); } } public void addREPActionListener(SessionManagerEventListener listener) { this.listener = listener; } }