KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > config > Settings


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.config;
17
18 import java.io.File JavaDoc;
19 import java.io.FileInputStream JavaDoc;
20 import java.io.FileOutputStream JavaDoc;
21
22 import java.util.Properties JavaDoc;
23
24
25 public class Settings
26 {
27     private static Properties JavaDoc p = new Properties JavaDoc();
28     public static final String JavaDoc propertyFilename = System.getProperty("user.home") +
29                                                   File.separator +
30                                                   ".jftp/jftp.properties".replace('/',
31                                                                                   File.separatorChar);
32
33     public static boolean IS_JAVA_1_6 = false;
34     
35
36     public static String JavaDoc sshHostKeyVerificationFile = System.getProperty("user.home") +
37                                                       File.separator + ".jftp" +
38                                                       File.separator +
39                                                       ".ssh_hostfile";
40     public static final String JavaDoc defaultWidth = "840";
41     public static final String JavaDoc defaultHeight = "640";
42     public static final String JavaDoc defaultX = "20";
43     public static final String JavaDoc defaultY = "20";
44     public static int maxConnections = 3;
45     public static boolean enableResuming = false; // overridden by JFtp
46
public static boolean enableUploadResuming = false;
47     public static boolean noUploadResumingQuestion = true;
48     public static boolean askToResume = true;
49     public static boolean reconnect = true;
50     public static int uiRefresh = 500;
51     public static int logFlushInterval = 2000; // obsolete
52
public static boolean useLogFlusher = false; // obsolete
53
public static int ftpTransferThreadPause = 2000;
54     public static int smallSize = 0; //100000;
55
public static int smallSizeUp = 0; //50000;
56
public static boolean autoUpdate = false;
57     public static boolean shortProgress = true;
58     private static String JavaDoc defaultFtpPasvMode = "true";
59     private static String JavaDoc defaultEnableDebug = "false";
60     private static String JavaDoc enableMultiThreading = "true";
61     private static String JavaDoc enableSmbMultiThreading = "true";
62     private static String JavaDoc enableSftpMultiThreading = "true";
63     private static String JavaDoc noUploadMultiThreading = "false";
64     private static String JavaDoc storePasswords = "false";
65     
66     public static boolean newTableGui = getUseJTableLayout();
67     public static boolean useFixedTableWidths = true;
68     public static boolean enableWebDav = false;
69
70     
71     // 1: manual, 2: onclick, 0: off
72
public static int runtimeCommands = 2;
73     public static boolean askToRun = true;
74
75     // currently changed by remotedir on-the-fly
76
public static boolean showDateNoSize = false;
77     public static boolean showLocalDateNoSize = false;
78
79     // hides some messages like MODE, Type etc.
80
public static boolean hideStatus = false;
81
82     public static boolean showNewlineOption = false;
83
84     // for DataConnection - lower means less buffer, more updates in the downloadmanager
85
// i recommend to use values greater than 2048 bytes
86
public static int bufferSize = 8192;
87
88     // sends NOOPs to ensure that buffers are empty
89
public static boolean safeMode = false;
90
91     // enables some delays
92
public static boolean enableFtpDelays = false;
93
94     // title of the app
95
public static final String JavaDoc title = "JFtp - The Java Network Browser";
96
97     // overridden title for insomniac client
98
public static final String JavaDoc insomniacTitle = ">>> Insomniac client BETA 1 <<< Based on JFtp ";
99
100     // override ui with the insomniac client configuration
101
public static boolean isInsomniacClient = false;
102     public static int refreshDelay = 250;
103     public static boolean useDefaultDir = true;
104
105     // may the windows be resized?
106
public static boolean resize = true;
107     public static boolean showFileSize = true;
108     public static boolean sortDir = true;
109     public static final int visibleFileRows = 15;
110     public static int scrollSpeed = 9;
111     public static int numFiles = 9;
112     public static final int connectionTimeout = 30000;
113     public static final int testTimeout = 5000;
114     public static int statusMessageAfterMillis = 1000;
115     public static final String JavaDoc defaultDir = "<default>";
116     public static final String JavaDoc defaultWorkDir = System.getProperty("user.home");
117     public static final String JavaDoc userHomeDir = System.getProperty("user.home");
118     public static final String JavaDoc appHomeDir = userHomeDir +
119                                             "/.jftp/".replace('/',
120                                                               File.separatorChar);
121     public static final String JavaDoc greeting = "Have a lot of fun...";
122     public static final String JavaDoc bookmarks = appHomeDir +
123                                            "bookmarks.txt".replace('/',
124                                                                    File.separatorChar);
125
126     public static final String JavaDoc ls_out = appHomeDir+".ls_out".replace('/', File.separatorChar);
127                                  
128     public static final String JavaDoc login_def = appHomeDir +
129                                            ".login_default".replace('/',
130                                                                     File.separatorChar);
131     public static final String JavaDoc login = appHomeDir +
132                                        ".login".replace('/', File.separatorChar);
133
134     //*** The new files that I have created
135
public static final String JavaDoc last_cons = appHomeDir +
136                                            ".last_cons".replace('/',
137                                                                 File.separatorChar);
138     public static final String JavaDoc login_def_sftp = appHomeDir +
139                                                 ".last_cons_sftp".replace('/',
140                                                                           File.separatorChar);
141     public static final String JavaDoc login_def_smb = appHomeDir +
142                                                ".last_cons_smb".replace('/',
143                                                                         File.separatorChar);
144     public static final String JavaDoc login_def_nfs = appHomeDir +
145                                                ".last_cons_nfs".replace('/',
146                                                                         File.separatorChar);
147
148     //***
149
//*** added in version 1.44
150
public static final String JavaDoc adv_settings = appHomeDir +
151                                               ".adv_settings".replace('/',
152                                                                       File.separatorChar);
153
154     //***
155
public static final String JavaDoc readme = "docs/readme";
156     public static final String JavaDoc changelog = "docs/CHANGELOG";
157     public static final String JavaDoc todo = "docs/TODO";
158     public static final String JavaDoc nfsinfo = "docs/doc/nfsinfo";
159     
160     
161     public static String JavaDoc iconImage;
162     public static String JavaDoc hostImage;
163     public static String JavaDoc closeImage;
164     public static String JavaDoc infoImage;
165     public static String JavaDoc listImage;
166  
167     public static String JavaDoc rmdirImage;
168     public static String JavaDoc mkdirImage;
169     public static String JavaDoc refreshImage;
170     public static String JavaDoc refreshImage2;
171     public static String JavaDoc cdImage;
172     public static String JavaDoc cmdImage;
173     public static String JavaDoc downloadImage;
174     public static String JavaDoc uploadImage;
175     public static String JavaDoc fileImage;
176     public static String JavaDoc dirImage;
177     public static String JavaDoc codeFileImage;
178     public static String JavaDoc textFileImage;
179     public static String JavaDoc execFileImage;
180     public static String JavaDoc audioFileImage;
181     public static String JavaDoc videoFileImage;
182     public static String JavaDoc htmlFileImage;
183     public static String JavaDoc zipFileImage;
184     public static String JavaDoc imageFileImage;
185     public static String JavaDoc presentationFileImage;
186     public static String JavaDoc spreadsheetFileImage;
187     public static String JavaDoc bookFileImage;
188     public static String JavaDoc copyImage;
189     public static String JavaDoc openImage;
190     public static String JavaDoc sftpImage;
191     public static String JavaDoc nfsImage;
192     public static String JavaDoc webdavImage;
193     public static String JavaDoc linkImage;
194     public static String JavaDoc typeImage;
195     public static String JavaDoc deleteImage;
196     public static String JavaDoc deleteImage2;
197     public static String JavaDoc clearImage;
198     public static String JavaDoc clearImage2;
199     public static String JavaDoc resumeImage;
200     public static String JavaDoc resumeImage2;
201     public static String JavaDoc pauseImage;
202     public static String JavaDoc pauseImage2;
203     public static String JavaDoc saveImage;
204     public static String JavaDoc cdUpImage;
205     public static String JavaDoc nextRSSImage;
206     public static String JavaDoc helpImage;
207     
208
209     public static String JavaDoc background = "images/back.jpg";
210     
211     public static boolean isStandalone = true;
212     public static String JavaDoc hiddenPassword = "<%hidden%>";
213
214     public static Object JavaDoc setProperty(String JavaDoc key, String JavaDoc value)
215     {
216         return p.setProperty(key, value);
217     }
218
219     public static String JavaDoc getProperty(String JavaDoc key) {
220         return ""+p.getProperty(key);
221     }
222     
223     public static Object JavaDoc setProperty(String JavaDoc key, int value)
224     {
225         return p.setProperty(key, Integer.toString(value));
226     }
227
228     public static Object JavaDoc setProperty(String JavaDoc key, boolean value)
229     {
230         String JavaDoc val = "false";
231
232         if(value)
233         {
234             val = "true";
235         }
236
237         return p.setProperty(key, val);
238     }
239
240     public static void save()
241     {
242         try
243         {
244             new File JavaDoc(System.getProperty("user.home") + File.separator +
245                      ".jftp").mkdir();
246             p.store(new FileOutputStream JavaDoc(propertyFilename), "jftp.properties");
247         }
248         catch(Exception JavaDoc e)
249         {
250             System.out.println("Cannot save properties...");
251
252             //e.printStackTrace();
253
}
254     }
255
256     public static boolean getHideLocalDotNames() {
257         String JavaDoc what = p.getProperty("jftp.hideHiddenDotNames", "false");
258
259         if(what.trim().equals("false"))
260         {
261             return false;
262         }
263         else
264         {
265             return true;
266         }
267     }
268     
269     public static int getMaxConnections()
270     {
271         return maxConnections;
272     }
273
274     public static String JavaDoc getSocksProxyHost()
275     {
276         String JavaDoc what = p.getProperty("jftp.socksProxyHost", "");
277
278         return what;
279     }
280
281     public static boolean getUseJTableLayout()
282     {
283         String JavaDoc what = p.getProperty("jftp.useJTableLayout", "true");
284
285         if(what.trim().equals("false"))
286         {
287             return false;
288         }
289         else
290         {
291             return true;
292         }
293     }
294     
295     public static String JavaDoc getSocksProxyPort()
296     {
297         String JavaDoc what = p.getProperty("jftp.socksProxyPort", "");
298
299         return what;
300     }
301
302     public static boolean getUseBackground()
303     {
304         String JavaDoc what = p.getProperty("jftp.useBackground", "true");
305
306         if(what.trim().equals("false"))
307         {
308             return false;
309         }
310         else
311         {
312             return true;
313         }
314     }
315
316     public static boolean getEnableSshKeys()
317     {
318         String JavaDoc what = p.getProperty("jftp.useSshKeyVerification", "false");
319
320         if(what.trim().equals("false"))
321         {
322             return false;
323         }
324         else
325         {
326             return true;
327         }
328     }
329
330     public static boolean getEnableResuming()
331     {
332         String JavaDoc what = p.getProperty("jftp.enableResuming", "true");
333
334         if(what.trim().equals("false"))
335         {
336             return false;
337         }
338         else
339         {
340             return true;
341         }
342     }
343
344     public static boolean getEnableDebug()
345     {
346         String JavaDoc what = p.getProperty("jftp.enableDebug", defaultEnableDebug);
347
348         if(what.trim().equals("false"))
349         {
350             return false;
351         }
352         else
353         {
354             return true;
355         }
356     }
357
358     public static boolean getDisableLog()
359     {
360         String JavaDoc what = p.getProperty("jftp.disableLog", "false");
361
362         if(what.trim().equals("false"))
363         {
364             return false;
365         }
366         else
367         {
368             return true;
369         }
370     }
371
372     public static boolean getEnableStatusAnimation()
373     {
374         String JavaDoc what = p.getProperty("jftp.gui.enableStatusAnimation", "false");
375
376         if(what.trim().equals("false"))
377         {
378             return false;
379         }
380         else
381         {
382             return true;
383         }
384     }
385
386     public static boolean getAskToDelete()
387     {
388         String JavaDoc what = p.getProperty("jftp.gui.askToDelete", "true");
389
390         if(what.trim().equals("false"))
391         {
392             return false;
393         }
394         else
395         {
396             return true;
397         }
398     }
399
400     public static String JavaDoc getLookAndFeel()
401     {
402         return p.getProperty("jftp.gui.look", null);
403     }
404     
405     public static boolean getUseNewIcons()
406     {
407         String JavaDoc what = p.getProperty("jftp.gui.look.newIcons", "true");
408         
409         if(what.trim().equals("false"))
410         {
411             return false;
412         }
413         else
414         {
415             return true;
416         }
417     }
418
419     public static boolean getEnableMultiThreading()
420     {
421         String JavaDoc what = p.getProperty("jftp.enableMultiThreading",
422                                     enableMultiThreading);
423
424         if(what.trim().equals("false"))
425         {
426             return false;
427         }
428         else
429         {
430             return true;
431         }
432     }
433
434     public static boolean getEnableSmbMultiThreading()
435     {
436         String JavaDoc what = p.getProperty("jftp.enableSmbMultiThreading",
437                                     enableSmbMultiThreading);
438
439         if(what.trim().equals("false"))
440         {
441             return false;
442         }
443         else
444         {
445             return true;
446         }
447     }
448
449     public static boolean getEnableSftpMultiThreading()
450     {
451         String JavaDoc what = p.getProperty("jftp.enableSftpMultiThreading",
452                                     enableSftpMultiThreading);
453
454         if(what.trim().equals("false"))
455         {
456             return false;
457         }
458         else
459         {
460             return true;
461         }
462     }
463
464     public static boolean getNoUploadMultiThreading()
465     {
466         String JavaDoc what = p.getProperty("jftp.noUploadMultiThreading",
467                                     noUploadMultiThreading);
468
469         if(what.trim().equals("false"))
470         {
471             return false;
472         }
473         else
474         {
475             return true;
476         }
477     }
478
479     public static boolean getFtpPasvMode()
480     {
481         String JavaDoc what = p.getProperty("jftp.ftpPasvMode", defaultFtpPasvMode);
482
483         if(what.trim().equals("false"))
484         {
485             return false;
486         }
487         else
488         {
489             return true;
490         }
491     }
492
493     public static boolean getUseDefaultDir()
494     {
495         String JavaDoc what = p.getProperty("jftp.useDefaultDir", "true");
496
497         if(what.trim().equals("false"))
498         {
499             return false;
500         }
501         else
502         {
503             return true;
504         }
505     }
506
507     public static boolean getEnableRSS()
508     {
509         String JavaDoc what = p.getProperty("jftp.enableRSS", "false");
510
511         if(what.trim().equals("false"))
512         {
513             return false;
514         }
515         else
516         {
517             return true;
518         }
519     }
520
521     public static String JavaDoc getRSSFeed()
522     {
523         String JavaDoc what = p.getProperty("jftp.customRSSFeed",
524                                     "http://slashdot.org/rss/slashdot.rss");
525
526         return what;
527     }
528
529     public static java.awt.Dimension JavaDoc getWindowSize()
530     {
531         int width = Integer.parseInt(p.getProperty("jftp.window.width",
532                                                    defaultWidth));
533         int height = Integer.parseInt(p.getProperty("jftp.window.height",
534                                                     defaultHeight));
535
536         return new java.awt.Dimension JavaDoc(width, height);
537     }
538
539     public static java.awt.Point JavaDoc getWindowLocation()
540     {
541         int x = Integer.parseInt(p.getProperty("jftp.window.x", defaultX));
542         int y = Integer.parseInt(p.getProperty("jftp.window.y", defaultY));
543
544         return new java.awt.Point JavaDoc(x, y);
545     }
546
547     public static int getSocketTimeout()
548     {
549         return 3000;
550     }
551
552     public static boolean getStorePasswords()
553     {
554         String JavaDoc what = p.getProperty("jftp.security.storePasswords",
555                                     storePasswords);
556
557         if(what.trim().equals("false"))
558         {
559             return false;
560         }
561         else
562         {
563             return true;
564         }
565     }
566     
567     static
568     {
569         try
570         {
571             p.load(new FileInputStream JavaDoc(propertyFilename));
572         }
573         catch(Exception JavaDoc e)
574         {
575             System.out.println("no property file loaded, using defaults... (" +
576                                e + ")");
577         }
578         
579         if(!getUseNewIcons()) {
580             iconImage = "images/org/javalobby/icons/20x20/ComputerIn.gif";
581             hostImage = "images/org/javalobby/icons/20x20/ComputerIn.gif";
582             closeImage = "images/org/javalobby/icons/20x20/Error.gif";
583             infoImage = "images/org/javalobby/icons/20x20/Inform.gif";
584             listImage = "images/org/javalobby/icons/20x20/List.gif";
585             deleteImage = "images/org/javalobby/icons/16x16/DeleteDocument.gif";
586             deleteImage2 = "images/org/javalobby/icons/16x16/DeleteDocument.gif";
587             rmdirImage = "images/org/javalobby/icons/16x16/DeleteFolder.gif";
588             mkdirImage = "images/org/javalobby/icons/16x16/NewFolder.gif";
589             refreshImage = "images/org/javalobby/icons/16x16/Undo.gif";
590             refreshImage2 = "images/org/javalobby/icons/16x16/Undo.gif";
591             cdImage = "images/org/javalobby/icons/16x16/Open.gif";
592             cmdImage = "images/org/javalobby/icons/16x16/ExecuteProject.gif";
593             downloadImage = "images/org/javalobby/icons/16x16/Left.gif";
594             uploadImage = "images/org/javalobby/icons/16x16/Right.gif";
595             fileImage = "images/org/javalobby/icons/16x16/Document.gif";
596             dirImage = "images/org/javalobby/icons/16x16/Folder.gif";
597             codeFileImage = "images/org/javalobby/icons/16x16/List.gif";
598             textFileImage = "images/org/javalobby/icons/16x16/DocumentDraw.gif";
599             execFileImage = "images/org/javalobby/icons/16x16/ExecuteProject.gif";
600             audioFileImage = "images/org/javalobby/icons/16x16/cd.gif";
601             videoFileImage = "images/org/javalobby/icons/16x16/CameraFlash.gif";
602             htmlFileImage = "images/org/javalobby/icons/16x16/World2.gif";
603             zipFileImage = "images/org/javalobby/icons/16x16/DataStore.gif";
604             imageFileImage = "images/org/javalobby/icons/16x16/Camera.gif";
605             presentationFileImage = "images/org/javalobby/icons/16x16/DocumentDiagram.gif";
606             spreadsheetFileImage = "images/org/javalobby/icons/16x16/DatePicker.gif";
607             bookFileImage = "images/org/javalobby/icons/16x16/Book.gif";
608             copyImage = "images/org/javalobby/icons/16x16/Copy.gif";
609             openImage = "images/org/javalobby/icons/16x16/World2.gif";
610             sftpImage = "images/org/javalobby/icons/16x16/NewEnvelope.gif";
611             nfsImage = "images/org/javalobby/icons/16x16/TrafficGreen.gif";
612             webdavImage = "images/org/javalobby/icons/16x16/DataStore.gif";
613             linkImage = "images/org/javalobby/icons/16x16/Right.gif";
614             typeImage = "images/org/javalobby/icons/20x20/Type.gif";
615             clearImage = "images/org/javalobby/icons/16x16/Undo.gif";
616             resumeImage = "images/org/javalobby/icons/16x16/GreenCircle.gif";
617             pauseImage = "images/org/javalobby/icons/16x16/RedCircle.gif";
618             clearImage2 = "images/org/javalobby/icons/16x16/Undo.gif";
619             resumeImage2 = "images/org/javalobby/icons/16x16/GreenCircle.gif";
620             pauseImage2 = "images/org/javalobby/icons/16x16/RedCircle.gif";
621             saveImage = "images/org/javalobby/icons/16x16/Save.gif";
622             cdUpImage = "images/org/javalobby/icons/16x16/Exit.gif";
623             nextRSSImage = "images/org/javalobby/icons/16x16/Forward.gif";
624             helpImage = "images/silk/help.png";
625         }
626         else {
627             iconImage = "images/silk/server_add.png";
628             hostImage = "images/silk/server_add.png";
629             closeImage = "images/silk/cancel.png";
630             infoImage = "images/silk/information.png";
631             listImage = "images/silk/page_white_text.png";
632
633             rmdirImage = "images/silk/folder_delete.png";
634             mkdirImage = "images/silk/folder_add.png";
635             refreshImage = "images/silk/control_repeat.png";
636             refreshImage2 = "images/silk/control_repeat_blue.png";
637             cdImage = "images/silk/folder_explore.png";
638             cmdImage = "images/silk/application_xp_terminal.png";
639             downloadImage = "images/silk/arrow_left.png";
640             uploadImage = "images/silk/arrow_right.png";
641             fileImage = "images/silk/page_white.png";
642             dirImage = "images/silk/folder.png";
643             codeFileImage = "images/silk/page_white_wrench.png";
644             textFileImage = "images/silk/page_white_text.png";
645             execFileImage = "images/silk/cog.png";
646             audioFileImage = "images/silk/ipod.png";
647             videoFileImage = "images/silk/camera.png";
648             htmlFileImage = "images/silk/html.png";
649             zipFileImage = "images/silk/page_white_zip.png";
650             imageFileImage = "images/silk/image.png";
651             presentationFileImage = "images/silk/page_white_powerpoint.png";
652             spreadsheetFileImage = "images/silk/page_excel.png";
653             bookFileImage = "images/silk/book.png";
654             copyImage = "images/silk/disk_multiple.png";
655             openImage = "images/silk/drive_web.png";
656             sftpImage = "images/silk/drive_link.png";
657             nfsImage = "images/silk/drive_network.png";
658             webdavImage = "images/silk/house_go.png";
659             linkImage = "images/silk/arrow_right.png";
660             typeImage = "images/silk/email_go.png";
661             deleteImage = "images/silk/control_stop.png";
662             deleteImage2 = "images/silk/control_stop_blue.png";
663             clearImage = "images/silk/control_eject.png";
664             clearImage2 = "images/silk/control_eject_blue.png";
665             resumeImage = "images/silk/control_play.png";
666             resumeImage2 = "images/silk/control_play_blue.png";
667             pauseImage = "images/silk/control_pause.png";
668             pauseImage2 = "images/silk/control_pause_blue.png";
669             saveImage = "images/silk/disk.png";
670             cdUpImage = "images/silk/arrow_up.png";
671             nextRSSImage = "images/silk/rss_go.png";
672             helpImage = "images/silk/help.png";
673         }
674
675     }
676
677 }
678
Popular Tags