comparison rep/gui/RPanel.java @ 320:83790b8b8174

*** empty log message ***
author kono
date Fri, 10 Oct 2008 14:10:15 +0900
parents
children d46f1e255919
comparison
equal deleted inserted replaced
319:dfed28488274 320:83790b8b8174
1 package rep.gui;
2
3 import java.awt.Dimension;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.awt.event.MouseEvent;
7 import java.awt.event.MouseListener;
8
9 import javax.swing.JButton;
10 import javax.swing.JLabel;
11 import javax.swing.JPanel;
12 import javax.swing.JScrollPane;
13 import javax.swing.JTable;
14 import javax.swing.JTextArea;
15 import javax.swing.JTextField;
16 import javax.swing.table.DefaultTableModel;
17
18 import rep.CloseButtonEvent;
19 import rep.ConnectButtonEvent;
20 import rep.Editor;
21 import rep.EditorPlus;
22 import rep.Forwarder;
23 import rep.REPCommand;
24 import rep.SelectButtonEvent;
25 import rep.Session;
26 import rep.SessionManagerEventListener;
27 import rep.channel.REPSocketChannel;
28
29 import java.util.*;
30
31 public class RPanel extends JPanel implements ActionListener, MouseListener {
32
33 /**
34 *
35 */
36 private static final long serialVersionUID = 1L;
37 private JButton connectButton;
38 private JTextField textField;
39 private String host;
40 private JLabel label;
41 private JTextArea textArea;
42 //private JScrollPane viewerPane;
43 private JTable session_table;
44 private JScrollPane s_sp;
45 private JTable editor_table;
46 private JScrollPane e_sp;
47 private String[] session_column = {"HOST", "PORT", "FILE", "SID", "EID"};
48 private String[] editor_column = {"EID", "SOCKET_CHANNEL"};
49 private DefaultTableModel s_tableModel = new DefaultTableModel(session_column, 0);
50 private DefaultTableModel e_tableModel = new DefaultTableModel(editor_column, 0);
51 //LinkedList<SessionPlus> s_list = new LinkedList<SessionPlus>();
52 LinkedList<EditorPlus> e_list = new LinkedList<EditorPlus>();
53 private String s_host;
54 private String s_port;
55 private String s_file;
56 private String s_sid;
57 private String s_eid;
58 private String e_eid;
59 private String e_socketchannel;
60 private JButton selectButton;
61 private JButton closeButton;
62 private SessionManagerEventListener listener;
63 private LinkedList<Editor> editorList;
64 private LinkedList<Session> sessionList;
65
66 public RPanel() {
67 connectButton = new JButton("Connect");
68 textField = new JTextField("firefly.cr.ie.u-ryukyu.ac.jp");
69 textArea = new JTextArea();
70 label = new JLabel("test");
71 session_table = new JTable(s_tableModel);
72 s_sp = new JScrollPane(session_table);
73 editor_table = new JTable(e_tableModel);
74 e_sp = new JScrollPane(editor_table);
75 selectButton = new JButton("Select Session");
76 closeButton = new JButton("Close Session");
77
78
79 connectButton.setBounds(160, 5, 100, 20);
80 textField.setBounds(5, 5, 150, 20);
81 textArea.setEditable(false);
82 textArea.setLineWrap(false);
83 session_table.setBounds(5,30,400,200);
84 s_sp.setPreferredSize(new Dimension(200, 200));
85 s_sp.setBounds(5,30,400,100);
86 e_sp.setPreferredSize(new Dimension(200, 200));
87 e_sp.setBounds(5,140,400,100);
88 selectButton.setBounds(430, 215, 130, 20);
89 closeButton.setBounds(430, 105, 130, 20);
90
91
92 this.setLayout(null);
93 this.add(textField);
94 this.add(connectButton);
95 this.add(label);
96 this.add(s_sp);
97 this.add(e_sp);
98 this.add(selectButton);
99 this.add(closeButton);
100
101 connectButton.addActionListener(this);
102 selectButton.addActionListener(this);
103 closeButton.addActionListener(this);
104 editor_table.addMouseListener(this);
105
106 }
107
108 public void actionPerformed(ActionEvent event) {
109 if (event.getSource() == connectButton) {
110 host = textField.getText();
111 listener.buttonPressed(new ConnectButtonEvent(listener, host));
112
113 }else if(event.getSource() == selectButton){
114 //System.out.println("RPanel.actionPerformed() : editorSelectedRow = " + editor_table.getSelectedRow());
115 listener.buttonPressed(
116 new SelectButtonEvent(editorList.get(editor_table.getSelectedRow()),
117 sessionList.get(session_table.getSelectedRow()), listener));
118 }else if(event.getSource() == closeButton){
119 listener.buttonPressed(new CloseButtonEvent(sessionList.get(session_table.getSelectedRow()), listener));
120 }
121 }
122
123 public void setTableEditor(int eid, REPSocketChannel<REPCommand> channel) {
124 //System.out.println("RPanel.setTableEditor() : channel = " + channel);
125 Vector<String> editor = new Vector<String>();
126 e_eid = "Editor : " + eid;
127 e_socketchannel = "SocketChannel : " + channel;
128 editor.add(e_eid);
129 editor.add(e_socketchannel);
130 e_tableModel.addRow(editor);
131 }
132
133 public void setTableSession(int sessionID, String string) {
134 //SessionPlus sp = new SessionPlus(sessionID, string);
135 //s_list.add(sp);
136 Vector<String> session = new Vector<String>();
137 s_host = " ";
138 s_port = " ";
139 s_file = "" + string;
140 s_sid = "" + sessionID;
141 s_eid = " ";
142 session.add(s_host);
143 session.add(s_port);
144 session.add(s_file);
145 session.add(s_sid);
146 session.add(s_eid);
147 s_tableModel.addRow(session);
148 }
149
150 public static void main(String[] args){
151 new RPanel();
152 }
153
154 protected void setTableSession(LinkedList<Session> list) {
155 s_tableModel.setRowCount(0);
156 sessionList = list;
157 for(Session session : list){
158 setTableSession(session.getSID(), session.getName());
159 }
160 }
161
162 protected void setTableEditor(LinkedList<Editor> list) {
163 e_tableModel.setRowCount(0);
164 editorList = list;
165 for(Forwarder editor : list){
166 setTableEditor(editor.getEID(), editor.getChannel());
167 }
168 }
169
170 public void addREPActionListener(SessionManagerEventListener listener) {
171 this.listener = listener;
172 }
173
174 public void mouseClicked(MouseEvent e) {
175 //System.out.println("RPanel.mouseClicked() : editorChannel = " + editorList.get(editor_table.getSelectedRow()).getChannel());
176 }
177
178 public void mouseEntered(MouseEvent e) {
179
180 }
181
182 public void mouseExited(MouseEvent e) {
183
184 }
185
186 public void mousePressed(MouseEvent e) {
187
188 }
189
190 public void mouseReleased(MouseEvent e) {
191
192 }
193
194 }