001: /*
002: * This program is free software; you can redistribute it and/or
003: * modify it under the terms of the GNU General Public License
004: * as published by the Free Software Foundation; either version 2
005: * of the License, or (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011:
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package net.sf.jftp.util;
017:
018: import net.sf.jftp.*;
019: import net.sf.jftp.config.*;
020: import net.sf.jftp.gui.framework.*;
021: import net.sf.jftp.net.*;
022: import net.sf.jftp.util.*;
023:
024: import java.awt.*;
025: import java.awt.event.*;
026:
027: import java.io.*;
028:
029: import java.util.*;
030:
031: import javax.swing.*;
032: import javax.swing.event.*;
033:
034: public class RawConnection extends JFrame implements ActionListener,
035: WindowListener {
036: public static HTextField host = new HTextField("Host:", "", 20);
037: public static HTextField port = new HTextField("Port:", "", 5);
038: public static JTextArea output = new JTextArea();
039: public static boolean established = false;
040: public static boolean mayDispose = false;
041: public static JScrollPane outputPane;
042: private JPanel p1 = new JPanel();
043: private HTextField com = new HTextField("Command:", "", 20);
044: private JPanel p2 = new JPanel();
045: private JButton send = new JButton("Send");
046: private JRawConnection c;
047: private JButton clear = new JButton("Clear");
048: JMenuBar mb = new JMenuBar();
049: JMenu file = new JMenu("Prog");
050: JMenu about = new JMenu("About");
051: JMenu session = new JMenu("Session");
052: JMenuItem close = new JMenuItem("ExIt");
053: JMenuItem changeHost = new JMenuItem("Host...");
054: JMenuItem info = new JMenuItem("Info");
055:
056: public RawConnection() {
057: this ("localhost", 25);
058: }
059:
060: public RawConnection(String hostname, int p) {
061: host.setText(hostname);
062:
063: setSize(550, 300);
064: setLocation(150, 150);
065: setTitle("Direct TCP/IP connection");
066: getContentPane().setLayout(new BorderLayout(2, 2));
067:
068: p1.add(host);
069: p1.add(port);
070: host.text.setEditable(false);
071: port.text.setEditable(false);
072: port.setText(Integer.toString(p));
073:
074: com.text.addActionListener(this );
075:
076: p2.add(com);
077:
078: com.addKeyListener(new KeyAdapter() {
079: public void keyReleased(KeyEvent e) {
080: if (e.getKeyCode() == KeyEvent.VK_ENTER) {
081: transmit();
082: }
083: }
084: });
085:
086: p2.add(send);
087: send.addActionListener(this );
088: p2.add(clear);
089: clear.addActionListener(this );
090:
091: output.setEditable(false);
092:
093: outputPane = new JScrollPane(output);
094: outputPane.setMinimumSize(new Dimension(400, 300));
095:
096: getContentPane().add("North", p1);
097: getContentPane().add("Center", outputPane);
098: getContentPane().add("South", p2);
099:
100: com.setText("");
101:
102: file.add(close);
103: close.addActionListener(this );
104: session.add(changeHost);
105: changeHost.addActionListener(this );
106: about.add(info);
107: info.addActionListener(this );
108:
109: //mb.add(file);
110: session.add(close);
111: mb.add(session);
112:
113: //mb.add(about);
114: setJMenuBar(mb);
115:
116: addWindowListener(this );
117: setVisible(true);
118:
119: JHostChooser jhc = new JHostChooser();
120: }
121:
122: private void transmit() {
123: if (!established) {
124: c = new JRawConnection(host.getText(), Integer
125: .parseInt(port.getText()), true);
126:
127: if (c.isThere()) {
128: c.send(com.getText());
129: established = true;
130: } else {
131: debugWrite("No connection!");
132: }
133: } else {
134: if (c.isThere()) {
135: c.send(com.getText());
136: } else {
137: debugWrite("No connection!");
138: }
139: }
140:
141: com.setText("");
142: }
143:
144: public void actionPerformed(ActionEvent e) {
145: if ((e.getSource() == send) || (e.getSource() == com.text)) {
146: transmit();
147: }
148:
149: if (e.getSource() == clear) {
150: output.setText("");
151: }
152:
153: if (e.getSource() == close) {
154: this .dispose();
155: }
156:
157: if (e.getSource() == changeHost) {
158: JHostChooser jhc = new JHostChooser();
159: }
160: }
161:
162: private void debugWrite(String str) {
163: output.append(str + "\n");
164: }
165:
166: public void windowClosing(WindowEvent e) {
167: if (mayDispose) {
168: this .dispose();
169: }
170: }
171:
172: public void windowIconified(WindowEvent e) {
173: }
174:
175: public void windowDeiconified(WindowEvent e) {
176: }
177:
178: public void windowClosed(WindowEvent e) {
179: }
180:
181: public void windowActivated(WindowEvent e) {
182: }
183:
184: public void windowDeactivated(WindowEvent e) {
185: }
186:
187: public void windowOpened(WindowEvent e) {
188: }
189: }
|