1 16 package net.sf.jftp.util; 17 18 import net.sf.jftp.*; 19 import net.sf.jftp.config.*; 20 import net.sf.jftp.gui.framework.*; 21 import net.sf.jftp.net.*; 22 import net.sf.jftp.util.*; 23 24 import java.awt.*; 25 import java.awt.event.*; 26 27 import java.io.*; 28 29 import java.util.*; 30 31 import javax.swing.*; 32 import javax.swing.event.*; 33 34 35 public class RawConnection extends JFrame implements ActionListener, 36 WindowListener 37 { 38 public static HTextField host = new HTextField("Host:", "", 20); 39 public static HTextField port = new HTextField("Port:", "", 5); 40 public static JTextArea output = new JTextArea(); 41 public static boolean established = false; 42 public static boolean mayDispose = false; 43 public static JScrollPane outputPane; 44 private JPanel p1 = new JPanel(); 45 private HTextField com = new HTextField("Command:", "", 20); 46 private JPanel p2 = new JPanel(); 47 private JButton send = new JButton("Send"); 48 private JRawConnection c; 49 private JButton clear = new JButton("Clear"); 50 JMenuBar mb = new JMenuBar(); 51 JMenu file = new JMenu("Prog"); 52 JMenu about = new JMenu("About"); 53 JMenu session = new JMenu("Session"); 54 JMenuItem close = new JMenuItem("ExIt"); 55 JMenuItem changeHost = new JMenuItem("Host..."); 56 JMenuItem info = new JMenuItem("Info"); 57 58 public RawConnection() 59 { 60 this("localhost", 25); 61 } 62 63 public RawConnection(String hostname, int p) 64 { 65 host.setText(hostname); 66 67 setSize(550, 300); 68 setLocation(150, 150); 69 setTitle("Direct TCP/IP connection"); 70 getContentPane().setLayout(new BorderLayout(2, 2)); 71 72 p1.add(host); 73 p1.add(port); 74 host.text.setEditable(false); 75 port.text.setEditable(false); 76 port.setText(Integer.toString(p)); 77 78 com.text.addActionListener(this); 79 80 p2.add(com); 81 82 com.addKeyListener(new KeyAdapter() 83 { 84 public void keyReleased(KeyEvent e) 85 { 86 if(e.getKeyCode() == KeyEvent.VK_ENTER) 87 { 88 transmit(); 89 } 90 } 91 }); 92 93 p2.add(send); 94 send.addActionListener(this); 95 p2.add(clear); 96 clear.addActionListener(this); 97 98 output.setEditable(false); 99 100 outputPane = new JScrollPane(output); 101 outputPane.setMinimumSize(new Dimension(400, 300)); 102 103 getContentPane().add("North", p1); 104 getContentPane().add("Center", outputPane); 105 getContentPane().add("South", p2); 106 107 com.setText(""); 108 109 file.add(close); 110 close.addActionListener(this); 111 session.add(changeHost); 112 changeHost.addActionListener(this); 113 about.add(info); 114 info.addActionListener(this); 115 116 session.add(close); 118 mb.add(session); 119 120 setJMenuBar(mb); 122 123 addWindowListener(this); 124 setVisible(true); 125 126 JHostChooser jhc = new JHostChooser(); 127 } 128 129 private void transmit() 130 { 131 if(!established) 132 { 133 c = new JRawConnection(host.getText(), 134 Integer.parseInt(port.getText()), true); 135 136 if(c.isThere()) 137 { 138 c.send(com.getText()); 139 established = true; 140 } 141 else 142 { 143 debugWrite("No connection!"); 144 } 145 } 146 else 147 { 148 if(c.isThere()) 149 { 150 c.send(com.getText()); 151 } 152 else 153 { 154 debugWrite("No connection!"); 155 } 156 } 157 158 com.setText(""); 159 } 160 161 public void actionPerformed(ActionEvent e) 162 { 163 if((e.getSource() == send) || (e.getSource() == com.text)) 164 { 165 transmit(); 166 } 167 168 if(e.getSource() == clear) 169 { 170 output.setText(""); 171 } 172 173 if(e.getSource() == close) 174 { 175 this.dispose(); 176 } 177 178 if(e.getSource() == changeHost) 179 { 180 JHostChooser jhc = new JHostChooser(); 181 } 182 } 183 184 private void debugWrite(String str) 185 { 186 output.append(str + "\n"); 187 } 188 189 public void windowClosing(WindowEvent e) 190 { 191 if(mayDispose) 192 { 193 this.dispose(); 194 } 195 } 196 197 public void windowIconified(WindowEvent e) 198 { 199 } 200 201 public void windowDeiconified(WindowEvent e) 202 { 203 } 204 205 public void windowClosed(WindowEvent e) 206 { 207 } 208 209 public void windowActivated(WindowEvent e) 210 { 211 } 212 213 public void windowDeactivated(WindowEvent e) 214 { 215 } 216 217 public void windowOpened(WindowEvent e) 218 { 219 } 220 } 221 | Popular Tags |