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