KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > localhistory > LocalHistorySettings


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.localhistory;
20
21 import java.io.File JavaDoc;
22 import java.util.prefs.Preferences JavaDoc;
23 import org.openide.ErrorManager;
24 import org.openide.util.NbPreferences;
25
26 /**
27  *
28  * Manages the Local Hisotry Settings
29  *
30  * XXX this is dummy
31  * XXX options
32  * @author Tomas Stupka
33  */

34 public class LocalHistorySettings {
35     
36     private static final LocalHistorySettings INSTANCE = new LocalHistorySettings();
37     
38     private static final String JavaDoc LAST_SELECTED_ENTRY = "RevertFileChanges.lastSelected"; // NOI18N
39

40     /** Creates a new instance of LocalHistorySettings */
41     private LocalHistorySettings() {
42     }
43     
44     public static LocalHistorySettings getInstance() {
45         return INSTANCE;
46     }
47     
48     private Preferences JavaDoc getPreferences() {
49         return NbPreferences.forModule(LocalHistorySettings.class);
50     }
51     
52     public static long getTTL() {
53         // XXX need options
54
String JavaDoc ttl = System.getProperty("netbeans.localhistory.ttl");
55         if( ttl != null && !ttl.trim().equals("") ) {
56             try {
57                 return Long.parseLong(ttl) * 24 * 60 * 60 * 1000; // supposed to be specified in days
58
} catch (Exception JavaDoc e) {
59                 ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
60             }
61         }
62         return 7 * 24 * 60 * 60 * 1000;
63     }
64
65     public static Long JavaDoc getMaxFileSize() {
66         String JavaDoc max = System.getProperty("netbeans.localhistory.maxFileSize");
67         if( max != null && !max.trim().equals("") ) {
68             try {
69                 return Long.parseLong(max);
70             } catch (Exception JavaDoc e) {
71                 ErrorManager.getDefault().notify(ErrorManager.WARNING, e);
72             }
73         }
74         return 1024L * 1024L;
75     }
76     
77     public static String JavaDoc getExludedFileNames() {
78         String JavaDoc excluded = System.getProperty("netbeans.localhistory.excludedFiles");
79         if( excluded != null && !excluded.trim().equals("") ) {
80             return excluded;
81         } else {
82             return ".*(\\.class|\\.jar|\\.zip|\\.rar|\\.gz|\\.bz|\\.tgz|\\.tar|\\.gif|\\.jpg|\\.jpeg|\\.png|\\.nbm)"; // this is going to be a very very long list ...
83
}
84     }
85
86     public void setLastSelectedEntry(File JavaDoc file, long ts) {
87         getPreferences().putLong(LAST_SELECTED_ENTRY + "#" + file.getAbsoluteFile(), ts);
88     }
89     
90     public long getLastSelectedEntry(File JavaDoc file) {
91         return getPreferences().getLong(LAST_SELECTED_ENTRY + "#" + file.getAbsoluteFile(), -1);
92     }
93     
94 }
95
Popular Tags