KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > gui > base > AppMenuBar


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package net.sf.jftp.gui.base;
17
18 import net.sf.jftp.JFtp;
19 import net.sf.jftp.config.Settings;
20 import net.sf.jftp.gui.framework.*;
21 import net.sf.jftp.gui.hostchooser.HostChooser;
22 import net.sf.jftp.gui.hostchooser.NfsHostChooser;
23 import net.sf.jftp.gui.hostchooser.SftpHostChooser;
24 import net.sf.jftp.gui.hostchooser.SmbHostChooser;
25 import net.sf.jftp.gui.hostchooser.WebdavHostChooser;
26 import net.sf.jftp.gui.tasks.AddBookmarks;
27 import net.sf.jftp.gui.tasks.AdvancedOptions;
28 import net.sf.jftp.gui.tasks.BookmarkItem;
29 import net.sf.jftp.gui.tasks.BookmarkManager;
30 import net.sf.jftp.gui.tasks.Displayer;
31 import net.sf.jftp.gui.tasks.HttpBrowser;
32 import net.sf.jftp.gui.tasks.HttpDownloader;
33 import net.sf.jftp.gui.tasks.LastConnections;
34 import net.sf.jftp.gui.tasks.ProxyChooser;
35 import net.sf.jftp.net.*;
36 import net.sf.jftp.system.logging.Log;
37 import net.sf.jftp.tools.*;
38 import net.sf.jftp.util.*;
39
40 import java.awt.*;
41 import java.awt.event.*;
42
43 import java.io.*;
44
45 import java.lang.Integer JavaDoc;
46
47 import java.util.*;
48
49 import javax.swing.*;
50
51 import javazoom.jl.decoder.*;
52 import javazoom.jl.player.*;
53
54
55 //***
56
public class AppMenuBar extends JMenuBar implements ActionListener
57 {
58     public static JCheckBoxMenuItem fadeMenu = new JCheckBoxMenuItem("Enable Status Animation",
59                                                                      Settings.getEnableStatusAnimation());
60     public static JCheckBoxMenuItem askToDelete = new JCheckBoxMenuItem("Confirm Remove",
61                                                                         Settings.getAskToDelete());
62     public static JCheckBoxMenuItem debug = new JCheckBoxMenuItem("Verbose Console Debugging",
63                                                                   Settings.getEnableDebug());
64     public static JCheckBoxMenuItem disableLog = new JCheckBoxMenuItem("Disable Log",
65                                                                        Settings.getDisableLog());
66     public static JMenuItem clearItems = new JMenuItem("Clear Finished Items");
67     private JFtp jftp;
68     JMenu file = new JMenu("File");
69     JMenu opt = new JMenu("Options");
70     JMenu view = new JMenu("View");
71     JMenu tools = new JMenu("Tools");
72     JMenu bookmarks = new JMenu("Bookmarks");
73     JMenu info = new JMenu("Info");
74     JMenu lf = new JMenu(" Switch Look & Feel to");
75     JMenu background = new JMenu("Desktop Background");
76     JMenu ftp = new JMenu(" FTP");
77     JMenu smb = new JMenu(" SMB");
78     JMenu sftp = new JMenu(" SFTP");
79     JMenu security = new JMenu("Security");
80     JMenu experimental = new JMenu("Experimental Features");
81     JMenu rss = new JMenu("RSS Feed");
82     JMenu cnn = new JMenu("CNN");
83     JMenuItem localFtpCon = new JMenuItem("Open FTP Connection in Local Tab...");
84     JMenuItem localSftpCon = new JMenuItem("Open SFTP Connection in Local Tab...");
85     JMenuItem localSmbCon = new JMenuItem("Open SMB/LAN Connection in Local Tab...");
86     JMenuItem localNfsCon = new JMenuItem("Open NFS Connection in Local Tab...");
87     JMenuItem localWebdavCon = new JMenuItem("Open WebDAV Connection in Local Tab... (ALPHA)");
88     JMenuItem closeLocalCon = new JMenuItem("Close Active Connection in Local Tab");
89     JMenuItem ftpCon = new JMenuItem("Connect to FTP Server...");
90     JMenuItem sftpCon = new JMenuItem("Connect to SFTP Server...");
91     JMenuItem smbCon = new JMenuItem("Connect to SMB Server / Browse LAN...");
92     JMenuItem nfsCon = new JMenuItem("Connect to NFS Server...");
93     JMenuItem webdavCon = new JMenuItem("Connect to WebDAV Server... (ALPHA)");
94     JMenuItem close = new JMenuItem("Disconnect and Connect to Filesystem");
95     JMenuItem exit = new JMenuItem("Exit");
96     JMenuItem readme = new JMenuItem("Show Readme...");
97     JMenuItem changelog = new JMenuItem("View Changelog...");
98     JMenuItem todo = new JMenuItem("What's Next...");
99     JMenuItem hp = new JMenuItem("Visit Project Homepage...");
100     JMenuItem opts = new JMenuItem("Advanced Options...");
101     JMenuItem http = new JMenuItem("Download File from URL...");
102     JMenuItem raw = new JMenuItem("Raw TCP/IP Connection...");
103     JMenuItem spider = new JMenuItem("Recursive HTTP Download...");
104     JMenuItem sshShell = new JMenuItem("SSH Shell...");
105     JMenuItem shell = new JMenuItem("Execute /bin/bash");
106     JMenuItem loadAudio = new JMenuItem("Play MP3");
107     JCheckBoxMenuItem rssDisabled = new JCheckBoxMenuItem("Enable RSS Feed",
108                                                           Settings.getEnableRSS());
109     JCheckBoxMenuItem nl = new JCheckBoxMenuItem("Show Newline Option",
110                                                           Settings.showNewlineOption);
111     JMenuItem loadSlash = new JMenuItem("Slashdot");
112     JMenuItem loadCNN1 = new JMenuItem("CNN Top Stories");
113     JMenuItem loadCNN2 = new JMenuItem("CNN World");
114     JMenuItem loadCNN3 = new JMenuItem("CNN Tech");
115     JMenuItem loadRss = new JMenuItem("Custom RSS Feed");
116     JCheckBoxMenuItem stdback = new JCheckBoxMenuItem("Background Image",
117                                                       Settings.getUseBackground());
118     JCheckBoxMenuItem resuming = new JCheckBoxMenuItem("Enable Resuming",
119                                                        Settings.enableResuming);
120     JCheckBoxMenuItem ask = new JCheckBoxMenuItem("Always Ask to Resume",
121                                                   Settings.askToResume);
122     JMenuItem proxy = new JMenuItem("Proxy Settings...");
123     JCheckBoxMenuItem smbThreads = new JCheckBoxMenuItem("Multiple Connections",
124                                                          Settings.getEnableSmbMultiThreading());
125     JCheckBoxMenuItem sftpThreads = new JCheckBoxMenuItem("Multiple Connections",
126                                                           Settings.getEnableSftpMultiThreading());
127     JCheckBoxMenuItem sshKeys = new JCheckBoxMenuItem("Enable Host Key check",
128                                                       Settings.getEnableSshKeys());
129     JCheckBoxMenuItem storePasswords = new JCheckBoxMenuItem("Store passwords (plaintext)",
130             Settings.getStorePasswords());
131     
132     JCheckBoxMenuItem useTableLayout = new JCheckBoxMenuItem("Use JTable layout",
133             Settings.getUseJTableLayout());
134     
135     JCheckBoxMenuItem useNewIcons = new JCheckBoxMenuItem("Use Silk Icons",
136             Settings.getUseNewIcons());
137     
138     JCheckBoxMenuItem hideHidden = new JCheckBoxMenuItem("Hide local hidden files (Unix only)",
139             Settings.getHideLocalDotNames());
140     
141     JMenuItem clear = new JMenuItem("Clear Log");
142
143     //*** the menu items for the last connections
144
JMenuItem[] lastConnections = new JMenuItem[jftp.CAPACITY];
145
146     //*** information on each of the last connections
147
//BUGFIX
148
String JavaDoc[][] cons = new String JavaDoc[jftp.CAPACITY][JFtp.CONNECTION_DATA_LENGTH];
149     String JavaDoc[] lastConData = new String JavaDoc[jftp.CAPACITY];
150     Character JavaDoc charTab = new Character JavaDoc('\t');
151     String JavaDoc tab = charTab.toString();
152     JMenuItem manage = new JMenuItem("Manage Bookmarks...");
153     JMenuItem add = new JMenuItem("Add Bookmark...");
154     Hashtable marks;
155     JMenu current = bookmarks;
156     JMenu last = bookmarks;
157
158     /*
159     String[] lastProtocols;
160     String[] lastHosts;
161     String[] lastUnames;
162     */

163     public AppMenuBar(JFtp jftp)
164     {
165         this.jftp = jftp;
166
167         ftpCon.addActionListener(this);
168         close.addActionListener(this);
169         exit.addActionListener(this);
170         readme.addActionListener(this);
171         changelog.addActionListener(this);
172         todo.addActionListener(this);
173         resuming.addActionListener(this);
174         ask.addActionListener(this);
175         smbCon.addActionListener(this);
176         clear.addActionListener(this);
177         sftpCon.addActionListener(this);
178         fadeMenu.addActionListener(this);
179         askToDelete.addActionListener(this);
180         smbThreads.addActionListener(this);
181         sftpThreads.addActionListener(this);
182         debug.addActionListener(this);
183         disableLog.addActionListener(this);
184         http.addActionListener(this);
185         hp.addActionListener(this);
186         raw.addActionListener(this);
187         nfsCon.addActionListener(this);
188         spider.addActionListener(this);
189         proxy.addActionListener(this);
190         stdback.addActionListener(this);
191         opts.addActionListener(this);
192         webdavCon.addActionListener(this);
193         sshShell.addActionListener(this);
194         shell.addActionListener(this);
195         nl.addActionListener(this);
196
197         localFtpCon.addActionListener(this);
198         localSftpCon.addActionListener(this);
199         localSmbCon.addActionListener(this);
200         localNfsCon.addActionListener(this);
201         localWebdavCon.addActionListener(this);
202         closeLocalCon.addActionListener(this);
203         add.addActionListener(this);
204         storePasswords.addActionListener(this);
205         rssDisabled.addActionListener(this);
206         loadRss.addActionListener(this);
207         loadSlash.addActionListener(this);
208         loadCNN1.addActionListener(this);
209         loadCNN2.addActionListener(this);
210         loadCNN3.addActionListener(this);
211         loadAudio.addActionListener(this);
212         useTableLayout.addActionListener(this);
213         useNewIcons.addActionListener(this);
214         hideHidden.addActionListener(this);
215
216         clearItems.addActionListener(JFtp.dList);
217
218         clear.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1,
219                                                     ActionEvent.ALT_MASK));
220         clearItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2,
221                                                          ActionEvent.ALT_MASK));
222         changelog.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3,
223                                                         ActionEvent.ALT_MASK));
224         readme.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4,
225                                                      ActionEvent.ALT_MASK));
226         todo.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5,
227                                                    ActionEvent.ALT_MASK));
228
229         //*** setMnemonics(); was here
230
//*** BELOW, ADDITIONS FOR THE FILE MENU ARE PUT IN PUBLIC METHOD
231
resetFileItems();
232
233         ftp.add(resuming);
234         ftp.add(ask);
235     ftp.add(nl);
236         smb.add(smbThreads);
237         sftp.add(sftpThreads);
238         sftp.add(sshKeys);
239         security.add(askToDelete);
240         security.add(storePasswords);
241
242         cnn.add(loadCNN1);
243         cnn.add(loadCNN2);
244         cnn.add(loadCNN3);
245
246         rss.add(rssDisabled);
247         rss.add(loadSlash);
248         rss.add(cnn);
249         rss.add(loadRss);
250
251         opt.add(security);
252         opt.addSeparator();
253         opt.add(ftp);
254         opt.add(smb);
255         opt.add(sftp);
256         opt.addSeparator();
257         opt.add(proxy);
258         opt.add(opts);
259
260         tools.add(http);
261         tools.add(spider);
262         tools.addSeparator();
263         tools.add(raw);
264         tools.addSeparator();
265         tools.add(sshShell);
266         tools.add(shell);
267
268         view.add(hideHidden);
269         view.addSeparator();
270         view.add(useTableLayout);
271         view.add(useNewIcons);
272         view.add(fadeMenu);
273         view.add(clear);
274         view.add(clearItems);
275
276         view.addSeparator();
277         view.add(debug);
278         view.add(disableLog);
279         view.addSeparator();
280         view.add(rss);
281         view.addSeparator();
282
283         info.add(readme);
284         info.add(changelog);
285         info.add(todo);
286         info.addSeparator();
287         info.add(hp);
288
289         UIManager.LookAndFeelInfo[] m = UIManager.getInstalledLookAndFeels();
290
291         for(int i = 0; i < m.length; i++)
292         {
293             //JMenuItem tmp = new JMenuItem(m[i].getName());
294
//tmp.addActionListener(this);
295
//lf.add(tmp);
296

297             /*
298              * Don't add menu items for unsupported look and feel's.
299              *
300              * It would be nice to use something like
301              * isSupportedLookandFeel, but the information provided by
302              * UIManager.LookAndFeelInfo is very limited. This is
303              * supposedly done on purpose according to the API docs,
304              * but what good does a non-supported look and feel in a
305              * menu item do?
306              */

307             try
308             {
309                 LookAndFeel lnf = (LookAndFeel) Class.forName(m[i].getClassName())
310                                                      .newInstance();
311
312                 if(lnf.isSupportedLookAndFeel())
313                 {
314                     JMenuItem tmp = new JMenuItem(m[i].getName());
315                     tmp.addActionListener(this);
316                     lf.add(tmp);
317                 }
318             }
319             catch(ClassNotFoundException JavaDoc cnfe)
320             {
321                 continue;
322             }
323             catch(InstantiationException JavaDoc ie)
324             {
325                 continue;
326             }
327             catch(IllegalAccessException JavaDoc iae)
328             {
329                 continue;
330             }
331         }
332
333         view.add(lf);
334
335         background.add(stdback);
336         view.add(background);
337
338         manage.addActionListener(this);
339
340         //UIManager.setLookAndFeel();
341
add(file);
342         add(opt);
343         add(view);
344         add(tools);
345         add(bookmarks);
346         add(info);
347
348         loadBookmarks();
349
350         //add(experimental);
351
}
352
353     public void loadBookmarks()
354     {
355         marks = new Hashtable();
356         bookmarks.removeAll();
357         bookmarks.add(add);
358         bookmarks.add(manage);
359         bookmarks.addSeparator();
360
361         String JavaDoc data = "";
362
363         try
364         {
365             DataInput in = new DataInputStream(new BufferedInputStream(new FileInputStream(Settings.bookmarks)));
366
367             while((data = in.readLine()) != null)
368             {
369                 if(!data.startsWith("#") && !data.trim().equals(""))
370                 {
371                     addBookmarkLine(data);
372                 }
373             }
374         }
375         catch(IOException e)
376         {
377             Log.debug("No bookmarks.txt found, using defaults.");
378             addBookmark("FTP", "ftp.kernel.org", "anonymous", "j-ftp@sf.net",
379                         21, "/pub/linux/kernel", "false");
380             addBookmark("FTP", "upload.sourceforge.net", "anonymous",
381                         "j-ftp@sf.net", 21, "/incoming", "false");
382             addBookmark("SMB", "(LAN)", "guest", "guest", -1, "-", "false");
383
384             return;
385         }
386     }
387
388     private void addBookmarkLine(String JavaDoc tmp)
389     {
390         try
391         {
392             StringTokenizer t = new StringTokenizer(tmp, "#", false);
393
394             if(tmp.toLowerCase().trim().startsWith("<dir>"))
395             {
396                 String JavaDoc dir = tmp.substring(tmp.indexOf(">") + 1,
397                                            tmp.lastIndexOf("<"));
398
399                 //Log.debug("Dir: " + dir);
400
JMenu m = new JMenu(dir);
401                 current.add(m);
402
403                 last = current;
404                 current = m;
405             }
406             else if(tmp.toLowerCase().trim().startsWith("<enddir>"))
407             {
408                 current = last;
409             }
410             else
411             {
412                 addBookmark(t.nextToken(), t.nextToken(), t.nextToken(),
413                             t.nextToken(), Integer.parseInt(t.nextToken()),
414                             t.nextToken(), t.nextToken());
415             }
416         }
417         catch(Exception JavaDoc ex)
418         {
419             Log.debug("Broken line: " + tmp);
420             ex.printStackTrace();
421         }
422     }
423
424     public void addBookmark(String JavaDoc pr, String JavaDoc h, String JavaDoc u, String JavaDoc p, int po,
425                             String JavaDoc d, String JavaDoc l)
426     {
427         BookmarkItem x = new BookmarkItem(h);
428         x.setUserdata(u, p);
429
430         if(l.trim().startsWith("t"))
431         {
432             x.setLocal(true);
433         }
434
435         x.setPort(po);
436         x.setProtocol(pr);
437         x.setDirectory(d);
438
439         //bookmarks
440
current.add(x);
441         marks.put(x.getLabel(), x);
442         x.addActionListener(this);
443     }
444
445     //*** Where changes to the file menu are made (iniitalization done here too)
446
public void resetFileItems()
447     {
448         file.removeAll();
449
450         file.add(ftpCon);
451         file.add(sftpCon);
452         file.add(smbCon);
453         file.add(nfsCon);
454         file.add(webdavCon);
455         file.addSeparator();
456         file.add(close);
457         file.addSeparator();
458         file.addSeparator();
459         file.add(localFtpCon);
460         file.add(localSftpCon);
461         file.add(localSmbCon);
462         file.add(localNfsCon);
463
464         //file.add(localWebdavCon); -> not yet
465
file.addSeparator();
466         file.add(closeLocalCon);
467         file.addSeparator();
468
469         //*** ADDITION OF THE REMEMBERED CONNECTIONS
470
boolean connectionsExist = false;
471
472         try
473         {
474             //*** get the information on the last connections
475
cons = new String JavaDoc[jftp.CAPACITY][jftp.CONNECTION_DATA_LENGTH];
476
477             cons = LastConnections.readFromFile(jftp.CAPACITY);
478
479             String JavaDoc protocol;
480
481             String JavaDoc htmp;
482
483             String JavaDoc utmp;
484
485             String JavaDoc conNumber;
486             String JavaDoc usingLocal = new String JavaDoc("");
487             Integer JavaDoc conNumberInt;
488
489             //lastConData = new String("");
490
//***
491
for(int i = 0; i < jftp.CAPACITY; i++)
492             {
493                 if(!(cons[i][0].equals("null")))
494                 {
495                     protocol = cons[i][0];
496                     htmp = cons[i][1];
497                     utmp = cons[i][2];
498
499                     int j = 3;
500
501                     while(!(cons[i][j].equals(LastConnections.SENTINEL)))
502                     {
503                         j++;
504                     }
505
506                     //usingLocal is always last piece of data!
507
usingLocal = cons[i][j - 1];
508
509                     if(usingLocal.equals("true"))
510                     {
511                         usingLocal = "(in local tab)";
512                     }
513
514                     else
515                     {
516                         usingLocal = "";
517                     }
518
519                     //lastConnections[i] = new JMenuItem(cons[i]);
520
conNumberInt = new Integer JavaDoc(i + 1);
521                     conNumber = conNumberInt.toString();
522
523                     //lastConData[i] = new String(conNumber + " " + protocol + ": Hostname: " + htmp + "; Username: " + utmp);
524
lastConData[i] = new String JavaDoc(conNumber + " " + protocol +
525                                                 ": " + htmp + " " + usingLocal);
526
527                     lastConnections[i] = new JMenuItem(lastConData[i]);
528                     lastConnections[i].addActionListener(this);
529
530                     connectionsExist = true;
531
532                     //*** code repetition: maybe getting these tokens
533
//*** should be in a separate private method
534
//file.add(protocol + ": Hostname: " + htmp + "; Username: " + utmp);
535
file.add(lastConnections[i]);
536                 }
537             }
538         }
539         catch(Exception JavaDoc ex)
540         {
541             Log.debug("WARNING: Remembered connections broken.");
542             ex.printStackTrace();
543         }
544
545         if(connectionsExist)
546         {
547             file.addSeparator();
548         }
549
550         file.add(exit);
551
552         setMnemonics();
553     }
554
555     //resetFileItems
556
public void actionPerformed(ActionEvent e)
557     {
558         if(e.getSource() == proxy)
559         {
560             //ProxyChooser p =
561
JFtp.statusP.jftp.addToDesktop("Proxy Settings",
562                                            new ProxyChooser(), 500, 110);
563         }
564         else if(e.getSource() == add)
565         {
566             Log.out("add called");
567
568             AddBookmarks a = new AddBookmarks(JFtp.statusP.jftp);
569             a.update();
570         }
571         else if(e.getSource() == webdavCon)
572         {
573             WebdavHostChooser hc = new WebdavHostChooser();
574             hc.toFront();
575             hc.update();
576         }
577         else if((e.getSource() == localFtpCon) && (!jftp.uiBlocked))
578         {
579             HostChooser hc = new HostChooser(null, true);
580             hc.toFront();
581
582             //hc.setModal(true);
583
hc.update();
584         }
585         else if((e.getSource() == localSmbCon) && (!jftp.uiBlocked))
586         {
587             SmbHostChooser hc = new SmbHostChooser(null, true);
588             hc.toFront();
589
590             //hc.setModal(true);
591
hc.update();
592         }
593         else if((e.getSource() == localSftpCon) && (!jftp.uiBlocked))
594         {
595             SftpHostChooser hc = new SftpHostChooser(null, true);
596             hc.toFront();
597
598             //hc.setModal(true);
599
hc.update();
600         }
601         else if((e.getSource() == localNfsCon) && (!jftp.uiBlocked))
602         {
603             NfsHostChooser hc = new NfsHostChooser(null, true);
604             hc.toFront();
605
606             //hc.setModal(true);
607
hc.update();
608         }
609         else if((e.getSource() == localWebdavCon) && (!jftp.uiBlocked))
610         {
611             WebdavHostChooser hc = new WebdavHostChooser(null, true);
612             hc.toFront();
613
614             //hc.setModal(true);
615
hc.update();
616         }
617         else if(e.getSource() == closeLocalCon)
618         {
619             JFtp.statusP.jftp.closeCurrentLocalTab();
620         }
621         else if(e.getSource() == clear)
622         {
623             jftp.clearLog();
624         }
625         else if(e.getSource() == spider)
626         {
627             jftp.addToDesktop("Http recursive download",
628                               new HttpSpider(jftp.localDir.getPath() +
629                                              "_httpdownload/"), 440, 250);
630         }
631         else if(e.getSource() == hp)
632         {
633             HttpBrowser h = new HttpBrowser("http://j-ftp.sourceforge.net");
634             JFtp.desktop.add(h, new Integer JavaDoc(Integer.MAX_VALUE - 10));
635         }
636         else if(e.getSource() == raw)
637         {
638             RawConnection c = new RawConnection();
639         }
640         else if(e.getSource() == readme)
641         {
642             show(Settings.readme);
643         }
644         else if(e.getSource() == changelog)
645         {
646             show(Settings.changelog);
647         }
648         else if(e.getSource() == todo)
649         {
650             show(Settings.todo);
651         }
652         else if(e.getSource() == shell)
653         {
654             UIUtils.runCommand("/bin/bash");
655         }
656         else if(e.getSource() == loadAudio)
657         {
658             try
659             {
660                 JFileChooser f = new JFileChooser();
661                 f.showOpenDialog(jftp);
662
663                 File file = f.getSelectedFile();
664
665                 Player p = new Player(new FileInputStream(file));
666
667                 p.play();
668             }
669             catch(Exception JavaDoc ex)
670             {
671                 ex.printStackTrace();
672                 Log.debug("Error: (" + ex + ")");
673             }
674         }
675         else if(e.getSource() == exit)
676         {
677             jftp.windowClosing(null); // handles everything
678
}
679         else if(e.getSource() == close)
680         {
681             JFtp.statusP.jftp.closeCurrentTab();
682
683             /*
684             jftp.safeDisconnect();
685             FilesystemConnection con = new FilesystemConnection();
686             jftp.remoteDir.setCon(con);
687             con.addConnectionListener((ConnectionListener)jftp.remoteDir);
688             if(!con.chdir("/")) con.chdir("C:\\");
689             */

690         }
691         else if((e.getSource() == ftpCon) && (!jftp.uiBlocked))
692         {
693             //jftp.safeDisconnect();
694
HostChooser hc = new HostChooser();
695             hc.toFront();
696
697             //hc.setModal(true);
698
hc.update();
699         }
700         else if((e.getSource() == smbCon) && (!jftp.uiBlocked))
701         {
702             //jftp.safeDisconnect();
703
SmbHostChooser hc = new SmbHostChooser();
704             hc.toFront();
705
706             //hc.setModal(true);
707
hc.update();
708         }
709         else if((e.getSource() == sftpCon) && (!jftp.uiBlocked))
710         {
711             //jftp.safeDisconnect();
712
SftpHostChooser hc = new SftpHostChooser();
713             hc.toFront();
714
715             //hc.setModal(true);
716
hc.update();
717         }
718         else if((e.getSource() == nfsCon) && (!jftp.uiBlocked))
719         {
720             // jftp.safeDisconnect();
721
NfsHostChooser hc = new NfsHostChooser();
722             hc.toFront();
723
724             //hc.setModal(true);
725
hc.update();
726         }
727         else if(e.getSource() == resuming)
728         {
729             boolean res = resuming.getState();
730             Settings.enableResuming = res;
731             Settings.setProperty("jftp.enableResuming", res);
732             ask.setEnabled(Settings.enableResuming);
733             Settings.save();
734         }
735         else if(e.getSource() == useTableLayout)
736         {
737             boolean res = useTableLayout.getState();
738             Settings.setProperty("jftp.useJTableLayout", res);
739             Settings.save();
740             
741             JOptionPane.showMessageDialog(this, "Please restart JFtp to have the UI changed.");
742         }
743         else if(e.getSource() == useNewIcons)
744         {
745             boolean res = useNewIcons.getState();
746             Settings.setProperty("jftp.gui.look.newIcons", res);
747             Settings.save();
748             
749             JOptionPane.showMessageDialog(this, "Please restart JFtp to have the UI changed.");
750         }
751         else if(e.getSource() == hideHidden)
752         {
753             boolean res = hideHidden.getState();
754             Settings.setProperty("jftp.hideHiddenDotNames", res);
755             Settings.save();
756             
757             JFtp.localUpdate();
758         }
759         else if(e.getSource() == nl)
760         {
761             boolean res = nl.getState();
762             Settings.showNewlineOption = res;
763         }
764         else if(e.getSource() == stdback)
765         {
766             Settings.setProperty("jftp.useBackground", stdback.getState());
767             Settings.save();
768             JFtp.statusP.jftp.fireUpdate();
769         }
770         else if(e.getSource() == sshKeys)
771         {
772             Settings.setProperty("jftp.useSshKeyVerification",
773                                  sshKeys.getState());
774             Settings.save();
775             JFtp.statusP.jftp.fireUpdate();
776         }
777         else if(e.getSource() == rssDisabled)
778         {
779             Settings.setProperty("jftp.enableRSS", rssDisabled.getState());
780             Settings.save();
781             JFtp.statusP.jftp.fireUpdate();
782         }
783         else if(e.getSource() == loadRss)
784         {
785             String JavaDoc what = JOptionPane.showInputDialog("Enter URL", "http://");
786
787             if(what == null)
788             {
789                 return;
790             }
791
792             Settings.setProperty("jftp.customRSSFeed", what);
793             Settings.save();
794
795             JFtp.statusP.jftp.feeder.switchTo(what);
796         }
797         else if(e.getSource() == loadSlash)
798         {
799             Settings.setProperty("jftp.customRSSFeed",
800                                  "http://slashdot.org/rss/slashdot.rss");
801             Settings.save();
802
803             JFtp.statusP.jftp.feeder.switchTo("http://slashdot.org/rss/slashdot.rss");
804         }
805         else if(e.getSource() == loadCNN1)
806         {
807             Settings.setProperty("jftp.customRSSFeed",
808                                  "http://rss.cnn.com/rss/cnn_topstories.rss");
809             Settings.save();
810
811             JFtp.statusP.jftp.feeder.switchTo("http://rss.cnn.com/rss/cnn_topstories.rss");
812         }
813         else if(e.getSource() == loadCNN2)
814         {
815             Settings.setProperty("jftp.customRSSFeed",
816                                  "http://rss.cnn.com/rss/cnn_world.rss");
817             Settings.save();
818
819             JFtp.statusP.jftp.feeder.switchTo("http://rss.cnn.com/rss/cnn_world.rss");
820         }
821         else if(e.getSource() == loadCNN3)
822         {
823             Settings.setProperty("jftp.customRSSFeed",
824                                  "http://rss.cnn.com/rss/cnn_tech.rss");
825             Settings.save();
826
827             JFtp.statusP.jftp.feeder.switchTo("http://rss.cnn.com/rss/cnn_tech.rss");
828         }
829         else if(e.getSource() == debug)
830         {
831             Settings.setProperty("jftp.enableDebug", debug.getState());
832             Settings.save();
833         }
834         else if(e.getSource() == disableLog)
835         {
836             Settings.setProperty("jftp.disableLog", disableLog.getState());
837             Settings.save();
838         }
839         else if(e.getSource() == smbThreads)
840         {
841             Settings.setProperty("jftp.enableSmbMultiThreading",
842                                  smbThreads.getState());
843             Settings.save();
844         }
845         else if(e.getSource() == sftpThreads)
846         {
847             Settings.setProperty("jftp.enableSftpMultiThreading",
848                                  sftpThreads.getState());
849             Settings.save();
850         }
851         else if(e.getSource() == ask)
852         {
853             Settings.askToResume = ask.getState();
854         }
855         else if(e.getSource() == http)
856         {
857             HttpDownloader dl = new HttpDownloader();
858             jftp.addToDesktop("Http download", dl, 480, 100);
859             jftp.setLocation(dl.hashCode(), 100, 150);
860         }
861         else if(e.getSource() == fadeMenu)
862         {
863             Settings.setProperty("jftp.gui.enableStatusAnimation",
864                                  fadeMenu.getState());
865             Settings.save();
866         }
867         else if(e.getSource() == askToDelete)
868         {
869             Settings.setProperty("jftp.gui.askToDelete", askToDelete.getState());
870             Settings.save();
871         }
872
873         //***MY ADDITIONS (***how can I make this flexible enough to
874
//*** easily add > 5 connections?)
875
else if((e.getSource() == lastConnections[0]) && (!jftp.uiBlocked))
876         {
877             connectionSelected(0);
878         }
879
880         else if((e.getSource() == lastConnections[1]) && (!jftp.uiBlocked))
881         {
882             connectionSelected(1);
883         }
884         else if((e.getSource() == lastConnections[2]) && (!jftp.uiBlocked))
885         {
886             connectionSelected(2);
887         }
888         else if((e.getSource() == lastConnections[3]) && (!jftp.uiBlocked))
889         {
890             connectionSelected(3);
891         }
892         else if((e.getSource() == lastConnections[4]) && (!jftp.uiBlocked))
893         {
894             connectionSelected(4);
895         }
896         else if((e.getSource() == lastConnections[5]) && (!jftp.uiBlocked))
897         {
898             connectionSelected(5);
899         }
900         else if((e.getSource() == lastConnections[6]) && (!jftp.uiBlocked))
901         {
902             connectionSelected(6);
903         }
904         else if((e.getSource() == lastConnections[7]) && (!jftp.uiBlocked))
905         {
906             connectionSelected(7);
907         }
908         else if((e.getSource() == lastConnections[8]) && (!jftp.uiBlocked))
909         {
910             connectionSelected(8);
911         }
912         else if(e.getSource() == opts)
913         {
914             AdvancedOptions adv = new AdvancedOptions();
915             jftp.addToDesktop("Advanced Options", adv, 500, 180);
916             jftp.setLocation(adv.hashCode(), 110, 180);
917         }
918         else if(e.getSource() == manage)
919         {
920             BookmarkManager m = new BookmarkManager();
921             JFtp.desktop.add(m, new Integer JavaDoc(Integer.MAX_VALUE - 10));
922         }
923         else if(marks.contains(e.getSource()))
924         {
925             ((BookmarkItem) e.getSource()).connect();
926         }
927         else if(e.getSource() == storePasswords)
928         {
929             boolean state = storePasswords.getState();
930
931             if(!state)
932             {
933                 JOptionPane j = new JOptionPane();
934                 int x = j.showConfirmDialog(storePasswords,
935                                             "You chose not to Save passwords.\n" +
936                                             "Do you want your old login data to be deleted?",
937                                             "Delete old passwords?",
938                                             JOptionPane.YES_NO_OPTION);
939
940                 if(x == JOptionPane.YES_OPTION)
941                 {
942                     File f = new File(Settings.login_def);
943                     f.delete();
944
945                     f = new File(Settings.login_def_sftp);
946                     f.delete();
947
948                     f = new File(Settings.login_def_nfs);
949                     f.delete();
950
951                     f = new File(Settings.login_def_smb);
952                     f.delete();
953
954                     f = new File(Settings.login);
955                     f.delete();
956
957                     f = new File(Settings.last_cons);
958                     f.delete();
959
960                     Log.debug("Deleted old login data files.\n" +
961                               "Please edit your bookmarks file manually!");
962                 }
963             }
964
965             Settings.setProperty("jftp.security.storePasswords", state);
966             Settings.save();
967         }
968         else if(e.getSource() == sshShell)
969         {
970             SftpHostChooser c = new SftpHostChooser(true);
971             c.update();
972         }
973
974         //*** END OF NEW LISTENERS
975
else
976         {
977             String JavaDoc tmp = ((JMenuItem) e.getSource()).getLabel();
978
979             UIManager.LookAndFeelInfo[] m = UIManager.getInstalledLookAndFeels();
980
981             for(int i = 0; i < m.length; i++)
982             {
983                 if(m[i].getName().equals(tmp))
984                 {
985                     JFtp.statusP.jftp.setLookAndFeel(m[i].getClassName());
986                     Settings.setProperty("jftp.gui.look", m[i].getClassName());
987                     Settings.save();
988                 }
989             }
990         }
991     }
992
993     private void show(String JavaDoc file)
994     {
995         java.net.URL JavaDoc url = ClassLoader.getSystemResource(file);
996
997         if(url == null)
998         {
999             url = HImage.class.getResource("/" + file);
1000        }
1001
1002        Displayer d = new Displayer(url, null);
1003        JFtp.desktop.add(d, new Integer JavaDoc(Integer.MAX_VALUE - 11));
1004    }
1005
1006    // by jake
1007
private void setMnemonics()
1008    {
1009        //*** I added accelerators for more menu items
1010
//*** (issue: should ALL accelerators have the CTRL modifier (so that
1011
//*** the ALT modifier is for mnemonics only?)
1012
//*** I added mnemonics for the main menu items
1013
file.setMnemonic('F');
1014        opt.setMnemonic('O');
1015        view.setMnemonic('V');
1016        tools.setMnemonic('T');
1017        bookmarks.setMnemonic('B');
1018        info.setMnemonic('I');
1019
1020        //*** set accelerators for the remote connection window
1021
ftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
1022                                                     ActionEvent.CTRL_MASK));
1023        sftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
1024                                                      ActionEvent.CTRL_MASK));
1025        smbCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
1026                                                     ActionEvent.CTRL_MASK));
1027        nfsCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
1028                                                     ActionEvent.CTRL_MASK));
1029
1030        //*** IMPORTANT NOTE: Adding an accelerator for disconnecting could
1031
//*** be something of a "gotcha" that we may not want
1032
close.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
1033                                                    ActionEvent.CTRL_MASK));
1034
1035        //*** These next five lines can be commented out if we decide against having accelerators
1036
//*** starting with the shift key
1037
//*** version 1.44: we have chosen not to have shift as a modifier
1038
//*** as we've found this is a "gotcha"
1039
/*
1040        localFtpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
1041                                                          ActionEvent.SHIFT_MASK));
1042        localSftpCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
1043                                                           ActionEvent.SHIFT_MASK));
1044        localSmbCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,
1045                                                          ActionEvent.SHIFT_MASK));
1046        localNfsCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
1047                                                          ActionEvent.SHIFT_MASK));
1048
1049        closeLocalCon.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
1050                                                            ActionEvent.SHIFT_MASK));
1051
1052        */

1053        //*** I have decided to get areound the problem by having mnemonics within the menu
1054
//*** as accelerators. So to quickly start an FTP connection in the local window,
1055
//*** the user can enter Alt+f+f, and Alt+f+s for SFTP,etc.
1056
localFtpCon.setMnemonic('F');
1057        localSftpCon.setMnemonic('S');
1058        localSmbCon.setMnemonic('L');
1059        localNfsCon.setMnemonic('N');
1060
1061        //localNfsCon.setMnemonic('N');
1062
closeLocalCon.setMnemonic('C');
1063
1064        //*** and here are some other menu mnemonics I thought I'd include:
1065
//*** (I'll add more if more are wanted)
1066
exit.setMnemonic('X');
1067
1068        proxy.setMnemonic('P');
1069
1070        http.setMnemonic('D');
1071        spider.setMnemonic('H');
1072        raw.setMnemonic('T');
1073
1074        readme.setMnemonic('R');
1075        todo.setMnemonic('N');
1076        changelog.setMnemonic('C');
1077        hp.setMnemonic('H');
1078
1079        opts.setMnemonic('A');
1080        manage.setMnemonic('M');
1081
1082        clear.setMnemonic('C');
1083        clearItems.setMnemonic('F');
1084
1085        try
1086        {
1087            //*** end of new code section
1088
Integer JavaDoc intI;
1089            String JavaDoc stringI;
1090            char charI;
1091
1092            for(int i = 0; i < jftp.CAPACITY; i++)
1093            {
1094                //*** I should note that functionality below only allows
1095
//*** a maximum of nine connections to be remembered
1096
//BUGFIX 1.40
1097
//if (!(cons[i].equals("null"))) {
1098
if(!(cons[i][0].equals("null")))
1099                {
1100                    intI = new Integer JavaDoc(i + 1);
1101                    stringI = intI.toString();
1102                    charI = stringI.charAt(0);
1103
1104                    lastConnections[i].setMnemonic(charI);
1105
1106                    //lastConnections[i].setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
1107
}
1108            }
1109
1110            //for
1111
}
1112        catch(Exception JavaDoc ex)
1113        {
1114            Log.out("WARNING: AppMenuBar produced Exception, ignored it");
1115            ex.printStackTrace();
1116        }
1117    }
1118
1119    //setMnemonics
1120
private void connectionSelected(int position)
1121    {
1122        //*** tokenize the string to extract the required data
1123
//*** or is this the thing done elsewhere in the code,
1124
//*** when the menu is being set up?
1125
//String connectionInfo = cons[position];
1126
//StringTokenizer tokens = new StringTokenizer(connectionInfo);
1127
//StringTokenizer tokens = new StringTokenizer(cons[position], " ", false); // tab);
1128
String JavaDoc protocol;
1129        int numTokens;
1130
1131        String JavaDoc htmp = new String JavaDoc("");
1132        String JavaDoc utmp = new String JavaDoc("");
1133        String JavaDoc ptmp = new String JavaDoc("");
1134        String JavaDoc dtmp = new String JavaDoc("");
1135        boolean useLocal = false;
1136        int potmp = 0;
1137        String JavaDoc potmpString = new String JavaDoc("0");
1138        String JavaDoc useLocalString = new String JavaDoc("false");
1139
1140        /*
1141        //numTokens = tokens.countTokens();
1142        protocol = tokens.nextToken();
1143
1144        htmp = tokens.nextToken();
1145        utmp = tokens.nextToken();
1146        ptmp = tokens.nextToken();
1147
1148        */

1149        protocol = cons[position][0];
1150        htmp = cons[position][1];
1151        utmp = cons[position][2];
1152        ptmp = cons[position][3];
1153
1154        if(ptmp.equals(""))
1155        {
1156            ptmp = UIUtils.getPasswordFromUser(JFtp.statusP.jftp);
1157        }
1158
1159        //int j=4;
1160
//while (cons[i][j].equals(LastConnections.SENTINEL)) {
1161
// j++;
1162
//}
1163
//usingLocal = cons[i][j-1];
1164

1165        /*
1166        System.out.println(position);
1167        System.out.println(protocol);
1168        System.out.println(cons[position][1]);
1169        System.out.println(cons[position][2]);
1170        System.out.println(cons[position][3]);
1171        */

1172
1173        //
1174
if(protocol.equals("FTP"))
1175        {
1176            potmpString = cons[position][4];
1177            dtmp = cons[position][5];
1178            useLocalString = cons[position][6];
1179
1180            /*
1181            potmpString = tokens.nextToken();
1182            dtmp = tokens.nextToken();
1183            useLocalString = tokens.nextToken();
1184
1185
1186            System.out.println(potmpString);
1187            System.out.println("FTP");
1188            */

1189            potmp = Integer.parseInt(potmpString);
1190
1191            if(useLocalString.equals("true"))
1192            {
1193                useLocal = true;
1194            }
1195            else
1196            {
1197                useLocal = false;
1198            }
1199
1200            StartConnection.startFtpCon(htmp, utmp, ptmp, potmp, dtmp, useLocal);
1201
1202            //System.out.println(htmp + utmp + ptmp + potmpString +dtmp + useLocalString);
1203
}
1204        else if(protocol.equals("SFTP"))
1205        {
1206            /*
1207                    htmp = tokens.nextToken();
1208                    utmp = tokens.nextToken();
1209                    ptmp = tokens.nextToken();
1210            */

1211
1212            //useLocalString = tokens.nextToken();
1213
//System.out.println("SFTP");
1214
potmpString = cons[position][4];
1215            useLocalString = cons[position][5];
1216
1217            //System.out.println(htmp + utmp + ptmp + useLocalString);
1218
//if (protocol == "SFTP")
1219
}
1220
1221        else if(protocol.equals("NFS"))
1222        {
1223            useLocalString = cons[position][4];
1224        }
1225
1226        else if(protocol.equals("SMB"))
1227        {
1228            /*
1229            htmp = tokens.nextToken();
1230            utmp = tokens.nextToken();
1231            ptmp = tokens.nextToken();
1232            */

1233            /*
1234            dtmp = tokens.nextToken();
1235            useLocalString = tokens.nextToken();
1236            */

1237            dtmp = cons[position][4];
1238            useLocalString = cons[position][5];
1239
1240            //System.out.println(htmp+utmp+ptmp+dtmp + useLocalString);
1241
}
1242
1243        //***StartConnection functionality to be put in each
1244
//***if statement
1245
potmp = Integer.parseInt(potmpString);
1246
1247        if(useLocalString.equals("true"))
1248        {
1249            useLocal = true;
1250        }
1251        else
1252        {
1253            useLocal = false;
1254        }
1255
1256        if(protocol.equals("SFTP"))
1257        {
1258            //BUGFIX 1.40: no longer setting port #
1259
//to 22, now potmp
1260
StartConnection.startCon(protocol, htmp, utmp, ptmp, potmp, dtmp,
1261                                     useLocal);
1262        }
1263        else if(!(protocol.equals("FTP")))
1264        {
1265            //System.out.println(protocol);
1266
StartConnection.startCon(protocol, htmp, utmp, ptmp, potmp, dtmp,
1267                                     useLocal);
1268        }
1269    }
1270
1271    //connectionSelected
1272
}
1273
Popular Tags