Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: plugins/CsBeagle/AddIpDlg.java


1   /*
2    * AddIpDlg.java
3    *
4    * Created on November 2, 2002, 10:36 PM
5    */
6   
7   package plugins.CsBeagle;
8   
9   /**
10   *
11   * @author  Tobias Riemer
12   */
13  public class AddIpDlg extends javax.swing.JFrame {
14      
15      private Server server;
16      private ServerList serverList;
17      /** Creates new form AddIpDlg */
18      public AddIpDlg(javax.swing.ImageIcon icon) {
19          super();
20          initComponents();
21          this.setIconImage(icon.getImage());
22      }
23      
24      /** This method is called from within the constructor to
25       * initialize the form.
26       * WARNING: Do NOT modify this code. The content of this method is
27       * always regenerated by the Form Editor.
28       */
29      private void initComponents() {//GEN-BEGIN:initComponents
30          java.awt.GridBagConstraints gridBagConstraints;
31  
32          jPanel1 = new javax.swing.JPanel();
33          jLabel1 = new javax.swing.JLabel();
34          jIp = new javax.swing.JTextField();
35          jLabel2 = new javax.swing.JLabel();
36          jPort = new javax.swing.JTextField();
37          jLabel3 = new javax.swing.JLabel();
38          jName = new javax.swing.JTextField();
39          jPanel2 = new javax.swing.JPanel();
40          jFind = new javax.swing.JButton();
41          jAdd = new javax.swing.JButton();
42          jCancel = new javax.swing.JButton();
43  
44          addWindowListener(new java.awt.event.WindowAdapter() {
45              public void windowClosing(java.awt.event.WindowEvent evt) {
46                  closeDialog(evt);
47              }
48          });
49  
50          jPanel1.setLayout(new java.awt.GridBagLayout());
51  
52          jPanel1.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(3, 3, 3, 3)));
53          jLabel1.setText("IP");
54          gridBagConstraints = new java.awt.GridBagConstraints();
55          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
56          gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 5);
57          gridBagConstraints.weightx = 0.4;
58          jPanel1.add(jLabel1, gridBagConstraints);
59  
60          gridBagConstraints = new java.awt.GridBagConstraints();
61          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
62          gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 0);
63          gridBagConstraints.weightx = 0.6;
64          jPanel1.add(jIp, gridBagConstraints);
65  
66          jLabel2.setText("Port");
67          gridBagConstraints = new java.awt.GridBagConstraints();
68          gridBagConstraints.gridx = 0;
69          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
70          gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 5);
71          jPanel1.add(jLabel2, gridBagConstraints);
72  
73          jPort.setText("27015");
74          gridBagConstraints = new java.awt.GridBagConstraints();
75          gridBagConstraints.gridx = 1;
76          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
77          gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 0);
78          jPanel1.add(jPort, gridBagConstraints);
79  
80          jLabel3.setText("Server Name");
81          jLabel3.setToolTipText("null");
82          gridBagConstraints = new java.awt.GridBagConstraints();
83          gridBagConstraints.gridx = 0;
84          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
85          gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 5);
86          jPanel1.add(jLabel3, gridBagConstraints);
87  
88          jName.setColumns(20);
89          jName.setEditable(false);
90          gridBagConstraints = new java.awt.GridBagConstraints();
91          gridBagConstraints.gridx = 1;
92          gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
93          gridBagConstraints.insets = new java.awt.Insets(0, 0, 3, 0);
94          jPanel1.add(jName, gridBagConstraints);
95  
96          getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
97  
98          jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
99  
100         jFind.setText("Find");
101         jFind.addActionListener(new java.awt.event.ActionListener() {
102             public void actionPerformed(java.awt.event.ActionEvent evt) {
103                 jFindActionPerformed(evt);
104             }
105         });
106 
107         jPanel2.add(jFind);
108 
109         jAdd.setText("Add");
110         jAdd.addActionListener(new java.awt.event.ActionListener() {
111             public void actionPerformed(java.awt.event.ActionEvent evt) {
112                 jAddActionPerformed(evt);
113             }
114         });
115 
116         jPanel2.add(jAdd);
117 
118         jCancel.setText("Exit");
119         jCancel.addActionListener(new java.awt.event.ActionListener() {
120             public void actionPerformed(java.awt.event.ActionEvent evt) {
121                 jCancelActionPerformed(evt);
122             }
123         });
124 
125         jPanel2.add(jCancel);
126 
127         getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
128 
129         pack();
130     }//GEN-END:initComponents
131 
132     private void jAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jAddActionPerformed
133         // Add your handling code here:
134         findServer();
135         serverList.add(server);
136     }//GEN-LAST:event_jAddActionPerformed
137 
138     private void jCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCancelActionPerformed
139         // Add your handling code here:
140         setVisible(false);
141         dispose();
142     }//GEN-LAST:event_jCancelActionPerformed
143 
144     private void jFindActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFindActionPerformed
145         // Add your handling code here:
146         findServer();
147         if (server.getState() == Server.DATA_READ)
148             jName.setText(server.getName());
149         else 
150             jName.setText("not found");
151     }//GEN-LAST:event_jFindActionPerformed
152     
153     private void findServer() {
154         try {
155             int port = Integer.decode(jPort.getText()).intValue();
156             server = new Server(jIp.getText(),port,true);
157             server.getData();
158         } catch (NumberFormatException nex) {
159             javax.swing.JOptionPane.showMessageDialog(null, "Invalid Port", "Error Message", javax.swing.JOptionPane.ERROR_MESSAGE);
160         }
161     }
162     
163     /** Closes the dialog */
164     private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
165         setVisible(false);
166         dispose();
167     }//GEN-LAST:event_closeDialog
168     
169     
170     public void setServerList(ServerList serverList) {
171         this.serverList = serverList;
172     }
173     /**
174      * @param args the command line arguments
175      */
176     public static void main(String args[]) {
177         //new AddIpDlg(new javax.swing.JFrame(), true).show();
178     }
179     
180     
181     // Variables declaration - do not modify//GEN-BEGIN:variables
182     private javax.swing.JTextField jIp;
183     private javax.swing.JLabel jLabel1;
184     private javax.swing.JLabel jLabel3;
185     private javax.swing.JTextField jPort;
186     private javax.swing.JLabel jLabel2;
187     private javax.swing.JPanel jPanel2;
188     private javax.swing.JButton jCancel;
189     private javax.swing.JTextField jName;
190     private javax.swing.JPanel jPanel1;
191     private javax.swing.JButton jFind;
192     private javax.swing.JButton jAdd;
193     // End of variables declaration//GEN-END:variables
194     
195 }