ClientFrame.java
Go to the documentation of this file.
1 package p2pgui;
2 
3 import p2putility.Config;
4 import java.awt.Frame;
5 import java.io.File;
6 import java.io.IOException;
7 import java.net.InetAddress;
8 import java.net.UnknownHostException;
9 import java.text.DateFormat;
10 import java.text.SimpleDateFormat;
11 import java.util.ArrayList;
12 import java.util.Hashtable;
13 import javax.swing.JTable;
14 import javax.swing.table.DefaultTableModel;
15 import javax.swing.table.TableColumn;
16 
17 
18 
19 
25 public class ClientFrame extends javax.swing.JFrame {
26 
27  String ipp;
28  public static boolean connection = false;
29  static int id_user = -1;
30  public static boolean DBG = true;
31  boolean serveron = true;
32  boolean amalive = true;
33  public static JTable jtabshare;
36  private static String user = " ";
37  private static String pswd = " ";
38  private static String ip_server;
39 
40  // Lista dei file in share
41  public static Hashtable h = new Hashtable();
42 
43 
49  @SuppressWarnings("static-access")
50  public ClientFrame() {
52 
53  //Nascondo la colonna contenente l'id del file
54  TableColumn col = jTableShare1.getColumnModel().getColumn(5);
55  col.setMinWidth(0);
56  col.setMaxWidth(0);
57  col.setPreferredWidth(0);
58 
59  jFileChooser1.setControlButtonsAreShown(false);
60  jtabshare = jTableShare;
61  //Thread per attivare C2C_server
63  TRRF.dbg = true;
64  Thread tt = new Thread(TRRF);
65  tt.start();
66 
67  }
68 
73  @SuppressWarnings("unchecked")
74  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
75  private void initComponents() {
76 
77  jSeparator1 = new javax.swing.JSeparator();
78  jLabel1 = new javax.swing.JLabel();
79  jLabel2 = new javax.swing.JLabel();
80  jButton2 = new javax.swing.JButton();
81  jButton1 = new javax.swing.JButton();
82  jButton3 = new javax.swing.JButton();
83  jButton4 = new javax.swing.JButton();
84  jSeparator2 = new javax.swing.JSeparator();
85  jButton5 = new javax.swing.JButton();
86  jScrollPane3 = new javax.swing.JScrollPane();
87  jList1 = new javax.swing.JList();
88  jLabel3 = new javax.swing.JLabel();
89  jButton6 = new javax.swing.JButton();
90  jButton7 = new javax.swing.JButton();
91  jLabel4 = new javax.swing.JLabel();
92  jSeparator3 = new javax.swing.JSeparator();
93  jFileChooser1 = new javax.swing.JFileChooser(".");
94  jLabel5 = new javax.swing.JLabel();
95  jScrollPane2 = new javax.swing.JScrollPane();
96  jTableShare = new javax.swing.JTable();
97  jButton10 = new javax.swing.JButton();
98  jLabel7 = new javax.swing.JLabel();
99  jLabel8 = new javax.swing.JLabel();
100  jLabel9 = new javax.swing.JLabel();
101  jTextField1 = new javax.swing.JTextField();
102  jTextField2 = new javax.swing.JTextField();
103  jTextField4 = new javax.swing.JTextField();
104  jTextField5 = new javax.swing.JTextField();
105  jScrollPane4 = new javax.swing.JScrollPane();
106  jTableShare1 = new javax.swing.JTable();
107  jButton11 = new javax.swing.JButton();
108  jButton12 = new javax.swing.JButton();
109  jButton8 = new javax.swing.JButton();
110  jLabel6 = new javax.swing.JLabel();
111  jMenuBar1 = new javax.swing.JMenuBar();
112  jMenu1 = new javax.swing.JMenu();
113  jMenuItem1 = new javax.swing.JMenuItem();
114  jMenu2 = new javax.swing.JMenu();
115  jMenu3 = new javax.swing.JMenu();
116  jMenuItem6 = new javax.swing.JMenuItem();
117  jMenuItem8 = new javax.swing.JMenuItem();
118  jMenuItem7 = new javax.swing.JMenuItem();
119  jMenuItem11 = new javax.swing.JMenuItem();
120  jSeparator4 = new javax.swing.JSeparator();
121  jMenuItem2 = new javax.swing.JMenuItem();
122  jMenuItem3 = new javax.swing.JMenuItem();
123  jMenuItem9 = new javax.swing.JMenuItem();
124  jMenu4 = new javax.swing.JMenu();
125  jMenuItem4 = new javax.swing.JMenuItem();
126  jMenuItem10 = new javax.swing.JMenuItem();
127  jMenuItem5 = new javax.swing.JMenuItem();
128 
129  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
130  setTitle("P2PFileSystem - Client");
131  setName("ClientFrame"); // NOI18N
132  setResizable(false);
133  addWindowListener(new java.awt.event.WindowAdapter() {
134  public void windowClosing(java.awt.event.WindowEvent evt) {
135  formWindowClosing(evt);
136  }
137  });
138 
139  jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
140 
141  jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
142  jLabel1.setText("Distributed File System ");
143 
144  jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
145  jLabel2.setText("Local File System");
146 
147  jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Update_ico.png"))); // NOI18N
148  jButton2.setText("Update file list");
149  jButton2.addActionListener(new java.awt.event.ActionListener() {
150  public void actionPerformed(java.awt.event.ActionEvent evt) {
152  }
153  });
154 
155  jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/OpenFile_ico.png"))); // NOI18N
156  jButton1.setText("Open file");
157  jButton1.addActionListener(new java.awt.event.ActionListener() {
158  public void actionPerformed(java.awt.event.ActionEvent evt) {
160  }
161  });
162 
163  jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Add_ico.png"))); // NOI18N
164  jButton3.setText("Share file");
165  jButton3.setToolTipText("Share");
166  jButton3.addActionListener(new java.awt.event.ActionListener() {
167  public void actionPerformed(java.awt.event.ActionEvent evt) {
169  }
170  });
171 
172  jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Remove_ico.png"))); // NOI18N
173  jButton4.setText("Remove file");
174  jButton4.addActionListener(new java.awt.event.ActionListener() {
175  public void actionPerformed(java.awt.event.ActionEvent evt) {
177  }
178  });
179 
180  jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/LogOut_ico.png"))); // NOI18N
181  jButton5.setText("Log out");
182  jButton5.addActionListener(new java.awt.event.ActionListener() {
183  public void actionPerformed(java.awt.event.ActionEvent evt) {
185  }
186  });
187 
188  jList1.addMouseListener(new java.awt.event.MouseAdapter() {
189  public void mouseClicked(java.awt.event.MouseEvent evt) {
190  jList1MouseClicked(evt);
191  }
192  });
193  jScrollPane3.setViewportView(jList1);
194 
195  jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
196  jLabel3.setLabelFor(jList1);
197  jLabel3.setText("Server attivi:");
198 
199  jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Connect_ico.png"))); // NOI18N
200  jButton6.setText("Connect to server");
201  jButton6.addActionListener(new java.awt.event.ActionListener() {
202  public void actionPerformed(java.awt.event.ActionEvent evt) {
204  }
205  });
206 
207  jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Refresh_ico.png"))); // NOI18N
208  jButton7.setText("Update server list");
209  jButton7.addActionListener(new java.awt.event.ActionListener() {
210  public void actionPerformed(java.awt.event.ActionEvent evt) {
212  }
213  });
214 
215  jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12));
216  jLabel4.setForeground(new java.awt.Color(0, 51, 204));
217  jLabel4.setText("No Connection");
218 
219  jFileChooser1.setApproveButtonText("Share");
220  jFileChooser1.setApproveButtonToolTipText("Share");
221  jFileChooser1.setControlButtonsAreShown(false);
222  jFileChooser1.setDialogTitle("");
223  jFileChooser1.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG);
224  jFileChooser1.setFileHidingEnabled(false);
225  jFileChooser1.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
226 
227  jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12));
228  jLabel5.setText("Directories and files shared");
229 
230  jTableShare.setModel(new javax.swing.table.DefaultTableModel(
231  new Object [][] {
232 
233  },
234  new String [] {
235  "Name", "Path"
236  }
237  ) {
238  Class[] types = new Class [] {
239  java.lang.String.class, java.lang.String.class
240  };
241  boolean[] canEdit = new boolean [] {
242  false, false
243  };
244 
245  public Class getColumnClass(int columnIndex) {
246  return types [columnIndex];
247  }
248 
249  public boolean isCellEditable(int rowIndex, int columnIndex) {
250  return canEdit [columnIndex];
251  }
252  });
253  jTableShare.setMinimumSize(new java.awt.Dimension(5, 0));
254  jTableShare.setRequestFocusEnabled(false);
255  jTableShare.getTableHeader().setReorderingAllowed(false);
256  jScrollPane2.setViewportView(jTableShare);
257  jTableShare.getColumnModel().getColumn(0).setPreferredWidth(30);
258  jTableShare.getColumnModel().getColumn(1).setPreferredWidth(50);
259 
260  jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add_server.png"))); // NOI18N
261  jButton10.setText("Add server");
262  jButton10.addActionListener(new java.awt.event.ActionListener() {
263  public void actionPerformed(java.awt.event.ActionEvent evt) {
265  }
266  });
267 
268  jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14));
269  jLabel7.setText(".");
270 
271  jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14));
272  jLabel8.setText(".");
273 
274  jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14));
275  jLabel9.setText(".");
276 
277  jTableShare1.setModel(new javax.swing.table.DefaultTableModel(
278  new Object [][] {
279 
280  },
281  new String [] {
282  "Owner", "Path", "Name", "Rights", "Size", "id"
283  }
284  ) {
285  Class[] types = new Class [] {
286  java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
287  };
288  boolean[] canEdit = new boolean [] {
289  false, false, false, false, false, false
290  };
291 
292  public Class getColumnClass(int columnIndex) {
293  return types [columnIndex];
294  }
295 
296  public boolean isCellEditable(int rowIndex, int columnIndex) {
297  return canEdit [columnIndex];
298  }
299  });
300  jTableShare1.setMinimumSize(new java.awt.Dimension(5, 0));
301  jTableShare1.setRequestFocusEnabled(false);
302  jTableShare1.getTableHeader().setReorderingAllowed(false);
303  jScrollPane4.setViewportView(jTableShare1);
304 
305  jButton11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Up_ico.png"))); // NOI18N
306  jButton11.setText("Upload to client...");
307  jButton11.addActionListener(new java.awt.event.ActionListener() {
308  public void actionPerformed(java.awt.event.ActionEvent evt) {
310  }
311  });
312 
313  jButton12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete_ico.png"))); // NOI18N
314  jButton12.setText("Delete file");
315  jButton12.addActionListener(new java.awt.event.ActionListener() {
316  public void actionPerformed(java.awt.event.ActionEvent evt) {
318  }
319  });
320 
321  jButton8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/disconnectIcon.png"))); // NOI18N
322  jButton8.setText("Disconnect from server");
323  jButton8.addActionListener(new java.awt.event.ActionListener() {
324  public void actionPerformed(java.awt.event.ActionEvent evt) {
326  }
327  });
328 
329  jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/no_connection_ico.png"))); // NOI18N
330 
331  jMenu1.setText("File");
332 
333  jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/LogOut_ico.png"))); // NOI18N
334  jMenuItem1.setText("Log out");
335  jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
336  public void actionPerformed(java.awt.event.ActionEvent evt) {
338  }
339  });
340  jMenu1.add(jMenuItem1);
341 
342  jMenuBar1.add(jMenu1);
343 
344  jMenu2.setText("Action");
345 
346  jMenu3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/folder_distributed_ico.png"))); // NOI18N
347  jMenu3.setText("Distributed File System");
348 
349  jMenuItem6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Refresh_ico.png"))); // NOI18N
350  jMenuItem6.setText("Update server list");
351  jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
352  public void actionPerformed(java.awt.event.ActionEvent evt) {
354  }
355  });
356  jMenu3.add(jMenuItem6);
357 
358  jMenuItem8.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/add_server.png"))); // NOI18N
359  jMenuItem8.setText("Add server");
360  jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
361  public void actionPerformed(java.awt.event.ActionEvent evt) {
363  }
364  });
365  jMenu3.add(jMenuItem8);
366 
367  jMenuItem7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Connect_ico.png"))); // NOI18N
368  jMenuItem7.setText("Connect to server");
369  jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
370  public void actionPerformed(java.awt.event.ActionEvent evt) {
372  }
373  });
374  jMenu3.add(jMenuItem7);
375 
376  jMenuItem11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/disconnectIcon.png"))); // NOI18N
377  jMenuItem11.setText("Disconnect from server");
378  jMenuItem11.addActionListener(new java.awt.event.ActionListener() {
379  public void actionPerformed(java.awt.event.ActionEvent evt) {
381  }
382  });
383  jMenu3.add(jMenuItem11);
384  jMenu3.add(jSeparator4);
385 
386  jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Update_ico.png"))); // NOI18N
387  jMenuItem2.setText("Update file list");
388  jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
389  public void actionPerformed(java.awt.event.ActionEvent evt) {
391  }
392  });
393  jMenu3.add(jMenuItem2);
394 
395  jMenuItem3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/OpenFile_ico.png"))); // NOI18N
396  jMenuItem3.setText("Open file");
397  jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
398  public void actionPerformed(java.awt.event.ActionEvent evt) {
400  }
401  });
402  jMenu3.add(jMenuItem3);
403 
404  jMenuItem9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/delete_ico.png"))); // NOI18N
405  jMenuItem9.setText("Delete file");
406  jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
407  public void actionPerformed(java.awt.event.ActionEvent evt) {
409  }
410  });
411  jMenu3.add(jMenuItem9);
412 
413  jMenu2.add(jMenu3);
414 
415  jMenu4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/folder_local_ico.png"))); // NOI18N
416  jMenu4.setText("Local File System");
417 
418  jMenuItem4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Add_ico.png"))); // NOI18N
419  jMenuItem4.setText("Share file");
420  jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
421  public void actionPerformed(java.awt.event.ActionEvent evt) {
423  }
424  });
425  jMenu4.add(jMenuItem4);
426 
427  jMenuItem10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Up_ico.png"))); // NOI18N
428  jMenuItem10.setText("Upload to client...");
429  jMenuItem10.addActionListener(new java.awt.event.ActionListener() {
430  public void actionPerformed(java.awt.event.ActionEvent evt) {
432  }
433  });
434  jMenu4.add(jMenuItem10);
435 
436  jMenuItem5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/Remove_ico.png"))); // NOI18N
437  jMenuItem5.setText("Remove file");
438  jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
439  public void actionPerformed(java.awt.event.ActionEvent evt) {
441  }
442  });
443  jMenu4.add(jMenuItem5);
444 
445  jMenu2.add(jMenu4);
446 
447  jMenuBar1.add(jMenu2);
448 
449  setJMenuBar(jMenuBar1);
450 
451  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
452  getContentPane().setLayout(layout);
453  layout.setHorizontalGroup(
454  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
455  .addGroup(layout.createSequentialGroup()
456  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
457  .addGroup(layout.createSequentialGroup()
458  .addContainerGap()
459  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
460  .addGroup(layout.createSequentialGroup()
461  .addComponent(jLabel3)
462  .addGap(285, 285, 285))
463  .addComponent(jLabel1)
464  .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 556, Short.MAX_VALUE)
465  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
466  .addGroup(layout.createSequentialGroup()
467  .addComponent(jButton2)
468  .addGap(31, 31, 31)
469  .addComponent(jButton1)
470  .addGap(26, 26, 26)
471  .addComponent(jButton12))
472  .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 503, javax.swing.GroupLayout.PREFERRED_SIZE))
473  .addGroup(layout.createSequentialGroup()
474  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
475  .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
476  .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 152, javax.swing.GroupLayout.PREFERRED_SIZE)
477  .addGap(34, 34, 34)
478  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
479  .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 170, Short.MAX_VALUE)
480  .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
481  .addGroup(layout.createSequentialGroup()
482  .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
483  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
484  .addComponent(jLabel7)
485  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
486  .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
487  .addGap(2, 2, 2)
488  .addComponent(jLabel8)
489  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
490  .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
491  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
492  .addComponent(jLabel9)
493  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
494  .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
495  .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
496  .addGap(50, 50, 50)
497  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
498  .addComponent(jLabel6)
499  .addComponent(jButton10)))
500  .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 412, javax.swing.GroupLayout.PREFERRED_SIZE))
501  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)))
502  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
503  .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)
504  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
505  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
506  .addGroup(layout.createSequentialGroup()
507  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
508  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
509  .addComponent(jFileChooser1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 464, javax.swing.GroupLayout.PREFERRED_SIZE)
510  .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)))
511  .addGroup(layout.createSequentialGroup()
512  .addGap(21, 21, 21)
513  .addComponent(jLabel5))
514  .addGroup(layout.createSequentialGroup()
515  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
516  .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 460, Short.MAX_VALUE))
517  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
518  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
519  .addComponent(jButton3)
520  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
521  .addComponent(jButton11)
522  .addGap(12, 12, 12)))
523  .addGroup(layout.createSequentialGroup()
524  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
525  .addComponent(jButton4))))
526  .addComponent(jButton5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
527  .addGroup(layout.createSequentialGroup()
528  .addContainerGap()
529  .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 1047, Short.MAX_VALUE)))
530  .addContainerGap())
531  );
532  layout.setVerticalGroup(
533  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
534  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
535  .addContainerGap()
536  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
537  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
538  .addComponent(jLabel1)
539  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
540  .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE)
541  .addGap(22, 22, 22)
542  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
543  .addComponent(jButton12)
544  .addComponent(jButton1)
545  .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
546  .addGap(18, 18, 18)
547  .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
548  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
549  .addComponent(jLabel3)
550  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
551  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
552  .addGroup(layout.createSequentialGroup()
553  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
554  .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
555  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
556  .addComponent(jLabel8)
557  .addGroup(layout.createSequentialGroup()
558  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
559  .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
560  .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
561  .addGap(4, 4, 4)))
562  .addGroup(layout.createSequentialGroup()
563  .addGap(10, 10, 10)
564  .addComponent(jLabel7))
565  .addGroup(layout.createSequentialGroup()
566  .addGap(10, 10, 10)
567  .addComponent(jLabel9))
568  .addComponent(jButton10)
569  .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
570  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
571  .addGroup(layout.createSequentialGroup()
572  .addGap(6, 6, 6)
573  .addComponent(jButton7)
574  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
575  .addComponent(jButton6)
576  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
577  .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 33, Short.MAX_VALUE))
578  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
579  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
580  .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
581  .addGap(22, 22, 22))))
582  .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE))
583  .addGap(23, 23, 23)
584  .addComponent(jLabel4))
585  .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 598, javax.swing.GroupLayout.PREFERRED_SIZE)
586  .addGroup(layout.createSequentialGroup()
587  .addComponent(jLabel2)
588  .addGap(8, 8, 8)
589  .addComponent(jFileChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)
590  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
591  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
592  .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
593  .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
594  .addGap(18, 18, 18)
595  .addComponent(jLabel5)
596  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
597  .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
598  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
599  .addComponent(jButton4)))
600  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
601  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 13, javax.swing.GroupLayout.PREFERRED_SIZE)
602  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
603  .addComponent(jButton5)
604  .addContainerGap())
605  );
606 
607  pack();
608  }// </editor-fold>//GEN-END:initComponents
609 
615  private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
616  LogOutFrameClient l = new LogOutFrameClient(new javax.swing.JFrame(), true);
617  l.setLocationRelativeTo(null);
618  l.setVisible(true);
619 }//GEN-LAST:event_jButton5ActionPerformed
620 
626  private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
627  LogOutFrameClient l = new LogOutFrameClient(new javax.swing.JFrame(), true);
628  l.setLocationRelativeTo(null);
629  l.setVisible(true);
630  }//GEN-LAST:event_jMenuItem1ActionPerformed
631 
637  private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
638  serveron = isServerOn(false);
639  amalive = amAlive(false);
640 
641  if((id_user!=-1) && (serveron) && (amalive))
642  if( (user.compareTo(" ")!=0) && (pswd.compareTo(" ")!=0) )
643  {
644  javax.swing.JOptionPane.showMessageDialog(null, "Warning: connection with server "+ ip_server+" already active.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
645  return;
646  }
647  if((!serveron) || (!amalive))
649 
650  serverSelected();
651  }//GEN-LAST:event_jButton6ActionPerformed
652 
658  private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
660  setServerInList();
661  }//GEN-LAST:event_jButton7ActionPerformed
662 
668  private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
670  setServerInList();
671  }//GEN-LAST:event_jMenuItem6ActionPerformed
672 
678  private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
679  serveron = isServerOn(false);
680  amalive = amAlive(false);
681  if((id_user!=-1) && (serveron) && (amalive))
682  if( (user.compareTo(" ")!=0) && (pswd.compareTo(" ")!=0) )
683  {
684  javax.swing.JOptionPane.showMessageDialog(null, "Warning: connection with server "+ ip_server+" already active.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
685  return;
686  }
687  if((!serveron) || (!amalive))
689 
690  serverSelected();
691  }//GEN-LAST:event_jMenuItem7ActionPerformed
692 
698  private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
699  if(id_user==-1){
700  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
701  return;
702  }
703  if((!isServerOn(true)) || (!amAlive(true))){
705  return;
706  }
707 
708 
710  }//GEN-LAST:event_jButton3ActionPerformed
711 
718  private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
719  if(id_user==-1){
720  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
721  return;
722  }
723  if((!isServerOn(true)) || (!amAlive(true))){
725  return;
726  }
727 
728  fileOpenRead();
729  }//GEN-LAST:event_jButton1ActionPerformed
730 
731 
736  private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
737  if (evt.getClickCount() != 2)
738  return;
739 
740  serveron = isServerOn(false);
741  amalive = amAlive(false);
742  if((id_user!=-1) && (serveron) && (amalive))
743  if( (user.compareTo(" ")!=0) && (pswd.compareTo(" ")!=0) )
744  {
745  javax.swing.JOptionPane.showMessageDialog(null, "Warning: connection with server "+ ip_server+" already active.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
746  return;
747  }
748  if((!serveron) || (!amalive))
750 
751  serverSelected();
752  }//GEN-LAST:event_jList1MouseClicked
753 
760  private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
761  if(id_user==-1){
762  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
763  return;
764  }
765  if((!isServerOn(true)) || (!amAlive(true))){
767  return;
768  }
769 
770  fileOpenRead();
771  }//GEN-LAST:event_jMenuItem3ActionPerformed
772 
778  private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
779  if(id_user==-1){
780  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
781  return;
782  }
783  if((!isServerOn(true)) || (!amAlive(true))){
785  return;
786  }
788  }//GEN-LAST:event_jMenuItem4ActionPerformed
789 
796  private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
797  if(id_user==-1){
798  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
799  return;
800  }
801  if((!isServerOn(true)) || (!amAlive(true))){
803  return;
804  }
806  }//GEN-LAST:event_jButton4ActionPerformed
807 
814  private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
815  if(id_user==-1){
816  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
817  return;
818  }
819  if((!isServerOn(true)) || (!amAlive(true))){
821  return;
822  }
824  }//GEN-LAST:event_jMenuItem5ActionPerformed
825 
831  private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
832  addServer();
833  }//GEN-LAST:event_jButton10ActionPerformed
834 
840  private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
842  jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource(p2putility.Config.r_ico_server_disable())));
843 
844  Frame[] f = Frame.getFrames();
845  Config.w_clientOpen(false);
846  for(int i =0; i< f.length; i++){
847  if(((f[i].getName()).equals("MainFrame")&&(!f[i].isVisible()))&&(!Config.r_serverOpen()))
848  System.exit(0);
849  }
850 
851  }//GEN-LAST:event_formWindowClosing
852 
859  private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
860  if(id_user==-1){
861  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
862  return;
863  }
864  if((!isServerOn(true)) || (!amAlive(true))){
866  return;
867  }
868 
869  updateFileList();
870  }//GEN-LAST:event_jButton2ActionPerformed
871 
877  private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
878  if(id_user==-1){
879  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
880  return;
881  }
882  if((!isServerOn(true)) || (!amAlive(true))){
884  return;
885  }
886  uploadFile();
887  }//GEN-LAST:event_jButton11ActionPerformed
888 
894  private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
895  if(id_user==-1){
896  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
897  return;
898  }
899  if((!isServerOn(true)) || (!amAlive(true))){
901  return;
902  }
903  deleteFile();
904  }//GEN-LAST:event_jButton12ActionPerformed
905 
911  private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
912  addServer();
913  }//GEN-LAST:event_jMenuItem8ActionPerformed
914 
921  private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
922  if(id_user==-1){
923  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
924  return;
925  }
926  if((!isServerOn(true)) || (!amAlive(true))){
928  return;
929  }
930 
931  updateFileList();
932  }//GEN-LAST:event_jMenuItem2ActionPerformed
933 
939  private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
940  if(id_user==-1){
941  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
942  return;
943  }
944  if((!isServerOn(true)) || (!amAlive(true))){
945  jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource(p2putility.Config.r_ico_server_disable())));
946  return;
947  }
948  deleteFile();
949  }//GEN-LAST:event_jMenuItem9ActionPerformed
950 
956  private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem10ActionPerformed
957  if(id_user==-1){
958  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
959  return;
960  }
961  if((!isServerOn(true)) || (!amAlive(true))){
963  return;
964  }
965  uploadFile();
966  }//GEN-LAST:event_jMenuItem10ActionPerformed
967 
973  private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
974  if(id_user==-1){
975  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
976  return;
977  }
978  if((isServerOn(false)) && (amAlive(false))){
981  return;
982  }
983 
984  }//GEN-LAST:event_jButton8ActionPerformed
985 
991  private void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem11ActionPerformed
992  if(id_user==-1){
993  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no active connection.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
994  return;
995  }
996  if((isServerOn(false)) && (amAlive(false))){
999  return;
1000  }
1001  }//GEN-LAST:event_jMenuItem11ActionPerformed
1002 
1003 
1004  // Variables declaration - do not modify//GEN-BEGIN:variables
1005  private javax.swing.JButton jButton1;
1006  private javax.swing.JButton jButton10;
1007  private javax.swing.JButton jButton11;
1008  private javax.swing.JButton jButton12;
1009  private javax.swing.JButton jButton2;
1010  private javax.swing.JButton jButton3;
1011  private javax.swing.JButton jButton4;
1012  private javax.swing.JButton jButton5;
1013  private javax.swing.JButton jButton6;
1014  private javax.swing.JButton jButton7;
1015  private javax.swing.JButton jButton8;
1016  private javax.swing.JFileChooser jFileChooser1;
1017  private javax.swing.JLabel jLabel1;
1018  private javax.swing.JLabel jLabel2;
1019  private javax.swing.JLabel jLabel3;
1020  public static javax.swing.JLabel jLabel4;
1021  private javax.swing.JLabel jLabel5;
1022  private javax.swing.JLabel jLabel6;
1023  private javax.swing.JLabel jLabel7;
1024  private javax.swing.JLabel jLabel8;
1025  private javax.swing.JLabel jLabel9;
1026  private javax.swing.JList jList1;
1027  private javax.swing.JMenu jMenu1;
1028  private javax.swing.JMenu jMenu2;
1029  private javax.swing.JMenu jMenu3;
1030  private javax.swing.JMenu jMenu4;
1031  private javax.swing.JMenuBar jMenuBar1;
1032  private javax.swing.JMenuItem jMenuItem1;
1033  private javax.swing.JMenuItem jMenuItem10;
1034  private javax.swing.JMenuItem jMenuItem11;
1035  private javax.swing.JMenuItem jMenuItem2;
1036  private javax.swing.JMenuItem jMenuItem3;
1037  private javax.swing.JMenuItem jMenuItem4;
1038  private javax.swing.JMenuItem jMenuItem5;
1039  private javax.swing.JMenuItem jMenuItem6;
1040  private javax.swing.JMenuItem jMenuItem7;
1041  private javax.swing.JMenuItem jMenuItem8;
1042  private javax.swing.JMenuItem jMenuItem9;
1043  private javax.swing.JScrollPane jScrollPane2;
1044  private javax.swing.JScrollPane jScrollPane3;
1045  private javax.swing.JScrollPane jScrollPane4;
1046  private javax.swing.JSeparator jSeparator1;
1047  private javax.swing.JSeparator jSeparator2;
1048  private javax.swing.JSeparator jSeparator3;
1049  private javax.swing.JSeparator jSeparator4;
1050  private javax.swing.JTable jTableShare;
1051  private javax.swing.JTable jTableShare1;
1052  private javax.swing.JTextField jTextField1;
1053  private javax.swing.JTextField jTextField2;
1054  private javax.swing.JTextField jTextField4;
1055  private javax.swing.JTextField jTextField5;
1056  // End of variables declaration//GEN-END:variables
1057 
1058 
1066  public void addServer(){
1067  if(jTextField1.getText().isEmpty()||jTextField4.getText().isEmpty()
1068  ||jTextField5.getText().isEmpty()|| jTextField2.getText().isEmpty()){
1069  javax.swing.JOptionPane.showMessageDialog(null, "Ip address not valid. Text box empty.", "Error", 0);
1070  return;
1071  }
1072 
1073  int ip1, ip2, ip3, ip4;
1074  try{
1075  ip1 = Integer.parseInt(jTextField1.getText());
1076  ip2 = Integer.parseInt(jTextField2.getText());
1077  ip3 = Integer.parseInt(jTextField4.getText());
1078  ip4 = Integer.parseInt(jTextField5.getText());
1079  }
1080  catch(Exception ex) {
1081  javax.swing.JOptionPane.showMessageDialog(null, "Ip address not valid.", "Error", 0);
1082  return;
1083  }
1084  if((ip1<0)||(ip1>255)||(ip2<0)||(ip2>255)||(ip3<0)||(ip3>255)||(ip4<0)||(ip4>255)){
1085  javax.swing.JOptionPane.showMessageDialog(null, "Ip address not valid.", "Error", 0);
1086  return;
1087  }
1088 
1089  String server_ip [] = new String[1];
1090  server_ip[0] = ip1+"."+ip2+"."+ip3+"."+ip4;
1091  jList1.setListData(server_ip);
1092  jTextField1.setText("");
1093  jTextField4.setText("");
1094  jTextField5.setText("");
1095  jTextField2.setText("");
1096  }
1097 
1103  @SuppressWarnings("static-access")
1104  public void updateFileList(){
1105  p2pclient.clientRMI.where = "";
1107  TRC.user = user;
1108  TRC.pswd = pswd;
1109  TRC.dbg = true;
1110  TRC.funct = "getList";
1111 
1112  Thread t = new Thread(TRC);
1113  t.start();
1114  try {
1115  //Attendi finche' non viene aggiornato il risultato
1116  t.join(p2putility.Config.r_threadtimeout()*3);
1117  } catch (InterruptedException ex) {
1118  return;
1119  }
1120  ArrayList l = null;
1121  l = p2pclient.clientRMI.list;
1122  if(l==null){
1123  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no connection with server", "Warning",javax.swing.JOptionPane.WARNING_MESSAGE );
1124  return;
1125  }
1126  p2putility.Util.logGeneric("DEBUG: "+l);
1127  int num_row = -1;
1128  DefaultTableModel model = (DefaultTableModel) jTableShare1.getModel();
1129 
1130  while(model.getRowCount()>0){
1131  model.removeRow(0);
1132  num_row ++;
1133  }
1134  if(num_row>0)
1135  model.fireTableRowsDeleted(0, num_row);
1136 
1137  //for(int i=0; i<model.getRowCount(); i++)
1138  // model.removeRow(i);
1139 
1140  if(l.isEmpty())
1141  return;
1142 
1143  String [] cols = new String [6];
1144  for(int i=0;i<l.size();i++)
1145  {
1146  ArrayList ll = (ArrayList)l.get(i);
1147  cols[0] = ll.get(3).toString();
1148  cols[1] = ll.get(2).toString();
1149  cols[2] = ll.get(1).toString();
1150  cols[3] = ll.get(7).toString();
1151  cols[4] = ll.get(5).toString();
1152  cols[5] = ll.get(0).toString();
1153  model.addRow(cols);
1154  }
1155  model.fireTableRowsInserted(0, l.size()-1);
1156  }
1157 
1162  public void setServerInList(){
1163  try{
1167  true);
1168  if(ip.size()==0){
1169  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no server available", "Warning",javax.swing.JOptionPane.WARNING_MESSAGE );
1170  return;
1171  }
1172  String server[] = new String[ip.size()];
1173 
1174  for(int i=0; !ip.isEmpty(); i++){
1175  server[i]=ip.get(i).toString();
1176  ip.remove(i);
1177  }
1178 
1179  jList1.removeAll();
1180  jList1.setListData(server);
1181  }
1182  catch (IOException ex){
1183  p2putility.Util.logClient("setServerInList error:\n"+ex);
1184  }
1185  }
1186 
1192  @SuppressWarnings("static-access")
1193  private void serverSelected(){
1194  String server = new String("");
1195  try{
1196  server = (jList1.getSelectedValue().toString().replaceAll(" ", ""));
1197  if(server.equals(""))
1198  jLabel4.setText("No server selected");
1199  else {
1200  //Connessione
1201 
1202  javax.swing.JLabel label1 = new javax.swing.JLabel("Insert username:");
1203  javax.swing.JTextField juf = new javax.swing.JTextField();
1204  javax.swing.JLabel label2 = new javax.swing.JLabel("Insert password:");
1205  javax.swing.JPasswordField jpf = new javax.swing.JPasswordField();
1206  javax.swing.JOptionPane.showConfirmDialog(null,new Object[]{label1,juf , label2, jpf}, "Password:", javax.swing.JOptionPane.OK_CANCEL_OPTION,1);
1207 
1208  //Thread per attivare ServerRMI
1210  pswd = p2putility.Util.hash_sha(jpf.getText());
1211  TRC.pswd = pswd;
1212  user = juf.getText();
1213  TRC.user = user;
1214  jpf.setText("*****");
1215 
1216  TRC.dbg = true;
1217  TRC.ip = server;
1218  TRC.funct = "registerToServer";
1219  Thread t = new Thread(TRC);
1220  t.start();
1221  try {
1222  //Attendi finche' non viene aggiornato il risultato
1223  t.join(p2putility.Config.r_threadtimeout());
1224  } catch (InterruptedException ex) {
1225  return;
1226  }
1227  if(p2pclient.clientRMI.id_user==-1){
1228  user = " ";
1229  pswd = " ";
1230  javax.swing.JOptionPane.showMessageDialog(null, "ID or PASSWORD not valid", "Error", 0);
1231  p2putility.Util.logGeneric("USERNAME or PASSWORD not valid");
1232  }
1233  else{
1234  id_user = p2pclient.clientRMI.id_user;
1235  ip_server = server;
1236  jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource(p2putility.Config.r_ico_server_enable())));
1237  }
1238 
1239 
1240  }
1241  }
1242  catch(Exception e)
1243  {p2putility.Util.logGeneric("Non e' stato selezionato nessun server a cui connettersi");}
1244 
1245 
1246  }
1247 
1253  @SuppressWarnings("static-access")
1254  private void fileOpenRead(){
1255  if(jTableShare1.getSelectedRow()!=-1 && jTableShare1.getRowCount()>0){
1256  int indexToOpen = jTableShare1.getSelectedRow();
1257  DefaultTableModel model = (DefaultTableModel) jTableShare1.getModel();
1258  p2putility.Util.logGeneric("File alla riga "+indexToOpen);
1259 
1260  String id_owner = model.getValueAt(indexToOpen, 0).toString();
1261  String id_file = model.getValueAt(indexToOpen, 5).toString();
1262  String path_file = model.getValueAt(indexToOpen, 1).toString();
1263  String name_file = model.getValueAt(indexToOpen, 2).toString();
1264  //String rights = model.getValueAt(indexToOpen, 3).toString();
1265  //String size = model.getValueAt(indexToOpen, 4).toString();
1266 
1267  String accessString = "-1";
1269  TRC.user = user;
1270  TRC.pswd = pswd;
1271  TRC.dbg = true;
1272  TRC.funct = "getAccessStringRead";
1273  p2pclient.clientRMI.id_owner = id_owner;
1274  p2pclient.clientRMI.id_file = id_file;
1275  Thread t = new Thread(TRC);
1276  t.start();
1277 
1278  //Attendi finche' non viene aggiornato il risultato
1279  try {
1280  //Attendi finche' non viene aggiornato il risultato
1281  t.join(p2putility.Config.r_threadtimeout());
1282  } catch (InterruptedException ex) {
1283  return;
1284  }
1285  accessString = p2pclient.clientRMI.accessString;
1286 
1287  if( (accessString==null) || (!accessString.contains((CharSequence)";")) ){
1288  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: generic error", "Access deny",0 );
1289  p2putility.Util.logGeneric("generic error...accesso non fattibile");
1290  return ;
1291  }
1292 
1293  if(accessString.equals("-2")){
1294  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: wrong id or password", "Access deny",0 );
1295  p2putility.Util.logGeneric("Id o pswd errati...accesso non fattibile");
1296  return ;
1297  }
1298 
1299  if(accessString.equals("-4")){
1300  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: no rights to open the file", "Access deny",0 );
1301  p2putility.Util.logGeneric("Access deny: no rights to open the file");
1302  return ;
1303  }
1304 
1305  if(accessString.equals("-3")){
1306  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: impossible to open a file in writing", "Access deny",0 );
1307  p2putility.Util.logGeneric("Impossible to open a file in writing");
1308  return ;
1309  }
1310 
1311  String k_to_connect = user + id_file;
1312  String ip_to_connect = accessString.substring(0, accessString.indexOf(';'));
1313  String v_to_connect = accessString.substring(accessString.indexOf(';')+1, accessString.length());
1314 
1316  TRF.server_ip = ip_to_connect;
1317  TRF.name = name_file;
1318  TRF.path = path_file.replace("//", "////");
1319  TRF.user = k_to_connect;
1320  TRF.pswd = v_to_connect;
1321  TRF.function = "getFile";
1322  Thread t2 = new Thread (TRF);
1323  t2.start();
1324  if(DBG) p2putility.Util.logGeneric("Thread getFile attivato.");
1325  }
1326 
1327  }
1328 
1329 
1336  @SuppressWarnings("static-access")
1337  private void deleteFile(){
1338  if(jTableShare1.getSelectedRow()!=-1 && jTableShare1.getRowCount()>0){
1339  int indexToDelete = jTableShare1.getSelectedRow();
1340  DefaultTableModel model = (DefaultTableModel) jTableShare1.getModel();
1341  p2putility.Util.logGeneric("File alla riga "+indexToDelete);
1342 
1343  String rights = model.getValueAt(indexToDelete, 3).toString();
1344  if(!rights.equals("2")){
1345  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: impossible to delete the selected file", "Access deny",0 );
1346  return;
1347  }
1348 
1349  String id_owner = model.getValueAt(indexToDelete, 0).toString();
1350  String id_file = model.getValueAt(indexToDelete, 5).toString();
1351  String path_file = model.getValueAt(indexToDelete, 1).toString();
1352  String name_file = model.getValueAt(indexToDelete, 2).toString();
1353  String size = model.getValueAt(indexToDelete, 4).toString();
1354 
1355  //Richiedo al ServerRMI la stringa d'accesso x cancellare il file
1356  String accessString = "-1";
1357 
1359  TRC.user = user;
1360  TRC.pswd = pswd;
1361  TRC.dbg = true;
1362  TRC.funct = "getAccessStringDelete";
1363  p2pclient.clientRMI.id_owner = id_owner;
1364  p2pclient.clientRMI.id_file = id_file;
1365  Thread t = new Thread(TRC);
1366  t.start();
1367  try {
1368  //Attendi finche' non viene aggiornato il risultato
1369  t.join(p2putility.Config.r_threadtimeout());
1370  } catch (InterruptedException ex) {
1371  return;
1372  }
1373  accessString = p2pclient.clientRMI.accessString;
1374 
1375  if( (accessString==null) || (!accessString.contains((CharSequence)";")) ){
1376  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: generic error", "Access deny",0 );
1377  p2putility.Util.logGeneric("generic error...accesso non fattibile");
1378  return ;
1379  }
1380 
1381  if(accessString.equals("-2")){
1382  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: id or password aren't correct", "Access deny",0 );
1383  return ;
1384  }
1385 
1386  if(accessString.equals("-4")){
1387  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: no rights to delete the file", "Access deny",0 );
1388  return ;
1389  }
1390 
1391  if(accessString.equals("-3")){
1392  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: impossible to delete a file in writing", "Access deny",0 );
1393  return;
1394  }
1395 
1396  if(accessString.equals("-5")){
1397  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: impossible to delete a file in reading", "Access deny",0 );
1398  return;
1399  }
1400 
1401  String k_to_connect = user + id_file;
1402  String ip_to_connect = accessString.substring(0, accessString.indexOf(';'));
1403  String v_to_connect = accessString.substring(accessString.indexOf(';')+1, accessString.length());
1404 
1406  TRF.server_ip = ip_to_connect;
1407  TRF.name = name_file;
1408  TRF.path = path_file.replace("\\", "\\\\");
1409  TRF.user = k_to_connect;
1410  TRF.pswd = v_to_connect;
1411  TRF.function = "deleteFile";
1412  Thread t2 = new Thread (TRF);
1413  t2.start();
1414 
1415  try {
1416  //Attendi finche' non viene aggiornato il risultato
1417  t2.join(p2putility.Config.r_threadtimeout());
1418  } catch (InterruptedException ex) {
1419  return;
1420  }
1421 
1423  TRCC.user = user;
1424  TRCC.pswd = pswd;
1425  TRCC.dbg = true;
1426  TRCC.funct = "removeFile";
1427  p2pclient.clientRMI.name_file = name_file;
1428  p2pclient.clientRMI.path_file = path_file.replace("\\", "\\\\");
1429  Thread tt = new Thread(TRCC);
1430  tt.start();
1431 
1432  try {
1433  //Attendi finche' non viene aggiornato il risultato
1434  tt.join(p2putility.Config.r_threadtimeout());
1435  } catch (InterruptedException ex) {
1436  return;
1437  }
1438 
1439  model.removeRow(indexToDelete);
1440 
1441  model.fireTableRowsDeleted(indexToDelete, indexToDelete);
1442  //model.setNumRows(model.getRowCount()-1);
1443 
1444 
1445  DefaultTableModel model2 = (DefaultTableModel) jTableShare.getModel();
1446  for(int i=0; i< model2.getRowCount(); i++){
1447  if(DBG) p2putility.Util.logGeneric(i+") "+model2.getValueAt(i, 0).toString()+" "+name_file);
1448  if(DBG) p2putility.Util.logGeneric(" "+model2.getValueAt(i, 1).toString()+" "+path_file);
1449  if((model2.getValueAt(i, 0).toString().compareTo(name_file)==0 )&& (model2.getValueAt(i, 1).toString().compareTo(path_file)==0)){
1450  model2.removeRow(i);
1451  model2.fireTableRowsDeleted(i, i);
1452  break;
1453  }
1454 
1455 
1456  }
1457 
1458  }
1459  }
1460 
1467  @SuppressWarnings("static-access")
1468  private void uploadFile() {
1469 
1470  File f = jFileChooser1.getSelectedFile();
1471  if(f==null) return;
1472  if(f.isDirectory()){
1473  jFileChooser1.setCurrentDirectory(f);
1474  return;
1475  }
1476 
1477  p2pclient.clientRMI.where = "";
1479  TRC.user = user;
1480  TRC.pswd = pswd;
1481  TRC.dbg = true;
1482  TRC.funct = "getUserList";
1483 
1484  Thread t = new Thread(TRC);
1485  t.start();
1486  try {
1487  //Attendi finche' non viene aggiornato il risultato
1488  t.join(p2putility.Config.r_threadtimeout()*3);
1489  } catch (InterruptedException ex) {
1490  return;
1491  }
1492  ArrayList l = null;
1493  l = p2pclient.clientRMI.list;
1494  if(l==null){
1495  javax.swing.JOptionPane.showMessageDialog(null, "Warning: no client available.", "Warning",javax.swing.JOptionPane.WARNING_MESSAGE );
1496  return;
1497  }
1498 
1499  Object o [] = new Object[l.size()];
1500 
1501  for(int i=0; i<l.size(); i++)
1502  o[i] = ((ArrayList)l.get(i)).get(2);
1503 
1504  javax.swing.JLabel label1 = new javax.swing.JLabel("Select CLIENT:");
1505  javax.swing.JComboBox clist = new javax.swing.JComboBox(o);
1506  int r = javax.swing.JOptionPane.showConfirmDialog(null,new Object[]{label1,clist}, "Upload to client...", javax.swing.JOptionPane.OK_CANCEL_OPTION, 1);
1507 
1508  if(r != javax.swing.JOptionPane.OK_OPTION)
1509  return;
1510  int ind = clist.getSelectedIndex();
1511  String ip_client =((ArrayList)l.get(ind)).get(1).toString();
1512 
1513 
1514  String accessString = "-1";
1516  TRCC.user = user;
1517  TRCC.pswd = pswd;
1518  TRCC.dbg = true;
1519  TRCC.funct = "getAccessStringUpload";
1520  p2pclient.clientRMI.id_file = f.getAbsolutePath();
1521  p2pclient.clientRMI.id_owner = ((ArrayList)l.get(ind)).get(0).toString();
1522  Thread tt = new Thread(TRCC);
1523  tt.start();
1524 
1525  //Attendi finche' non viene aggiornato il risultato
1526  try {
1527  //Attendi finche' non viene aggiornato il risultato
1528  tt.join(p2putility.Config.r_threadtimeout());
1529  } catch (InterruptedException ex) {
1530  return;
1531  }
1532  accessString = p2pclient.clientRMI.accessString;
1533 
1534  if( accessString==null ){
1535  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: generic error", "Access deny",0 );
1536  p2putility.Util.logGeneric("generic error...accesso non fattibile");
1537  return ;
1538  }
1539 
1540  if(accessString.equals("-2")){
1541  javax.swing.JOptionPane.showMessageDialog(null, "Access deny: id or password aren't correct", "Access deny",0 );
1542  p2putility.Util.logGeneric("Id o pswd errati...accesso non fattibile");
1543  return ;
1544  }
1545 
1547  TRF.server_ip = ip_client;
1548  TRF.name = f.getName();
1549  TRF.path = f.getAbsolutePath().substring(0, f.getAbsolutePath().length()-f.getName().length());
1550  TRF.user = user + p2putility.Util.hash_sha(f.getAbsolutePath()); //k_to_connect
1551  TRF.pswd = accessString; //v_to_connect
1552  TRF.function = "sendFile";
1553  Thread t2 = new Thread (TRF);
1554  t2.start();
1555 
1556  }
1557 
1558 
1564  @SuppressWarnings("static-access")
1566  File f =jFileChooser1.getSelectedFile();
1567 
1568  if(f==null) return;
1569  if(f.isDirectory()){
1570  jFileChooser1.setCurrentDirectory(f);
1571  return;
1572  }
1573 
1574  Rights r = new Rights(new javax.swing.JFrame(), true);
1575  r.setLocationRelativeTo(null);
1576  r.setVisible(true);
1577 
1578  String path = f.getAbsolutePath();
1579 
1580  // Il file esiste gia' nella tabella
1581  if(h.containsKey(path)){
1582  javax.swing.JOptionPane.showMessageDialog(null, "Warning: selected file already shared.", "Warning", javax.swing.JOptionPane.WARNING_MESSAGE);
1583  return;
1584  }
1585 
1586  h.put(path,"");
1587 
1588  path = path.substring(0, path.length()-f.getName().length());
1589  path = path.replace("\\", "\\\\");
1590 
1591  int permission = booleanToRight(p2pgui.Rights.read, p2pgui.Rights.write);
1592  long length = f.length();
1593  java.util.Date date = new java.util.Date(f.lastModified());
1594  DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
1595 
1596  ArrayList l2 = new ArrayList();
1597  l2.add(h.size()-1);
1598  l2.add(f.getName());
1599  l2.add(path);
1600  l2.add(id_user);
1601  l2.add(f.isDirectory());
1602  l2.add(length);
1603  l2.add(df.format(date));
1604  l2.add(permission);
1605  l2.add(0);
1606  ArrayList l1 = new ArrayList();
1607  l1.add(0,l2);
1608 
1609  p2pclient.clientRMI.list = l1;
1610 
1612  TRC.user = user;
1613  TRC.pswd = pswd;
1614  TRC.funct = "sendList";
1615  Thread t = new Thread(TRC);
1616  t.start();
1617 
1618  String [] cols = new String [2];
1619  DefaultTableModel model = (DefaultTableModel) jTableShare.getModel();
1620  cols[0] = f.getName();
1621  cols[1] = f.getAbsolutePath().substring(0, f.getAbsolutePath().length()-cols[0].length());
1622  model.addRow(cols);
1623 
1624  }
1625 
1633  private static int booleanToRight(boolean read, boolean write){
1634 
1635  int right =0;
1636 
1637  if(read && write){
1638  right = 2;
1639  }
1640  /*else
1641  if(write){
1642  right = 2;
1643  }*/
1644  else
1645  if(read){
1646  right = 1;
1647  }
1648 
1649  return right;
1650  }
1651 
1658  @SuppressWarnings("static-access")
1659  private void removeRowSelectedShared(){
1660  if(jTableShare.getSelectedRow()!=-1 && jTableShare.getRowCount()>0){
1661  int indexToRemove = jTableShare.getSelectedRow();
1662  p2putility.Util.logGeneric("File alla riga "+indexToRemove);
1663  String name = jTableShare.getModel().getValueAt(indexToRemove, 0).toString();
1664  String path = jTableShare.getModel().getValueAt(indexToRemove, 1).toString();
1665  DefaultTableModel model = (DefaultTableModel) jTableShare.getModel();
1666  model.removeRow(indexToRemove);
1667  model.fireTableRowsDeleted(indexToRemove, indexToRemove);
1668 
1669  h.remove(path+name);
1670 
1671  p2pclient.clientRMI.name_file = name;
1672  //path = path.substring(0, path.length()-name.length());
1673  path = path.replace("\\", "\\\\");
1674  p2pclient.clientRMI.path_file = path;
1676  TRC.user = user;
1677  TRC.pswd = pswd;
1678  TRC.funct = "removeFile";
1679  Thread t = new Thread(TRC);
1680  t.start();
1681 
1682  javax.swing.JOptionPane.showMessageDialog(null, "The file "+name+" has been unshared", "File unshared",javax.swing.JOptionPane.INFORMATION_MESSAGE );
1683  p2putility.Util.logGeneric("Ho rimosso il file alla riga "+indexToRemove+" di nome "+name+" e path "+path);
1684  //Rimozione della condivisione dell'oggetto selezionato
1685  }
1686  }
1687 
1693  private String setBroadcastIp() throws UnknownHostException{
1694  String bcast = "";
1695 
1696  String iipp = "";
1697  String netmask = "";
1698  String v = InetAddress.getLocalHost().getHostAddress();
1699  String n = p2putility.Config.r_netmask();
1700 
1701 
1702  //p2putility.Util.logGeneric(v+" "+n);
1703 
1704  for(int i=0; i< 3; i++){
1705  int y = v.indexOf(".");
1706  iipp = v.substring(0,y);
1707  v = v.substring(y+1);
1708  //p2putility.Util.logGeneric(ipp[i]);
1709 
1710  int hi = n.indexOf(".");
1711  netmask = n.substring(0,hi);
1712  n = n.substring(hi+1);
1713  //p2putility.Util.logGeneric(netmask[i]);
1714 
1715  short v_ip = Short.parseShort(iipp);
1716  short v_netmask = Short.parseShort(netmask);
1717 
1718  bcast += 256+(v_ip|(~v_netmask))+".";
1719 
1720 
1721  }
1722  short v_ip = Short.parseShort(v);
1723  short v_netmask = Short.parseShort(n);
1724  bcast += 256+(v_ip|(~v_netmask))+"";
1725 
1726  //p2putility.Util.logGeneric(bcast);
1727  return bcast;
1728  }
1729 
1730 
1737  public static boolean isMyUser(String u){
1738  try{
1739  if(user.equals(u))
1740  return true;
1741  }
1742  catch(Exception e) {return false;}
1743  return false;
1744  }
1745 
1752  public static boolean isMyPswd(String p){
1753  try{
1754  if(pswd.equals(p))
1755  return true;
1756  }
1757  catch(Exception e) {return false;}
1758  return false;
1759  }
1760 
1766  @SuppressWarnings("static-access")
1767  private static boolean isServerOn(boolean output){
1768  if( (user.compareTo(" ")==0) && (pswd.compareTo(" ")==0) )
1769  return true;
1770 
1771  boolean on = false;
1772 
1773  try{
1775  TRC.ip = ip_server;
1776  TRC.funct = "serverOn";
1777  Thread g = new Thread(TRC);
1778  g.start();
1779 
1780  //Attendi finche' non viene aggiornato il risultato
1781  g.join(p2putility.Config.r_threadtimeout());
1782  }
1783  catch(Exception ex){
1784  p2putility.Util.logGeneric("IsServerOn: "+ex.getMessage());
1785  return false;
1786  }
1787 
1788  on = p2pclient.clientRMI.ison;
1789 
1790  if((!on) && (output))
1791  javax.swing.JOptionPane.showMessageDialog(null, "Error: server "+ip_server+" is down.", "Error", 0);
1792 
1793  p2putility.Util.logGeneric("Server on: "+ on);
1794  return on ;
1795  }
1796 
1802  @SuppressWarnings("static-access")
1803  private static boolean amAlive(boolean output){
1804  if( (user.compareTo(" ")==0) && (pswd.compareTo(" ")==0) )
1805  return true;
1806 
1807  boolean alive = false;
1809  TRC.user = user;
1810  TRC.pswd = pswd;
1811  TRC.ip = ip_server;
1812  TRC.dbg = true;
1813  TRC.funct = "clientAlive";
1814  Thread g = new Thread(TRC);
1815  g.start();
1816 
1817  try {
1818  //Attendi finche' non viene aggiornato il risultato
1819  g.join(p2putility.Config.r_threadtimeout());
1820  } catch (InterruptedException ex) {
1821  p2putility.Util.logClient("Timeout-join in amAlive error: "+ex.getMessage());
1822  return false;
1823  }
1824  alive = p2pclient.clientRMI.alive;
1825 
1826  if((!alive) && (output)){
1827  javax.swing.JOptionPane.showMessageDialog(null, "Error: connection with server "+ip_server+" is not alive.", "Error", 0);
1828  jLabel4.setText("No Connection");
1829  }
1830 
1831 
1832  //p2putility.Util.logClient("Am alive: "+ alive);
1833  return alive;
1834  }
1835 
1840  public void removeAllFromTable(){
1841  int num_row = 0;
1842 
1843  try{
1844  h.clear();
1845  }
1846  catch(Exception e)
1847  {p2putility.Util.logGeneric("Hash table error: "+e.getMessage());}
1848 
1849  try{
1850  num_row = -1;
1851  DefaultTableModel model = (DefaultTableModel) jTableShare.getModel();
1852 
1853  while(model.getRowCount()>0){
1854  model.removeRow(0);
1855  num_row ++;
1856  }
1857  if(num_row>0)
1858  model.fireTableRowsDeleted(0, num_row);
1859  }
1860  catch(Exception e)
1861  {p2putility.Util.logGeneric("Graphic error in jTableShare: "+e.getMessage());}
1862 
1863  try{
1864  num_row = -1;
1865  DefaultTableModel model1 = (DefaultTableModel) jTableShare1.getModel();
1866 
1867  while(model1.getRowCount()>0){
1868  model1.removeRow(0);
1869  num_row ++;
1870  }
1871  if(num_row>0)
1872  model1.fireTableRowsDeleted(0, num_row);
1873  }
1874  catch(Exception e)
1875  {p2putility.Util.logGeneric("Graphic error in jTableShare1: "+e.getMessage());}
1876 
1877  try{
1878  Object o [] = new Object[0];
1879  jList1.setListData(o);
1880  }
1881  catch(Exception e)
1882  {p2putility.Util.logGeneric("Graphic error in jList1: "+e.getMessage());}
1883 
1884  jLabel4.setText("No Connection");
1885 
1886  jLabel6.setIcon(new javax.swing.ImageIcon(getClass().getResource(p2putility.Config.r_ico_server_disable())));
1887 
1888  //javax.swing.JOptionPane.showMessageDialog(null, "Information: client disconnected ", "Information", 1);
1889  }
1890 
1895  @SuppressWarnings("static-access")
1896  public static void disconnectClient(){
1897  if((id_user!=-1) && (isServerOn(false)) && (amAlive(false))){
1898 
1899  p2putility.Util.logGeneric("Client is trying to disconnect...");
1901  TRC.ip = ip_server;
1902  TRC.funct = "disconnectClient";
1903  TRC.user = user;
1904  TRC.pswd = pswd;
1905  Thread t = new Thread(TRC);
1906  t.start();
1907 
1908  try {
1909  //Attendi finche' non viene aggiornato il risultato
1910  t.join(p2putility.Config.r_threadtimeout());
1911  } catch (InterruptedException ex) {
1912  p2putility.Util.logClient("Timeout-join in disconnectClient error: "+ex.getMessage());
1913  return;
1914  }
1915 
1916  user = " ";
1917  pswd = " ";
1918  }
1919  else
1920  p2putility.Util.logGeneric("Client can't be disconnect");
1921  }
1922 
1923 }
javax.swing.JSeparator jSeparator3
static int booleanToRight(boolean read, boolean write)
Converte i diritti da due boolean a un intero.
Classe che permette la configurazione di tutto il programma in base alle specifiche esigenze dell&#39;ute...
Definition: Config.java:14
Classe che implementa il metodo run dell&#39;interfaccia Runnable e crea un&#39;istanza di C2C_client...
static javax.swing.JLabel jLabel4
static ArrayList list
Definition: clientRMI.java:17
Classe che implementa metodi vari di utilita&#39; generale.
Definition: Util.java:14
javax.swing.JLabel jLabel1
javax.swing.JTable jTableShare
javax.swing.JButton jButton7
static void disconnectClient()
Metodo che effettua la disconnessione del client dal ServerRMI chiamando la funzione "disconnectClien...
Classe che implementa il servizio Client.
static Hashtable h
javax.swing.JButton jButton3
javax.swing.JTextField jTextField2
javax.swing.JScrollPane jScrollPane2
javax.swing.JMenu jMenu4
static String user
User e password che il client usa per connettersi al server.
void uploadFile()
Metodo che dato un file selezionato dal jFileChooser e un client selezionato da una combo box in una ...
void jList1MouseClicked(java.awt.event.MouseEvent evt)
Evento doubleclick sulla lista, che richiama la funzione serverSelected()
javax.swing.JSeparator jSeparator2
static String where
Definition: clientRMI.java:20
void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dal JMenu Remove.
void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di share.
static boolean isMyPswd(String p)
Metodo che verifica se la stringa passata corrisponde alla password del client.
javax.swing.JButton jButton8
javax.swing.JMenuItem jMenuItem11
javax.swing.JList jList1
Classe che implementa il metodo run dell&#39;interfaccia Runnable e crea un&#39;istanza di clientRMI...
javax.swing.JTextField jTextField4
static boolean connection
void formWindowClosing(java.awt.event.WindowEvent evt)
Azione da effettuare alla chiusura della finestra: disconnessione del client.
void jButton7ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di update dei server disponibili.
void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dael JMenu Upload file to client...
static boolean read
Definition: Rights.java:14
javax.swing.JMenuItem jMenuItem10
javax.swing.JLabel jLabel5
javax.swing.JSeparator jSeparator4
void jButton12ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone Delete file.
void jButton6ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di connessione al server. ...
javax.swing.JButton jButton12
void jButton1ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone Open.
static int r_threadtimeout()
Permette la lettura della varibile relativa in modo sicuro.
Definition: Config.java:330
void initComponents()
Metodo chiamato dal costruttore per inizializzare la form WARNING: Do NOT modify this code...
void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone del JMenu di share.
void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dal JMenu di connessione al server...
static Hashtable start(String bip, int port, int timeout, boolean dbg)
Funzione che invia un Datagram in broadcast e che fino allo scadere del timeout resta in attesa delle...
void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di LogOut dal JMenu: creazione di un istanza ...
void deleteFile()
Metodo che dato un file selezionato dalla jTableShare1, richiede tramite la funzione RMI "getAccessSt...
javax.swing.JMenuItem jMenuItem1
javax.swing.JLabel jLabel2
javax.swing.JLabel jLabel9
static boolean dbg
Variabile boolean per attivare il degug.
javax.swing.JMenu jMenu1
static boolean write
Definition: Rights.java:15
javax.swing.JMenu jMenu2
void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dal JMenu Delete file.
javax.swing.JFileChooser jFileChooser1
javax.swing.JMenuItem jMenuItem4
static int r_port()
Permette la lettura della varibile relativa in modo sicuro.
Definition: Config.java:305
javax.swing.JLabel jLabel8
javax.swing.JButton jButton4
static void logGeneric(String data)
Scrive i dati in input sul file di log Generico (se questo esiste valido)
Definition: Util.java:132
javax.swing.JLabel jLabel7
Classe che implementa il client RMI che si interfaccia a ServerRMI, richiamando le funzione dell&#39;inte...
Definition: clientRMI.java:13
javax.swing.JMenuItem jMenuItem7
static String accessString
Definition: clientRMI.java:21
javax.swing.JMenuItem jMenuItem2
Classe che implementa il metodo run dell&#39;interfaccia Runnable e crea un&#39;istanza di C2C_server...
javax.swing.JScrollPane jScrollPane4
void removeAllFromTable()
Metodo che rimuove tutto il contenuto di tabelle e liste nella GUI dei client.
Classe che genera graficamente la finestra Rights che richiede di selezionare i permessi d&#39;accesso al...
Definition: Rights.java:8
void jButton11ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone Upload file to client.
void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dal jMenu Open.
static String r_netmask()
Permette la lettura della varibile relativa in modo sicuro.
Definition: Config.java:325
static boolean amAlive(boolean output)
Metodo che verifica se questo client e&#39; ancora connesso al server.
javax.swing.JButton jButton5
javax.swing.JMenuItem jMenuItem6
javax.swing.JTable jTableShare1
void removeRowSelectedShared()
Metodo che dato il file selezionato dalla tabella jTableShare, lo rimuove e invia la richiesta di rim...
static boolean isMyUser(String u)
Metodo che verifica se la stringa passata corrisponde allo username del client.
javax.swing.JMenuItem jMenuItem5
static boolean ison
Definition: clientRMI.java:25
void setServerInList()
Metodo che richiando p2pclient.ClientGetLocalServerList.start ottiene la lista dei server attivi e la...
javax.swing.JMenuItem jMenuItem3
static int id_user
Definition: clientRMI.java:15
void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone Update file list.
static boolean alive
Definition: clientRMI.java:26
void jButton5ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone di LogOut: creazione di un istanza di LogOutF...
static boolean r_serverOpen()
Permette la lettura della varibile relativa in modo sicuro.
Definition: Config.java:400
Classe che genera graficamente la finestra di LogOut dal frame Client.
void jMenuItem11ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dal JMenu Disconnect client.
javax.swing.JButton jButton11
static String pswd
javax.swing.JButton jButton2
static String name_file
Definition: clientRMI.java:18
void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dal JMenu AddServer.
void updateFileList()
Chiamando la funzione "getList" nel ServerRMI, riceve la lista aggiornata dei file condivisi e la ins...
void jButton8ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone Disconnect client.
javax.swing.JLabel jLabel6
javax.swing.JMenuItem jMenuItem9
javax.swing.JSeparator jSeparator1
static boolean isServerOn(boolean output)
Metodo che verifica se il server a cui sono connesso e&#39; attivo.
javax.swing.JMenu jMenu3
void jButton4ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone Remove.
void jButton10ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone AddServer.
static String ip_server
javax.swing.JTextField jTextField5
void setFileDirectoryListShared()
Metodo che dato il file selezionato dal jFileChooser, lo invia al ServerRmi tramite la funzione "send...
void fileOpenRead()
Metodo che dato un file selezionato dalla jTableShare1, richiede tramite la funzione RMI "getAccessSt...
void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dal JMenu di update dei server disponibili...
String setBroadcastIp()
Metodo che genera l&#39;indirizzo di broadcast di una sottorete.
void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt)
Azione effettuata in seguito alla pressione del bottone dal JMenu Update file list.
static String hash_sha(String text)
Converte una stringa nel corrispondente HASH SHA-1 in forma esadecimale.
Definition: Util.java:89
javax.swing.JTextField jTextField1
javax.swing.JButton jButton1
static void w_clientOpen(boolean value)
Permette la scrittura della varibile relativa in modo sicuro.
Definition: Config.java:415
void serverSelected()
Metodo che estrae l&#39;ip del server selezionato dalla jList1, richiede username e password, stabilisce la connessione tramite la funzione RMI "registerToServer" su ServerRMI.
javax.swing.JButton jButton10
static boolean DBG
static String r_ico_server_enable()
Permette la lettura della varibile relativa in modo sicuro.
Definition: Config.java:420
Classe che implementa un client mediante socket, che effettua in broadcast la richiesta dei server at...
javax.swing.JButton jButton6
void addServer()
Metodo che estrae dai quattro jTextField i valori numerici, controlla se la stringa ottenuta e&#39; un in...
javax.swing.JMenuBar jMenuBar1
javax.swing.JMenuItem jMenuItem8
static String id_file
Definition: clientRMI.java:22
static String id_owner
Definition: clientRMI.java:16
static String r_ico_server_disable()
Permette la lettura della varibile relativa in modo sicuro.
Definition: Config.java:425
static JTable jtabshare
javax.swing.JLabel jLabel3
static String path_file
Definition: clientRMI.java:19
static void logClient(String data)
Scrive i dati in input sul file di log del Client (se questo esiste valido)
Definition: Util.java:121
javax.swing.JScrollPane jScrollPane3