1
|
1 package rep;
|
|
2
|
2
|
3 import java.awt.Dimension;
|
1
|
4 import java.awt.event.ActionEvent;
|
|
5 import java.awt.event.ActionListener;
|
|
6 import javax.swing.JButton;
|
|
7 import javax.swing.JLabel;
|
|
8 import javax.swing.JPanel;
|
2
|
9 import javax.swing.JScrollPane;
|
54
|
10 import javax.swing.JTable;
|
1
|
11 import javax.swing.JTextArea;
|
|
12 import javax.swing.JTextField;
|
185
|
13 import javax.swing.SwingUtilities;
|
54
|
14 import javax.swing.table.DefaultTableModel;
|
134
|
15
|
|
16 import rep.channel.REPSocketChannel;
|
|
17
|
54
|
18 import java.util.*;
|
1
|
19
|
|
20 public class RPanel extends JPanel implements ActionListener {
|
|
21
|
140
|
22 /**
|
|
23 *
|
|
24 */
|
|
25 private static final long serialVersionUID = 1L;
|
1
|
26 private JButton button;
|
2
|
27 private JTextField textField;
|
|
28 private String host;
|
1
|
29 private JLabel label;
|
2
|
30 private JTextArea textArea;
|
54
|
31 //private JScrollPane viewerPane;
|
|
32 private JTable session_table;
|
|
33 private JScrollPane s_sp;
|
|
34 private JTable editor_table;
|
|
35 private JScrollPane e_sp;
|
|
36 private String[] session_column = {"HOST", "PORT", "FILE", "SID", "EID"};
|
|
37 private String[] editor_column = {"EID", "SOCKET_CHANNEL"};
|
|
38 private DefaultTableModel s_tableModel = new DefaultTableModel(session_column, 0);
|
|
39 private DefaultTableModel e_tableModel = new DefaultTableModel(editor_column, 0);
|
|
40 LinkedList<SessionPlus> s_list = new LinkedList<SessionPlus>();
|
140
|
41 LinkedList<EditorPlus<REPCommand>> e_list = new LinkedList<EditorPlus<REPCommand>>();
|
54
|
42 private String s_host;
|
|
43 private String s_port;
|
|
44 private String s_file;
|
|
45 private String s_sid;
|
|
46 private String s_eid;
|
|
47 private String e_eid;
|
|
48 private String e_socketchannel;
|
178
|
49 private SessionManager listener;
|
185
|
50 //private JComboBox comboEditor;
|
|
51 //private JComboBox comboSession;
|
8
|
52 private JButton buttonSelect;
|
140
|
53 private REPActionListener<REPCommand> actionListener;
|
185
|
54 private List<Session> sessionList;
|
|
55 private List<Editor> editorList;
|
|
56 private SessionManager manager;
|
1
|
57
|
|
58 public RPanel() {
|
|
59 button = new JButton("Connect");
|
6
|
60 textField = new JTextField("firefly.cr.ie.u-ryukyu.ac.jp");
|
2
|
61 textArea = new JTextArea();
|
1
|
62 label = new JLabel("test");
|
54
|
63 session_table = new JTable(s_tableModel);
|
|
64 s_sp = new JScrollPane(session_table);
|
|
65 editor_table = new JTable(e_tableModel);
|
|
66 e_sp = new JScrollPane(editor_table);
|
8
|
67 buttonSelect = new JButton("Select");
|
2
|
68
|
|
69
|
|
70 button.setBounds(160, 5, 100, 20);
|
|
71 textField.setBounds(5, 5, 150, 20);
|
|
72 textArea.setEditable(false);
|
|
73 textArea.setLineWrap(false);
|
54
|
74 session_table.setBounds(5,30,400,200);
|
|
75 s_sp.setPreferredSize(new Dimension(200, 200));
|
|
76 s_sp.setBounds(5,30,400,100);
|
|
77 e_sp.setPreferredSize(new Dimension(200, 200));
|
|
78 e_sp.setBounds(5,140,400,100);
|
|
79 buttonSelect.setBounds(450, 180, 100, 20);
|
|
80
|
1
|
81
|
2
|
82 this.setLayout(null);
|
|
83 this.add(textField);
|
|
84 this.add( button);
|
|
85 this.add(label);
|
54
|
86 this.add(s_sp);
|
|
87 this.add(e_sp);
|
8
|
88 this.add(buttonSelect);
|
1
|
89
|
|
90 button.addActionListener(this);
|
8
|
91 buttonSelect.addActionListener(this);
|
179
|
92
|
1
|
93 }
|
|
94
|
185
|
95 public RPanel(SessionManager manager) {
|
|
96 this();
|
|
97 this.manager = manager;
|
192
|
98 sessionList = manager.getSessionList();
|
|
99 editorList = manager.getEditorList();
|
2
|
100 }
|
185
|
101
|
1
|
102 public void actionPerformed(ActionEvent event) {
|
|
103 if (event.getSource() == button) {
|
2
|
104 host = textField.getText();
|
178
|
105 listener.connectionOccured(new ConnectionEvent(listener, host));
|
8
|
106 }else if(event.getSource() == buttonSelect){
|
61
|
107 /*
|
8
|
108 actionListener.ActionOccured(new REPActionEvent((EditorPlus) comboEditor.getSelectedItem(),
|
|
109 (SessionPlus)comboSession.getSelectedItem()));
|
61
|
110 */
|
213
|
111 actionListener.selectOccured(new REPActionEvent<REPCommand>((EditorPlus<REPCommand>) e_list.get(editor_table.getSelectedRow()),
|
212
|
112 (SessionPlus)s_list.get(session_table.getSelectedRow()), listener));
|
1
|
113 }
|
|
114 }
|
|
115
|
2
|
116 public void addConnectionListener(ConnectionListener listener) {
|
|
117 System.out.println(listener.toString());
|
178
|
118 this.listener = (SessionManager) listener;
|
2
|
119 }
|
122
|
120
|
2
|
121
|
134
|
122 public void setComboEditor(int eid, REPSocketChannel<REPCommand> channel) {
|
8
|
123 //comboEditor.addItem("Editor:"+eid);
|
185
|
124 //comboEditor.addItem(new EditorPlus<REPCommand>(eid, channel));
|
8
|
125 }
|
|
126
|
140
|
127 public void addREPActionListener(REPActionListener<REPCommand> listener2) {
|
8
|
128 this.actionListener = listener2;
|
|
129 }
|
|
130
|
|
131 public void setComboSession(int sessionID, String string) {
|
185
|
132 //comboSession.addItem(new SessionPlus(sessionID, string));
|
8
|
133 }
|
54
|
134
|
134
|
135 public void setTableEditor(int eid, REPSocketChannel<REPCommand> channel) {
|
195
|
136 System.out.println("RPanel.setTableEditor()");
|
140
|
137 EditorPlus<REPCommand> ep = new EditorPlus<REPCommand>(eid, channel);
|
54
|
138 e_list.add(ep);
|
185
|
139 Vector<String> editor = new Vector<String>();
|
54
|
140 e_eid = "Editor : " + eid;
|
|
141 e_socketchannel = "SocketChannel : " + channel;
|
|
142 editor.add(e_eid);
|
|
143 editor.add(e_socketchannel);
|
|
144 e_tableModel.addRow(editor);
|
|
145 }
|
|
146
|
|
147 public void setTableSession(int sessionID, String string) {
|
|
148 SessionPlus sp = new SessionPlus(sessionID, string);
|
|
149 s_list.add(sp);
|
185
|
150 Vector<String> session = new Vector<String>();
|
54
|
151 s_host = " ";
|
|
152 s_port = " ";
|
61
|
153 s_file = "" + string;
|
54
|
154 s_sid = "" + sessionID;
|
|
155 s_eid = " ";
|
|
156 session.add(s_host);
|
|
157 session.add(s_port);
|
|
158 session.add(s_file);
|
|
159 session.add(s_sid);
|
|
160 session.add(s_eid);
|
|
161 s_tableModel.addRow(session);
|
|
162 }
|
185
|
163
|
|
164 public static void main(String[] args){
|
|
165 new RPanel();
|
|
166 }
|
|
167
|
198
|
168 protected void setTableSession(LinkedList<Session> list) {
|
199
|
169 e_tableModel.setRowCount(0);
|
198
|
170 for(Session session : list){
|
185
|
171 setTableSession(session.getSID(), session.getName());
|
|
172 }
|
|
173 }
|
|
174
|
198
|
175 protected void setTableEditor(LinkedList<Editor> list) {
|
199
|
176 e_tableModel.setRowCount(0);
|
198
|
177 for(Editor editor : list){
|
185
|
178 setTableEditor(editor.getEID(), editor.getChannel());
|
|
179 }
|
|
180 }
|
8
|
181
|
1
|
182 }
|