Source code: plugins/CsBeagle/PingDlg.java
1 /*
2 * PingDlg.java
3 *
4 * Created on November 5, 2002, 1:48 PM
5 */
6
7 package plugins.CsBeagle;
8 import java.io.*;
9 /**
10 *
11 * @author Tobias Riemer
12 */
13 public class PingDlg extends javax.swing.JFrame implements Runnable {
14
15 Server server;
16 Process process;
17 String exec;
18 String param;
19 /** Creates new form PingDlg */
20 public PingDlg(javax.swing.ImageIcon icon, Server server, String exec, String param) {
21 super();
22 this.setIconImage(icon.getImage());
23 initComponents();
24 this.setTitle("Ping: " + server.getName() + " " + server.getIp());
25 //setIconImage(CsBeagle.getWindowIcon().getImage());
26 this.server = server;
27 this.exec = exec;
28 this.param = param;
29 (new Thread(this)).start();
30 }
31
32 /** This method is called from within the constructor to
33 * initialize the form.
34 * WARNING: Do NOT modify this code. The content of this method is
35 * always regenerated by the Form Editor.
36 */
37 private void initComponents() {//GEN-BEGIN:initComponents
38 jScrollPane1 = new javax.swing.JScrollPane();
39 jOutput = new javax.swing.JTextArea();
40 jPanel1 = new javax.swing.JPanel();
41 jExit = new javax.swing.JButton();
42
43 addWindowListener(new java.awt.event.WindowAdapter() {
44 public void windowClosing(java.awt.event.WindowEvent evt) {
45 closeDialog(evt);
46 }
47 });
48
49 jScrollPane1.setPreferredSize(new java.awt.Dimension(560, 300));
50 jOutput.setEditable(false);
51 jScrollPane1.setViewportView(jOutput);
52
53 getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
54
55 jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
56
57 jExit.setText("Exit");
58 jExit.addActionListener(new java.awt.event.ActionListener() {
59 public void actionPerformed(java.awt.event.ActionEvent evt) {
60 jExitActionPerformed(evt);
61 }
62 });
63
64 jPanel1.add(jExit);
65
66 getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);
67
68 pack();
69 }//GEN-END:initComponents
70
71 private void jExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jExitActionPerformed
72 // Add your handling code here:
73 setVisible(false);
74 if (process != null) process.destroy();
75 dispose();
76 }//GEN-LAST:event_jExitActionPerformed
77
78 /** Closes the dialog */
79 private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
80 setVisible(false);
81 if (process != null) process.destroy();
82 dispose();
83 }//GEN-LAST:event_closeDialog
84
85 /**
86 * @param args the command line arguments
87 */
88 public static void main(String args[]) {
89 //new PingDlg(new javax.swing.JFrame(), true).show();
90 }
91
92 /** When an object implementing interface <code>Runnable</code> is used
93 * to create a thread, starting the thread causes the object's
94 * <code>run</code> method to be called in that separately executing
95 * thread.
96 * <p>
97 * The general contract of the method <code>run</code> is that it may
98 * take any action whatsoever.
99 *
100 * @see java.lang.Thread#run()
101 */
102 public void run() {
103 Runtime rt = Runtime.getRuntime();
104 BufferedReader pInput;
105 try {
106 process =
107 rt.exec( exec + " " + server.getIp() + " " + param);
108 //process.waitFor();
109 pInput = new BufferedReader(
110 new InputStreamReader(
111 process.getInputStream()));
112
113 String s = pInput.readLine();
114 while ( s != null ) {
115 jOutput.append(s);
116 jOutput.append("\n");
117 jOutput.setCaretPosition(jOutput.getText().length());
118 s = pInput.readLine();
119 }
120
121 } catch ( IOException ex ) {
122 ex.printStackTrace();
123 }
124 /* catch (InterruptedException iex) {
125 iex.printStackTrace();
126 }*/
127 }
128
129 // Variables declaration - do not modify//GEN-BEGIN:variables
130 private javax.swing.JTextArea jOutput;
131 private javax.swing.JScrollPane jScrollPane1;
132 private javax.swing.JButton jExit;
133 private javax.swing.JPanel jPanel1;
134 // End of variables declaration//GEN-END:variables
135
136 }