Mercurial > hg > RemoteEditor > REPSessionManager
view rep/RPanel.java @ 217:4deaaaa6354e
*** empty log message ***
author | kono |
---|---|
date | Sun, 31 Aug 2008 00:26:35 +0900 |
parents | 4d9b32666ed2 |
children | 827c439d0da4 |
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.SwingUtilities; 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 button; 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 SessionManager listener; //private JComboBox comboEditor; //private JComboBox comboSession; private JButton buttonSelect; private REPActionListener<REPCommand> actionListener; private List<Session> sessionList; private List<Editor> editorList; private SessionManager manager; public RPanel() { button = 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); buttonSelect = new JButton("Select"); button.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); buttonSelect.setBounds(450, 180, 100, 20); this.setLayout(null); this.add(textField); this.add( button); this.add(label); this.add(s_sp); this.add(e_sp); this.add(buttonSelect); button.addActionListener(this); buttonSelect.addActionListener(this); } public RPanel(SessionManager manager) { this(); this.manager = manager; sessionList = manager.getSessionList(); editorList = manager.getEditorList(); } public void actionPerformed(ActionEvent event) { if (event.getSource() == button) { host = textField.getText(); listener.connectionOccured(new ConnectionEvent(listener, host)); }else if(event.getSource() == buttonSelect){ /* actionListener.ActionOccured(new REPActionEvent((EditorPlus) comboEditor.getSelectedItem(), (SessionPlus)comboSession.getSelectedItem())); */ actionListener.selectOccured(new REPActionEvent<REPCommand>((EditorPlus<REPCommand>) e_list.get(editor_table.getSelectedRow()), (SessionPlus)s_list.get(session_table.getSelectedRow()), listener)); } } public void addConnectionListener(ConnectionListener listener) { System.out.println(listener.toString()); this.listener = (SessionManager) listener; } public void setComboEditor(int eid, REPSocketChannel<REPCommand> channel) { //comboEditor.addItem("Editor:"+eid); //comboEditor.addItem(new EditorPlus<REPCommand>(eid, channel)); } public void addREPActionListener(REPActionListener<REPCommand> listener2) { this.actionListener = listener2; } public void setComboSession(int sessionID, String string) { //comboSession.addItem(new SessionPlus(sessionID, string)); } 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) { e_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){ setTableEditor(editor.getEID(), editor.getChannel()); } } }