view rep/RPanel.java @ 18:b429fe1e15a8

*** empty log message ***
author pin
date Fri, 02 Nov 2007 15:40:40 +0900
parents b774b87cc2c1
children ece6aaddfec4
line wrap: on
line source

package rep;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.nio.channels.SocketChannel;

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class RPanel extends JPanel implements ActionListener {

	private JButton button;
	private JTextField textField;
	private String host;
	private JLabel label;
	private JTextArea textArea;
	private JScrollBar scrollBar;
	private JScrollPane scrollPane;
	private SessionViewer sessionViewer;
	private JScrollPane viewerPane;
	private ConnectionListener listener;
	private JComboBox comboEditor;
	private JComboBox comboSession;
	private JButton buttonSelect;
	private REPActionListener actionListener;

	public RPanel() {
		button = new JButton("Connect");
		textField = new JTextField("firefly.cr.ie.u-ryukyu.ac.jp");
		textArea = new JTextArea();
		label = new JLabel("test");
		scrollPane = new JScrollPane(textArea);
		sessionViewer = new SessionViewer();
		viewerPane = new JScrollPane(sessionViewer.getTree());
		//scrollBar = new JScrollBar(JScrollBar.VERTICAL);
		comboEditor = new JComboBox();
		comboSession = new JComboBox();
		buttonSelect = new JButton("Select");
		
		
		button.setBounds(160, 5, 100, 20);
		textField.setBounds(5, 5, 150, 20);
		textArea.setEditable(false);
		textArea.setLineWrap(false);
		scrollPane.setBounds(5, 30, 200, 200);
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		viewerPane.setBounds(5, 30, 200, 200);
		viewerPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		//scrollPane.setPreferredSize(new Dimension(200, 200));
		//textArea.setBounds(5, 30, 200, 200);
		//textArea.add(scrollBar, BorderLayout.EAST);
		comboEditor.setBounds(250, 50, 100, 50);
		comboSession.setBounds(250, 100, 100, 50);
		buttonSelect.setBounds(250, 180, 100, 20);

		this.setLayout(null);
		this.add(textField);
		this.add( button);
		this.add(label);
		//this.add(textArea);
		//this.add(scrollPane, BorderLayout.CENTER);
		this.add(viewerPane, BorderLayout.CENTER);
		//this.add(label, BorderLayout.CENTER);
		this.add(comboEditor);
		this.add(comboSession);
		this.add(buttonSelect);

		button.addActionListener(this);
		buttonSelect.addActionListener(this);
	}
	
	public void addSessionTree(int SID){
		sessionViewer.addSessionTree(SID);
	}
	
	public void actionPerformed(ActionEvent event) {
		if (event.getSource() == button) {
			host = textField.getText();
			listener.connectionOccured(new ConnectionEvent(host));
		}else if(event.getSource() == buttonSelect){
			actionListener.ActionOccured(new REPActionEvent((EditorPlus) comboEditor.getSelectedItem(),
					(SessionPlus)comboSession.getSelectedItem()));
		}
	}

	public void addConnectionListener(ConnectionListener listener) {
		System.out.println(listener.toString());
		this.listener = listener;
	}

	public void setComboEditor(int eid, SocketChannel channel) {
		//comboEditor.addItem("Editor:"+eid);
		comboEditor.addItem(new EditorPlus(eid, channel));
	}

	public void REPActionListener(REPActionListener listener2) {
		this.actionListener = listener2;
	}

	public void setComboSession(int sessionID, String string) {
		comboSession.addItem(new SessionPlus(sessionID, string));
	}

}