Mercurial > hg > RemoteEditor > REPSessionManager
view rep/gui/RPanel.java @ 320:83790b8b8174
*** empty log message ***
author | kono |
---|---|
date | Fri, 10 Oct 2008 14:10:15 +0900 |
parents | |
children | d46f1e255919 |
line wrap: on
line source
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) { } }